Skip to content

fix(nodeenv): do not put the venv bin on PATH twice with -p - #448

Merged
ekalinin merged 1 commit into
masterfrom
fix/duplicate-venv-bin-path
Oct 26, 2026
Merged

ekalinin merged 1 commit into
masterfrom
fix/duplicate-venv-bin-path

Conversation

@ekalinin

Copy link
Copy Markdown
Owner

Fixes #332

What happens

With nodeenv -p, the python venv's own bin/activate and bin/activate.fish put $VIRTUAL_ENV/bin on PATH, and the part nodeenv appends to them puts $NODE_VIRTUAL_ENV/bin there again. Reproduced on master in sh, dash, bash, zsh and fish. On macOS the two entries are not even the same text: /tmp/x/bin from python and /private/tmp/x/bin from nodeenv's cd -P. Deactivation restores PATH correctly, so the duplicate is the whole problem.

The patches proposed in the issue were not used: the first one drops bin for plain (non -p) environments too, and the conditional ones use bash-only [[ ]] and a substring match, which misses the /tmp vs /private/tmp case.

What changes

  • install_activate() leaves the bin entry out of the PATH line of activate and activate.fish when -p appends to a script of the python venv, so that part adds only node_modules/.bin.
  • A file nodeenv wrote itself keeps the entry. A conda env has no bin/activate, so nodeenv writes it from scratch, and a rerun with other options (--isolate-npm, say) appends to that file: a block without bin would take it off PATH again through deactivate_node nondestructive. Such a file is told apart by its first bytes, which are the DISABLE_PROMPT part.
  • Windows keeps the entry. Before python 3.12 the venv's Scripts/activate sets VIRTUAL_ENV to a C:\... path, which git-bash splits at the colon, so the venv's own entry only works while the current directory is on the same drive (If the working directory and the venv are on different disks, venv doesn't work in bash on Windows python/cpython#103088). activate.bat and Activate.ps1 never had the duplicate.
  • Running nodeenv -p again on an already affected venv fixes it: the new block is appended and resets PATH before adding node_modules/.bin.

Tests

The new tests fail on master and pass with the fix:

  • test_python_virtualenv_puts_bin_on_path_once in test_activate_shells.py creates a real venv with python -m venv, appends the -p part and checks the whole PATH in every shell;
  • test_python_virtualenv_puts_bin_on_path_once in test_install_activate.py checks the generated PATH lines, and test_python_virtualenv expects the shorter line;
  • test_win_python_virtualenv_appends_to_activate checks that the git-bash activate keeps Scripts.

test_python_virtualenv_rerun_leaves_activate_alone and test_python_virtualenv_own_activate_keeps_bin pass on master. They guard the reruns: the second one fails if bin is dropped whenever the file already exists.

The python venv's own activate and activate.fish put bin/ on PATH, and
the part nodeenv -p appends to them added it a second time. That part
now adds only node_modules/.bin.

A file nodeenv wrote itself (a conda env has none) keeps the entry, so
a rerun with other options does not take bin/ off PATH again. Windows
keeps it too: before python 3.12 the venv's git-bash activate puts a
C:\ path there, which the shell splits at the colon.

Fixes #332
@ekalinin
ekalinin merged commit b68eb29 into master Oct 26, 2026
46 checks passed
ekalinin added a commit to jihtsan/nodeenv that referenced this pull request Oct 29, 2026
Resolve the conflicts with ekalinin#439 and ekalinin#448: keep the ekalinin#399 entry above the
ekalinin#332 and ekalinin#436 entries in CHANGES, and keep the new python_venv test from
ekalinin#448 under @every_shell, since this branch drops @restoring_shell.

The earlier merge f506999 cut the "Nodeenv changelog" underline to 10
characters and dropped the blank line after it. docutils reports "Title
underline too short" and readme_renderer refuses README.rst + CHANGES,
so restore the title as it is on master.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

duplicate path in python-virtualenv

1 participant