Repository navigation
Conversation
|
Please rebase on master. |
f79bb4f to
62783ba
Compare
|
Rebased. |
ekalinin
left a comment
There was a problem hiding this comment.
Thanks for the patch! Three things before merge.
-
The anchors match only the newest CPython venv templates.
activate.bathas the quotedset "PATH=%VIRTUAL_ENV%\Scripts;%PATH%"in 3.12.10, 3.13.5 and later, but 3.10, 3.11, 3.12.0-3.12.7 and 3.13.0 write it without quotes. The bashactivatehas# Call hash to forget past locations.in the same versions, while older ones say# Call hash to forget past commands.or# This should detect bash and zsh. For a venv made by any of those, the utility stops withexpected one insertion point, though the README says Python 3.10+. I ranpatch_activationon the templates from the CPython tags: 3.10.11, 3.11.9, 3.12.0, 3.12.7 and 3.13.0 fail, 3.12.10, 3.13.5, 3.13.9 and 3.14.0 pass. The test fixtures are hand-written excerpts, so they don't catch it.The inserted blocks also differ from what nodeenv puts into these scripts. They never set
npm_config_prefix, so #309 comes back in a migrated venv:npxexports a prefix andScripts\npm.cmdthen runs the npm found under it. In Git Bash they clearNODE_PATH, while nodeenv'sactivatesets it toScripts/node_modules.nodeenv can already do this part. Since 1.11.0,
nodeenv -p .venv --node=<version>skips the download when that node version is already in the venv (#403), and then appends its own blocks toactivate,activate.bat,deactivate.batandActivate.ps1, including the PowerShell signature handling. So the utility could move the files and then run that command with the installed version (or the README could tell the user to run it), andPATCHESandpatch_activationwith their tests can go. I checked it on macOS with a venv that already held node 26.13.0: nothing was downloaded, andactivategot theNODE_PATHandnpm_config_prefixblocks. I haven't tried it on Windows. -
If a rename fails halfway, for example because an editor or a dev server holds
node.exeor a file undernode_modules, the entries moved before it stay in.venv, the activation scripts are not changed, and neither environment works. Please move them back on failure, or at least list what was moved in the error. Also, "You can now delete the source directory" is printed whenskipped > 0too. The files kept inenvare not compared with those in.venv, so the user can be told to delete the only copy of a differentnode.exe. I'd print it only when nothing was skipped, and list the skipped entries otherwise. -
README.rstis also the PyPI description (setup.pyreads it), and the relative linkutils/README.mddoesn't resolve on pypi.org. A full GitHub URL works in both places.
92325ef to
526958c
Compare
|
Thanks for the review.
I switched the helper to native nodeenv -p, added rollback for failed tasks, and made list for skipped entries.
The cleanup message now appears only when no entries were skipped.
I fixed the README link and rebased on current master.
I've verified work on Windows 11 (und 10), on some of my existed projects.
|
There was a problem hiding this comment.
🟡 Changes recommended
Active issues can leave Python activation unvalidated, mix or duplicate CRLF activation patches, and leave Node environment variables set after normal Python deactivation.
3 open issues
What changed in this PR
Adds an optional Windows migration helper for consolidating an existing Node environment into a Python venv, complementing the recommended nodeenv -p workflow for new setups.
Changes:
- Adds migration planning, collision checks, dry-run output, move rollback, and activation through
nodeenv -p. - Adds offline tests for migration behavior and failure handling.
- Documents the workflow and includes
utilsin lint checks.
| File | Description |
|---|---|
utils/README.md |
Documents migration usage, prerequisites, and limitations. |
utils/integrate_nodeenv.py |
Implements the Windows migration helper. |
tox.ini |
Adds utilities to tox lint checks. |
tests/test_integrate_nodeenv.py |
Tests migration planning, safety checks, and failures. |
README.rst |
Links to the optional migration workflow. |
CONTRIBUTING.md |
Updates the documented lint command. |
CHANGES |
Announces the migration utility. |
.github/workflows/tests.yml |
Includes utilities in CI lint checks. |
Review effort: Balanced
| subprocess.run([ | ||
| sys.executable, str(nodeenv), '-p', str(destination), | ||
| f'--node={version[1]}', '--config-file=', '--no-clean-src', | ||
| ], check=True) |
| subprocess.run([ | ||
| sys.executable, str(nodeenv), '-p', str(destination), | ||
| f'--node={version[1]}', '--config-file=', '--no-clean-src', | ||
| ], check=True) |
| for name in ('activate', 'activate.bat', 'deactivate.bat', | ||
| 'Activate.ps1', 'predeactivate.bat', 'predeactivate.ps1'): | ||
| existing = resulting_file(scripts / name) | ||
| if os.path.lexists(existing): | ||
| if is_link(existing) or not existing.is_file(): |
|
I change this three problem from Copilot. I am agree with this comments. It is hard to check all use cases once.
|

Motivation
In an existing project with both Python and Node.js, I wanted activating the
Python virtual environment to also select the project's already installed
Node/npm. The runtimes had been set up separately, so consolidating them meant
manually moving files without replacing the Python activation scripts and then
editing activation and deactivation for each Windows shell.
This adds an optional, repeatable utility for that migration: simply add an
existing Node installation to an existing Python environment, reuse the installed
files, and use one activation entry point for both runtimes.
For a new setup,
nodeenv -pis strongly recommended. Create and activate thePython venv first, then run
nodeenv -p. The new utility is for consolidatingenvironments that already exist, without downloading Node/npm again.
Changes
utils/integrate_nodeenv.pywith--source,--venvand--dry-run.Defaults are
envand.venvin the project's current working directory.entries and retaining their source copies. Reject overlapping roots,
incompatible file/directory collisions and unsafe activation links.
NODE_PATHsave/restore into CMD, PowerShell and Git Bash activation anddeactivation. Repeated runs preserve existing recognized patches and mtimes.
deleted only after migration and patching both succeed.
nodeenv -pworkflow and migration stepsin
utils/README.md; link it from the main README and add a changelog entry.utilsin flake8 checks.The utility is Windows-only, runs on Python 3.10+, and accepts recognized CPython
activation layouts. It preserves UTF-8 BOMs and line endings. An edited
Activate.ps1loses its original signature; execution policy is left unchanged.Validation
Tested locally on Windows with Python 3.12.10 and Git Bash available on PATH:
The 40 new tests cover migration/no overwrite, dry runs, preflight failures,
repeated runs, working-directory defaults, junction handling, platform checks,
line endings, BOMs and PowerShell signatures. Download-based integration tests
were excluded from the local run.
type(scope): subject.