1. PyPA
  2. Python Packaging Authority Projects
  3. setuptools
Issue #12 resolved

Update or remove warning when namespace package doesn't use declare_namespace()

Adrian Sampson
created an issue

When building a namespace package, Setuptools checks (by searching in the code) whether the __init__.py therein calls declare_namespace from pkg_resources. If it doesn't it, it logs a warning, emitted here, which reads:

WARNING: (package) is a namespace package, but its __init__.py does not declare_namespace(); setuptools 0.7 will REQUIRE this! (See the setuptools manual under "Namespace Packages" for details.)

First of all, setuptools 0.7 now exists, so the future tense is somewhat worrisome. Also, I'm not sure whether requiring a declare_namespace call is actually in the plans anymore. (My package, for example, accomplishes namespace packages using pkgutil.extend_path from the standard library instead.) Some clarification, either in the warning or the docs, about what the plans are here would be helpful.

Comments (5)

  1. Jason R. Coombs

    Good find. Yes, it does say that, but setuptools 0.7 is now meeting a different goal, and if there was code that removed the compatibility and warning, it's not part of this 0.7 release. I'll comb through the 'setuptools' branch (which was not merged and was originally slated for 0.7) and see if there's a corresponding changeset.

    Secondarily, we need to determine what's the proper thing to do about this warning and behavior. If it should be kept, it should be slated for setuptools 1.0 or later major increment release (per semantic versioning).

    I seem to think pkgutil.extend_path and pkg_resources.declare_namespace meet similar goals but from a different perspective. My hunch tells me that if the package is declared to be a namespace package (in the metadata), that's a setuptools feature and may be enforced by setuptools. I'll have to learn more.

    In the meantime, if anyone can shed some light on the issue, please feel free to do so.

  2. Jason R. Coombs

    I found the original changeset in the setuptools 0.7 branch: f3c5c1984206

    I've since grafted that change to the master. This change will force a 3.0 release to signal backward incompatibility.

    pje Are you aware of any issues with moving this intention forward other than the obvious backward incompatibility (which has long had a warning)?

  3. pje

    I don't see any issues with it, but to properly support PEP 420-style namespace packages (Python 3.3+), there are more changes needed. Notably, setuptools needs to be able to handle packages without an __init__.py, and to thus not do its special __init__.py handling for them. In addition, declare_namespace() is going to need to be a lot smarter. These are not really issues with this, though.

  4. Log in to comment