Skip to content

[bug] Plugins can only inject envs as default but not additional #3510

Open
@webknjaz

Description

@webknjaz

Over the course of having discoveries related to #3507, I realized that all the examples with injecting MemoryLoader(env_list=env_list) add envs as default.

And so typing in tox would attempt running them:

$ tox l
default environments:
pip-compile              -> [tox-lock] Invoke pip-compile of pip-tools
pip-compile-build-lock   -> [tox-lock] Produce a PEP 517/660 build deps lock
pip-compile-tox-env-lock -> [tox-lock] Produce a lock file for the passed tox env using current python

additional environments:
build-dists              -> Build dists and put them into the dist/ folder
pre-commit               -> Run the quality checks under python3; run as `SKIP=check-id1,check-id2 tox r -e pre-commit` to instruct the underlying `pre-commit` invocation avoid running said checks; Use `tox r -e pre-commit -- check-id1 --all-files` to select checks matching IDs aliases: `tox r -e pre-commit -- mypy --all-files` will run 3 MyPy invocations, but `tox r -e pre-commit -- mypy-py313 --all-files` runs one.
build-docs               -> Build The Docs

I don't want to influence whatever the end-user configures as env_list in their config, only providing additional envs that should be requested via tox r -e <env> (or through the env var, or config explicitly).

It seems to me like a gap in the plugin API. Having stared long enough at the source code, it seems that the discovery of additional envs is tightly coupled with the source objects. It's effectively happening @

yield self._state.conf, everything_active
.
And if we unwrap a few layers of indirection, that effectively does state.conf._src._discover_tox_envs(state.conf.core).

It looks like this currently means that adding a memory loader into the core config adds default envs that are processed separately when discovering all envs:

env_list, everything_active = self._state.conf.core["env_list"], False
. And this is what makes it work.
But adding “inactive” / “additional” envs would only be possible by monkey-patching the private state.conf._src object or state.conf.__iter__().

@gaborbernat should the plugin API just implement a tox_discover_envs() hook or a method on the state or config objects for declaring additional environments?

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