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] vendor package typeguard installed to entrypoints #4480

Closed
hfudev opened this issue Jul 18, 2024 · 7 comments · Fixed by #4485
Closed

[BUG] vendor package typeguard installed to entrypoints #4480

hfudev opened this issue Jul 18, 2024 · 7 comments · Fixed by #4485
Assignees
Labels

Comments

@hfudev
Copy link

hfudev commented Jul 18, 2024

setuptools version

setuptools==71.0.1

Python version

python 3.8

OS

arch linux

Additional environment information

No response

Description

bug introduced by https://github.com/pypa/setuptools/compare/v71.0.1..v71.0.0#diff-50c86b7ed8ac2cf95bd48334961bf0530cdc77b5a56f852c5c61b89d735fd711R181-R183

pytest would search the plugins by the entrypoint pytest11. the vendor/typeguard got installed to the entrypoint, but without a correct metadata. Got error message

Traceback (most recent call last):
  ... unrelated ..
  File "myenv/lib/python3.8/site-packages/_pytest/config/__init__.py", line 159, in main
    config = _prepareconfig(args, plugins)
  File "myenv/lib/python3.8/site-packages/_pytest/config/__init__.py", line 346, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "myenv/lib/python3.8/site-packages/pluggy/_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "myenv/lib/python3.8/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "myenv/lib/python3.8/site-packages/pluggy/_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "myenv/lib/python3.8/site-packages/pluggy/_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "myenv/lib/python3.8/site-packages/_pytest/helpconfig.py", line 106, in pytest_cmdline_parse
    config = yield
  File "myenv/lib/python3.8/site-packages/pluggy/_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
  File "myenv/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1152, in pytest_cmdline_parse
    self.parse(args)
  File "myenv/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1501, in parse
    self._preparse(args, addopts=addopts)
  File "myenv/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1388, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "myenv/lib/python3.8/site-packages/pluggy/_manager.py", line 421, in load_setuptools_entrypoints
    plugin = ep.load()
  File "myenv/lib/python3.8/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 183, in load
    module = import_module(match.group('module'))
  File "myuser/.pyenv/versions/3.8.19/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "myenv/lib/python3.8/site-packages/setuptools/_vendor/typeguard/__init__.py", line 21, in <module>
    from ._importhook import ImportHookManager as ImportHookManager
  File "myenv/lib/python3.8/site-packages/setuptools/_vendor/typeguard/_importhook.py", line 35, in <module>
    OPTIMIZATION = "typeguard" + "".join(version("typeguard").split(".")[:3])
  File "myenv/lib/python3.8/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 982, in version
    return distribution(distribution_name).version
  File "myenv/lib/python3.8/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 475, in version
    return self.metadata['Version']
  File "myenv/lib/python3.8/site-packages/setuptools/_vendor/importlib_metadata/_adapters.py", line 54, in __getitem__
    raise KeyError(item)
KeyError: 'Version'

succeeded with version 71.0.0

Expected behavior

run successfully

How to Reproduce

as description

Output

as description

@hfudev hfudev added bug Needs Triage Issues that need to be evaluated for severity and status. labels Jul 18, 2024
@hfudev hfudev changed the title [BUG] vendor packages installed to entrypoints [BUG] vendor package typeguard installed to entrypoints Jul 18, 2024
@neutrinoceros
Copy link

I think I'm seeing another aspect of the same problem where this line

OPTIMIZATION = "typeguard" + "".join(version("typeguard").split(".")[:3])

fails with

...
  File "/Users/clm/dev/astropy-project/astropy-compatbility-checks/numpy-dev/.venv/lib/python3.12/site-packages/setuptools/_vendor/typeguard/__init__.py", line 21, in <module>
    from ._importhook import ImportHookManager as ImportHookManager
  File "/Users/clm/dev/astropy-project/astropy-compatbility-checks/numpy-dev/.venv/lib/python3.12/site-packages/setuptools/_vendor/typeguard/_importhook.py", line 35, in <module>
    OPTIMIZATION = "typeguard" + "".join(version("typeguard").split(".")[:3])
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'split'

But I'm only seeing this in the context of launching pytest in a complicated setup and I haven't found how to reproduce this simply yet.

@jaraco
Copy link
Member

jaraco commented Jul 18, 2024

Indeed, when I list the files in the wheel, I see that only the *.txt files from _vendor/*.dist-info are being included (no METADATA or RECORD or WHEEL).

I can repro the issue pretty simply:

 draft 🐚 py -m venv .venv
 draft 🐚 py -m pip install -q setuptools
 draft 🐚 py -c "import setuptools; import typeguard"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import setuptools; import typeguard
                       ^^^^^^^^^^^^^^^^
  File "/Users/jaraco/draft/.venv/lib/python3.13/site-packages/setuptools/_vendor/typeguard/__init__.py", line 21, in <module>
    from ._importhook import ImportHookManager as ImportHookManager
  File "/Users/jaraco/draft/.venv/lib/python3.13/site-packages/setuptools/_vendor/typeguard/_importhook.py", line 35, in <module>
    OPTIMIZATION = "typeguard" + "".join(version("typeguard").split(".")[:3])
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'split'

@jaraco
Copy link
Member

jaraco commented Jul 18, 2024

I've yanked 71.0.1, as it's worse than 71.0.0.

@jaraco jaraco self-assigned this Jul 18, 2024
@jaraco jaraco removed the Needs Triage Issues that need to be evaluated for severity and status. label Jul 18, 2024
megies added a commit to obspy/obspy that referenced this issue Jul 18, 2024
crashes our test runner script "obspy-runtests"

see pypa/setuptools#4480
@jaraco
Copy link
Member

jaraco commented Jul 18, 2024

Aha!

The issue is that the metadata is not included in the sdist.

Here's what's happened:

  • Prior to 70.0, Setuptools kept all of its vendored dependencies in a private namespace (under setuptools/_vendor) so it never exposed package metadata to the environment.
  • The metadata was never included, but it also was never needed.
  • In 70.0, Setuptools starts exposing those packages to the environment, including the entry points.
  • When pytest searched for entry points and the now visible typeguard provided one, it invoked new behavior in typeguard.
  • That behavior in typeguard causes a lookup of its own metadata, which is missing.

Probably, making sure all vendored metadata is in the sdist will correct the issue.

@jaraco
Copy link
Member

jaraco commented Jul 18, 2024

This issue would not have occurred if setuptools was using setuptools_scm for source code discovery.

I've confirmed that the failing test now passes when including all files from the vendored dependencies.

@zzacharo
Copy link

zzacharo commented Jul 18, 2024

Confirming that the latest patch 71.0.2 fixes the issue, see invenio-opendefinition:

@hfudev
Copy link
Author

hfudev commented Jul 19, 2024

Thanks a lot for the fix :D

espressif-bot pushed a commit to espressif/esp-idf that referenced this issue Aug 6, 2024
Currently, when the venv is installed or updated, we attempt to
automatically update pip and setuptools within the venv. Unfortunately,
the setuptools package is installed or updated without adhering to the
constraints file, which restricts the setuptools version due to
pypa/setuptools#4480. Resolve this issue by
applying the constraints file to the installation and update of both pip
and setuptools.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
espressif-bot pushed a commit to espressif/esp-idf that referenced this issue Aug 6, 2024
Currently, when the venv is installed or updated, we attempt to
automatically update pip and setuptools within the venv. Unfortunately,
the setuptools package is installed or updated without adhering to the
constraints file, which restricts the setuptools version due to
pypa/setuptools#4480. Resolve this issue by
applying the constraints file to the installation and update of both pip
and setuptools.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
espressif-bot pushed a commit to espressif/esp-idf that referenced this issue Aug 7, 2024
Currently, when the venv is installed or updated, we attempt to
automatically update pip and setuptools within the venv. Unfortunately,
the setuptools package is installed or updated without adhering to the
constraints file, which restricts the setuptools version due to
pypa/setuptools#4480. Resolve this issue by
applying the constraints file to the installation and update of both pip
and setuptools.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
espressif-bot pushed a commit to espressif/esp-idf that referenced this issue Aug 7, 2024
Currently, when the venv is installed or updated, we attempt to
automatically update pip and setuptools within the venv. Unfortunately,
the setuptools package is installed or updated without adhering to the
constraints file, which restricts the setuptools version due to
pypa/setuptools#4480. Resolve this issue by
applying the constraints file to the installation and update of both pip
and setuptools.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
espressif-bot pushed a commit to espressif/esp-idf that referenced this issue Aug 19, 2024
Currently, when the venv is installed or updated, we attempt to
automatically update pip and setuptools within the venv. Unfortunately,
the setuptools package is installed or updated without adhering to the
constraints file, which restricts the setuptools version due to
pypa/setuptools#4480. Resolve this issue by
applying the constraints file to the installation and update of both pip
and setuptools.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants