Fix setenv PATH modifications being overwritten#3723
Fix setenv PATH modifications being overwritten#3723gaborbernat merged 7 commits intotox-dev:mainfrom
Conversation
gaborbernat
left a comment
There was a problem hiding this comment.
Please add tests. We must ensure that path modification expands the trailing part of the path, and the virtual environment paths we add are at the begining.
|
@gaborbernat Added tests and an additional fix. Here's what I found and changed: Tests added:
Additional fix in Fixed by re-prepending the virtual environment paths (
All 17 tests in |
gaborbernat
left a comment
There was a problem hiding this comment.
Are we still removing duplicates from PATH as we did before? Also are we still using self._make_path() or any reason why we're not using it now?
|
Thanks for the review! Addressed both points:
|
|
Good point — inlined |
gaborbernat
left a comment
There was a problem hiding this comment.
Please don't mark the PR ready for review until the CI passes.
|
Comment condensed per feedback. The type and type-min CI failures are pre-existing on main — |
6dcd206 to
642ae4a
Compare
|
Rebased on main, all tests pass. The only failures are |
|
Note: the type/type-min CI failures are caused by |
The _paths setter in ToxEnv directly overwrote _env_vars["PATH"] with
the result of _make_path(), which only includes tox env paths and the
system PATH. This caused any user-defined setenv PATH modifications
(e.g., PATH = {env:PATH}:/custom) to be lost, because the cached
_env_vars was returned on subsequent accesses without re-applying
set_env.
The fix invalidates the _env_vars cache when _paths changes, forcing
environment_variables to be rebuilt on next access. This correctly
applies set_env after the base PATH is set.
Fixes tox-dev#3445
for more information, see https://pre-commit.ci
Per review feedback: add tests verifying that setenv PATH modifications
are preserved and that virtual environment paths always appear at the
beginning of PATH. Also fix the environment_variables property to
re-prepend venv paths after setenv processing, ensuring that
PATH = {env:PATH}:/test correctly appends /test without losing the
virtual environment bin directory.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
for more information, see https://pre-commit.ci
…modifies PATH Address review feedback: - Extract _make_path_with() to reuse the same dict.fromkeys dedup pattern - Only re-prepend venv paths when set_env actually modified PATH - Align comment to 120 chars Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
5e6198b to
fe6f09b
Compare
|
Rebased on main (which now includes #3728). All CI checks pass — including type/type-min which were previously failing. Marking ready for review. |
Summary
setenvmodifiesPATH, those modifications were being silently overwritten when tox set up environment paths (via the_pathssetter)_pathssetter directly wrote to_env_vars["PATH"]using_make_path(), which only includes tox-managed paths — losing any user-defined PATH modifications fromsetenvFix
Changed the
_pathssetter to invalidate the_env_varscache (set toNone) instead of directly modifyingPATH. This ensures theenvironment_variablesproperty rebuilds from scratch on next access, properly incorporating bothsetenvPATH modifications and tox-managed paths in the correct order.Test plan
environment_variablesproperty already handles merging setenv with system PATH correctly — the bug was only in the setter bypassing this logic🤖 Generated with Claude Code