Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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

Closed
rjgildea opened this issue Feb 17, 2023 · 7 comments · Fixed by #25381
Closed

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

rjgildea opened this issue Feb 17, 2023 · 7 comments · Fixed by #25381
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues 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 https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues 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
Contributor

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).

ndevenish added a commit to dials/dials that referenced this issue Apr 12, 2023
Until this matplotlib bug is fixed:
  matplotlib/matplotlib#25244

We cannot have both updated setuptools and warnings. This is
because subprocesses also print out warnings, and this
causes the tests to fail because of stderr output.
anjakefala added a commit to anjakefala/ibis that referenced this issue Apr 12, 2023
…mespace

A lot of third party dependencies (e.g.
matplotlib/matplotlib#25244) are still using
it. Helpful to ignore for now.
cpcloud pushed a commit to ibis-project/ibis that referenced this issue Apr 12, 2023
…mespace

A lot of third party dependencies (e.g.
matplotlib/matplotlib#25244) are still using
it. Helpful to ignore for now.
ndevenish added a commit to dials/dials that referenced this issue Apr 13, 2023
Python 3.10 remains the default, for now.

Also, update CI to either disable or suppress PYTHONDEVMODE
warnings from this matplotlib bug:
  matplotlib/matplotlib#25244
toastisme pushed a commit to toastisme/dials that referenced this issue May 3, 2023
Python 3.10 remains the default, for now.

Also, update CI to either disable or suppress PYTHONDEVMODE
warnings from this matplotlib bug:
  matplotlib/matplotlib#25244
toastisme pushed a commit to toastisme/dxtbx that referenced this issue Jul 18, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues 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