Visitar URL original
[Bug]: DeprecationWarning for pkg_resources.declare_namespace usage in mpl_toolkit · Issue #25244 · matplotlib/matplotlib · GitHub
The Wayback Machine - https://web.archive.org/web/20230323083617/https://github.com/matplotlib/matplotlib/issues/25244
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: DeprecationWarning for pkg_resources.declare_namespace usage in mpl_toolkit #25244

Open
rjgildea opened this issue Feb 17, 2023 · 7 comments · May be fixed by #25381
Open

[Bug]: DeprecationWarning for pkg_resources.declare_namespace usage in mpl_toolkit #25244

rjgildea opened this issue Feb 17, 2023 · 7 comments · May be fixed by #25381
Labels
Difficulty: Medium Good first issue Open a pull request against these issues if there are no active ones!
Milestone

Comments

@rjgildea
Copy link

Bug summary

As of setuptools v67.3.0 the use of pkg_resources.declare_namespace in lib/mpl_toolkits/__init__.py raises a DeprecationWarning.

Code for reproduction

$ mamba create -n test python=3.10 matplotlib-base -y
$ mamba activate test
$ export PYTHONDEVMODE=1
$ python -c "import pkg_resources"

Actual outcome

/path/to/test/lib/python3.10/site-packages/pkg_resources/__init__.py:2804: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('mpl_toolkits')`.
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)

Expected outcome

No output

Additional information

See also:
https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
https://packaging.python.org/en/latest/guides/packaging-namespace-packages/
https://peps.python.org/pep-0420/

Operating system

No response

Matplotlib Version

3.7.0

Matplotlib Backend

TkAgg

Python version

Python 3.10.9

Jupyter version

No response

Installation

conda

@tacaswell
Copy link
Member

Is there a good guide for how to migrate from "old" namespace packages to "new" namespace packages? What is going to break if we just delete this __init__.py and how do we warn our users we are about to break them (I asked these in the linked setuptools issue as well)?

@tacaswell tacaswell added this to the v3.8.0 milestone Feb 17, 2023
@tacaswell tacaswell added Difficulty: Medium Good first issue Open a pull request against these issues if there are no active ones! labels Feb 17, 2023
@tacaswell
Copy link
Member

Medium difficulty because it requires understanding packaging related issues but good first issue because it requires no understanding of Matplotlib to do.

Tasks:

  • sort out what even needs to be done (just delete the __init__.py?)
  • document if / how this will break any downstream packages and how they also need to migrate
  • add an API change note that we did this.

rjgildea added a commit to cctbx/dxtbx that referenced this issue Feb 20, 2023
See also:
matplotlib/matplotlib#25244

Run tests directly rather than as a subprocess so that pytest
filterwarnings options have their intended effect.
rjgildea added a commit to cctbx/dxtbx that referenced this issue Feb 20, 2023
As of setuptools v67.3.0 the use of pkg_resources.declare_namespace
in lib/mpl_toolkits/__init__.py raises a DeprecationWarning.

See also:
matplotlib/matplotlib#25244

Run tests directly rather than as a subprocess so that pytest
filterwarnings options have their intended effect.
@neutrinoceros
Copy link

What is going to break if we just delete this init.py

To answer this, I'll quote https://packaging.python.org/en/latest/guides/packaging-namespace-packages/#native-namespace-packages

It is extremely important that every distribution that uses the namespace package omits the init.py or uses a pkgutil-style init.py. If any distribution does not, it will cause the namespace logic to fail and the other sub-packages will not be importable.

And from the same source:

Warning While native namespace packages and pkgutil-style namespace packages are largely compatible, pkg_resources-style namespace packages are not compatible with the other methods. It’s inadvisable to use different methods in different distributions that provide packages to the same namespace.

In other words, any dependent code that implements a mpl_toolkits.* subpackage will break immediately when the deprecated __init__.py is removed.
It also seems that there is no way for dependent code to support both implementations of namespace packages at the same time, so I assume they'll have to drop support for all versions of matplotlib previous to the one that does the change... or renounce supporting that version and newer ones.

I haven't found a solution to warn about the transition from within matplotlib, so currently my recommendation would be to just reach out to downstream developers by any means appropriate.
Is there a list of such sub packages somewhere that'd be relevant ? there seem to be only one on PyPI (https://pypi.org/project/mpl-toolkits.clifford/)

rjgildea added a commit to cctbx/dxtbx that referenced this issue Feb 22, 2023
As of setuptools v67.3.0 the use of pkg_resources.declare_namespace
in lib/mpl_toolkits/__init__.py raises a DeprecationWarning.

See also:
matplotlib/matplotlib#25244

Run tests directly rather than as a subprocess so that pytest
filterwarnings options have their intended effect.
@ssbarnea
Copy link

ssbarnea commented Mar 1, 2023

I remember facing this issue few years back and the conclusion was to avoid using namespaces in general. Much safer and you do not depend on someone else which could break you.

@tacaswell
Copy link
Member

Per pypa/setuptools#3434 (comment) it seems we can just delete the __init__.py files and everything will be OK.

@BabaYaga1221
Copy link

BabaYaga1221 commented Mar 12, 2023 •

@tacaswell I just look the same resource on python version 3.10.10 and the excepted outcome was verified. I think that it just needs to update python to a newer version.

correct me if I am wrong. Thanks

image

@tacaswell
Copy link
Member

@BabaYaga1221 The dependency is on the version of setuptools (not the version of Python).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Medium Good first issue Open a pull request against these issues if there are no active ones!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants