-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accept Python 3 when NODE_GYP_PYTHON3 is defined #1815
Conversation
I thought we were there already? Don't we have Travis tests for this? This python garbage is doing my head in and I wish we had more actual python people working on this or at least helping review. The sooner we get to gyp.js the better. |
I thought so too. Node-gyp was doing what it's supposed to do, find a compatible version of Python somewhere and run it. The tests don't show info output so we had no confirmation of version. All the Linux machines have Python 2 installed, so the tests pass with no errors.
This shows that when actually using Python 3 the tests don't pass, but I don't know how hard those issues are to fix.
|
At least https://travis-ci.com/nodejs/node-gyp/jobs/214237690#L2234-L2241 +Traceback (most recent call last):
+ File "/home/travis/build/nodejs/node-gyp/gyp/gyp_main.py", line 13, in <module>
+ import gyp
+ File "/home/travis/build/nodejs/node-gyp/gyp/pylib/gyp/__init__.py", line 10, in <module>
+ import gyp.input
+ File "/home/travis/build/nodejs/node-gyp/gyp/pylib/gyp/input.py", line 7, in <module>
+ from compiler.ast import Const
+ModuleNotFoundError: No module named 'compiler' looks like it would be fixed by refack/GYP3@f989ef9. |
@@ -4,32 +4,61 @@ cache: pip | |||
matrix: | |||
include: | |||
- name: "Python 2.7 on Linux" | |||
env: NODE_GYP_FORCE_PYTHON=python2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Linux runs Travis will set the environment variable $TRAVIS_PYTHON_VERSION == 2.7 so perhaps that it would be better to leverage that rather than create a new environment variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I think about it more, I now understand that you are looking for a more general solution that is useful well beyond just Travis CI. What if we name the variable NODE_GYP_PYTHON2 and set it to True in legacy Python environments and set it to False or leave it undefined in Python 3 environments? In this way we would not need to carry this baggage into future years. With just 176 days left before Python 2 end of life we should be making execution on Python 3 the default behavior and making running on Python 2 be the special case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. Thanks for doing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NODE_GYP_PYTHON3 --> NODE_GYP_PYTHON2
@cclauss I don't understand which variable you'd like to change. Changing
|
I like the idea behind NODE_GYP_FORCE_PYTHON. It will not be needed on Travis CI Linux because those jobs run in virtualenvs where by definition python points to the version of Python which is specified in the python: tag. On Travis CI Mac, NODE_GYP_FORCE_PYTHON plays a very useful role because both python2 and and python3 will be present and you know the Windows story better than I do. I would like to resist the NODE_GYP_PYTHON3 variable unless we have an agreed upon method of deprecating it. My sense is that once we introduce new configuration vocabulary, it is nearly impossible to drop it. For example, our README.md clearly states that we no longer support Python 2.6 yet contributors continue to try to push it back into our scripts. As I wrote above, Python 3 should the default and Python 2 should be the opt-in. Python 3 has been available for 8+ years and is the present and future of the language. Python 2 is legacy and is no longer supported at yearend. Therefore, I would much rather see us introduce a variable called NODE_GYP_PYTHON2 and force those who wish to remain on legacy Python to set that variable. I advocate that continuing to rely on a soon-to-be-EOLed platform should to be a deliberate, conscious, and documented choice. |
lib/find-python.js
Outdated
log: logWithPrefix(log, 'find Python'), | ||
argsExecutable: [ '-c', 'import sys; print(sys.executable);' ], | ||
argsVersion: [ '-c', 'import sys; print("%s.%s.%s" % sys.version_info[:3]);' ], | ||
semverRange: process.env.NODE_GYP_PYTHON3 ? '>=2.7.0' : '>=2.6.0 <3.0.0', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove v2.6.0 to align with this project's README.md.
For this project:
- Python2 is >=2.7.0 <3.0.0
- Python3 is >=3.5.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only to extend the range of acceptable versions, not select which version to use.
@cclauss I might be missing something here, but I don't understand where you're trying to get to. Node-gyp does not work with Python 3, as Travis shows. By making Python 3 the default, node-gyp will be broken by default for every user. How is that acceptable? |
This PR is supposed to make node-gyp Python 3 compatible. We all already thought that it was with all the tests passing until you demonstrated to us that find_python.js was actually silently preventing us from finding Python. That script was hardcoded to legacy which is exactly want I would like us to avoid continuing in this PR. I have been on this mission for a year now... I also worked on https://github.com/refack/GYP which was more advanced in Python 3 support but unfortunately was not adopted. |
This PR does not make node-gyp Python 3 compatible, it only allows testing with it.
The only test that actually runs node-gyp end-to-end is @cclauss it's great that you can put some effort into making node-gyp Python 3 compatible, thank you for moving that forward. I can't look into it myself, but I think this is a very important goal and that's why I'm trying to help where I can. With all changes that happened so far, I was not finding it surprising that node-gyp was already compatible until I started looking into the Windows failures. I hope that even if this is a bit disappointing, there won't be much left to do. |
This allows us to start testing Python 3 without breaking node-gyp for users. This also adds support for NODE_GYP_FORCE_PYTHON, which will be the only Python binary acceptable when defined.
ea08a83
to
e2c75b4
Compare
The ModuleNotFoundError: No module named 'compiler' errors are caused by the fact that the compiler package was removed in Python 3 in favor of the ast module that exists in both Python 2 and Python 3. |
I renamed @cclauss when this lands (or even before by depending on this), fixing that error should require only picking those changes and adapting for any possible difference. |
Thanks for our WebEx on this topic and the resulting changes that you have made. If you can fix the Travis CI Py2 issues then I will give this PR a LGTM. It is a bummer that our Py3 tests now fail but at least with PR we are able to run the desired version of Python. We can leave the Py3 Travis tests in allow_failures mode in this PR and then we can work to make those tests green in future PRs. |
@cclauss fixed, thanks! CI: https://ci.nodejs.org/view/All/job/nodegyp-test-pull-request/142/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work here! Thanks.
PR-URL: #1815 Reviewed-By: Christian Clauss <cclauss@me.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
This allows us to start testing Python 3 without breaking node-gyp for users. This also adds support for NODE_GYP_FORCE_PYTHON, which will be the only Python binary acceptable when defined. PR-URL: #1815 Reviewed-By: Christian Clauss <cclauss@me.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Landed in bb92c76...66ad305 |
Why have we created a new NODE_GYP_FORCE_PYTHON environment variable when there is already a well documented gyp --python option? Do they do the same thing or different things? Which one takes precedence? |
The
Note that the verbose log output shows clearly what is used, what can't be used, by what order and why. Precedence works like this:
The code is here: Lines 47 to 125 in 66ad305
|
Checklist
npm install && npm test
passesDescription of change
This depends on #1812, I'll rebase when that PR lands.This allows for Python 3 to be tested without breaking node-gyp for users.
This uses two new environment variables:
NODE_GYP_FORCE_PYTHON
is the only Python binary checked when it is defined (so we can be sure of what version is being tested in Travis), andNODE_GYP_PYTHON3
conditionally enables Python 3.When Python 3 is fully supported, enabling it unconditionally should be as simple as removing
NODE_GYP_PYTHON3
, which is only used on one line.This includes two commits. One just moves Python detection to a new file. The other contains the rest of the changes. Separately, they should be easy to review.
The tests that check for a "Python version too new" were deleted. Hopefully we won't need them again.