Skip to content

✨ feat(runner): add PEP 723 inline script metadata support#3912

Merged
gaborbernat merged 2 commits intotox-dev:mainfrom
gaborbernat:3897
Mar 30, 2026
Merged

✨ feat(runner): add PEP 723 inline script metadata support#3912
gaborbernat merged 2 commits intotox-dev:mainfrom
gaborbernat:3897

Conversation

@gaborbernat
Copy link
Copy Markdown
Member

@gaborbernat gaborbernat commented Mar 30, 2026

Closes #3897.

PEP 723 lets Python scripts declare their dependencies and required Python version inline via comment blocks. Currently tox users must duplicate this information in their tox config, which drifts out of sync and defeats the purpose of the standard. The new virtualenv-pep-723 runner reads metadata directly from the script file, so a tox environment needs only a runner and script key.

[testenv:check]
runner = virtualenv-pep-723
script = tools/check.py

The shared PEP 723 logic lives in Pep723Mixin at tox.tox_env.python.pep723, independent of any venv backend. The concrete Pep723Runner composes the mixin with VirtualEnv and RunToxEnv, skipping PythonRun entirely so config keys like deps, extras, dependency_groups, and pylock are structurally absent rather than registered and rejected. Packaging is unconditionally disabled via _register_package_conf returning False. Setting base_python explicitly is rejected to prevent conflicts with the script's requires-python specifier.

The mixin design means tox-uv can add PEP 723 support by composing Pep723Mixin with UvVenv and RunToxEnv — zero code duplication.

@gaborbernat gaborbernat force-pushed the 3897 branch 2 times, most recently from 04815cc to 42e4de4 Compare March 30, 2026 19:39
@gaborbernat gaborbernat enabled auto-merge (squash) March 30, 2026 19:41
@gaborbernat gaborbernat disabled auto-merge March 30, 2026 19:43
PEP 723 lets scripts declare dependencies and Python version inline.
The new virtualenv-pep-723 runner reads this metadata so environments
need only a runner and script key — no deps/base_python duplication.

The shared logic lives in Pep723Mixin (tox.tox_env.python.pep723) so
third-party plugins like tox-uv can compose it with their own venv
backend without duplicating code. The concrete runner composes the
mixin with VirtualEnv and RunToxEnv, skipping PythonRun entirely so
config keys like deps/extras/pylock are structurally absent.

Closes tox-dev#3897
@gaborbernat gaborbernat enabled auto-merge (squash) March 30, 2026 19:54
@gaborbernat gaborbernat merged commit da0f890 into tox-dev:main Mar 30, 2026
50 of 51 checks passed
@henryiii
Copy link
Copy Markdown
Contributor

The mixin design means tox-uv can add PEP 723 support by composing Pep723Mixin with UvVenv and RunToxEnv — zero code duplication.

tox-uv will also need an update to use it there?

@gaborbernat
Copy link
Copy Markdown
Member Author

Yes.

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.

Pep 723 support

3 participants