Brett Cannon
8e2f5564b3
Issue #15210 : If _frozen_importlib is not found in sys.modules by
...
importlib.__init__, then catch the KeyError raised, not ImportError.
2012-07-02 14:53:10 -04:00
Brett Cannon
1e331560ee
Closes #15030 : Make importlib.abc.PyPycLoader respect the new .pyc
...
file size header field.
Thanks to Marc Abramowitz and Ronan Lamy for helping out with various
parts of the patch.
2012-07-02 14:35:34 -04:00
Eric V. Smith
b10951549b
Use assertIsNone. Thanks Terry Reedy.
2012-06-28 06:15:01 -04:00
Eric V. Smith
faae3adbb9
Changed importlib tests to use assertIs, assertIsInstance, etc., instead of just assertTrue.
2012-06-27 15:26:26 -04:00
Eric V. Smith
e51a36922f
Fixes issue 15039: namespace packages are no longer imported in preference to modules of the same name.
2012-06-24 19:13:55 -04:00
Antoine Pitrou
310f95b04d
A better repr() for FileFinder
2012-06-23 02:12:56 +02:00
Antoine Pitrou
d5a1a21a89
Prevent test_inspect from keeping alive a ton of frames and local variables by way of a global variable keeping a reference to a traceback.
...
Should fix some buildbot failures.
2012-06-17 23:18:07 +02:00
Antoine Pitrou
48114b952b
Issue #14657 : The frozen instance of importlib used for bootstrap is now also the module imported as importlib._bootstrap.
2012-06-17 22:33:38 +02:00
Brett Cannon
ea0b823940
Issue #14938 : importlib.abc.SourceLoader.is_package() now takes the
...
module name into consideration when determining whether a module is a
package or not. This prevents importing a module's __init__ module
directly and having it considered a package, which can lead to
duplicate sub-modules.
Thanks to Ronan Lamy for reporting the bug.
2012-06-15 20:00:53 -04:00
Nick Coghlan
5c6eba3a93
Tweak importlib._bootstrap to avoid zero-argument super so I can work on issue #14857 without breaking imports
2012-05-27 17:49:58 +10:00
Brett Cannon
d785cb3955
Remove some redundant decorators.
2012-05-26 14:28:21 -04:00
Eric V. Smith
283d0ba45d
Whitespace cleanup.
2012-05-24 20:22:10 -04:00
Eric V. Smith
984b11f88f
issue 14660: Implement PEP 420, namespace packages.
2012-05-24 20:21:04 -04:00
Antoine Pitrou
ea3eb88bca
Issue #9260 : A finer-grained import lock.
...
Most of the import sequence now uses per-module locks rather than the
global import lock, eliminating well-known issues with threads and imports.
2012-05-17 18:55:59 +02:00
Brett Cannon
d200bf534b
Add importlib.util.resolve_name().
2012-05-13 13:45:09 -04:00
Brett Cannon
ee78a2b51c
Issue #13959 : Introduce importlib.find_loader().
...
The long-term goal is to deprecate imp.find_module() in favour of this
API, but it will take some time as some APIs explicitly return/use what
imp.find_module() returns.
2012-05-12 17:43:17 -04:00
Brett Cannon
c049952de7
Issue #13959 : Have
...
importlib.abc.FileLoader.load_module()/get_filename() and
importlib.machinery.ExtensionFileLoader.load_module() have their
single argument be optional as the loader's constructor has all the
ncessary information.
This allows for the deprecation of
imp.load_source()/load_compile()/load_package().
2012-05-11 14:48:41 -04:00
Brett Cannon
cb66eb0dec
Issue #13959 : Deprecate imp.get_suffixes() for new attributes on
...
importlib.machinery that provide the suffix details for import.
The attributes were not put on imp so as to compartmentalize
everything importlib needs for setting up imports in
importlib.machinery.
This also led to an indirect deprecation of inspect.getmoduleinfo() as
it directly returned imp.get_suffix's returned tuple which no longer
makes sense.
2012-05-11 12:58:42 -04:00
Brett Cannon
810c64df8f
Issue #14764 : Update importlib.test.benchmark to work in a world where
...
import machinery is no longer implicit.
2012-05-11 11:12:00 -04:00
Antoine Pitrou
6efa50a384
Issue #14583 : Fix importlib bug when a package's __init__.py would first import one of its modules then raise an error.
2012-05-07 21:41:59 +02:00
Brett Cannon
feccc09952
Clean up a docstring.
2012-05-04 16:47:54 -04:00
Brett Cannon
f19c191067
Jython-friendly tweak.
2012-05-04 15:46:04 -04:00
Brett Cannon
2657df4744
Issue #13959 : Re-implement imp.get_suffixes() in Lib/imp.py.
...
This introduces a new function, imp.extension_suffixes(), which is
currently undocumented. That is forthcoming once issue #14657 is
resolved and how to expose file suffixes is decided.
2012-05-04 15:20:40 -04:00
Brett Cannon
17098a5447
Properly mark names in importlib._bootstrap as private.
2012-05-04 13:52:49 -04:00
Brett Cannon
efad00d520
Issue #14646 : __import__() now sets __loader__ if need be.
...
importlib.util.module_for_loader also will set __loader__ along with
__package__. This is in conjunction to a forthcoming update to PEP 302
which will make these two attributes required for loaders to set.
2012-04-27 17:27:14 -04:00
Brett Cannon
aa93642a35
Issue #14605 : Use None in sys.path_importer_cache to represent no
...
finder instead of using some (now non-existent) implicit finder.
2012-04-27 15:30:58 -04:00
Brett Cannon
ce418b448f
Issue #14605 : Stop having implicit entries for sys.meta_path.
...
ImportWarning is raised if sys.meta_path is found to be empty.
2012-04-27 14:01:58 -04:00
Brett Cannon
e0d88a173c
Issue #14605 : Make explicit the entries on sys.path_hooks that used to
...
be implicit.
Added a warning for when sys.path_hooks is found to be empty. Also
changed the meaning of None in sys.path_importer_cache to represent
trying sys.path_hooks again (an interpretation of previous semantics).
Also added a warning for when None was found.
The long-term goal is for None in sys.path_importer_cache to represent
the same as imp.NullImporter: no finder found for that sys.path entry.
2012-04-25 20:54:04 -04:00
Marc-Andre Lemburg
7541c8ea37
Issue #14605 and #14642 :
...
Issue a warning in case Python\importlib.h needs to be rebuilt,
but there's no Python interpreter around to freeze the bootstrap
script.
2012-04-25 10:54:48 +02:00
Marc-Andre Lemburg
4fe29c9657
Issue #14605 : Rename _SourcelessFileLoader to SourcelessFileLoader.
...
This time also recreating the Python/importlib.h file to make
make happy. See the ticket for details.
2012-04-25 02:31:37 +02:00
Marc-Andre Lemburg
ac8805a01a
Issue #14605 : Revert renaming of _SourcelessFileLoader, since it caused
...
the buildbots to fail.
2012-04-25 02:11:07 +02:00
Marc-Andre Lemburg
2945e78b05
Issue #14605 : Rename _SourcelessFileLoader to SourcelessFileLoader
2012-04-25 01:36:48 +02:00
Brett Cannon
938d44d59c
Issue #14605 : Expose importlib.abc.FileLoader and
...
importlib.machinery.(FileFinder, SourceFileLoader,
_SourcelessFileLoader, ExtensionFileLoader).
This exposes all of importlib's mechanisms that will become public on
the sys module.
2012-04-22 19:58:33 -04:00
Brett Cannon
5c903e6ee1
Issue #13959 : Continue to try to accomodate altsep in importlib by not
...
ignoring altsep if it already exists on a path when doing a join.
2012-04-22 11:45:07 -04:00
Brett Cannon
cf649958f7
Revert to os.path.join() semantics for path manipulation in importlib
...
which is different than what imp.cache_from_source() operates on.
2012-04-22 02:06:23 -04:00
Brett Cannon
a846236855
Continue the good fight to get Windows to like importlib by fixing a
...
variable name.
2012-04-21 21:46:32 -04:00
Brett Cannon
0d05a7698b
Have importlib look for pre-existing path separators when joining
...
paths.
2012-04-21 21:21:27 -04:00
Brett Cannon
2f92389d5c
Don't worry about moving imp.get_tag() over to Lib/imp.py.
2012-04-21 18:55:51 -04:00
Brett Cannon
a64faf0771
Issue #13959 : Re-implement imp.source_from_cache() in Lib/imp.py.
2012-04-21 18:52:52 -04:00
Brett Cannon
ea59dbff16
Issue #13959 : Re-implement imp.cache_from_source() in Lib/imp.py.
2012-04-20 21:44:46 -04:00
Brett Cannon
ed672d6872
Make path manipulation more robust for platforms with alternative path
...
separators.
2012-04-20 21:19:53 -04:00
Brett Cannon
24117a748b
Issue #13959 : Keep imp.get_magic() in C code, but cache in importlib
...
for performance. While get_magic() could move to Lib/imp.py, having to
support PyImport_GetMagicNumber() would lead to equal, if not more, C
code than sticking with the status quo.
2012-04-20 18:04:03 -04:00
Brett Cannon
1032af95ff
Issue #14585 : test_import now runs all tests under
...
importlib.test.import_ using builtins.__import__() instead of just the
relative import tests.
2012-04-20 15:52:17 -04:00
Brett Cannon
8ff6baf25b
Issue #14581 : Windows users are allowed to import modules w/o taking
...
the file suffix's case into account, even when doing a case-sensitive
import.
2012-04-20 12:53:14 -04:00
Brett Cannon
91900eaf96
Have importlib.test.regrtest clear sys.path_importer_cache to make
...
sure finders from importlib are used instead of _frozen_importlib.
2012-04-20 12:51:44 -04:00
Benjamin Peterson
2a481e58ff
don't bother keeping a set we'll never use
2012-04-18 15:25:50 -04:00
Benjamin Peterson
d76bc7abac
rollback 005fd1fe31ab (see #14609 and #14582 )
...
Being able to overload a sys.module entry during import of a module was broken
by this changeset.
2012-04-18 10:55:43 -04:00
Brett Cannon
7bd329d800
Issue #12599 : Be more strict in accepting None vs. a false-like object
...
in importlib.
Thanks to PJE for pointing out the issue and Nick Coghlan for filing
the bug.
2012-04-17 21:41:35 -04:00
Brett Cannon
273323cf68
Issue #14592 : A relative import will raise a KeyError if __package__
...
or __name__ are not set in globals.
Thanks to Stefan Behnel for the bug report.
2012-04-17 19:05:11 -04:00
Brett Cannon
6f44d66bc4
Issue #13959 : Rename imp to _imp and add Lib/imp.py and begin
...
rewriting functionality in pure Python.
To start, imp.new_module() has been rewritten in pure Python, put into
importlib (privately) and then publicly exposed in imp.
2012-04-15 16:08:47 -04:00
Brett Cannon
7788838473
merge
2012-04-15 15:25:10 -04:00
Brett Cannon
881535b726
Issue #14582 : Import returns the module returned by a loader instead
...
of sys.modules when possible.
This is being done for two reasons. One is to gain a little bit of
performance by skipping an unnecessary dict lookup in sys.modules. But
the other (and main) reason is to be a little bit more clear in how
things should work from the perspective of import's interactions with
loaders. Otherwise loaders can easily forget to return the module even
though PEP 302 explicitly states they are expected to return the module
they loaded.
2012-04-15 15:24:04 -04:00
Philip Jenvey
f8f3190d32
utilize startswith(tuple)
2012-04-15 12:21:32 -07:00
Brett Cannon
49f8d8b016
Handle importing pkg.mod by executing
...
__import__('mod', {'__packaging__': 'pkg', level=1) w/o properly (and
thus not segfaulting).
2012-04-14 21:50:00 -04:00
Brett Cannon
44590e4786
Add some comments.
2012-04-14 18:37:07 -04:00
Brett Cannon
fd0741555b
Issue #2377 : Make importlib the implementation of __import__().
...
importlib._bootstrap is now frozen into Python/importlib.h and stored
as _frozen_importlib in sys.modules. Py_Initialize() loads the frozen
code along with sys and imp and then uses _frozen_importlib._install()
to set builtins.__import__() w/ _frozen_importlib.__import__().
2012-04-14 14:10:13 -04:00
Brett Cannon
bbb6680ee5
Have importlib take advantage of ImportError's new 'name' and 'path'
...
attributes.
2012-04-12 21:09:01 -04:00
Brett Cannon
d62cd5627f
Issue #14500 : Fix importlib.test.import_.test_packages to clean up
...
after itself properly.
2012-04-06 13:13:08 -04:00
Brett Cannon
927d87470a
If a module injects something into sys.modules as a side-effect of
...
importation, then respect that injection.
Discovered thanks to Lib/xml/parsers/expat.py injecting
xml.parsers.expat.errors and etree now importing that directly as a
module.
2012-04-02 20:33:56 -04:00
Brett Cannon
0d4d410b2d
Remove a dead docstring.
2012-03-02 12:32:14 -05:00
Brett Cannon
b46a1793a7
Update importlib.invalidate_caches() to be more general.
2012-02-27 18:15:42 -05:00
Philip Jenvey
4b42ff609d
unused imports, pep8
2012-02-24 21:48:17 -08:00
Brett Cannon
625cd23da4
Simplify importib._resolve_name().
2012-02-24 11:20:54 -05:00
Brett Cannon
4b03b68635
Turn _return_module() into _handle_fromlist().
2012-02-23 20:47:57 -05:00
Brett Cannon
dfc32706a0
Make the benchmark recording more sensible for importlib.test.benchmark.
2012-02-23 19:34:35 -05:00
Brett Cannon
f500778f65
Improper type for __package__ should raise TypeError, not ValueError.
2012-02-23 18:29:12 -05:00
Brett Cannon
068915cc8b
Do a type check instead of an interface check.
2012-02-23 18:18:48 -05:00
Brett Cannon
34d8e41a47
Refactor importlib to make it easier to re-implement in C.
2012-02-22 18:33:05 -05:00
Charles-François Natali
6db1c40b37
Issue #14077 : importlib: Fix regression introduced by de6703671386.
2012-02-22 21:03:09 +01:00
Antoine Pitrou
b5c793a0b3
Issue #14063 : fix test_importlib failure under OS X case-insensitive filesystems
...
(regression)
2012-02-20 22:06:59 +01:00
Benjamin Peterson
6ddac006be
put docstrings on functions
2012-02-20 15:06:35 -05:00
Antoine Pitrou
b67075beb5
_relax_case -> _make_relax_case
2012-02-20 13:52:47 +01:00
Antoine Pitrou
c541f8ef40
Issue #14043 : Speed up importlib's _FileFinder by at least 8x, and add a new importlib.invalidate_caches() function.
...
importlib is now often faster than imp.find_module() at finding modules.
2012-02-20 01:48:16 +01:00
Brett Cannon
336b2f45e5
Fix a failing importlib test under Windows.
...
Closes issue #14054 .
2012-02-19 19:36:44 -05:00
Brett Cannon
082f177c67
Fix importlib.test.__main__ to only worry about command-line flags when directly executed.
2012-02-17 10:44:24 -05:00
Brett Cannon
f2e86751cc
Optimize importlib's case-sensitivity check by wasting as little time as possible under case-sensitive OSs.
2012-02-17 09:46:48 -05:00
Brett Cannon
1f14bebe3c
Have importlib.test use argparse instead of some hacked up solution.
2012-02-17 09:37:39 -05:00
Brett Cannon
ba17fe256e
Have importlib use os.replace() for atomic renaming.
...
Closes issue #13961 . Thanks to Charles-François Natali for the patch.
2012-02-17 09:26:53 -05:00
Brett Cannon
f58d45c649
Tweak the handling of the empty string in sys.path for importlib.
...
It seems better to cache the finder for the cwd under its full path
insetad of '' in case the cwd changes. Otherwise FileFinder needs to
dynamically change itself based on whether it is given '' instead of
caching a finder for every change to the cwd.
2012-02-16 18:12:00 -05:00
Brett Cannon
3b1a06c1ea
importlib.__import__() now raises ValueError when level < 0.
...
This is to bring it more in line with what PEP 328 set out to do with
removing ambiguous absolute/relative import semantics.
2012-02-16 17:47:48 -05:00
Brett Cannon
7fab676e87
Refactor importlib.__import__() and _gcd_import() to facilitate using
...
an __import__ implementation that takes care of basics in C and punts
to importlib for more complicated code.
2012-02-16 13:43:41 -05:00
Brett Cannon
0568d6fd4e
Bring importlib in line w/ changes made in my personal bootstrap branch in the sandbox.
2012-02-14 18:38:11 -05:00
Philip Jenvey
353c10772a
simplify
2012-02-10 11:45:03 -08:00
Brett Cannon
4a2e1a0da7
Undo a bad mq management thingy.
2012-02-08 19:11:53 -05:00
Brett Cannon
97771096ab
Whitespace normalization.
2012-02-08 18:55:37 -05:00
Brett Cannon
b4e63b3177
Use the cwd when the empty string is found in sys.path. This leads to
...
__file__ being an absolute path when the module is found in the
current directory.
2012-02-08 18:52:56 -05:00
Brett Cannon
354c26ecd6
Move setup code from importlib.__init__ to
...
importlib._bootstrap._setup().
2012-02-08 18:50:22 -05:00
Brett Cannon
8490fab4ad
Don't fail in the face of a lacking attribute when wrapping a
...
function.
2012-02-08 18:44:14 -05:00
Brett Cannon
cae1068e82
Re-order importlib benchmarks to be consistent. Also print out what implementation of __import__ is used.
2012-02-07 09:40:33 -05:00
Brett Cannon
466e6a90f2
Have importlib.test.benchmark test with tabnanny as a medium-sized test.
2012-02-07 09:19:12 -05:00
Brett Cannon
5ea5b67a0b
Fix a minor output typo as found by Terry Reedy.
2012-01-31 17:02:10 -05:00
Brett Cannon
e3a9ae5ece
Let importlib.test.benchmark take a specific benchmark name to run.
2012-01-30 19:27:51 -05:00
Brett Cannon
190f33cd2b
Allow for the specification of a file to dump importlib benchmark
...
results to (and to compare against previous runs).
* * *
Move importlib.test.benchmark to argparse.
2012-01-30 19:12:29 -05:00
Brett Cannon
8a8945085f
Issue #13890 : Also fix for extension module tests for case-insensitivity.
2012-01-30 12:51:49 -05:00
Brett Cannon
01ad3251ae
Issue #13890 : Fix importlib case-sensitivity tests to not run on Windows.
...
Thanks to os.environ under Windows only updating the dict and not the
environment itself (as exposed by nt.environ), tests using
PYTHONCASEOK always fail. Now the tests are skipped when os.environ
does not do what is expected.
2012-01-30 12:48:16 -05:00
Brett Cannon
51d14f8e56
Relocate importlib._case_ok to importlib._bootstrap.
...
This required updating the code to use posix instead of os. This is
all being done to make bootstrapping easier to removing dependencies
that are kept in importlib.__init__ and thus outside of the single
file to bootstrap from.
2012-01-26 19:03:52 -05:00
Brett Cannon
c264e3ee20
Move some code from importlib.__init__ to importlib._bootstrap that
...
does not need to be exposed from C code for bootstrapping reasons.
2012-01-25 18:58:03 -05:00
Antoine Pitrou
581616624d
Port import fixes from 2.7.
2012-01-25 18:06:07 +01:00
Antoine Pitrou
33d15f7c85
Port import fixes from 2.7.
2012-01-25 18:01:45 +01:00
Antoine Pitrou
157c1263a2
Port remaining test fixes, and fix test_importlib too.
2012-01-25 03:01:34 +01:00