Commit Graph

12 Commits

Author SHA1 Message Date
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
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 5d43cff623 Remove a stale comment. 2011-03-23 18:12:24 -07:00
Brett Cannon 61b14251d3 Make importlib.abc.SourceLoader the primary mechanism for importlib.
This required moving the class from importlib/abc.py into
importlib/_bootstrap.py and jiggering some code to work better with the class.
This included changing how the file finder worked to better meet import
semantics. This also led to fixing importlib to handle the empty string from
sys.path as import currently does (and making me wish we didn't support that
instead just required people to insert '.' instead to represent cwd).

It also required making the new set_data abstractmethod create
any needed subdirectories implicitly thanks to __pycache__ (it was either this
or grow the SourceLoader ABC to gain an 'exists' method and either a mkdir
method or have set_data with no data arg mean to create a directory).

Lastly, as an optimization the file loaders cache the file path where the
finder found something to use for loading (this is thanks to having a
sourceless loader separate from the source loader to simplify the code and
cut out stat calls).
Unfortunately test_runpy assumed a loader would always work for a module, even
if you changed from underneath it what it was expected to work with. By simply
dropping the previous loader in test_runpy so the proper loader can be returned
by the finder fixed the failure.

At this point importlib deviates from import on two points:

1. The exception raised when trying to import a file is different (import does
an explicit file check to print a special message, importlib just says the path
cannot be imported as if it was just some module name).

2. the co_filename on a code object is not being set to where bytecode was
actually loaded from instead of where the marshalled code object originally
came from (a solution for this has already been agreed upon on python-dev but has
not been implemented yet; issue8611).
2010-07-03 21:48:25 +00:00
Brett Cannon d95863f6f3 Clarify why test_import is failing under importlib. 2009-08-30 23:41:40 +00:00
Brett Cannon 1c1dcbfd5d Trying to import a submodule from another module and not a package was raising
AttributeError in importlib when it should be an ImportError.

Found when running importlib against test_runpy.
2009-08-30 20:22:21 +00:00
Brett Cannon 82a23fe392 test_pep3120 is no longer a problem for importlib as the test was tweaked. 2009-08-30 20:08:15 +00:00
Brett Cannon ce7d4cbc3b Turn on verbose2 for importlib.test.regrtest so as to see failures when they occur. 2009-08-30 19:44:32 +00:00
Brett Cannon 6afbaef2fd Raise TypeError if the name given to importlib.__import__() lacks an rpartition
attribute. Was throwing AttributeError before. Discovered when running
test_builtin against importlib.

This exception change is specific to importlib.__import__() and does not apply to
import_module() as it is being done for compatibility reasons only.
2009-08-30 19:08:58 +00:00
Brett Cannon 12c3fc9343 Provide module docstrings for the two main test drivers in importlib that
explain what they are for and how to use command-line arguments to tweak
semantics.
2009-08-30 08:39:57 +00:00
Brett Cannon 6cc8310ded Tweak importlib.test.regrtest to only specify the implicit tests to exclude
when running entire test suite. Allows normal command-line arguments normally
given to test.regrtest to work (e.g. specifying a single test).
2009-08-30 08:30:35 +00:00
Brett Cannon 5e129dbc16 Add a test file to importlib that runs regrtest using importlib.__import__.
The file must be run using runpy. Certain tests are currently excluded from
being run as they have known failures based on golden value checks that fail
for various reasons (typically because __loader__ is not expected to be set on
modules). Running the tests with this file does discover some incompatibilites
in importlib that will be fixed in the near future (as noted currently in the
docstring).
2009-08-27 23:52:35 +00:00