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

ImportError when importing hookimpl #2929

Closed
niccokunzmann opened this issue Feb 28, 2023 · 3 comments
Closed

ImportError when importing hookimpl #2929

niccokunzmann opened this issue Feb 28, 2023 · 3 comments

Comments

@niccokunzmann
Copy link

Issue

I would like tox to run out of the box but it does not on my computer and CI. There is an import error, I think it started between version 3.5 and 4.

Examples:

Traceback (most recent call last):
  File "/home/xxx/.local/bin/tox", line 8, in <module>
    sys.exit(run())
  File "/home/xxx/.local/lib/python3.10/site-packages/tox/run.py", line 19, in run
    result = main(sys.argv[1:] if args is None else args)
  File "/home/xxx/.local/lib/python3.10/site-packages/tox/run.py", line 38, in main
    state = setup_state(args)
  File "/home/xxx/.local/lib/python3.10/site-packages/tox/run.py", line 53, in setup_state
    options = get_options(*args)
  File "/home/xxx/.local/lib/python3.10/site-packages/tox/config/cli/parse.py", line 38, in get_options
    guess_verbosity, log_handler, source = _get_base(args)
  File "/home/xxx/.local/lib/python3.10/site-packages/tox/config/cli/parse.py", line 61, in _get_base
    MANAGER.load_plugins(source.path)
  File "/home/xxx/.local/lib/python3.10/site-packages/tox/plugin/manager.py", line 90, in load_plugins
    self._register_plugins(inline)
  File "/home/xxx/.local/lib/python3.10/site-packages/tox/plugin/manager.py", line 38, in _register_plugins
    self.manager.load_setuptools_entrypoints(NAME)
  File "/home/xxx/.local/lib/python3.10/site-packages/pluggy/_manager.py", line 287, in load_setuptools_entrypoints
    plugin = ep.load()
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/xxx/.local/lib/python3.10/site-packages/tox_pyenv.py", line 48, in <module>
    from tox import hookimpl as tox_hookimpl
ImportError: cannot import name 'hookimpl' from 'tox' (/home/xxx/.local/lib/python3.10/site-packages/tox/__init__.py)
Traceback (most recent call last):
  File "/usr/local/bin/tox", line 8, in <module>
    sys.exit(run())
             ^^^^^
  File "/usr/local/lib/python3.11/site-packages/tox/run.py", line 19, in run
    result = main(sys.argv[1:] if args is None else args)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/tox/run.py", line 38, in main
    state = setup_state(args)
            ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/tox/run.py", line 53, in setup_state
    options = get_options(*args)
              ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/tox/config/cli/parse.py", line 38, in get_options
    guess_verbosity, log_handler, source = _get_base(args)
                                           ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/tox/config/cli/parse.py", line 61, in _get_base
    MANAGER.load_plugins(source.path)
  File "/usr/local/lib/python3.11/site-packages/tox/plugin/manager.py", line 90, in load_plugins
    self._register_plugins(inline)
  File "/usr/local/lib/python3.11/site-packages/tox/plugin/manager.py", line 38, in _register_plugins
    self.manager.load_setuptools_entrypoints(NAME)
  File "/usr/local/lib/python3.11/site-packages/pluggy/_manager.py", line 287, in load_setuptools_entrypoints
    plugin = ep.load()
             ^^^^^^^^^
  File "/usr/local/lib/python3.11/importlib/metadata/__init__.py", line 202, in load
    module = import_module(match.group('module'))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/local/lib/python3.11/site-packages/tox_run_before.py", line 3, in <module>
    from tox import hookimpl
ImportError: cannot import name 'hookimpl' from 'tox' (/usr/local/lib/python3.11/site-packages/tox/__init__.py)

Environment

Provide at least:

  • OS: Ubuntu
  • pip list of the host Python where tox is installed:
Package                      Version        Editable project location
---------------------------- -------------- --------------------------
acme                         1.30.0
appdirs                      1.4.4
apturl                       0.5.2
astroid                      2.12.10
asttokens                    2.0.8
atom                         0.8.1
attrs                        21.2.0
Automat                      20.2.0
backcall                     0.2.0
beautifulsoup4               4.10.0
beniget                      0.4.1
black                        21.10b0
blinker                      1.4
Brotli                       1.0.9
build                        0.10.0
bytecode                     0.13.0
CacheControl                 0.12.11
cachetools                   5.3.0
catfish                      4.16.3
certbot                      1.30.0
certifi                      2020.6.20
cffi                         1.15.0
cfgv                         3.3.1
chardet                      5.1.0
cleo                         2.0.1
click                        8.0.3
colorama                     0.4.6
command-not-found            0.3
ConfigArgParse               1.5.3
configobj                    5.0.6
constantly                   15.1.0
crashtest                    0.4.1
cryptography                 38.0.1
cupshelpers                  1.0
cycler                       0.11.0
dbus-python                  1.2.18
debugpy                      1.6.3
decorator                    4.4.2
defer                        1.0.6
dill                         0.3.5.1
distlib                      0.3.6
distro                       1.7.0
distro-info                  1.1build1
docutils                     0.19
dulwich                      0.21.3
enaml                        0.15.2
enamlx                       0.6.1
entrypoints                  0.4
executing                    1.0.0
filelock                     3.9.0
fonttools                    4.29.1
fs                           2.4.12
gast                         0.5.2
gitdb                        4.0.9
GitPython                    3.1.24
gpg                          1.16.0-unknown
html5lib                     1.1
httplib2                     0.20.2
hyperlink                    21.0.0
identify                     2.5.17
idna                         3.3
img2pdf                      0.4.2
importlib-metadata           6.0.0
incremental                  21.3.0
iniconfig                    1.1.1
inkcut                       2.1.5
installer                    0.6.0
ipykernel                    6.15.3
ipython                      8.5.0
ipython-genutils             0.2.0
isort                        5.10.1
jaraco.classes               3.2.3
jedi                         0.18.1
jeepney                      0.7.1
josepy                       1.13.0
jsonpickle                   2.2.0
jsonschema                   4.17.3
jupyter_client               7.3.5
jupyter-core                 4.11.1
keyring                      23.13.1
kiwisolver                   1.3.2
language-selector            0.1
launchpadlib                 1.10.16
lazr.restfulclient           0.14.4
lazr.uri                     1.0.6
lazy-object-proxy            1.7.1
lightdm-gtk-greeter-settings 1.2.2
lockfile                     0.12.2
lxml                         4.8.0
lz4                          3.1.3+dfsg
Mako                         1.1.3
MarkupSafe                   2.0.1
matplotlib                   3.5.1
matplotlib-inline            0.1.6
mccabe                       0.7.0
menulibre                    2.2.2
more-itertools               8.10.0
mpmath                       0.0.0
msgpack                      1.0.4
mugshot                      0.4.3
mypy                         0.981
mypy-extensions              0.4.3
nest-asyncio                 1.5.5
netifaces                    0.11.0
nodeenv                      1.7.0
numpy                        1.21.5
oauthlib                     3.2.0
olefile                      0.46
onboard                      1.4.1
packaging                    23.0
parsedatetime                2.6
parso                        0.8.3
pathspec                     0.9.0
pdfarranger                  1.8.2
pexpect                      4.8.0
pickleshare                  0.7.5
pikepdf                      5.0.1+dfsg
Pillow                       9.0.1
pip                          22.0.2
Pivy                         0.6.5
pkginfo                      1.9.6
platformdirs                 2.6.2
pluggy                       1.0.0
ply                          3.11
poetry                       1.4.0
poetry-core                  1.5.1
poetry-plugin-export         1.3.0
pre-commit                   3.1.1
prompt-toolkit               3.0.31
psutil                       5.9.0
ptyprocess                   0.7.0
pure-eval                    0.2.2
py                           1.11.0
pycairo                      1.20.1
pycparser                    2.21
pycups                       2.0.1
Pygments                     2.11.2
PyGObject                    3.42.1
PyJWT                        2.3.0
pylint                       2.15.3
pyOpenSSL                    22.1.0
pyparsing                    2.4.7
pyproject_api                1.5.0
pyproject_hooks              1.0.0
PyQt5                        5.15.6
PyQt5-sip                    12.9.1
pyqtgraph                    0.12.4
pyRFC3339                    1.1
pyrsistent                   0.19.3
pyserial                     3.5
pysmbc                       1.0.23
PySocks                      1.7.1
pytest                       7.1.3
python-apt                   2.4.0+ubuntu1
python-dateutil              2.8.2
python-debian                0.1.43ubuntu1
python-slugify               4.0.0
pythran                      0.10.0
pytz                         2022.1
PyYAML                       5.4.1
pyzmq                        24.0.0
qt-reactor                   0.6
qtconsole                    5.3.2
QtPy                         2.2.0
rapidfuzz                    2.13.7
reportlab                    3.6.8
requests                     2.25.1
requests-toolbelt            0.9.1
scipy                        1.8.0
scour                        0.38.2
SecretStorage                3.3.1
Send2Trash                   1.8.0
setuptools                   59.6.0
sgt-launcher                 0.2.7
shellingham                  1.5.0.post1
six                          1.16.0
smmap                        5.0.0
soupsieve                    2.3.1
ssh-import-id                5.11
stack-data                   0.5.0
stdeb                        0.10.0
sympy                        1.9
systemd-python               234
thonny                       4.0.1
toml                         0.10.2
tomli                        2.0.1
tomlkit                      0.11.5
torbrowser-launcher          0.3.5
tornado                      6.2
tox                          4.4.6
tox-pyenv                    1.1.0
tox-run-before               0.1            /home/sabin/tox-run-before
traitlets                    5.4.0
transifex-client             0.14.2
trove-classifiers            2023.2.20
Twisted                      22.8.0
typing_extensions            4.3.0
ubuntu-advantage-tools       8001
ubuntu-drivers-common        0.0.0
ufoLib2                      0.13.1
ufw                          0.36.1
unattended-upgrades          0.1
unicodedata2                 14.0.0
Unidecode                    1.3.3
urllib3                      1.26.5
virtualenv                   20.19.0
wadllib                      1.3.6
wcwidth                      0.2.5
webencodings                 0.5.1
wheel                        0.37.1
wrapt                        1.14.1
xcffib                       0.11.1
xkit                         0.0.0
youtube-dl                   2021.12.17
zipp                         1.0.0
zope.component               5.0.1
zope.event                   4.5.0
zope.hookable                5.2
zope.interface               5.4.0

Output of running tox

Provide the output of tox -rvv:

Traceback (most recent call last):
  File "/home/sabin/.local/bin/tox", line 8, in <module>
    sys.exit(run())
  File "/home/sabin/.local/lib/python3.10/site-packages/tox/run.py", line 19, in run
    result = main(sys.argv[1:] if args is None else args)
  File "/home/sabin/.local/lib/python3.10/site-packages/tox/run.py", line 38, in main
    state = setup_state(args)
  File "/home/sabin/.local/lib/python3.10/site-packages/tox/run.py", line 53, in setup_state
    options = get_options(*args)
  File "/home/sabin/.local/lib/python3.10/site-packages/tox/config/cli/parse.py", line 38, in get_options
    guess_verbosity, log_handler, source = _get_base(args)
  File "/home/sabin/.local/lib/python3.10/site-packages/tox/config/cli/parse.py", line 61, in _get_base
    MANAGER.load_plugins(source.path)
  File "/home/sabin/.local/lib/python3.10/site-packages/tox/plugin/manager.py", line 90, in load_plugins
    self._register_plugins(inline)
  File "/home/sabin/.local/lib/python3.10/site-packages/tox/plugin/manager.py", line 38, in _register_plugins
    self.manager.load_setuptools_entrypoints(NAME)
  File "/home/sabin/.local/lib/python3.10/site-packages/pluggy/_manager.py", line 287, in load_setuptools_entrypoints
    plugin = ep.load()
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/sabin/.local/lib/python3.10/site-packages/tox_pyenv.py", line 48, in <module>
    from tox import hookimpl as tox_hookimpl
ImportError: cannot import name 'hookimpl' from 'tox' (/home/sabin/.local/lib/python3.10/site-packages/tox/__init__.py)

Minimal example

If possible, provide a minimal reproducer for the issue:

This could do it, since this is also a problem for tox-run-before.

pip install tox tox-run-before

See also:

@niccokunzmann niccokunzmann changed the title ImportError when importing hookiml ImportError when importing hookimpl Feb 28, 2023
@niccokunzmann
Copy link
Author

My guess is that plugins should move to tox.plugin.impl.
see https://tox.wiki/en/4.4.6/plugins.html#tox.plugin.impl

@gaborbernat
Copy link
Member

Yeah, tox 4 is a major new version; you can't expect to behave the same.

@stefansjs
Copy link

Can we get better error logging on this one? I cannot figure out who is trying to import hookimpl. AFAIK I do not have any plugins installed with tox, so I can't tell who the offender is.

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

No branches or pull requests

3 participants