Repository navigation
feat(nodeenv): add --prefer-system to use system node when available - #395
Merged
Merged
Conversation
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 #153
Summary
Adds
--prefer-system(and theprefer_systemkey in~/.nodeenvrc): when set, nodeenv uses the system-wide node.js ifnodejsornodeis found inPATH, otherwise it installs the version given by--nodeas usual.--nodekeeps its meaning and becomes the fallback:latest,lts, an exact version, a semver range or a.node-versionfile all work.args.nodebecomessystembefore any version resolution, so no request toindex.jsonis made (same offline contract as--node=system).find_system_node()helper, extracted frominstall_activate(), which keeps excluding the environment's ownbindirectory (matters for-pinside an activated virtualenv).--node=systemis 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.--node.Two pre-existing problems of the
systemmode that the new flag made easier to hit are fixed here as well:node_version_from_args()ran a literalnode --version, so a host exposing node.js only asnodejscrashed withFileNotFoundErrorright after the system node had been found. It now runs the executablefind_system_node()returns, falling back tonode.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 onlyPATHentry, or given as a relative path, and mangledPATHin the relative case. With--prefer-system --forceon an existing environment that could select the environment's own node and overwrite it with a shim pointing at itself. It now drops exactPATHentries compared byrealpath, so symlinked paths match too.Changes
nodeenv.py:find_system_node(),Config.prefer_system,--prefer-systemargument, decision block inmain(), 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,PATHfiltering 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 passedflake8 --extend-ignore=E127 nodeenv.py tests setup.py: cleanPATHthe shim points at the system binary; with onlynodejsinPATHthe environment is created and the shim points at it; withPATHstripped, install proceeds with--node; an existing environment whosebinis last inPATHis no longer picked as the system node under--prefer-system --force.