fix(nodeenv): let -p target a virtualenv nodeenv isn't installed in - #402
Merged
Merged
Conversation
-p now takes an optional directory, so a pipx/pipsi/uv tool installation can set up node.js in any python virtualenv. Without an argument the activated VIRTUAL_ENV is preferred over sys.prefix: when nodeenv lives in its own virtualenv, sys.prefix points at that virtualenv instead of the activated one. Closes #156
The activated VIRTUAL_ENV and the virtualenv nodeenv is installed in can only differ when nodeenv is installed elsewhere, and then the choice is ambiguous, so log which one is used and how to override it. The three sys.prefix branches all resolved to the same value, they are folded into a single check reused by the warning.
ekalinin
force-pushed
the
fix/python-virtualenv-arg
branch
from
September 19, 2026 12:19
9afae88 to
e60ab77
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #156
Problem
-ptakes no argument, and the env dir detection checkssys.prefixbeforeVIRTUAL_ENV. When nodeenv is installed into its own virtualenv (pipx,pipsi,uv tool),sys.prefixis that virtualenv, so-psilently installs node.js there instead of the activated one:nodeenv --force $VIRTUAL_ENVis not a workaround: without-pthe activation script is written withappend=False, so the virtualenv's ownbin/activategets overwritten, and the predeactivate hook is not installed.Changes
-paccepts an optional directory (nargs='?',const=True), so any virtualenv can be targeted explicitly. A missing directory is an error (exit 2) instead of silently creating a new one, since the "environment already exists" check is skipped for-p.VIRTUAL_ENVnow wins oversys.prefix.sys.prefixbranches all resolved to the same value, so they are folded into a single check that the warning reuses.get_env_dirtests did not isolateos.environ; they now clear it, so the result no longer depends on whether pytest runs from an activated virtualenv.VIRTUAL_ENVpreference and both quiet cases.Compatibility
With nodeenv installed into virtualenv
inplace:inplaceinplaceinplaceinplace/bin/nodeenv -pinplaceinplaceVIRTUAL_ENVinherited from an outer shell,inplace/bin/nodeenv -pby pathinplaceThe common case - node.js installed into the virtualenv you are in - is unchanged, including activation through a symlink, where
venvexports the resolved path inVIRTUAL_ENV. The last row is a behaviour change; it is no longer silent and-p DIRselects the intended virtualenv.nodeenv -p somedirpreviously ignoredsomedirand used the current virtualenv; it now treats it as the target virtualenv.Verification
Beyond the unit tests, the scenario from the issue end to end - nodeenv installed in
nodeenv-home,targetactivated:-presolves totarget(previouslynodeenv-home)-p /path/to/targetworks with noVIRTUAL_ENVsetnodeenv -p /path/to/target --node=systemappends to the existingbin/activate(76 -> 220 lines); aftersource, bothVIRTUAL_ENVandNODE_VIRTUAL_ENVare set andnoderesolves inside the target virtualenv