Commit Graph

38 Commits

Author SHA1 Message Date
Georg Brandl 8a1caa2361 #6522: add a "decorator" directive to explicitly document decorators, and use it in a few places. 2010-07-29 16:01:11 +00:00
Brett Cannon 6dfbff3ff3 Minor clarification about importlib.abc.SourceLoader.get_filename. 2010-07-21 09:48:31 +00: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 0e13c9451e Make a sentence a little less awkward. 2010-06-29 18:26:11 +00:00
Brett Cannon 0cf9e6a621 Move importlib.abc.SourceLoader to _bootstrap.
Required updating code relying on other modules to switch to _bootstrap's
unique module requirements. This led to the realization that
get_code was being too liberal in its exception catching when calling set_data
by blindly grabbing IOError. Shifted the responsibility of safely ignoring
writes to a read-only path to set_data.

Importlib is still not relying on SourceLoader yet; requires creating a
SourcelessLoader and updating the source finder.
2010-06-28 04:57:24 +00:00
Brett Cannon f23e374441 Implement importlib.abc.SourceLoader and deprecate PyLoader and PyPycLoader.
SourceLoader is a simplification of both PyLoader and PyPycLoader. If one only
wants to use source, then they need to only implement get_data and
get_filename. To also use bytecode -- sourceless loading is not supported --
then two abstract methods -- path_mtime and set_data -- need to be implemented.
Compared to PyLoader and PyPycLoader, there are less abstract methods
introduced and bytecode files become an optimization controlled by the ABC and
hidden from the user (this need came about as PEP 3147 showed that not treating
bytecode as an optimization can cause problems for compatibility).

PyLoader is deprecated in favor of SourceLoader. To be compatible from Python
3.1 onwards, a subclass need only use simple methods for source_path and
is_package. Otherwise conditional subclassing based on whether Python 3.1 or
Python 3.2 is being is the only change. The documentation and docstring for
PyLoader explain what is exactly needed.

PyPycLoader is deprecated also in favor of SourceLoader. Because PEP 3147
shifted bytecode path details so much, there is no foolproof way to provide
backwards-compatibility with SourceLoader. Because of this the class is simply
deprecated and users should move to SourceLoader (and optionally PyLoader for
Python 3.1). This does lead to a loss of support for sourceless loading
unfortunately.

At some point before Python 3.2 is released, SourceLoader will be moved over to
importlib._bootstrap so that the core code of importlib relies on the new code
instead of the old PyPycLoader code. This commit is being done now so that
there is no issue in having the API in Python 3.1a1.
2010-06-27 23:57:46 +00:00
Brett Cannon 30b7a90033 Add a link to PEP 3147 from the importlib docs.
Closes issue 8667. Thanks Ashley Sands for the patch.
2010-06-27 21:49:22 +00:00
Brett Cannon 8917d5e598 Fix the wrong numbering of a PEP. 2010-01-13 19:21:00 +00:00
Brett Cannon 3e761a9802 Wording clarification. 2009-12-10 00:24:21 +00:00
Brett Cannon fee82f4f9c Clarify the intention of raising ImportError for importlib.abc.PyLoader.(source|bytecode)_path. 2009-12-09 01:48:31 +00:00
Benjamin Peterson 0089d75c56 update to reality 2009-11-13 00:52:43 +00:00
Brett Cannon 1b184d547f Pluralize a word. 2009-11-07 08:22:58 +00:00
Brett Cannon 6253871910 Clean up a minor bit of wording. 2009-08-18 23:54:07 +00:00
Brett Cannon 23460291ec Make the wdocs for importlib.abc.ExecutionLoader to be weaker in terms of what is needed to execute a module. 2009-07-20 22:59:00 +00:00
Brett Cannon 6919427e94 Implement the PEP 302 protocol for get_filename() as
importlib.abc.ExecutionLoader. PyLoader now inherits from this ABC instead of
InspectLoader directly. Both PyLoader and PyPycLoader provide concrete
implementations of get_filename in terms of source_path and bytecode_path.
2009-07-20 04:23:48 +00:00
Tarek Ziadé 434caaab75 typo 2009-05-14 12:48:09 +00:00
Brett Cannon bc6c2b5c6b Explain a little about the explanation. 2009-04-01 23:36:48 +00:00
Brett Cannon 9f4cb1c89d Add a meta path importer example. 2009-04-01 23:26:47 +00:00
Brett Cannon 16248a49b9 Add some clarification to the importlib docs. 2009-04-01 20:47:14 +00:00
Guido van Rossum 0961354874 Thorough review of importlib docs. Reviewed by Brett himself. 2009-03-30 20:34:57 +00:00
Brett Cannon 44c5481941 Fix a doc typo. 2009-03-16 22:30:11 +00:00
Brett Cannon 8d11013169 Implement InspectLoader for FrozenImporter. 2009-03-15 02:20:16 +00:00
Brett Cannon a113ac58be Implement InspectLoader for BuiltinImporter. 2009-03-15 01:41:33 +00:00
Georg Brandl ae2dbe2543 #5486: typos. 2009-03-13 19:04:40 +00:00
Brett Cannon 2cf03a8204 Implement importlib.util.set_loader: a decorator to automatically set
__loader__ on modules.
2009-03-10 05:17:37 +00:00
Brett Cannon d43b30b046 Implement get_source for importlib.abc.PyLoader using source_path and get_data. 2009-03-10 03:29:23 +00:00
Brett Cannon 9c751b7246 Fix some reST mishaps. 2009-03-09 16:28:16 +00:00
Brett Cannon ad876c7083 Clarify an assumption that importlib.abc.PyLoader makes when importing a
package and setting __path__.
2009-03-09 07:53:09 +00:00
Brett Cannon 2a922ed6ad Introduce importlib.abc. The module contains various ABCs related to imports
(mostly stuff specified by PEP 302). There are two ABCs, PyLoader and
PyPycLoader, which help with implementing source and source/bytecode loaders by
implementing load_module in terms of other methods. This removes a lot of
gritty details loaders typically have to worry about.
2009-03-09 03:35:50 +00:00
Brett Cannon 435aad878c Rename importlib.util.set___package__ to set_package. 2009-03-04 16:07:00 +00:00
Brett Cannon 57b46f5b0e Expose importlib.util.set___package__. 2009-03-02 14:38:26 +00:00
Brett Cannon d2e7b33815 Implement the more specific PEP 302 semantics for loaders and what happens upon
load failure in relation to reloads. Also expose
importlib.util.module_for_loader to handle all of the details of this along
with making sure all current loaders behave nicely.
2009-02-17 02:45:03 +00:00
Brett Cannon debb98d91f Document importlib.machinery.PathFinder. 2009-02-16 04:18:01 +00:00
Brett Cannon 2c318a1390 Rewrite the code implementing __import__ for importlib. Now it is much simpler
and relies much more on meta path finders to abstract out various parts of
import.

As part of this the semantics for import_module tightened up and now follow
__import__ much more closely (biggest thing is that the 'package' argument must
now already be imported, else a SystemError is raised).
2009-02-07 01:15:27 +00:00
Benjamin Peterson 97d3aa50b7 use the classmethod directive 2009-01-25 19:44:16 +00:00
Brett Cannon 78246b6b45 Document both importlib.machinery.BuiltinImporter and FrozenImporter. 2009-01-25 04:56:30 +00:00
Brett Cannon 33418c8feb Fix markup for arguments in importlib docs. 2009-01-22 18:37:20 +00:00
Brett Cannon afccd63ac9 Document the (very small) public API for importlib. As time goes on and some
key refactorings occur more of the API will be exposed and documented.
2009-01-20 02:21:27 +00:00