Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

tox 4.x and tox-pyenv: ImportError: cannot import name 'hookimpl' from 'tox' #22

Closed
ModeSevenIndustrialSolutions opened this issue Dec 8, 2022 · 2 comments

Comments

@ModeSevenIndustrialSolutions

Looks like the current release 1.1.0 does NOT play nicely with tox 4.x.

In addition to the bug documented here:
#21

On adding the "py" package, the next error uncovered is:

(tox) root@9cb1a471f174:~# tox --version
ROOT: No tox.ini or setup.cfg or pyproject.toml found, assuming empty tox.ini at /root
Traceback (most recent call last):
File "/root/tox/bin/tox", line 8, in
sys.exit(run())
File "/root/tox/lib/python3.8/site-packages/tox/run.py", line 19, in run
result = main(sys.argv[1:] if args is None else args)
File "/root/tox/lib/python3.8/site-packages/tox/run.py", line 38, in main
state = setup_state(args)
File "/root/tox/lib/python3.8/site-packages/tox/run.py", line 53, in setup_state
options = get_options(*args)
File "/root/tox/lib/python3.8/site-packages/tox/config/cli/parse.py", line 38, in get_options
guess_verbosity, log_handler, source = _get_base(args)
File "/root/tox/lib/python3.8/site-packages/tox/config/cli/parse.py", line 61, in _get_base
MANAGER.load_plugins(source.path)
File "/root/tox/lib/python3.8/site-packages/tox/plugin/manager.py", line 83, in load_plugins
self._register_plugins(inline)
File "/root/tox/lib/python3.8/site-packages/tox/plugin/manager.py", line 37, in _register_plugins
self.manager.load_setuptools_entrypoints(NAME)
File "/root/tox/lib/python3.8/site-packages/pluggy/_manager.py", line 287, in load_setuptools_entrypoints
plugin = ep.load()
File "/root/.pyenv/versions/3.8.13/lib/python3.8/importlib/metadata.py", line 77, in load
module = import_module(match.group('module'))
File "/root/.pyenv/versions/3.8.13/lib/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "", line 843, in exec_module
File "", line 219, in _call_with_frames_removed
File "/root/tox/lib/python3.8/site-packages/tox_pyenv.py", line 48, in
from tox import hookimpl as tox_hookimpl
ImportError: cannot import name 'hookimpl' from 'tox' (/root/tox/lib/python3.8/site-packages/tox/init.py)

@Warchant
Copy link

Warchant commented May 3, 2023

I was able to solve it (without tox-pyenv):
https://warchantua.hashnode.dev/how-to-use-tox-4-with-pyenv-and-poetry

@un-def
Copy link

un-def commented Jul 14, 2023

tox 4 delegates the Python discovery job to virtualenv: https://tox.wiki/en/latest/plugins.html#tox-get-python-executable

A special tox plugin like this is no longer needed.

I just released a new version of the virtualenv-pyenv discovery plugin that is compatible with tox 4.

How to migrate:

  1. Uninstall tox-pyenv.
  2. Install virtualenv-pyenv.
  3. Set the discovery mechanism to pyenv. Both export VIRTUALENV_DISCOVERY=pyenv in a shell and setenv = VIRTUALENV_DISCOVERY=pyenv in a tox config do the job. Another option is a virtualenv.ini config file: https://virtualenv.pypa.io/en/latest/cli_interface.html#conf-file

Sorry for the self-promotion.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants