Repository navigation
fix: do not require python2 to build node from source - #429
Conversation
build_node_from_src() raised OSError whenever nodeenv ran on Python 3 and no python2 command was on PATH, and otherwise prepended a tmpbin dir that points `python` at python2. node.js has built with Python 3 for years and its ./configure picks python3.x on its own, so drop the shim and let the build use the inherited environment. Fixes ekalinin#419.
|
Thanks for picking up #419! Not requiring python2 for current node.js versions is the right goal, but removing the shim entirely breaks source builds of older ones. Older node.js versions still need python2 Before 8.5 (and 6.12 on the 6.x line), node's With this change, the README example Could we keep the shim only for the versions that need it instead? if parse_version(args.node) < (8, 5):
# before 8.5, ./configure is a `#!/usr/bin/env python` script
# that only runs on Python 2, so point `python` at python2
python2_path = shutil.which('python2')
if not python2_path:
raise OSError(
'no python2 command (required for building '
'node.js %s) was found' % args.node
)
... # the existing tmpbin / PATH codeThis also keeps a clear error for old versions. Without the check, a user without Tests The new test only covers
Please check the call kwargs as well, so an CHANGES Please add an entry for #419 under |
ekalinin
left a comment
There was a problem hiding this comment.
See #429 (comment) for the details.
Before 8.5, node's ./configure is a `#!/usr/bin/env python` script that only runs on Python 2, so source builds of those versions (e.g. the README's 0.10.25 example) still need `python` pointed at python2. Only set up the tmpbin link and PATH override when args.node < 8.5, and keep a clear OSError naming the version when python2 is missing. Tests cover a current version with python2 on PATH (no tmpbin, no extra_env, positional or keyword), an old version with python2 (tmpbin link created, PATH starts with it) and an old version without python2. Add a CHANGES entry for ekalinin#419.
|
Thanks for checking the old releases, you're right. I pushed 9bb0da6:
|
|
Thanks for the quick update, and sorry: the
So the link is needed for if parse_version(args.node) < (8, 8):
# before 8.8, gyp and make run `python` by name and node does not
# point it at Python 2 itself, so point `python` at python2The test that uses 8.5.0 as a "no link" version would then need 8.8.0, and an 8.7.x case would cover the boundary. The CHANGES entry also needs a fix: up to 12.x, |
The 8.5 cutoff only looked at the first line of ./configure. Before 8.8 gyp and make still run `python` by name (toolchain.gypi during configure, the js2c actions during make) and node does not point it at Python 2 itself: 8.5/8.6 have no override and 8.7's get_bin_override() crashes when there is no `python` at all. So keep the tmpbin link for < 8.8. Up to 12.x ./configure only accepts Python 2.7, so 8.8-12.x still need python2 even though they find it on their own; keep the early "no python2" OSError for < 13 so a missing python2 is not reported as a bare `./configure ... failed` without --verbose. Tests: 8.8.0/12.22.12/22.11.0 with python2 get no link, 13.0.0/22.11.0 build without python2, 0.10.25/8.5.0/8.7.0 get the link, and 0.10.25/8.7.0/12.22.12 without python2 raise OSError. Fix the CHANGES entry accordingly.
|
Thanks for digging into the gyp and make side, I only checked
|
|
Thanks! |
Fixes #419.
build_node_from_src()always looked uppython2on Python 3, raisedOSErrorif there wasn't one, and otherwise prepended atmpbindir whosepythonpoints at python2. Since nodeenv only runs on Python 3 now,nodeenv --sourcefailed for every node.js version on machines withoutpython2, which is most of them.What node itself needs, by version:
pythonby name (deps/v8/gypfiles/toolchain.gypiduring configure, the js2c actions innode.gypduring make), and node does not point it at Python 2 itself. 8.7.0 addsget_bin_override(), but it crashes when there is nopythonat all. 8.8.0 adds theNonecheck../configureonly accepts Python 2.7 (Please use Python 2.7), so 8.8-12.x still need python2, they just find it on their own../configurealso accepts Python 3.So this:
tmpbin/pythonto python2 and prepends it toPATHonly forargs.node < 8.8,OSErrornaming the version whenpython2is missing forargs.node < 13, instead of a bareCommand ./configure ... failedwithout--verbose,configure/make/make installwith the inherited environment otherwise.Tests:
tmpbin, noextra_envpassed tocallit(positional or keyword).tmpbin, noextra_env.tmpbin/pythonis linked to python2 andPATHstarts withtmpbinfor all three build commands.OSError.pytest -m 'not integration' tests: 364 passed, 46 skipped.flake8 --extend-ignore=E127 nodeenv.py tests setup.pyis clean.Added a CHANGES entry under
Version [unreleased].