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] Setuptools 71.0.1 provides only partial metadata for its vendored dependencies #4482

Closed
rokm opened this issue Jul 18, 2024 · 1 comment

Comments

@rokm
Copy link

rokm commented Jul 18, 2024

setuptools version

71.0.1

Python version

tested with 3.12, but applies to any supported version

OS

tested on linux, but applies to any OS

Additional environment information

No response

Description

Setuptools 71.0.1 provides only partial metadata for its vendored dependencies, which causes issues with code that expects to be dealing with original upstream dists (for example, to query versions of importlib-resources or importlib-metadata).

This applies both to the wheel and the sdist archive found on PyPI.

I assume this is a packaging oversight, because git repository seems to contain full metadata for those dependencies (example).

Expected behavior

Complete metadata to be included for vendored dependencies, since they seem to be visible to the outside world now.

How to Reproduce

Consider the following example program:

# Suppose we are importing a 3rd party package here that (conditionally)
# imports setuptools, without us being aware of it.
try:
    import setuptools
except Exception:
    pass

# Try to see if we have importlib_metadata available
try:
    import importlib_metadata
except ImportError:
    importlib_metadata = None


# Check importlib_metadata version
if importlib_metadata:
    dist = importlib_metadata.distribution('importlib-metadata')
    version = dist.version
    print(f"Version: {version}")  # Do something with version
else:
    print("Not available.")

Output

If ran in virtual environment without importlib-metadata and without setuptools installed:

$ python example.py 
Not available.

If ran in virtual environment with latest importlib-metadata installed but setuptools not installed:

$ python example.py 
Version: 8.0.0

If ran in virtual environment without importlib-metadata installed and with setuptools 70.3.0 installed:

$ python example.py 
Not available.

If ran in virtual environment without importlib-metadata installed and with setuptools 71.0.0 installed:

Traceback (most recent call last):
  File "/home/rok/venv/lib64/python3.12/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 391, in from_name
    return next(iter(cls.discover(name=name)))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/rok/example.py", line 17, in <module>
    dist = importlib_metadata.distribution('importlib-metadata')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rok/venv/lib64/python3.12/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 950, in distribution
    return Distribution.from_name(distribution_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rok/venv/lib64/python3.12/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 393, in from_name
    raise PackageNotFoundError(name)
importlib_metadata.PackageNotFoundError: No package metadata was found for importlib-metadata

This happens because 70.0.0 does not provide any metadata for its vendored dependencies:

$ ls venv/lib/python3.12/site-packages/setuptools/_vendor/
autocommand  backports  importlib_metadata  importlib_resources  inflect  jaraco  more_itertools  ordered_set  packaging  platformdirs  __pycache__  tomli  typeguard  typing_extensions.py  wheel  zipp

This is also the cause of #4477.


If ran in virtual environment without importlib-metadata installed and with setuptools 71.0.1 installed:

Traceback (most recent call last):
  File "/home/rok/example.py", line 18, in <module>
    version = dist.version
              ^^^^^^^^^^^^
  File "/home/rok/venv/lib64/python3.12/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 470, in version
    return self.metadata['Version']
           ~~~~~~~~~~~~~^^^^^^^^^^^
  File "/home/rok/venv/lib64/python3.12/site-packages/setuptools/_vendor/importlib_metadata/_adapters.py", line 54, in __getitem__
    raise KeyError(item)
KeyError: 'Version'

The metadata is now seemingly provided

$ ls venv/lib/python3.12/site-packages/setuptools/_vendor/
autocommand                  backports.tarfile-1.2.0.dist-info   importlib_resources                  inflect-7.3.1.dist-info         jaraco.functools-4.0.1.dist-info  ordered_set   __pycache__  typeguard-4.3.0.dist-info  wheel-0.43.0.dist-info
autocommand-2.2.2.dist-info  importlib_metadata                  importlib_resources-6.4.0.dist-info  jaraco                          jaraco.text-3.12.1.dist-info      packaging     tomli        typing_extensions.py       zipp
backports                    importlib_metadata-8.0.0.dist-info  inflect                              jaraco.context-5.3.0.dist-info  more_itertools                    platformdirs  typeguard    wheel                      zipp-3.19.2.dist-info

but it is incomplete, and hence cannot be used to obtain version:

venv/lib/python3.12/site-packages/setuptools/_vendor/autocommand-2.2.2.dist-info:
top_level.txt

venv/lib/python3.12/site-packages/setuptools/_vendor/backports.tarfile-1.2.0.dist-info:
top_level.txt

venv/lib/python3.12/site-packages/setuptools/_vendor/importlib_metadata-8.0.0.dist-info:
top_level.txt

venv/lib/python3.12/site-packages/setuptools/_vendor/importlib_resources-6.4.0.dist-info:
top_level.txt

venv/lib/python3.12/site-packages/setuptools/_vendor/inflect-7.3.1.dist-info:
top_level.txt

venv/lib/python3.12/site-packages/setuptools/_vendor/jaraco.context-5.3.0.dist-info:
top_level.txt

venv/lib/python3.12/site-packages/setuptools/_vendor/jaraco.functools-4.0.1.dist-info:
top_level.txt

venv/lib/python3.12/site-packages/setuptools/_vendor/jaraco.text-3.12.1.dist-info:
top_level.txt

venv/lib/python3.12/site-packages/setuptools/_vendor/typeguard-4.3.0.dist-info:
entry_points.txt  top_level.txt

venv/lib/python3.12/site-packages/setuptools/_vendor/wheel-0.43.0.dist-info:
entry_points.txt  LICENSE.txt

venv/lib/python3.12/site-packages/setuptools/_vendor/zipp-3.19.2.dist-info:
top_level.txt

#4480 is likely related to this as well.

@rokm rokm added bug Needs Triage Issues that need to be evaluated for severity and status. labels Jul 18, 2024
rouault added a commit to rouault/gdal that referenced this issue Jul 18, 2024
Fixes following error:
```
Traceback (most recent call last):
  File "/home/runner/work/gdal/gdal/superbuild/build/gdal/swig/python/setup.py", line 15, in <module>
    from setuptools.command.build_ext import build_ext
  File "/home/runner/.local/lib/python3.8/site-packages/setuptools/__init__.py", line 19, in <module>
    from .dist import Distribution
  File "/home/runner/.local/lib/python3.8/site-packages/setuptools/dist.py", line 30, in <module>
    from . import _entry_points
  File "/home/runner/.local/lib/python3.8/site-packages/setuptools/_entry_points.py", line 44, in <module>
    def validate(eps: metadata.EntryPoints):
AttributeError: module 'importlib_metadata' has no attribute 'EntryPoints'
CMake Error at build_ext.cmake:5 (message):
  setup.py bdist_wheel failed
```

Likely related to similar pypa/setuptools#4482
rouault added a commit to rouault/gdal that referenced this issue Jul 18, 2024
Fixes following error:
```
Traceback (most recent call last):
  File "/home/runner/work/gdal/gdal/superbuild/build/gdal/swig/python/setup.py", line 15, in <module>
    from setuptools.command.build_ext import build_ext
  File "/home/runner/.local/lib/python3.8/site-packages/setuptools/__init__.py", line 19, in <module>
    from .dist import Distribution
  File "/home/runner/.local/lib/python3.8/site-packages/setuptools/dist.py", line 30, in <module>
    from . import _entry_points
  File "/home/runner/.local/lib/python3.8/site-packages/setuptools/_entry_points.py", line 44, in <module>
    def validate(eps: metadata.EntryPoints):
AttributeError: module 'importlib_metadata' has no attribute 'EntryPoints'
CMake Error at build_ext.cmake:5 (message):
  setup.py bdist_wheel failed
```

Likely related to similar pypa/setuptools#4482
@jaraco
Copy link
Member

jaraco commented Jul 18, 2024

Thanks for the report. This is essentially a dupe of #4480. Thanks for the extra context.

@jaraco jaraco closed this as completed Jul 18, 2024
@jaraco jaraco added duplicate and removed Needs Triage Issues that need to be evaluated for severity and status. labels Jul 18, 2024
rouault added a commit to OSGeo/gdal that referenced this issue Jul 18, 2024
Fixes following error:
```
Traceback (most recent call last):
  File "/home/runner/work/gdal/gdal/superbuild/build/gdal/swig/python/setup.py", line 15, in <module>
    from setuptools.command.build_ext import build_ext
  File "/home/runner/.local/lib/python3.8/site-packages/setuptools/__init__.py", line 19, in <module>
    from .dist import Distribution
  File "/home/runner/.local/lib/python3.8/site-packages/setuptools/dist.py", line 30, in <module>
    from . import _entry_points
  File "/home/runner/.local/lib/python3.8/site-packages/setuptools/_entry_points.py", line 44, in <module>
    def validate(eps: metadata.EntryPoints):
AttributeError: module 'importlib_metadata' has no attribute 'EntryPoints'
CMake Error at build_ext.cmake:5 (message):
  setup.py bdist_wheel failed
```

Likely related to similar pypa/setuptools#4482
bashonly added a commit to yt-dlp/yt-dlp that referenced this issue Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants