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

build: better support for python3 systems #14737

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
9 participants
@bnoordhuis
Member

bnoordhuis commented Aug 10, 2017

Improve support for systems where python is actually python3.

Not all systems have a python2 binary, so simply updating the shebang
won't work.

What we can do is apply some cleverness: start life as a shell script,
locate the python binary, then re-execute the script but this time as
python code.

Special care is taken to ensure that spaces in arguments are passed on
verbatim.

This would need to be applied to other python scripts as well but I figured
I'd start with a single script in case everyone hates the approach.

CI: https://ci.nodejs.org/job/node-test-pull-request/9594/

@addaleax

I’m okay with this.

@danbev

danbev approved these changes Aug 10, 2017

@gibfahn

Couple of suggestions

Also branch name should have been I-shpy-with-my-little-eye-something-beginning-with-python2

@@ -1,4 +1,14 @@
#!/usr/bin/env python
#!/bin/sh

This comment has been minimized.

@gibfahn

gibfahn Aug 12, 2017

Member

This will stop syntax highlighting from working. Not the end of the world I guess.

@gibfahn

gibfahn Aug 12, 2017

Member

This will stop syntax highlighting from working. Not the end of the world I guess.

Show outdated Hide outdated configure
# Locate python2 interpreter and re-execute the script. Note that the
# mix of single and double quotes is intentional, as is the fact that
# the ] goes on a new line.
_=[ 'exec' '/bin/sh' '-c' '''

This comment has been minimized.

@gibfahn

gibfahn Aug 12, 2017

Member

Is changing $_ definitely okay in all shells? I know it's normally not user-modifiable, but IDK about csh and other arcane shells. I checked zsh, bash, and dash.

@gibfahn

gibfahn Aug 12, 2017

Member

Is changing $_ definitely okay in all shells? I know it's normally not user-modifiable, but IDK about csh and other arcane shells. I checked zsh, bash, and dash.

This comment has been minimized.

@bnoordhuis

bnoordhuis Aug 14, 2017

Member

/bin/sh is always a Bourne-compatible shell, so it should be okay.

@bnoordhuis

bnoordhuis Aug 14, 2017

Member

/bin/sh is always a Bourne-compatible shell, so it should be okay.

# the ] goes on a new line.
_=[ 'exec' '/bin/sh' '-c' '''
which python2.7 >/dev/null && exec python2.7 "$0" "$@"
which python2 >/dev/null && exec python2 "$0" "$@"

This comment has been minimized.

@gibfahn

gibfahn Aug 12, 2017

Member

Maybe check for python2.6 as well?

@gibfahn

gibfahn Aug 12, 2017

Member

Maybe check for python2.6 as well?

This comment has been minimized.

@bnoordhuis

bnoordhuis Aug 14, 2017

Member

So, I deliberately didn't add python2.6 for two reasons:

  1. I wasn't sure if it should go before or after python2, and
  2. We supported python2.6 because of centos 5 but since we no longer support that platform...
@bnoordhuis

bnoordhuis Aug 14, 2017

Member

So, I deliberately didn't add python2.6 for two reasons:

  1. I wasn't sure if it should go before or after python2, and
  2. We supported python2.6 because of centos 5 but since we no longer support that platform...

This comment has been minimized.

@gibfahn

gibfahn Aug 14, 2017

Member

Okay, I guess dropping python2.6 should be a separate PR.

@gibfahn

gibfahn Aug 14, 2017

Member

Okay, I guess dropping python2.6 should be a separate PR.

@gibfahn

This comment has been minimized.

Show comment
Hide comment
@gibfahn

gibfahn Aug 12, 2017

Member

Ben this is witchcraft, did you just come up with this? I can't get over how many python specific things it relies on.

Member

gibfahn commented Aug 12, 2017

Ben this is witchcraft, did you just come up with this? I can't get over how many python specific things it relies on.

@bnoordhuis

This comment has been minimized.

Show comment
Hide comment
@bnoordhuis

bnoordhuis Aug 14, 2017

Member

I got the idea from a perl script. :-) It's a lot easier in perl though because just about any shell syntax is also valid perl.

Member

bnoordhuis commented Aug 14, 2017

I got the idea from a perl script. :-) It's a lot easier in perl though because just about any shell syntax is also valid perl.

build: better support for python3 systems
Improve support for systems where `python` is actually `python3`.

Not all systems have a `python2` binary, so simply updating the shebang
won't work.

What we can do is apply some cleverness: start life as a shell script,
locate the python binary, then re-execute the script but this time as
python code.

Special care is taken to ensure that spaces in arguments are passed on
verbatim.
@bnoordhuis

This comment has been minimized.

Show comment
Hide comment
@bnoordhuis

bnoordhuis Aug 17, 2017

Member

Added a del statement. New CI for good measure: https://ci.nodejs.org/job/node-test-pull-request/9706/

Member

bnoordhuis commented Aug 17, 2017

Added a del statement. New CI for good measure: https://ci.nodejs.org/job/node-test-pull-request/9706/

@jasnell

This comment has been minimized.

Show comment
Hide comment
Member

jasnell commented Aug 23, 2017

jasnell added a commit that referenced this pull request Aug 23, 2017

build: better support for python3 systems
Improve support for systems where `python` is actually `python3`.

Not all systems have a `python2` binary, so simply updating the shebang
won't work.

What we can do is apply some cleverness: start life as a shell script,
locate the python binary, then re-execute the script but this time as
python code.

Special care is taken to ensure that spaces in arguments are passed on
verbatim.

PR-URL: #14737
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
@jasnell

This comment has been minimized.

Show comment
Hide comment
@jasnell

jasnell Aug 23, 2017

Member

Landed in c6da5c8

Member

jasnell commented Aug 23, 2017

Landed in c6da5c8

@jasnell jasnell closed this Aug 23, 2017

addaleax added a commit to addaleax/ayo that referenced this pull request Aug 25, 2017

build: better support for python3 systems
Improve support for systems where `python` is actually `python3`.

Not all systems have a `python2` binary, so simply updating the shebang
won't work.

What we can do is apply some cleverness: start life as a shell script,
locate the python binary, then re-execute the script but this time as
python code.

Special care is taken to ensure that spaces in arguments are passed on
verbatim.

PR-URL: nodejs/node#14737
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>

addaleax added a commit to ayojs/ayo that referenced this pull request Aug 28, 2017

build: better support for python3 systems
Improve support for systems where `python` is actually `python3`.

Not all systems have a `python2` binary, so simply updating the shebang
won't work.

What we can do is apply some cleverness: start life as a shell script,
locate the python binary, then re-execute the script but this time as
python code.

Special care is taken to ensure that spaces in arguments are passed on
verbatim.

PR-URL: nodejs/node#14737
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>

MylesBorins added a commit that referenced this pull request Sep 10, 2017

build: better support for python3 systems
Improve support for systems where `python` is actually `python3`.

Not all systems have a `python2` binary, so simply updating the shebang
won't work.

What we can do is apply some cleverness: start life as a shell script,
locate the python binary, then re-execute the script but this time as
python code.

Special care is taken to ensure that spaces in arguments are passed on
verbatim.

PR-URL: #14737
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>

@MylesBorins MylesBorins referenced this pull request Sep 10, 2017

Merged

v8.5.0 proposal #15308

MylesBorins added a commit that referenced this pull request Sep 12, 2017

build: better support for python3 systems
Improve support for systems where `python` is actually `python3`.

Not all systems have a `python2` binary, so simply updating the shebang
won't work.

What we can do is apply some cleverness: start life as a shell script,
locate the python binary, then re-execute the script but this time as
python code.

Special care is taken to ensure that spaces in arguments are passed on
verbatim.

PR-URL: #14737
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>

MylesBorins added a commit that referenced this pull request Sep 20, 2017

build: better support for python3 systems
Improve support for systems where `python` is actually `python3`.

Not all systems have a `python2` binary, so simply updating the shebang
won't work.

What we can do is apply some cleverness: start life as a shell script,
locate the python binary, then re-execute the script but this time as
python code.

Special care is taken to ensure that spaces in arguments are passed on
verbatim.

PR-URL: #14737
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
@MylesBorins

This comment has been minimized.

Show comment
Hide comment
@MylesBorins

MylesBorins Sep 20, 2017

Member

I've landed on v6.x. Please let me know if it should be backed out

Member

MylesBorins commented Sep 20, 2017

I've landed on v6.x. Please let me know if it should be backed out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment