Commit Graph

116 Commits

Author SHA1 Message Date
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 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 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 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 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 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
Brett Cannon f522aea7a1 Issue #13588: Rename decorators in importlib.
More descriptive names are now used in order to make tracebacks
more readable.
2012-01-16 11:46:22 -05:00
Antoine Pitrou 5136ac0ca2 Issue #13645: pyc files now contain the size of the corresponding source
code, to avoid timestamp collisions (especially on filesystems with a low
timestamp resolution) when checking for freshness of the bytecode.
2012-01-13 18:52:16 +01:00
Meador Inge 96ff0840b6 Issue #13593: updating the importlib utility decorators for __qualname__. 2011-12-14 22:53:13 -06:00
Meador Inge d7afeeeb8d Issue #13591: import_module potentially imports a module twice. 2011-12-14 22:27:28 -06:00
Meador Inge 416f12ddb3 Issue #13591: import_module potentially imports a module twice. 2011-12-14 22:23:46 -06:00
Antoine Pitrou 28e401e717 Issue #13392: Writing a pyc file should now be atomic under Windows as well. 2011-11-15 19:15:19 +01:00
Charles-François Natali 0c929d9d39 Issue #13303: Fix bytecode file default permission. 2011-11-10 19:12:29 +01:00
Charles-François Natali e695eec24a Issue #13303: Fix a race condition in the bytecode file creation. 2011-10-31 20:47:31 +01:00
Florent Xicluna 68f71a34f4 Simplify and remove few dependencies on 'errno', thanks to PEP 3151. 2011-10-28 16:06:23 +02:00
Antoine Pitrou daaaec9ee7 Silence the FileExistsError which can be raised because of the O_EXCL flag
(as in import.c)
2011-10-19 23:28:40 +02:00
Antoine Pitrou 707033a694 Issue #13146: Writing a pyc file is now atomic under POSIX. 2011-10-17 19:28:44 +02:00
Brett Cannon 442c9b92d8 Make importlib compatible with __import__ by "fixing" code.co_filename
paths.

__import__ does a little trick when importing from bytecode by
back-patching the co_filename paths to point to the file location
where the code object was loaded from, *not* where the code object was
originally created. This allows co_filename to point to a valid path.
Problem is that co_filename is immutable from Python, so a private
function -- imp._fix_co_filename() -- had to be introduced in order to
get things working properly. Originally the plan was to add a file
argument to marshal.loads(), but that failed as the algorithm used by
__import__ is not fully recursive as one might expect, so to be fully
backwards-compatible the code used by __import__ needed to be exposed.

This closes issue #6811 by taking a different approach than outlined
in the issue.
2011-03-23 16:14:42 -07:00
Brett Cannon a7468bc5c6 Have importlib use the repr of a module name in error messages.
This makes it obvious that an import failed because of some extraneous
whitespace (e.g., a newline).

This is a partial fix for issue #8754.
2011-03-23 16:06:00 -07:00
Ezio Melotti 4969f709cc #11515: Merge with 3.1. 2011-03-15 05:59:46 +02:00
Ezio Melotti 42da663e6f #11515: fix several typos. Patch by Piotr Kasprzyk. 2011-03-15 05:18:48 +02:00
Ezio Melotti 373089239b #11515: Merge with 3.2. 2011-03-15 06:03:08 +02:00
Eric V. Smith 91f0359ee4 Skip test if zlib not present. Closes #11498. Patch by Natalia B. Bidart. 2011-03-14 11:57:16 -04:00
Eric V. Smith 4169826a00 Typos. 2011-03-14 10:56:33 -04:00