zope.interface icon indicating copy to clipboard operation
zope.interface copied to clipboard

`pkg_resources.declare_namespace` is deprecated

Open bluetech opened this issue 2 years ago • 5 comments
trafficstars

BUG

What I did:

Imported zope.interface (through gevent).

What I expect to happen:

No warning.

What actually happened:

The method zope.interface uses to declare a namespace package is deprecated in latest setuptools:

DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('zope')`.
  Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
    declare_namespace(pkg)

The relevant code:

https://github.com/zopefoundation/zope.interface/blob/405017fef489ff9d517d0e86e6cb0e6a14fb9bd6/src/zope/init.py

Linkified link:

https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages

What version of Python and Zope/Addons I am using:

zope.interface==6.0

bluetech avatar Jun 05 '23 08:06 bluetech

Unfortunately as https://packaging.python.org/en/latest/guides/packaging-namespace-packages/#pkg-resources-style-namespace-packages says:

If you are creating a new distribution within an existing namespace package that uses this method then it’s recommended to continue using this as the different methods are not cross-compatible and it’s not advisable to try to migrate an existing package.

It's not clear that it's possible to fix this. If a method exists that doesn't break things then I'd be very interested to hear about it!

cjwatson avatar Jun 05 '23 09:06 cjwatson

Hmm a way forward is definitely unclear, I've opened a setuptools issue asking about this: https://github.com/pypa/setuptools/issues/3943

bluetech avatar Jun 06 '23 05:06 bluetech

Takeaway from the above PyPA issue:

Once we have one pep420 namespace package in our installation we lose the ability to do a pip install -e on all packages in the same namespace not converted to the new standard.

This according to the example package here https://github.com/pypa/sample-namespace-packages and specifically the compatibility table there.

jensens avatar Jun 09 '23 10:06 jensens

A major breaking change for any namespace then 😱 if we coordinate enough, for zope and plone that might still work, but for collective... that's going to be a minefield 😕

gforcada avatar Jun 09 '23 17:06 gforcada

What I found out is that it is not always possible to mix PEP 420 installations with the currently used namespaces: If I install a namespaced package using pip (which does PEP 420 now by default) and install later on packages using zc.buildout (which does not know about PEP 420) it depends on the import order if the packages installed using zc.buildout can be found: It seem that one of these modules has to be imported first.

The only way I see is to migrate the whole namespace. See also https://github.com/zopefoundation/meta/issues/194 where this issue is discussed for the whole zopefoundation ecosystem.

icemac avatar Jun 21 '23 06:06 icemac