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

[Forward compatibility][BUG] pkg_resources.extern.VendorImporter lacks find_spec() method #2632

Closed
hroncok opened this issue Apr 8, 2021 · 6 comments · Fixed by #2633
Closed
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

@hroncok
Copy link
Contributor

hroncok commented Apr 8, 2021

setuptools version

54.1.2 and main

Python version

3.10.0a7

OS

All

Additional environment information

When running tests for setuptools_scm.

Description

We get:

<frozen importlib._bootstrap>:933: in _find_spec
    ???
E   AttributeError: 'VendorImporter' object has no attribute 'find_spec'

During handling of the above exception, another exception occurred:
/usr/lib/python3.10/site-packages/pluggy/hooks.py:286: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
/usr/lib/python3.10/site-packages/pluggy/manager.py:93: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
/usr/lib/python3.10/site-packages/pluggy/manager.py:84: in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
/usr/lib/python3.10/site-packages/_pytest/doctest.py:129: in pytest_collect_file
    elif _is_doctest(config, path, parent):
/usr/lib/python3.10/site-packages/_pytest/doctest.py:147: in _is_doctest
    if path.check(fnmatch=glob):
/usr/lib/python3.10/site-packages/py/_path/local.py:387: in check
    return super(LocalPath, self).check(**kw)
/usr/lib/python3.10/site-packages/py/_path/common.py:241: in check
    return self.Checkers(self)._evaluate(kw)
/usr/lib/python3.10/site-packages/py/_path/common.py:108: in _evaluate
    if py.code.getrawcode(meth).co_argcount > 1:
/usr/lib/python3.10/site-packages/py/_vendored_packages/apipkg/__init__.py:152: in __makeattr
    result = importobj(modpath, attrname)
/usr/lib/python3.10/site-packages/py/_vendored_packages/apipkg/__init__.py:72: in importobj
    module = __import__(modpath, None, None, ['__doc__'])
/usr/lib/python3.10/site-packages/py/_code/code.py:7: in <module>
    reprlib = py.builtin._tryimport('repr', 'reprlib')
/usr/lib/python3.10/site-packages/py/_builtin.py:144: in _tryimport
    __import__(name)
<frozen importlib._bootstrap>:1021: in _find_and_load
    ???
<frozen importlib._bootstrap>:996: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:935: in _find_spec
    ???
<frozen importlib._bootstrap>:908: in _find_spec_legacy
    ???
E   ImportWarning: VendorImporter.find_spec() not found; falling back to find_module()

The traceback is not very helpful, but the VendorImporter is from pkg_resourecs.

Python added a warning: https://bugs.python.org/issue42134 but other packages treat it as error.

Expected behavior

No ImportWarning.

How to Reproduce

  1. Get Python 3.10.0a7 and tox (e.g. on Fedora via $ sudo dnf --enablerepo=updates-testing install python3.10 tox)
  2. git clone https://github.com/pypa/setuptools_scm.git and cd in
  3. Run tox -e py310-test

Output

py310-test develop-inst-nodeps: .../setuptools_scm
py310-test installed: attrs==20.3.0,iniconfig==1.1.1,packaging==20.9,pluggy==0.13.1,py==1.10.0,pyparsing==2.4.7,pytest==6.2.3,-e git+https://github.com/pypa/setuptools_scm.git@abb67b15985f380d8cf4451b9f2ef3dd11cb8a91#egg=setuptools_scm,toml==0.10.2
py310-test run-test-pre: PYTHONHASHSEED='1426720794'
py310-test run-test: commands[0] | pytest
============================= test session starts ==============================
platform linux -- Python 3.10.0a7, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
cachedir: .tox/py310-test/.pytest_cache
setuptools version 53.0.0 from '.../setuptools_scm/.tox/py310-test/lib/python3.10/site-packages/setuptools/__init__.py'
setuptools_scm version 6.0.1 from '.../setuptools_scm/src/setuptools_scm/__init__.py'
rootdir: .../setuptools_scm, configfile: tox.ini, testpaths: testing
collected 0 items / 1 error

==================================== ERRORS ====================================
________________________ ERROR collecting test session _________________________
<frozen importlib._bootstrap>:933: in _find_spec
    ???
E   AttributeError: 'VendorImporter' object has no attribute 'find_spec'

During handling of the above exception, another exception occurred:
.tox/py310-test/lib/python3.10/site-packages/pluggy/hooks.py:286: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
.tox/py310-test/lib/python3.10/site-packages/pluggy/manager.py:93: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
.tox/py310-test/lib/python3.10/site-packages/pluggy/manager.py:84: in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
.tox/py310-test/lib/python3.10/site-packages/_pytest/doctest.py:129: in pytest_collect_file
    elif _is_doctest(config, path, parent):
.tox/py310-test/lib/python3.10/site-packages/_pytest/doctest.py:147: in _is_doctest
    if path.check(fnmatch=glob):
.tox/py310-test/lib/python3.10/site-packages/py/_path/local.py:387: in check
    return super(LocalPath, self).check(**kw)
.tox/py310-test/lib/python3.10/site-packages/py/_path/common.py:241: in check
    return self.Checkers(self)._evaluate(kw)
.tox/py310-test/lib/python3.10/site-packages/py/_path/common.py:108: in _evaluate
    if py.code.getrawcode(meth).co_argcount > 1:
.tox/py310-test/lib/python3.10/site-packages/py/_vendored_packages/apipkg/__init__.py:152: in __makeattr
    result = importobj(modpath, attrname)
.tox/py310-test/lib/python3.10/site-packages/py/_vendored_packages/apipkg/__init__.py:72: in importobj
    module = __import__(modpath, None, None, ['__doc__'])
.tox/py310-test/lib/python3.10/site-packages/py/_code/code.py:7: in <module>
    reprlib = py.builtin._tryimport('repr', 'reprlib')
.tox/py310-test/lib/python3.10/site-packages/py/_builtin.py:144: in _tryimport
    __import__(name)
<frozen importlib._bootstrap>:1021: in _find_and_load
    ???
<frozen importlib._bootstrap>:996: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:935: in _find_spec
    ???
<frozen importlib._bootstrap>:908: in _find_spec_legacy
    ???
E   ImportWarning: VendorImporter.find_spec() not found; falling back to find_module()
=========================== short test summary info ============================
ERROR  - ImportWarning: VendorImporter.find_spec() not found; falling back to...
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.16s ===============================
ERROR: InvocationError for command .../setuptools_scm/.tox/py310-test/bin/pytest (exited with code 2)
___________________________________ summary ____________________________________
ERROR:   py310-test: commands failed

Code of Conduct

I agree to follow the PSF Code of Conduct

@hroncok
Copy link
Contributor Author

hroncok commented Apr 8, 2021

def find_module(self, fullname, path=None):
"""
Return self when fullname starts with root_name and the
target module is one vendored through this importer.
"""
root, base, target = fullname.partition(self.root_name + '.')
if root:
return
if not any(map(target.startswith, self.vendored_names)):
return
return self

def find_module(self, fullname, path=None):
"""
Return self when fullname starts with root_name and the
target module is one vendored through this importer.
"""
root, base, target = fullname.partition(self.root_name + '.')
if root:
return
if not any(map(target.startswith, self.vendored_names)):
return
return self

@webknjaz
Copy link
Member

webknjaz commented Apr 8, 2021

@hroncok pro tip: you can mark code blocks that have tracebacks with python-traceback and they'll be more colorful.

@webknjaz
Copy link
Member

webknjaz commented Apr 8, 2021

@webknjaz
Copy link
Member

webknjaz commented Apr 8, 2021

In that bug, @vstinner asks @brettcannon how to fix this issue — I think the answer would be more useful right here on GitHub rather than on bpo so I tag you both in case you want to comment here :)

@webknjaz
Copy link
Member

webknjaz commented Apr 8, 2021

@hroncok @jaraco a more minimalist reproducer is

$ python3.10 -W error -c 'import pkg_resources'                 
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 939, in _find_spec
AttributeError: 'VendorImporter' object has no attribute 'find_spec'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "~/.pyenv/versions/3.10-dev/lib/python3.10/site-packages/pkg_resources/__init__.py", line 74, in <module>
    from pkg_resources.extern import appdirs
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1002, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 941, in _find_spec
  File "<frozen importlib._bootstrap>", line 914, in _find_spec_legacy
ImportWarning: VendorImporter.find_spec() not found; falling back to find_module()
$ python3.10 -m pip show setuptools                                     
Name: setuptools
Version: 52.0.0
Summary: Easily download, build, install, upgrade, and uninstall Python packages
Home-page: https://github.com/pypa/setuptools
Author: Python Packaging Authority
Author-email: distutils-sig@python.org
License: UNKNOWN
Location: ~/.pyenv/versions/3.10-dev/lib/python3.10/site-packages
Requires: 
Required-by:

(I used pyenv install 3.10-dev which just got the bleeding edge CPython from the main repository, I didn't even need to change the setuptools version — the one bundled with Python 3.10 causes this same problem; And yeah... it's under Gentoo Linux but the bug is clearly unrelated to the OS)

webknjaz added a commit to webknjaz/setuptools that referenced this issue Apr 8, 2021
webknjaz added a commit to webknjaz/setuptools that referenced this issue Apr 8, 2021
This change makes the import warning emitted by Python 3.10 disappear
but implementing the hook that is supposed to replace the old import
mechanism.

Refs:
* https://bugs.python.org/issue42134
* https://bugs.python.org/issue43540
* pypa#2632 (comment)

Fixes pypa#2632
webknjaz added a commit to webknjaz/setuptools that referenced this issue Apr 8, 2021
This change makes the import warning emitted by Python 3.10 disappear
but implementing the hook that is supposed to replace the old import
mechanism.

Refs:
* https://bugs.python.org/issue42134
* https://bugs.python.org/issue43540
* pypa#2632 (comment)

Fixes pypa#2632
@webknjaz
Copy link
Member

webknjaz commented Apr 8, 2021

@hroncok this should address the problem #2633

webknjaz added a commit to webknjaz/setuptools that referenced this issue Apr 8, 2021
This change makes the import warning emitted by Python 3.10 disappear
but implementing the hook that is supposed to replace the old import
mechanism.

Refs:
* https://bugs.python.org/issue42134
* https://bugs.python.org/issue43540
* pypa#2632 (comment)

Fixes pypa#2632

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
@webknjaz webknjaz added 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. labels Apr 8, 2021
ctheune added a commit to flyingcircusio/batou that referenced this issue May 21, 2021
tox/pytest are running into this issue:
pypa/setuptools#2632
ctheune added a commit to flyingcircusio/batou that referenced this issue May 21, 2021
tox/pytest are running into this issue:
pypa/setuptools#2632
ctheune added a commit to flyingcircusio/batou that referenced this issue May 21, 2021
tox/pytest are running into this issue:
pypa/setuptools#2632
ctheune added a commit to flyingcircusio/batou that referenced this issue Aug 21, 2022
tox/pytest are running into this issue:
pypa/setuptools#2632
gforcada pushed a commit to gforcada/batou that referenced this issue Nov 2, 2022
tox/pytest are running into this issue:
pypa/setuptools#2632
ctheune added a commit to flyingcircusio/batou that referenced this issue Dec 21, 2022
tox/pytest are running into this issue:
pypa/setuptools#2632
elikoga pushed a commit to flyingcircusio/batou that referenced this issue Sep 9, 2023
author Christian Theune <ct@flyingcircus.io> 1621585346 +0200
committer Eli Kogan-Wang <elikowa@gmail.com> 1694227372 +0200

Try enabling Python 3.10 support in github actions / tox

Pin setuptools versions for development

tox/pytest are running into this issue:
pypa/setuptools#2632

We need a newer setuptools to fix a Python 3.10 issue.

bump (transitive) six dependency to force Python 3.10 compatibility

Grrr. Keep poking tox to pick up my Python 3.10 locally properly.

Update tox.ini

Co-authored-by: Jürgen Gmach <juergen.gmach@googlemail.com>

update lock files

enable python 3.11, too. fix test with changed output

update dev dependency

update dev dependencies, hopefully to fix 3.11

update appenv to include setuptools pinning
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.

2 participants