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] AttributeError: 'str' object has no attribute 'name' with setuptools 60.9.1+ #3293

Closed
edmorley opened this issue Apr 28, 2022 · 4 comments · Fixed by #3296
Closed

[BUG] AttributeError: 'str' object has no attribute 'name' with setuptools 60.9.1+ #3293

edmorley opened this issue Apr 28, 2022 · 4 comments · Fixed by #3296
Labels
bug Needs Triage Issues that need to be evaluated for severity and status.

Comments

@edmorley
Copy link
Contributor

edmorley commented Apr 28, 2022

setuptools version

setuptools==62.1.0 (however the earliest affected version is setuptools==60.9.1)

Python version

Python 3.9 (though 3.7 and 3.8 are also affected)

OS

Docker image python:3.9.12 which is Debian 11 (it also occurs on Ubuntu on Heroku)

Additional environment information

importlib-metadata==0.20

Description

Between setuptools 60.9.0 and 60.9.1, a previously working project now encounters an error during the python setup.py egg_info phase of pip install:

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [22 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 14, in <module>
        File "/usr/local/lib/python3.9/site-packages/setuptools/__init__.py", line 18, in <module>
          from setuptools.dist import Distribution
        File "/usr/local/lib/python3.9/site-packages/setuptools/dist.py", line 35, in <module>
          from ._importlib import metadata
        File "/usr/local/lib/python3.9/site-packages/setuptools/_importlib.py", line 28, in <module>
          disable_importlib_metadata_finder(metadata)
        File "/usr/local/lib/python3.9/site-packages/setuptools/_importlib.py", line 12, in disable_importlib_metadata_finder
          import importlib_metadata
        File "/usr/local/lib/python3.9/site-packages/importlib_metadata/__init__.py", line 490, in <module>
          __version__ = version(__name__)
        File "/usr/local/lib/python3.9/site-packages/importlib_metadata/__init__.py", line 457, in version
          return distribution(package).version
        File "/usr/local/lib/python3.9/site-packages/importlib_metadata/__init__.py", line 430, in distribution
          return Distribution.from_name(package)
        File "/usr/local/lib/python3.9/site-packages/importlib_metadata/__init__.py", line 179, in from_name
          dists = resolver(name)
        File "/usr/local/lib/python3.9/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 886, in find_distributions
          found = self._search_paths(context.name, context.path)
      AttributeError: 'str' object has no attribute 'name'

The changes between those two setuptools versions are:
v60.9.0...v60.9.1

In addition to the workaround of downgrading setuptools to 60.9.0, I also found that making any of the following changes prevents the error from occurring:

  • Upgrading Python to 3.10 (it only seems to affect <=3.9)
  • Upgrading importlib-metadata from 0.20 to 0.21+ (changelog)

It looks like the two copies of importlib-metadata (the older one in the environment, and the newer one vendored in setuptools) are inadvertently interacting.

I'm presuming the root cause of this and #3292 are similar/the same, however filing separately in case they are not (particularly given one is build-time, the other run-time etc).

Expected behavior

Either:

  1. The python setup.py egg_info phase of pip install succeeds with newer versions of setuptools, as it did before.
  2. Or, setuptools outputs a warning/error to make debugging this easier, or otherwise blocks usage with incompatible importlib-metadata versions.

How to Reproduce

  1. docker run --rm -it python:3.9.12 bash
  2. mkdir -p testcase/mypackage && touch testcase/mypackage/__init__.py
  3. echo 'from setuptools import setup; setup(name="mypackage", version="0.0.1", packages=["mypackage"])' > testcase/setup.py
  4. pip install setuptools==62.1.0
  5. pip install importlib-metadata==0.20
  6. pip install ./testcase

Output

$ docker run --rm -it python:3.9.12 bash
...
root@f2eceebb1668:/# mkdir -p testcase/mypackage && touch testcase/mypackage/__init__.py
root@f2eceebb1668:/# echo 'from setuptools import setup; setup(name="mypackage", version="0.0.1", packages=["mypackage"])' > testcase/setup.py
root@f2eceebb1668:/# pip install setuptools==62.1.0
...
Successfully installed setuptools-62.1.0
root@f2eceebb1668:/# pip install importlib-metadata==0.20
...
Successfully installed importlib-metadata-0.20 zipp-3.8.0

root@f2eceebb1668:/# pip install ./testcase
Processing /testcase
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [22 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 14, in <module>
        File "/usr/local/lib/python3.9/site-packages/setuptools/__init__.py", line 18, in <module>
          from setuptools.dist import Distribution
        File "/usr/local/lib/python3.9/site-packages/setuptools/dist.py", line 35, in <module>
          from ._importlib import metadata
        File "/usr/local/lib/python3.9/site-packages/setuptools/_importlib.py", line 28, in <module>
          disable_importlib_metadata_finder(metadata)
        File "/usr/local/lib/python3.9/site-packages/setuptools/_importlib.py", line 12, in disable_importlib_metadata_finder
          import importlib_metadata
        File "/usr/local/lib/python3.9/site-packages/importlib_metadata/__init__.py", line 490, in <module>
          __version__ = version(__name__)
        File "/usr/local/lib/python3.9/site-packages/importlib_metadata/__init__.py", line 457, in version
          return distribution(package).version
        File "/usr/local/lib/python3.9/site-packages/importlib_metadata/__init__.py", line 430, in distribution
          return Distribution.from_name(package)
        File "/usr/local/lib/python3.9/site-packages/importlib_metadata/__init__.py", line 179, in from_name
          dists = resolver(name)
        File "/usr/local/lib/python3.9/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 886, in find_distributions
          found = self._search_paths(context.name, context.path)
      AttributeError: 'str' object has no attribute 'name'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.
@edmorley edmorley added bug Needs Triage Issues that need to be evaluated for severity and status. labels Apr 28, 2022
@abravalheri abravalheri linked a pull request Apr 29, 2022 that will close this issue
2 tasks
midnightercz added a commit to release-engineering/pubtools-iib that referenced this issue Apr 29, 2022
@abravalheri
Copy link
Contributor

With PR #3296 we would have the following:

> docker run --rm -it python:3.9.12 bash
mkdir -p testcase/mypackage && touch testcase/mypackage/__init__.py
echo 'from setuptools import setup; setup(name="mypackage", version="0.0.1", packages=["mypackage"])' > testcase/setup.py
pip install 'setuptools @ git+https://github.com/abravalheri/setuptools@issue-3292'
pip install importlib-metadata==0.20
pip install ./testcase
Processing /testcase
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [25 lines of output]
      /usr/local/lib/python3.9/site-packages/setuptools/_importlib.py:23: UserWarning: `importlib-metadata` version is incompatible with `setuptools`.
      This problem is likely to be solved by installing an updated version of `importlib-metadata`.
        warnings.warn(msg)  # Ensure a descriptive message is shown.
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 14, in <module>
        File "/usr/local/lib/python3.9/site-packages/setuptools/__init__.py", line 18, in <module>
          from setuptools.dist import Distribution
        File "/usr/local/lib/python3.9/site-packages/setuptools/dist.py", line 35, in <module>
          from ._importlib import metadata
        File "/usr/local/lib/python3.9/site-packages/setuptools/_importlib.py", line 39, in <module>
          disable_importlib_metadata_finder(metadata)
        File "/usr/local/lib/python3.9/site-packages/setuptools/_importlib.py", line 12, in disable_importlib_metadata_finder
          import importlib_metadata
        File "/usr/local/lib/python3.9/site-packages/importlib_metadata/__init__.py", line 490, in <module>
          __version__ = version(__name__)
        File "/usr/local/lib/python3.9/site-packages/importlib_metadata/__init__.py", line 457, in version
          return distribution(package).version
        File "/usr/local/lib/python3.9/site-packages/importlib_metadata/__init__.py", line 430, in distribution
          return Distribution.from_name(package)
        File "/usr/local/lib/python3.9/site-packages/importlib_metadata/__init__.py", line 179, in from_name
          dists = resolver(name)
        File "/usr/local/lib/python3.9/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 886, in find_distributions
          found = self._search_paths(context.name, context.path)
      AttributeError: 'str' object has no attribute 'name'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

This solution is also not ideal, but the users would at least be able to see a message in the traceback advising to update importlib-metadata.

@mihaimaruseac
Copy link

This is currently blocking TensorFlow releases.

@abravalheri
Copy link
Contributor

Hi @mihaimaruseac, I can merge #3296 soon if that helps, however that solution will improve the error message and point out to the user how they can solve the problem (i.e. update importlib-metadata).

Does that improve your workflow?
(Please note that you can importlib-metadata today, without waiting for #3296 to be merged).

@mihaimaruseac
Copy link

Thank you for the hint. We'll try upgrading importlib-metadata, it seems our only breaking job uses a very old version (all passing ones are using upgraded version).

mihaimaruseac added a commit to tensorflow/tensorflow that referenced this issue May 11, 2022
mihaimaruseac added a commit to tensorflow/tensorflow that referenced this issue May 11, 2022
mihaimaruseac added a commit to tensorflow/tensorflow that referenced this issue May 11, 2022
mruffalo added a commit to hubmapconsortium/ingest-validation-tests that referenced this issue May 12, 2022
mruffalo added a commit to hubmapconsortium/ingest-validation-tests that referenced this issue May 12, 2022
Newer versions have at least one bug under old Python, as per
pypa/setuptools#3293
mihaimaruseac added a commit to tensorflow/tensorflow that referenced this issue May 13, 2022
smartin015 added a commit to smartin015/continuousprint that referenced this issue May 15, 2022
s3bw added a commit to s3bw/py-envconfig that referenced this issue May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Needs Triage Issues that need to be evaluated for severity and status.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants