Sitelet https://github.com/tox-dev/tox/pull/4095
Skip to content

Create change_dir before running the external package build command - #4095

Merged
gaborbernat merged 3 commits into
tox-dev:mainfrom
Rodrigo-Palma:fix/external-builder-change-dir
Sep 26, 2026
Merged

gaborbernat merged 3 commits into
tox-dev:mainfrom
Rodrigo-Palma:fix/external-builder-change-dir

Conversation

@Rodrigo-Palma

Copy link
Copy Markdown
Contributor

The external package builder is the only one of the four change_dir call sites that does not create the directory before running commands in it.

The documentation for the external builder's change_dir states the opposite:

Change to this working directory when executing the package build command. If the directory does not exist yet, it will be created (required for Windows to be able to execute any command).

The three siblings all do it, one line above their run_command_set call:

call site creates the directory
session/cmd/run/single.py:89 yes
tox_env/runner.py:176 yes
tox_env/python/runner.py:213 yes
tox_env/python/virtual_env/package/cmd_builder.py:87 no

Without it, pointing change_dir at a directory that does not exist yet fails the whole run from the subprocess layer:

.pkg_external: Exception running subprocess [Errno 2] No such file or directory: '.../build-here'
py: FAIL code 1

while the same change_dir on a run env creates the directory and works.

The fix is the same line the siblings use. The added test asserts the directory exists after the run, and it fails on main with assert PosixPath('.../build-here').is_dir().

tests/tox_env/python/virtual_env/package/test_package_cmd_builder.py is 11 passed, 2 skipped (the two integration cases). ruff check and ruff format --check are clean with the 0.16.8 pinned in .pre-commit-config.yaml.

I will add the docs/changelog/ entry as soon as this PR has a number.

The external package builder is the only one of the four change_dir call
sites that does not create the directory first. The documented behaviour
for the external builder says it will be created, and the three siblings
(session/cmd/run/single.py, tox_env/runner.py and tox_env/python/runner.py)
all do it.

Without it, pointing change_dir at a directory that does not exist yet
fails the whole run with "No such file or directory" from the subprocess
layer, while the same change_dir on a run env works.

@gaborbernat gaborbernat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@gaborbernat
gaborbernat merged commit 31ed8d9 into tox-dev:main Sep 26, 2026
30 checks passed
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.

2 participants