Skip to content

feat(nodeenv): add --prefer-system to use system node when available - #395

Merged
ekalinin merged 8 commits into
masterfrom
feat/prefer-system
Sep 13, 2026
Merged

ekalinin merged 8 commits into
masterfrom
feat/prefer-system

Conversation

@ekalinin

@ekalinin ekalinin commented Sep 12, 2026 •

Copy link
Copy Markdown
Owner

Closes #153

Summary

Adds --prefer-system (and the prefer_system key in ~/.nodeenvrc): when set, nodeenv uses the system-wide node.js if nodejs or node is found in PATH, otherwise it installs the version given by --node as usual.

  • --node keeps its meaning and becomes the fallback: latest, lts, an exact version, a semver range or a .node-version file all work.
  • When a system node is found, args.node becomes system before any version resolution, so no request to index.json is made (same offline contract as --node=system).
  • The lookup is done by a new find_system_node() helper, extracted from install_activate(), which keeps excluding the environment's own bin directory (matters for -p inside an activated virtualenv).
  • --node=system is unchanged and still fails when no node is found. On Windows the flag logs a warning and is ignored, since system mode is not supported there.
  • A found system node is used as is, its version is not checked against --node.

Two pre-existing problems of the system mode that the new flag made easier to hit are fixed here as well:

  • node_version_from_args() ran a literal node --version, so a host exposing node.js only as nodejs crashed with FileNotFoundError right after the system node had been found. It now runs the executable find_system_node() returns, falling back to node.
  • remove_env_bin_from_path() was a substring replace of <bin>:, so it missed the environment's bin directory when it was the last or only PATH entry, or given as a relative path, and mangled PATH in the relative case. With --prefer-system --force on an existing environment that could select the environment's own node and overwrite it with a shim pointing at itself. It now drops exact PATH entries compared by realpath, so symlinked paths match too.

Changes

  • nodeenv.py: find_system_node(), Config.prefer_system, --prefer-system argument, decision block in main(), the two fixes above.
  • tests/nodeenv_test.py: 20 new tests (helper, config, argparse, every row of the decision table incl. Windows and --list, no-network assertions, nodejs-only host, PATH filtering for last, sole, relative and symlinked entries).
  • README.rst, CHANGES: option description, usage example, config block line, changelog entry.

Checks

  • pytest tests -m "not integration": 216 passed
  • flake8 --extend-ignore=E127 nodeenv.py tests setup.py: clean
  • Manual: with node in PATH the shim points at the system binary; with only nodejs in PATH the environment is created and the shim points at it; with PATH stripped, install proceeds with --node; an existing environment whose bin is last in PATH is no longer picked as the system node under --prefer-system --force.

@ekalinin
ekalinin merged commit 7266e35 into master Sep 13, 2026
38 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.

Request: Install if system is not available

1 participant