Skip to content

Conversation

webknjaz
Copy link
Contributor

@webknjaz webknjaz commented Aug 29, 2025

This patch adds a new hook point in the tox lifecycle that lets plugin authors declare additional environment names dynamically. This can be used to provide extra tox environments shipped as installable plugins.

Resolves #3510.

This patch adds a new hook point in the tox lifecycle that lets plugin
authors declare additional environment names dynamically. This can be
used to provide extra tox environments shipped as installable plugins.

Resolves tox-dev#3510.
Copy link
Member

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with this if you add a tests demonstrating it.

@webknjaz
Copy link
Contributor Author

Yep, that's why it's still a draft. I've been playing with a PoC in a toxfile.py of another project locally and confirmed that this is usable. I'll need to look into turning that into test coverage and add a change note before undrafting.

webknjaz added a commit to webknjaz/tox that referenced this pull request Aug 29, 2025
@webknjaz webknjaz marked this pull request as ready for review August 29, 2025 17:00
webknjaz added a commit to webknjaz/tox that referenced this pull request Aug 29, 2025
@webknjaz webknjaz force-pushed the features/3510-dynamic-additional-envs-list branch from a774591 to 5c1c534 Compare August 29, 2025 17:00
@webknjaz webknjaz force-pushed the features/3510-dynamic-additional-envs-list branch from 5c1c534 to 34b4342 Compare August 29, 2025 17:03
@webknjaz
Copy link
Contributor Author

cc @sirosen @jugmac00 — this is a new API that @gaborbernat and I hacked together at PyCon US in the spring. FYI.

@webknjaz webknjaz requested a review from gaborbernat August 29, 2025 17:06
@gaborbernat gaborbernat merged commit bf558e3 into tox-dev:main Aug 29, 2025
29 checks passed
@github-project-automation github-project-automation bot moved this from 🚧 In progress 🚧 to 🌈 Done 🦄 in 📅 Procrastinating in public Aug 29, 2025
@webknjaz
Copy link
Contributor Author

@gaborbernat thanks for merging 🙏

Would you mind releasing so I could use this in a plugin, finally?

@gaborbernat
Copy link
Member

https://github.com/tox-dev/tox/releases/tag/4.29.0

webknjaz added a commit to webknjaz/tox that referenced this pull request Sep 1, 2025
This is a follow-up for tox-dev#3591 that makes it prominent in the docs when
the hook was first added.
webknjaz added a commit to webknjaz/tox that referenced this pull request Sep 2, 2025
Previously (PR tox-dev#3591) a new hook point was added. The tests checked
that it works well with the `tox config` and `tox list` commands.
However, `tox run` turned out to have a problem — it would complain
that there's no such env, when invoked:

```console
ROOT: 170 E HandledError| provided environments not found in configuration file:
pip-compile-tox-env-lock [tox/run.py:23]
```

Turned out, this was because the config object is being interated twice
in some subcommands. This in turn iterates over the discovered
additional ephemeral environments list object. The implementation passes
an iterator into it and so when it's first accessed, it's exhausted and
the second attempt does not give the same envs, causing inconsistency.

The patch solves this by using `itertools.tee()`, making sure that the
underlying iterable is always cached and it's possible to repeat
iteration as many times as possible without loosing the data in the
process.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] Plugins can only inject envs as default but not additional
2 participants