diff options
author | PJ Eby <distutils-sig@python.org> | 2006-04-14 19:13:24 +0000 |
---|---|---|
committer | PJ Eby <distutils-sig@python.org> | 2006-04-14 19:13:24 +0000 |
commit | 52dcb6d1c888a4a7a047f380783f572055a175dc (patch) | |
tree | e7f74685afa9a96c1c8b6658f2bba093b66813d6 | |
parent | 2fbffe9bf4bf6c71c5bbe94e3386d69a2db5f37c (diff) | |
download | external_python_setuptools-52dcb6d1c888a4a7a047f380783f572055a175dc.tar.gz external_python_setuptools-52dcb6d1c888a4a7a047f380783f572055a175dc.tar.bz2 external_python_setuptools-52dcb6d1c888a4a7a047f380783f572055a175dc.zip |
Don't eagerly import namespace packages. This was the big reason for
branching to 0.7 now, as I wanted this wart gone before anything went
into Python 2.5. But it's gone now, yay!
--HG--
extra : source : f3c5c19842064dd4a497baef0171aac54464a484
extra : amend_source : 3f79e71eedfc5f37a1813967bb53cf9d92a11919
-rw-r--r-- | CHANGES.txt | 13 | ||||
-rw-r--r-- | docs/pkg_resources.txt | 17 | ||||
-rw-r--r-- | pkg_resources.py | 4 | ||||
-rw-r--r-- | setuptools/command/build_py.py | 10 |
4 files changed, 31 insertions, 13 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 4214aca5..8200b99a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -3,6 +3,19 @@ CHANGES ======= --- +3.0 +--- + +* Issue #12: Namespace packages are now imported lazily. That is, the mere + declaration of a namespace package in an egg on ``sys.path`` no longer + causes it to be imported when ``pkg_resources`` is imported. Note that this + change means that all of a namespace package's ``__init__.py`` files must + include a ``declare_namespace()`` call in order to ensure that they will be + handled properly at runtime. In 2.x it was possible to get away without + including the declaration, but only at the cost of forcing namespace + packages to be imported early, which 3.0 no longer does. + +--- 2.3 --- diff --git a/docs/pkg_resources.txt b/docs/pkg_resources.txt index 8dd3e9ab..18b68db7 100644 --- a/docs/pkg_resources.txt +++ b/docs/pkg_resources.txt @@ -137,13 +137,16 @@ Namespace Package Support A namespace package is a package that only contains other packages and modules, with no direct contents of its own. Such packages can be split across -multiple, separately-packaged distributions. Normally, you do not need to use -the namespace package APIs directly; instead you should supply the -``namespace_packages`` argument to ``setup()`` in your project's ``setup.py``. -See the `setuptools documentation on namespace packages`_ for more information. - -However, if for some reason you need to manipulate namespace packages or -directly alter ``sys.path`` at runtime, you may find these APIs useful: +multiple, separately-packaged distributions. They are normally used to split +up large packages produced by a single organization, such as in the ``zope`` +namespace package for Zope Corporation packages, and the ``peak`` namespace +package for the Python Enterprise Application Kit. + +To create a namespace package, you list it in the ``namespace_packages`` +argument to ``setup()``, in your project's ``setup.py``. (See the `setuptools +documentation on namespace packages`_ for more information on this.) Also, +you must add a ``declare_namespace()`` call in the package's ``__init__.py`` +file(s): ``declare_namespace(name)`` Declare that the dotted package name `name` is a "namespace package" whose diff --git a/pkg_resources.py b/pkg_resources.py index 2a47c58b..2d656f1a 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -2311,7 +2311,9 @@ class Distribution(object): self.insert_on(path) if path is sys.path: fixup_namespace_packages(self.location) - list(map(declare_namespace, self._get_metadata('namespace_packages.txt'))) + for pkg in self._get_metadata('namespace_packages.txt'): + if pkg in sys.modules: + declare_namespace(pkg) def egg_name(self): """Return what this distribution's standard .egg filename should be""" diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 090b44d2..1efabc02 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -167,12 +167,12 @@ class build_py(_build_py, Mixin2to3): f = open(init_py,'rbU') if 'declare_namespace'.encode() not in f.read(): - from distutils import log - log.warn( - "WARNING: %s is a namespace package, but its __init__.py does\n" - "not declare_namespace(); setuptools 0.7 will REQUIRE this!\n" + from distutils.errors import DistutilsError + raise DistutilsError( + "Namespace package problem: %s is a namespace package, but its\n" + "__init__.py does not call declare_namespace()! Please fix it.\n" '(See the setuptools manual under "Namespace Packages" for ' - "details.)\n", package + "details.)\n" % (package,) ) f.close() return init_py |