Skip to content

[BUG] v70.0.0 removes 'packaging' from pkg_resources #4385

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
dmick opened this issue May 23, 2024 · 6 comments
Closed

[BUG] v70.0.0 removes 'packaging' from pkg_resources #4385

dmick opened this issue May 23, 2024 · 6 comments

Comments

@dmick
Copy link

dmick commented May 23, 2024

setuptools version

setuptools=70.0.0

Python version

3.8

OS

Ubuntu 22.04

Additional environment information

first noticed on readthedocs.org builds today

Description

from pkg_resources import packaging

fails with

ImportError: cannot import name 'packaging' from 'pkg_resources'

Expected behavior

expected the import to succeed as in v69.5.1 and prior

How to Reproduce

python3 -mvenv v
v/bin/pip install pkg_resources
v/bin/python3

from pkg_resources import packaging

Output

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'packaging' from 'pkg_resources' (/home/dmick/vsetup/lib64/python3.9/site-packages/pkg_resources/__init__.py)



@dmick dmick added bug Needs Triage Issues that need to be evaluated for severity and status. labels May 23, 2024
dmick pushed a commit to dmick/ceph that referenced this issue May 23, 2024
from pkg_resources import packaging no longer works.  See
pypa/setuptools#4385

Signed-off-by: Dan Mick <[email protected]>
dmick pushed a commit to dmick/ceph that referenced this issue May 23, 2024
from pkg_resources import packaging no longer works.  See
pypa/setuptools#4385

Signed-off-by: Dan Mick <[email protected]>
dmick pushed a commit to dmick/ceph that referenced this issue May 23, 2024
from pkg_resources import packaging no longer works.  See
pypa/setuptools#4385

Signed-off-by: Dan Mick <[email protected]>
dmick pushed a commit to dmick/ceph that referenced this issue May 23, 2024
from pkg_resources import packaging no longer works.  See
pypa/setuptools#4385.  Try pinning
(which will need to downgrade) here.

Signed-off-by: Dan Mick <[email protected]>
@jeffhataws
Copy link

This is also breaking PyTorch 2.1 (not PyTorch 2.2+). Will you consider adding it back?

(aws_neuron_venv_pytorch) ubuntu@ip-10-0-8-190:~$ python -c "from torch.utils import cpp_extension"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/ubuntu/aws_neuron_venv_pytorch/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 28, in <module>
    from pkg_resources import packaging  # type: ignore[attr-defined]
ImportError: cannot import name 'packaging' from 'pkg_resources' (/home/ubuntu/aws_neuron_venv_pytorch/lib/python3.8/site-packages/pkg_resources/__init__.py)

@abravalheri
Copy link
Contributor

abravalheri commented May 23, 2024

Hi @dmick , please see the explanation for the behaviour you are observing in #4376 (comment).

Tl;DR: the package you are using was relying on an internal implementation detail of pkg_resources and that implementation detail was not part of the public API.

I recommend contacting the maintainers of that package and reporting the bug on their end. The easiest way to fix this is to install and import packaging directly.

The API documentation for pkg_resources can be found in https://setuptools.pypa.io/en/latest/pkg_resources.html.

You can also check which "names" are public in the package by inspecting the __all__ property.

@abravalheri abravalheri removed bug Needs Triage Issues that need to be evaluated for severity and status. labels May 23, 2024
@abravalheri abravalheri closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2024
dmick pushed a commit to dmick/ceph that referenced this issue May 23, 2024
"from pkg_resources import packaging" no longer works.  See
pypa/setuptools#4385.  Pin setuptools
to v65.5.1 to avoid this until we can fix the various usages.

See https://tracker.ceph.com/issues/66201 for more info.

Signed-off-by: Dan Mick <[email protected]>
tchaikov added a commit to tchaikov/ceph that referenced this issue May 25, 2024
instead of relying on the internal implementation of pkg_resources,
let's import packaging directly.

in this change, we also add the dependency to the packaging module
in the packaging recipes.

See also pypa/setuptools#4385

Refs https://tracker.ceph.com/issues/66201
Signed-off-by: Kefu Chai <[email protected]>
tchaikov added a commit to tchaikov/ceph that referenced this issue May 25, 2024
instead of relying on the internal implementation of pkg_resources,
let's import packaging directly.

in this change, we also add the dependency to the packaging module
in the packaging recipes.

See also pypa/setuptools#4385

Fixes https://tracker.ceph.com/issues/66201
Signed-off-by: Kefu Chai <[email protected]>
tchaikov added a commit to tchaikov/ceph that referenced this issue May 25, 2024
instead of relying on the internal implementation of pkg_resources,
let's import packaging directly.

in this change, we also add the dependency to the packaging module
in the packaging recipes.

See also pypa/setuptools#4385

Fixes https://tracker.ceph.com/issues/66201
Signed-off-by: Kefu Chai <[email protected]>
tchaikov added a commit to ceph/ceph-ci that referenced this issue May 27, 2024
instead of relying on the internal implementation of pkg_resources,
let's import packaging directly.

in this change, we also add the dependency to the packaging module
in the packaging recipes.

See also pypa/setuptools#4385

Fixes https://tracker.ceph.com/issues/66201
Signed-off-by: Kefu Chai <[email protected]>
zdover23 pushed a commit to zdover23/ceph that referenced this issue Jun 24, 2024
instead of relying on the internal implementation of pkg_resources,
let's import packaging directly.

in this change, we also add the dependency to the packaging module
in the packaging recipes.

See also pypa/setuptools#4385

Fixes https://tracker.ceph.com/issues/66201
Signed-off-by: Kefu Chai <[email protected]>
(cherry picked from commit 844b66d)
zdover23 pushed a commit to zdover23/ceph that referenced this issue Jun 24, 2024
instead of relying on the internal implementation of pkg_resources,
let's import packaging directly.

in this change, we also add the dependency to the packaging module
in the packaging recipes.

See also pypa/setuptools#4385

Fixes https://tracker.ceph.com/issues/66201
Signed-off-by: Kefu Chai <[email protected]>
(cherry picked from commit 844b66d)
@rsxdalv
Copy link

rsxdalv commented Jul 7, 2024

Although the argument is understandable, from pkg_resources import packaging does not seem like an internal API, if it was named _packaging or otherwise it could have been easier to spot. The fact that even PyTorch missed out on this and there are countless broken projects and build pipelines will probably mean a that v70+ ends up underused.

@abravalheri
Copy link
Contributor

abravalheri commented Jul 7, 2024

@rsxdalv , that is the side effect of imports, and that is why __all__ exists. This is a well-known and documented characteristic of the Python language.

It is unfortunate that so many people missed it. But all the public names in pkg_resources have been documented on the website for years.

If people desire to use packaging, they can include it as a dependency, as it is available on the PyPI.

@rsxdalv
Copy link

rsxdalv commented Jul 8, 2024

I agree, once I realized about python imports causing a side-effect where they are automatically exported I was not very happy.
Though, outside the scope of this issue, I would like to ask you this - since this is a potentially widespread issue, would it make sense for new library packages to have an init.py which only imports the things that are to be exported or uses aliases to prevent leaks, such as import packaging as _packaging?

Alternatively, should projects have a deep-lint to check if somebody-somewhere is importing outside of all declaration?

Meanwhile, javascript has some extremely strict linting because every bad pattern (such as importing what you are not supposed to) that can be done will be done.

@abravalheri
Copy link
Contributor

abravalheri commented Jul 8, 2024

@rsxdalv I believe that every Python developer will have a different answer for that, as there are many styles and workflows for package development 😅1. I think the best is always to check for the docs of a particular project that you want to use.

You may be able to find some linters that check against "non-exported names". Maybe it is worth asking around if the ruff community has something for that? (update, it is probably under discussion: astral-sh/ruff#167).

Footnotes

  1. For example, some projects use __all__, some projects use a specific .api submodule, some projects use _impl subpackage + __init__.py... there are many variations in the ecosystem, it would be difficult to standardize one.

adk3798 pushed a commit to adk3798/ceph that referenced this issue Jul 16, 2024
instead of relying on the internal implementation of pkg_resources,
let's import packaging directly.

in this change, we also add the dependency to the packaging module
in the packaging recipes.

See also pypa/setuptools#4385

Fixes https://tracker.ceph.com/issues/66201
Signed-off-by: Kefu Chai <[email protected]>
(cherry picked from commit 844b66d)
adk3798 pushed a commit to adk3798/ceph that referenced this issue Jul 16, 2024
instead of relying on the internal implementation of pkg_resources,
let's import packaging directly.

in this change, we also add the dependency to the packaging module
in the packaging recipes.

See also pypa/setuptools#4385

Fixes https://tracker.ceph.com/issues/66201
Signed-off-by: Kefu Chai <[email protected]>
(cherry picked from commit 844b66d)
adk3798 pushed a commit to adk3798/ceph that referenced this issue Jul 16, 2024
instead of relying on the internal implementation of pkg_resources,
let's import packaging directly.

in this change, we also add the dependency to the packaging module
in the packaging recipes.

See also pypa/setuptools#4385

Fixes https://tracker.ceph.com/issues/66201
Signed-off-by: Kefu Chai <[email protected]>
(cherry picked from commit 844b66d)

Conflicts:
	debian/ceph-mgr-modules-core.requires
	src/pybind/mgr/prometheus/module.py
kshtsk pushed a commit to kshtsk/ceph that referenced this issue Jul 18, 2024
instead of relying on the internal implementation of pkg_resources,
let's import packaging directly.

in this change, we also add the dependency to the packaging module
in the packaging recipes.

See also pypa/setuptools#4385

Fixes https://tracker.ceph.com/issues/66201
Signed-off-by: Kefu Chai <[email protected]>
(cherry picked from commit 844b66d)

Conflicts:
	debian/ceph-mgr-modules-core.requires
	src/pybind/mgr/prometheus/module.py
kshtsk pushed a commit to kshtsk/ceph that referenced this issue Jul 18, 2024
instead of relying on the internal implementation of pkg_resources,
let's import packaging directly.

in this change, we also add the dependency to the packaging module
in the packaging recipes.

See also pypa/setuptools#4385

Fixes https://tracker.ceph.com/issues/66201
Signed-off-by: Kefu Chai <[email protected]>
(cherry picked from commit 844b66d)

Conflicts:
	debian/ceph-mgr-modules-core.requires
	src/pybind/mgr/prometheus/module.py
kshtsk pushed a commit to kshtsk/ceph that referenced this issue Jul 21, 2024
instead of relying on the internal implementation of pkg_resources,
let's import packaging directly.

in this change, we also add the dependency to the packaging module
in the packaging recipes.

See also pypa/setuptools#4385

Fixes https://tracker.ceph.com/issues/66201
Signed-off-by: Kefu Chai <[email protected]>
(cherry picked from commit 844b66d)

Conflicts:
	debian/ceph-mgr-modules-core.requires
	src/pybind/mgr/prometheus/module.py
kshtsk pushed a commit to kshtsk/ceph that referenced this issue Jul 21, 2024
instead of relying on the internal implementation of pkg_resources,
let's import packaging directly.

in this change, we also add the dependency to the packaging module
in the packaging recipes.

See also pypa/setuptools#4385

Fixes https://tracker.ceph.com/issues/66201
Signed-off-by: Kefu Chai <[email protected]>
(cherry picked from commit 844b66d)

Conflicts:
	debian/ceph-mgr-modules-core.requires
	src/pybind/mgr/prometheus/module.py
kshtsk pushed a commit to kshtsk/ceph that referenced this issue Jul 21, 2024
instead of relying on the internal implementation of pkg_resources,
let's import packaging directly.

in this change, we also add the dependency to the packaging module
in the packaging recipes.

See also pypa/setuptools#4385

Fixes https://tracker.ceph.com/issues/66201
Signed-off-by: Kefu Chai <[email protected]>
(cherry picked from commit 844b66d)

Conflicts:
	debian/ceph-mgr-modules-core.requires
	src/pybind/mgr/prometheus/module.py
kshtsk pushed a commit to kshtsk/ceph that referenced this issue Jul 21, 2024
instead of relying on the internal implementation of pkg_resources,
let's import packaging directly.

in this change, we also add the dependency to the packaging module
in the packaging recipes.

See also pypa/setuptools#4385

Fixes https://tracker.ceph.com/issues/66201
Signed-off-by: Kefu Chai <[email protected]>
(cherry picked from commit 844b66d)

Conflicts:
	debian/ceph-mgr-modules-core.requires
	src/pybind/mgr/prometheus/module.py
adk3798 pushed a commit to ceph/ceph-ci that referenced this issue Jul 24, 2024
instead of relying on the internal implementation of pkg_resources,
let's import packaging directly.

in this change, we also add the dependency to the packaging module
in the packaging recipes.

See also pypa/setuptools#4385

Fixes https://tracker.ceph.com/issues/66201
Signed-off-by: Kefu Chai <[email protected]>
(cherry picked from commit 844b66d)

Conflicts:
	debian/ceph-mgr-modules-core.requires
	src/pybind/mgr/prometheus/module.py
(cherry picked from commit 28f69d6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants