Added dynamic path calculation.

This commit is contained in:
Eric V. Smith 2012-05-11 12:56:56 -04:00
parent 57f945902a
commit b7a0f00a30
1 changed files with 16 additions and 17 deletions

View File

@ -140,12 +140,6 @@ The new namespace package:
* Does not have a ``__file__`` attribute.
There is no mechanism to automatically recompute the ``__path__`` if
``sys.path`` is altered after a namespace package has already been
created. However, existing namespace utilities (like
``pkgutil.extend_path``) can be used to update them explicitly if
desired.
Note that if "import foo" is executed and "foo" is found as a
namespace package (using the above rules), then "foo" is immediately
created as a package. The creation of the namespace package is not
@ -159,6 +153,20 @@ that the namespace package's ``__file__`` attribute will end with a
path separator (typically a slash or backslash, depending on the
platform).
Dynamic path computation
------------------------
A namespace package's ``__path__`` will be recomputed if the value of
the parent path changes. In order for this feature to work, the parent
path must be modified in-place, not replaced with a new object. For
example, for top-level namespace packages, this will work::
sys.path.append('new-dir')
But this will not::
sys.path = sys.path + ['new-dir']
Impact on Import Finders and Loaders
------------------------------------
@ -265,12 +273,6 @@ Nick gave a detailed response [4]_, which is summarized here:
4. This will also be addressed in PEP 395.
Phillip Eby asked about auto-updating of ``__path__``, instead of it
being a simple list [5]_. It is the intent of this PEP to get the
simplest possible solution working. It will be possible at a later
date to add such features. Several possible ways to do so were
discussed in the referenced email thread.
``find_module`` versus ``find_loader``
--------------------------------------
@ -288,7 +290,7 @@ specifies that finders that want to provide namespace portions must
implement the ``find_loader`` method, described above.
The use case for supporting multiple portions per ``find_loader`` call
is given in [6]_.
is given in [5]_.
Module reprs
@ -345,10 +347,7 @@ References
.. [4] Nick Coghlan's response to his initial objections
(http://mail.python.org/pipermail/import-sig/2012-April/000464.html)
.. [5] Phillip Eby's question about auto-updating __path__
(http://mail.python.org/pipermail/import-sig/2012-April/000468.html)
.. [6] Use case for multiple portions per ``find_loader`` call
.. [5] Use case for multiple portions per ``find_loader`` call
(http://mail.python.org/pipermail/import-sig/2012-May/000585.html)
Copyright