GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Accept Python 3 when NODE_GYP_PYTHON3 is defined by joaocgreis · Pull Request #1815 · nodejs/node-gyp

Accept Python 3 when NODE_GYP_PYTHON3 is defined #1815

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.

Sign up for GitHub

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

Closed
joaocgreis wants to merge 5 commits into nodejs:master from JaneaSystems:joaocgreis-J77-python3

Uh oh!

There was an error while loading. Please reload this page.

Closed

Accept Python 3 when NODE_GYP_PYTHON3 is defined #1815

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit Hold shift + click to select a range
c79708d
python: move Python detection to its own file
joaocgreis Jul 8, 2019
e2c75b4
python: accept Python 3 when NODE_GYP_PYTHON3=1
joaocgreis Jul 8, 2019
cc6c659
fixup: rename NODE_GYP_PYTHON3 to EXPERIMENTAL_NODE_GYP_PYTHON3
joaocgreis Jul 9, 2019
4617ecb
fixup: reject outdated versions 3.0-3.4
joaocgreis Jul 9, 2019
19f02f6
fixup: fix linting
joaocgreis Jul 10, 2019
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Prev Previous commit
Next Next commit
python: accept Python 3 when NODE_GYP_PYTHON3=1
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.
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@joaocgreis
joaocgreis committed Jul 9, 2019
commit e2c75b4cf5ed0300561c134bde41d82e020e73d8

There are no files selected for viewing

30 changes: 28 additions & 2 deletions 30 .travis.yml
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,61 @@ cache: pip
matrix:
include:
- name: "Python 2.7 on Linux"
env: NODE_GYP_FORCE_PYTHON=python2
Comment thread

@cclauss cclauss Jul 9, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@cclauss cclauss Jul 9, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
python: 2.7
- name: "Python 2.7 on macOS"
os: osx
osx_image: xcode10.2
language: shell # 'language: python' is not yet supported on macOS
env: NODE_GYP_FORCE_PYTHON=python2
before_install: HOMEBREW_NO_AUTO_UPDATE=1 brew install npm
- name: "Node.js 6 & Python 2.7 on Windows"
os: windows
language: node_js
node_js: 6 # node
env: PATH=/c/Python27:/c/Python27/Scripts:$PATH
env: >-
PATH=/c/Python27:/c/Python27/Scripts:$PATH
NODE_GYP_FORCE_PYTHON=/c/Python27/python.exe
before_install: choco install python2
- name: "Node.js 12 & Python 2.7 on Windows"
os: windows
language: node_js
node_js: 12 # node
env: PATH=/c/Python27:/c/Python27/Scripts:$PATH
env: >-
PATH=/c/Python27:/c/Python27/Scripts:$PATH
NODE_GYP_FORCE_PYTHON=/c/Python27/python.exe
before_install: choco install python2
- name: "Node.js 6 & Python 3.7 on Linux"
python: 3.7
env: NODE_GYP_FORCE_PYTHON=python3 NODE_GYP_PYTHON3=1
before_install: nvm install 6
- name: "Node.js 8 & Python 3.7 on Linux"
python: 3.7
env: NODE_GYP_FORCE_PYTHON=python3 NODE_GYP_PYTHON3=1
before_install: nvm install 8
- name: "Node.js 10 & Python 3.7 on Linux"
python: 3.7
env: NODE_GYP_FORCE_PYTHON=python3 NODE_GYP_PYTHON3=1
before_install: nvm install 10
- name: "Node.js 12 & Python 3.7 on Linux"
python: 3.7
env: NODE_GYP_FORCE_PYTHON=python3 NODE_GYP_PYTHON3=1
before_install: nvm install 12
- name: "Node.js 12 & Python 3.7 on Windows"
os: windows
language: node_js
node_js: 12 # node
env: >-
PATH=/c/Python37:/c/Python37/Scripts:$PATH
NODE_GYP_FORCE_PYTHON=/c/Python37/python.exe
NODE_GYP_PYTHON3=1
before_install: choco install python
allow_failures:
- env: NODE_GYP_FORCE_PYTHON=python3 NODE_GYP_PYTHON3=1
- env: >-
PATH=/c/Python37:/c/Python37/Scripts:$PATH
NODE_GYP_FORCE_PYTHON=/c/Python37/python.exe
NODE_GYP_PYTHON3=1
install:
#- pip install -r requirements.txt
- pip install flake8 # pytest # add another testing frameworks later
Expand All @@ -45,6 +70,7 @@ before_script:
- flake8 . --count --exit-zero --ignore=E111,E114,W503 --max-complexity=10 --max-line-length=127 --statistics
- npm install
script:
- node -e 'require("npmlog").level="verbose"; require("./lib/find-python")(null,()=>{})'
- npm test
#- pytest --capture=sys # add other tests here
notifications:
Expand Down
140 changes: 82 additions & 58 deletions 140 lib/find-python.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ PythonFinder.prototype = {
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: '>=2.6.0 <3.0.0',
semverRange: process.env.NODE_GYP_PYTHON3 ? '>=2.7.0' : '>=2.6.0 <3.0.0',
Comment thread Outdated

@cclauss cclauss Jul 9, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@joaocgreis joaocgreis Jul 9, 2019

Copy link
Copy Markdown
Member Author

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

// These can be overridden for testing:
execFile: cp.execFile,
env: process.env,
win: win,
pyLauncher: 'py.exe',
defaultLocation: path.join(process.env.SystemDrive || 'C:', 'Python27',
'python.exe'),
winDefaultLocations: [
path.join(process.env.SystemDrive || 'C:', 'Python27', 'python.exe'),
path.join(process.env.SystemDrive || 'C:', 'Python37', 'python.exe')
],

// Logs a message at verbose level, but also saves it to be displayed later
// at error level if an error occurs. This should help diagnose the problem.
Expand All @@ -39,65 +41,87 @@ PythonFinder.prototype = {
// Ignore errors, keep trying until Python is found.
findPython: function findPython () {
const SKIP = 0; const FAIL = 1
const toCheck = [
{
before: () => {
if (!this.configPython) {
var toCheck = getChecks.apply(this)

function getChecks () {
if (this.env.NODE_GYP_FORCE_PYTHON) {
return [ {
before: () => {
this.addLog(
'Python is not set from command line or npm configuration')
return SKIP
}
this.addLog('checking Python explicitly set from command line or ' +
'npm configuration')
this.addLog('- "--python=" or "npm config get python" is ' +
`"${this.configPython}"`)
},
check: this.checkCommand,
arg: this.configPython
},
{
before: () => {
if (!this.env.PYTHON) {
this.addLog('Python is not set from environment variable PYTHON')
return SKIP
}
this.addLog(
'checking Python explicitly set from environment variable PYTHON')
this.addLog(`- process.env.PYTHON is "${this.env.PYTHON}"`)
'checking Python explicitly set from NODE_GYP_FORCE_PYTHON')
this.addLog('- process.env.NODE_GYP_FORCE_PYTHON is ' +
`"${this.env.NODE_GYP_FORCE_PYTHON}"`)
},
check: this.checkCommand,
arg: this.env.NODE_GYP_FORCE_PYTHON
} ]
}

var checks = [
{
before: () => {
if (!this.configPython) {
this.addLog(
'Python is not set from command line or npm configuration')
return SKIP
}
this.addLog('checking Python explicitly set from command line or ' +
'npm configuration')
this.addLog('- "--python=" or "npm config get python" is ' +
`"${this.configPython}"`)
},
check: this.checkCommand,
arg: this.configPython
},
check: this.checkCommand,
arg: this.env.PYTHON
},
{
before: () => { this.addLog('checking if "python2" can be used') },
check: this.checkCommand,
arg: 'python2'
},
{
before: () => { this.addLog('checking if "python" can be used') },
check: this.checkCommand,
arg: 'python'
},
{
before: () => {
if (!this.win) {
// Everything after this is Windows specific
return FAIL
}
this.addLog(
'checking if the py launcher can be used to find Python 2')
{
before: () => {
if (!this.env.PYTHON) {
this.addLog('Python is not set from environment variable ' +
'PYTHON')
return SKIP
}
this.addLog('checking Python explicitly set from environment ' +
'variable PYTHON')
this.addLog(`- process.env.PYTHON is "${this.env.PYTHON}"`)
},
check: this.checkCommand,
arg: this.env.PYTHON
},
check: this.checkPyLauncher
},
{
before: () => {
this.addLog(
'checking if Python 2 is installed in the default location')
{
before: () => { this.addLog('checking if "python" can be used') },
check: this.checkCommand,
arg: 'python'
},
check: this.checkExecPath,
arg: this.defaultLocation
{
before: () => { this.addLog('checking if "python2" can be used') },
check: this.checkCommand,
arg: 'python2'
}
]

if (this.win) {
checks.push({
before: () => {
this.addLog(
'checking if the py launcher can be used to find Python 2')
},
check: this.checkPyLauncher
})
for (var i = 0; i < this.winDefaultLocations.length; ++i) {
const location = this.winDefaultLocations[i]
checks.push({
before: () => {
this.addLog('checking if Python is ' +
`${location}`)
},
check: this.checkExecPath,
arg: location
})
}
}
]

return checks
}

function runChecks (err) {
this.log.silly('runChecks: err = %j', (err && err.stack) || err)
Expand Down Expand Up @@ -276,7 +300,7 @@ PythonFinder.prototype = {

this.log.error(`\n${errorLog}\n\n${info}\n`)
process.nextTick(this.callback.bind(null, new Error(
'Could not find any Python 2 installation to use')))
'Could not find any Python installation to use')))
}
}

Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.