Commit Graph

257 Commits

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