Commit Graph

268 Commits

Author SHA1 Message Date
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