Rename proposed files from .pkg into .pth. Drop
claims that this extends the .pkg mechanism.
This commit is contained in:
parent
d0df1270f4
commit
35daf4cb35
45
pep-0382.txt
45
pep-0382.txt
|
@ -49,8 +49,8 @@ invoked independent of which portion of the package gets imported
|
||||||
first. As a consequence, the package's ``__init__.py`` cannot
|
first. As a consequence, the package's ``__init__.py`` cannot
|
||||||
practically define any names as it depends on the order of the package
|
practically define any names as it depends on the order of the package
|
||||||
fragments on sys.path which portion is imported first. As a special
|
fragments on sys.path which portion is imported first. As a special
|
||||||
feature, extend_path reads files named ``*.pkg`` which allow to
|
feature, extend_path reads files named ``<packagename>.pkg`` which
|
||||||
declare additional portions.
|
allow to declare additional portions.
|
||||||
|
|
||||||
setuptools provides a similar function pkg_resources.declare_namespace
|
setuptools provides a similar function pkg_resources.declare_namespace
|
||||||
that is used in the form::
|
that is used in the form::
|
||||||
|
@ -91,29 +91,27 @@ Specification
|
||||||
|
|
||||||
Rather than using an imperative mechanism for importing packages, a
|
Rather than using an imperative mechanism for importing packages, a
|
||||||
declarative approach is proposed here, as an extension to the existing
|
declarative approach is proposed here, as an extension to the existing
|
||||||
``*.pkg`` mechanism.
|
``*.pth`` mechanism available on the top-level python path.
|
||||||
|
|
||||||
The import statement is extended so that it directly considers ``*.pkg``
|
The import statement is extended so that it directly considers
|
||||||
files during import; a directory is considered a package if it either
|
``*.pth`` files during import; a directory is considered a package if
|
||||||
contains a file named __init__.py, or a file whose name ends with
|
it either contains a file named __init__.py, or a file whose name ends
|
||||||
".pkg".
|
with ".pth". Unlike .pth files on the top level, lines starting with
|
||||||
|
"import" are not supported in per-package .pth files.
|
||||||
|
|
||||||
In addition, the format of the ``*.pkg`` file is extended: a line with
|
In addition, the format of the ``*.pth`` file is extended: a line with
|
||||||
the single character ``*`` indicates that the entire sys.path will
|
the single character ``*`` indicates that the entire sys.path will
|
||||||
be searched for portions of the namespace package at the time the
|
be searched for portions of the namespace package at the time the
|
||||||
namespace packages is imported.
|
namespace packages is imported.
|
||||||
|
|
||||||
Importing a package will immediately compute the package's __path__;
|
Importing a package will immediately compute the package's __path__;
|
||||||
the ``*.pkg`` files are not considered anymore after the initial import.
|
the ``*.pth`` files are not considered anymore after the initial
|
||||||
If a ``*.pkg`` package contains an asterisk, this asterisk is prepended
|
import. If a ``*.pth`` package contains an asterisk, this asterisk is
|
||||||
to the package's __path__ to indicate that the package is a namespace
|
prepended to the package's __path__ to indicate that the package is a
|
||||||
package (and that thus further extensions to sys.path might also
|
namespace package (and that thus further extensions to sys.path might
|
||||||
want to extend __path__). At most one such asterisk gets prepended
|
also want to extend __path__). At most one such asterisk gets
|
||||||
to the path. In addition, the (possibly dotted) names of all namespace
|
prepended to the path. In addition, the (possibly dotted) names of all
|
||||||
packages are added to the set sys.namespace_packages.
|
namespace packages are added to the set sys.namespace_packages.
|
||||||
|
|
||||||
extend_path will be extended to recognize namespace packages according
|
|
||||||
to this PEP, and avoid adding directories twice to __path__.
|
|
||||||
|
|
||||||
No other change to the importing mechanism is made; searching modules
|
No other change to the importing mechanism is made; searching modules
|
||||||
(including __init__.py) will continue to stop at the first module
|
(including __init__.py) will continue to stop at the first module
|
||||||
|
@ -122,22 +120,22 @@ this:
|
||||||
|
|
||||||
1. sys.path is search for a directory foo, or a file foo.<ext>.
|
1. sys.path is search for a directory foo, or a file foo.<ext>.
|
||||||
If a file is found, it is treated as a module, and imported.
|
If a file is found, it is treated as a module, and imported.
|
||||||
2. if it is a directory, it checks for \*.pkg files. If it finds
|
2. if it is a directory, it checks for \*.pth files. If it finds
|
||||||
any, a package is created, and its __path__ is extended.
|
any, a package is created, and its __path__ is extended.
|
||||||
3. The __init__ module is imported; this import will search the
|
3. The __init__ module is imported; this import will search the
|
||||||
__path__ that got computed already.
|
__path__ that got computed already.
|
||||||
4. If neither a \*.pkg file nor an __init__.py was found, the
|
4. If neither a \*.pth file nor an __init__.py was found, the
|
||||||
directory is skipped, and search for the module/package
|
directory is skipped, and search for the module/package
|
||||||
continues.
|
continues.
|
||||||
|
|
||||||
Discussion
|
Discussion
|
||||||
==========
|
==========
|
||||||
|
|
||||||
With the addition of ``*.pkg`` files to the import mechanism, namespace
|
With the addition of ``*.pth`` files to the import mechanism, namespace
|
||||||
packages can stop filling out the namespace package's __init__.py.
|
packages can stop filling out the namespace package's __init__.py.
|
||||||
As a consequence, extend_path and declare_namespace become obsolete.
|
As a consequence, extend_path and declare_namespace become obsolete.
|
||||||
|
|
||||||
It is recommended that distributions put a file <distribution>.pkg
|
It is recommended that distributions put a file <distribution>.pth
|
||||||
into their namespace packages, with a single asterisk. This allows
|
into their namespace packages, with a single asterisk. This allows
|
||||||
vendor packages to install multiple portions of namespace package
|
vendor packages to install multiple portions of namespace package
|
||||||
into a single directory, with no risk of overlapping files.
|
into a single directory, with no risk of overlapping files.
|
||||||
|
@ -160,9 +158,6 @@ having users and tools starting to special-case 2.7). Prospective
|
||||||
users of this feature are encouraged to comment on this particular
|
users of this feature are encouraged to comment on this particular
|
||||||
question.
|
question.
|
||||||
|
|
||||||
It also has been proposed to rename the extension from .pkg to
|
|
||||||
something else.
|
|
||||||
|
|
||||||
Copyright
|
Copyright
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue