Skip to content

[BUG] minversion and requires should be processed before loading the toxfile.py hooks #3593

@webknjaz

Description

@webknjaz

Issue

So I was experimenting with using #3591 in a toxfile.py. I already had tox_extend_envs in there, from my tests during the PR implementation. Obviously, I was playing with it against an editable install of tox.

I've added minversion = 4.29.0 to tox.ini before trying it out and was expecting it to self-provision the right version. But instead, it seems to have loaded toxfile.py before checking the minimum version, crashing in pluggy.

I don't know if local plugins do indeed need to be loaded this early. If they are, it might be a good idea to suppress the exception if the minversion value declared in the config is higher than the current version. If not, maybe adjusting the load order would fix this. Perhaps, we need some sort of a multi-stage loading thingy.

I suspect that [tox].requires might have a similar problem but haven't checked. UPD: I checked and it's as problematic.

Environment

Irrelevant.

Output of running tox

Output of tox r -e py312 -v
$ tox r -e py312 -v                                                                                     
Traceback (most recent call last):
  File "~/.local/bin/tox", line 8, in <module>
    sys.exit(run())
             ^^^^^
  File "~/.local/share/pipx/venvs/tox/lib/python3.12/site-packages/tox/run.py", line 20, in run
    result = main(sys.argv[1:] if args is None else args)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.local/share/pipx/venvs/tox/lib/python3.12/site-packages/tox/run.py", line 39, in main
    state = setup_state(args)
            ^^^^^^^^^^^^^^^^^
  File "~/.local/share/pipx/venvs/tox/lib/python3.12/site-packages/tox/run.py", line 53, in setup_state
    options = get_options(*args)
              ^^^^^^^^^^^^^^^^^^
  File "~/.local/share/pipx/venvs/tox/lib/python3.12/site-packages/tox/config/cli/parse.py", line 38, in get_options
    guess_verbosity, log_handler, source = _get_base(args)
                                           ^^^^^^^^^^^^^^^
  File "~/.local/share/pipx/venvs/tox/lib/python3.12/site-packages/tox/config/cli/parse.py", line 62, in _get_base
    MANAGER.load_plugins(source.path)
  File "~/.local/share/pipx/venvs/tox/lib/python3.12/site-packages/tox/plugin/manager.py", line 111, in load_plugins
    self._register_plugins(inline)
  File "~/.local/share/pipx/venvs/tox/lib/python3.12/site-packages/tox/plugin/manager.py", line 76, in _register_plugins
    self.manager.check_pending()
  File "~/.local/share/pipx/venvs/tox/lib/python3.12/site-packages/pluggy/_manager.py", line 387, in check_pending
    raise PluginValidationError(
pluggy._manager.PluginValidationError: unknown hook 'tox_extend_envs' in plugin <module 'toxfile' from '~/src/github/sphinx-contrib/towncrier/toxfile.py'>

Minimal example

$ pip install 'tox < 4.29'
$ nvim toxfile.py  # <- add new hook handler for `tox_extend_envs()`
$ nvim tox.ini  # add a `minversion = 4.29.0`
# tox.ini
[tox]
# NOTE: v4.29 is the first one to implement the `tox_extend_envs`
# NOTE: lifecycle hook.
#
# Refs:
# * https://github.com/tox-dev/tox/issues/3510
# * https://github.com/tox-dev/tox/pull/3591
minversion = 4.29.0
# toxfile.py
from tox.plugin import impl

@impl
def tox_extend_envs() -> tuple[str]:
    """Declare plugin-provided in-memory tox envs."""
    return ('blah',)

UPD: Using requires as follows crashes the same way.

# tox.ini
[tox]
requires =
  tox >= 4.29.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions