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

[20.0.8] import hook assumes existence of exec_module but the api is optional according to PEP 302/451 #1690

Closed
asottile opened this issue Mar 5, 2020 · 2 comments · Fixed by #1691
Labels

Comments

@asottile
Copy link
Contributor

asottile commented Mar 5, 2020

A contained example is https://github.com/asottile/pymonkey

the import machinery in virtualenv 20.0.8 assumes all loaders have an exec_module attribute, however that's optional (and not part of PEP 302 at all)

The crash in my case looks like:

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 888, in _find_spec
AttributeError: 'PymonkeyImportHook' object has no attribute 'find_spec'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/pymonkey/testing/pkg1/patchingmod_main.py", line 8, in <module>
    exit(main())
  File "/tmp/pymonkey/pymonkey.py", line 270, in entry
    tuple(patches) + ('--', original_entry_point) + tuple(argv)
  File "/tmp/pymonkey/pymonkey.py", line 258, in main
    return entry.load()()
  File "/tmp/pymonkey/.tox/py36/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2445, in load
    return self.resolve()
  File "/tmp/pymonkey/.tox/py36/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2451, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/tmp/pymonkey/pymonkey.py", line 173, in load_module
    module = importmod(fullname)
  File "/tmp/pymonkey/pymonkey.py", line 94, in importmod
    return __import__(mod, fromlist=[str('__name__')], level=0)
  File "/tmp/pymonkey/testing/pkg2/targetmod.py", line 4, in <module>
    import setuptools  # Some weird import hook
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/tmp/pymonkey/pymonkey.py", line 173, in load_module
    module = importmod(fullname)
  File "/tmp/pymonkey/pymonkey.py", line 94, in importmod
    return __import__(mod, fromlist=[str('__name__')], level=0)
  File "/tmp/pymonkey/.tox/py36/lib/python3.6/site-packages/setuptools/__init__.py", line 5, in <module>
    import distutils.core
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/tmp/pymonkey/pymonkey.py", line 173, in load_module
    module = importmod(fullname)
  File "/tmp/pymonkey/pymonkey.py", line 94, in importmod
    return __import__(mod, fromlist=[str('__name__')], level=0)
  File "/usr/lib/python3.6/distutils/core.py", line 16, in <module>
    from distutils.dist import Distribution
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 951, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 890, in _find_spec
  File "<frozen importlib._bootstrap>", line 864, in _find_spec_legacy
  File "/tmp/pymonkey/pymonkey.py", line 162, in find_module
    elif self._module_exists(fullname, path):
  File "/tmp/pymonkey/pymonkey.py", line 122, in _module_exists
    getattr(entry, 'find_spec', _noop)(module, path) or
  File "/tmp/pymonkey/.tox/py36/lib/python3.6/site-packages/_virtualenv.py", line 58, in find_spec
    old = spec.loader.exec_module
AttributeError: 'PymonkeyImportHook' object has no attribute 'exec_module'
@asottile asottile added the bug label Mar 5, 2020
@asottile
Copy link
Contributor Author

asottile commented Mar 5, 2020

here's the sample loading code from PEP 451: https://www.python.org/dev/peps/pep-0451/#how-loading-will-work

@gaborbernat
Copy link
Contributor

Hello, a fix for this issue has been released via virtualenv 20.0.9; see https://pypi.org/project/virtualenv/20.0.9/ (https://virtualenv.pypa.io/en/latest/changelog.html#v20-0-9-2020-03-08). Please give a try and report back if your issue has not been addressed; if not, please comment here, and we'll reopen the ticket. We want to apologize for the inconvenience this has caused you and say thanks for having patience while we resolve the unexpected bugs with this new major release.
thanks

@pypa pypa locked and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants