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] vendored importlib.metadata of setuptools 60.9.0 fails with 'PathDistribution' object has no attribute '_normalized_name' #3102

Closed
kasium opened this issue Feb 14, 2022 · 6 comments · Fixed by #3108
Assignees
Labels
bug Needs Implementation Issues that are ready to be implemented. Needs Investigation Issues which are likely in scope but need investigation to figure out the cause

Comments

@kasium
Copy link

kasium commented Feb 14, 2022

setuptools version

setuptools==60.9.0

Python version

3.7.1

OS

Linux

Additional environment information

Pip freeze

argcomplete==1.12.3
colorlog==6.6.0
distlib==0.3.4
filelock==3.4.2
importlib-metadata==4.2.0
nox==2022.1.7
packaging==21.3
pip==22.0.3
platformdirs==2.5.0
py==1.11.0
pyparsing==3.0.7
setuptools==60.9.0
six==1.16.0
typing_extensions==4.1.1
virtualenv==20.13.1
wheel==0.37.1
zipp==3.7.0

Description

If I use the below python dependencies (mainly virtualenv, setuptools and importlib.metadata), setuptools fails with an error.

It works fine with the previous version of setuptools and newer versions of importlib.metadata. It seems like, that the current vendored version of importlib.metadata is not compatible with my environment.

Expected behavior

It should work fine

How to Reproduce

  1. Install the above dependencies
  2. Run nox -s

Output

Traceback (most recent call last):
  File "/usr/lib64/python3.7/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib64/python3.7/runpy.py", line 142, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/lib64/python3.7/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/root/git/empty_test/venv/lib/python3.7/site-packages/virtualenv/__init__.py", line 3, in <module>
    from .run import cli_run, session_via_cli
  File "/root/git/empty_test/venv/lib/python3.7/site-packages/virtualenv/run/__init__.py", line 14, in <module>
    from .plugin.creators import CreatorSelector
  File "/root/git/empty_test/venv/lib/python3.7/site-packages/virtualenv/run/plugin/creators.py", line 6, in <module>
    from virtualenv.create.via_global_ref.builtin.builtin_way import VirtualenvBuiltin
  File "/root/git/empty_test/venv/lib/python3.7/site-packages/virtualenv/create/via_global_ref/builtin/builtin_way.py", line 7, in <module>
    from virtualenv.create.creator import Creator
  File "/root/git/empty_test/venv/lib/python3.7/site-packages/virtualenv/create/creator.py", line 15, in <module>
    from virtualenv.discovery.cached_py_info import LogCmd
  File "/root/git/empty_test/venv/lib/python3.7/site-packages/virtualenv/discovery/cached_py_info.py", line 23, in <module>
    _CACHE[Path(sys.executable)] = PythonInfo()
  File "/root/git/empty_test/venv/lib/python3.7/site-packages/virtualenv/discovery/py_info.py", line 86, in __init__
    self.distutils_install = {u(k): u(v) for k, v in self._distutils_install().items()}
  File "/root/git/empty_test/venv/lib/python3.7/site-packages/virtualenv/discovery/py_info.py", line 152, in _distutils_install
    d = dist.Distribution({"script_args": "--no-user-cfg"})  # conf files not parsed so they do not hijack paths
  File "/root/git/empty_test/venv/lib/python3.7/site-packages/setuptools/dist.py", line 456, in __init__
    for ep in metadata.entry_points(group='distutils.setup_keywords'):
  File "/root/git/empty_test/venv/lib/python3.7/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 1003, in entry_points
    return SelectableGroups.load(eps).select(**params)
  File "/root/git/empty_test/venv/lib/python3.7/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 453, in load
    ordered = sorted(eps, key=by_group)
  File "/root/git/empty_test/venv/lib/python3.7/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 1001, in <genexpr>
    dist.entry_points for dist in unique(distributions())
  File "/root/git/empty_test/venv/lib/python3.7/site-packages/setuptools/_vendor/importlib_metadata/_itertools.py", line 16, in unique_everseen
    k = key(element)
AttributeError: 'PathDistribution' object has no attribute '_normalized_name'
@kasium kasium added bug Needs Triage Issues that need to be evaluated for severity and status. labels Feb 14, 2022
@kasium
Copy link
Author

kasium commented Feb 14, 2022

I'm very sorry if this belongs to nox or virtualenv, but I have no clue where to start

@armanckeser
Copy link

armanckeser commented Feb 14, 2022

I have the same issue, the setup is failing python 3.7.1 with poetry

@mardiros
Copy link

Same issue, running Python 3.7.3 and poetry@latest.

Downgrade to setuptools==60.8.2 fix the issue.

@zanieb
Copy link

zanieb commented Feb 14, 2022

I'm also encountering this when using the latest virtualenv with setuptools==60.9.0 on Python 3.7. No issues on later Python versions. Let me know if more information would be helpful!

wmfgerrit pushed a commit to wikimedia/wikimedia-toolhub that referenced this issue Feb 14, 2022
Work around <pypa/setuptools#3102> by pinning
our base image to a version known to have a working cached layer for the
Blubber generated `RUN python3 "-m" "easy_install" "pip" && python3 "-m"
"pip" "install" "-U" "setuptools" "wheel" "tox" "pip"` instruction.

In the .pipeline/*.Dockerfile files that we generate and commit based on
Blubber builds we also manually add `setuptools!=60.9.0` constraints so
that the broken package will not be installed locally where we cannot
know what cached layers may be available.

This is a temporary rather than long term solution, but hopefully it
will get CI and local dev working for folks again until a better
solution is found.

Bug: T301690
Change-Id: I2ca341350b3295500a88c0b14990c35a28aa30eb
jcugat added a commit to jcugat/django-custom-user that referenced this issue Feb 14, 2022
jcugat added a commit to jcugat/django-custom-user that referenced this issue Feb 14, 2022
jcugat added a commit to jcugat/django-custom-user that referenced this issue Feb 14, 2022
@jaraco jaraco self-assigned this Feb 14, 2022
@jaraco
Copy link
Member

jaraco commented Feb 14, 2022

I was able to replicate the error with these steps:

draft $ python3.9 -m venv env
draft $ env/bin/pip install -q -U pip setuptools
draft $ env/bin/pip install importlib_metadata==4.2.0
draft $ env/bin/python
Python 3.9.6 (v3.9.6:db3ff76da1, Jun 28 2021, 11:14:58) 
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import importlib_metadata
>>> from setuptools._importlib import metadata as md
>>> md.entry_points(group='distutils.setup_keywords')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jaraco/draft/env/lib/python3.9/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 1003, in entry_points
    return SelectableGroups.load(eps).select(**params)
  File "/Users/jaraco/draft/env/lib/python3.9/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 453, in load
    ordered = sorted(eps, key=by_group)
  File "/Users/jaraco/draft/env/lib/python3.9/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 1000, in <genexpr>
    eps = itertools.chain.from_iterable(
  File "/Users/jaraco/draft/env/lib/python3.9/site-packages/setuptools/_vendor/importlib_metadata/_itertools.py", line 16, in unique_everseen
    k = key(element)
AttributeError: 'PathDistribution' object has no attribute '_normalized_name'

The issue is that importlib_metadata is expected to exist at exactly one version, but now that there's a vendored copy in Setuptools, one could encounter multiple, perhaps incompatible versions. The Distribution._normalized_name property was added in importlib_metadata 4.3, so the presence of importlib_metadata 4.2 causes its MetadataPathFinder to be installed and thus for Distribution objects without _normalized_name property to be provided.

It's not yet obvious to me what the right fix is going to be.

I would not expect the issue to affect Python 3.10 or later, as in that case, vendored importlib_metadata is not used.

@jaraco jaraco added Needs Discussion Issues where the implementation still needs to be discussed. Needs Implementation Issues that are ready to be implemented. Needs Investigation Issues which are likely in scope but need investigation to figure out the cause and removed Needs Triage Issues that need to be evaluated for severity and status. Needs Discussion Issues where the implementation still needs to be discussed. labels Feb 14, 2022
jaraco added a commit that referenced this issue Feb 15, 2022
jaraco added a commit that referenced this issue Feb 15, 2022
@jaraco
Copy link
Member

jaraco commented Feb 15, 2022

I can confirm that the proposed (ugly) workaround does address the issue:

draft $ env/bin/pip install -q git+https://github.com/pypa/setuptools@bugfix/3102-old-metadata-conflict
draft $ env/bin/pip install -q importlib_metadata==4.2
draft $ env/bin/python -c "import importlib_metadata; from setuptools._importlib import metadata as md; md.entry_points(group='distutils.setup_keywords')"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Needs Implementation Issues that are ready to be implemented. Needs Investigation Issues which are likely in scope but need investigation to figure out the cause
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants