setuptools: [BUG] packages of the form package.something renamed to package_something in 75.8.1

setuptools version

setuptools==75.8.1

Python version

python3.10

OS

windows

Additional environment information

Description

We have packages using pyproject.toml of the form:

something.module that use implicit namespaces for something

The latest 75.8.1 seems to rename the something.module-1.2.3.dist-info to be instead: something_module-1.2.3.dist-info

rolling back to 75.8.0 this problem does not exist.

This breaks folks using something of the form pkg_resources.require('something.module') as it now only works if they have pkg_resources.require('something-module')

Expected behavior

packages should continue to have the something.module form

How to Reproduce

git clone https://github.com/krpatter-intc/setuptools-example.git
cd setuptools-example
python -m build

And you’ll note the naming difference in the wheel (and the .dist-info file)

You can then run:

import pkg_resources
pkg_resources.require("something.module") # this now throws an exception

Output


I’m aware pkg_resources is on its way out, but this still feels bad that the package has a new name. I’m not sure what the new equivalent/replacement for pkg_resources.require is.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 28 (11 by maintainers)

Commits related to this issue

Most upvoted comments

I confirmed that this is a bug that exists in importlib.metadata provided in Python 3.9 (all the way up to 3.9.16) that is fixed in Python 3.10 (starting at 3.10.0).

Looks like this was fixed in https://pypi.org/project/importlib-metadata/2.1.0/ and https://pypi.org/project/importlib-metadata/3.1.0/. The entry at https://github.com/python/importlib_metadata/blob/main/NEWS.rst#v210 says:

#253: When querying for package metadata, the lookup now honors package normalization rules.

@Zoltag Note that if you’re unable to upgrade your Python version and instead installing importlib_metadata from PyPI, you need to make the following change to your file:

- from importlib.metadata import version
+ from importlib_metadata import version

Same issue here. All our jobs are broken since yesterday because of this change. Any workaround for that? What is weird is that I tried to pin setuptools to older versions, and it doesn’t help 😦

This issue sounds relevant to what we’re experiencing.

We started getting Docker image runtime failures today (very unusual), where as far as we can tell the only difference is setuptools version 75.8.0 versus 75.8.1.

...
File "/opt/venv/lib/python3.11/site-packages/paste/deploy/loadwsgi.py", line 410, in get_context
return loadcontext(object_type, name,
File "/opt/venv/lib/python3.11/site-packages/paste/deploy/loadwsgi.py", line 299, in loadcontext
return _loaders[scheme](
File "/opt/venv/lib/python3.11/site-packages/paste/deploy/loadwsgi.py", line 334, in _loadegg
return loader.get_context(object_type, name, global_conf)
File "/opt/venv/lib/python3.11/site-packages/paste/deploy/loadwsgi.py", line 624, in get_context
entry_point, protocol, ep_name = self.find_egg_entry_point(
File "/opt/venv/lib/python3.11/site-packages/paste/deploy/loadwsgi.py", line 645, in find_egg_entry_point
pkg_resources.require(self.spec)
File "/opt/venv/lib/python3.11/site-packages/pkg_resources/__init__.py", line 1061, in require
needed = self.resolve(parse_requirements(requirements))
File "/opt/venv/lib/python3.11/site-packages/pkg_resources/__init__.py", line 888, in resolve
dist = self._resolve_dist(
File "/opt/venv/lib/python3.11/site-packages/pkg_resources/__init__.py", line 929, in _resolve_dist
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'zope.interface==5.3.0' distribution was not found and is required...

Also: pkg_resources.DistributionNotFound: The 'repoze.debug==1.1' distribution was not found

So seems related to packages with . in name, and https://github.com/pypa/setuptools/issues/3777 actually mentions zope.interface so guessing it’s related.

Our solution was to bump PasteDeploy package, which apparently dropped setuptools dependency and started using importlib.metadata instead: https://docs.pylonsproject.org/projects/pastedeploy/en/latest/news.html

Not sure there is fix needed here, but commenting since this broke us in prod.

The CI is working now to release a new patched version of setuptools that should solve the problem with pkg_resources.require(...).

For people having problems with the exact name of the distribution file has changed a character to _, I recommend trying something more flexible like glob patterns/regexes or wildcards in general. Since Setuptools is required to comply with the PyPA standards, the change in the file name itself is not considered a bug.