apm icon indicating copy to clipboard operation
apm copied to clipboard

Python2 regression with 1.15.3

Open Hufschmidt opened this issue 9 years ago • 4 comments

Prerequisites

  • [x] Put an X between the brackets on this line if you have done all of the following:
    • Reproduced the problem in Safe Mode: http://flight-manual.atom.io/hacking-atom/sections/debugging/#using-safe-mode
    • Followed all applicable steps in the debugging guide: http://flight-manual.atom.io/hacking-atom/sections/debugging/
    • Checked the FAQs on the message board for common solutions: https://discuss.atom.io/c/faq
    • Checked that your issue isn't already filed: https://github.com/issues?utf8=✓&q=is%3Aissue+user%3Aatom
    • Checked that there is not already an Atom package that provides the described functionality: https://atom.io/packages

Description

It seems like b364c3cfc1e28fce66418266bc719d08e614baf9 introduced a regression for Arch-Linux users, as node-gyp tries to use python3 instead of python2 when beeing executed via apm.

This is the same issue as with #95, but due to the aforementioned commit the workarounds export PYTHON=python2 or npm config set python /usr/bin/python2 -g do no work anymore.

Steps to Reproduce

Method 1

  1. Boot into an arch-linux system (eg. Manjaro LiveCD)
  2. Install atom-editor from AUR (Version 1.15.0 at the time of this writing)
  3. Install git-blame via apm (which uses node-gyp)

Method 2

  1. Temporary symlink /usr/bin/python to /usr/bin/python3 instead of /usr/bin/python2.
  2. Try (re-)installing git-blame via apm (which uses node-gyp)

Expected behavior: git-blame installs

Actual behavior: git blame fails with

$ apm install git-blame
Installing git-blame to /home/hufschmt/.atom/packages ✗

> [email protected] install /tmp/apm-install-dir-117214-7034-190qczt/node_modules/git-blame/node_modules/runas                                                                                                               
> node-gyp rebuild                                                                                                                                                                                                     

/tmp/apm-install-dir-117214-7034-190qczt                                                                                                                                                                               
└── (empty)                                                                                                                                                                                                            


gyp ERR! configure error                                                                                                                                                                                               
gyp ERR! stack Error: Python executable "/usr/share/atom/resources/app/apm/bin/python-interceptor.sh" is v3.6.0, which is not supported by gyp.                                                                        
gyp ERR! stack You can pass the --python switch to point to Python >= v2.5.0 & < 3.0.0.                                                                                                                                
gyp ERR! stack     at failPythonVersion (/usr/share/atom/resources/app/apm/node_modules/node-gyp/lib/configure.js:454:14)                                                                                              
gyp ERR! stack     at /usr/share/atom/resources/app/apm/node_modules/node-gyp/lib/configure.js:443:9                                                                                                                   
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:204:7)                                                                                                                                                
gyp ERR! stack     at emitTwo (events.js:87:13)                                                                                                                                                                        
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)                                                                                                                                                              
gyp ERR! stack     at maybeClose (internal/child_process.js:827:16)                                                                                                                                                    
gyp ERR! stack     at Socket.<anonymous> (internal/child_process.js:319:11)                                                                                                                                            
gyp ERR! stack     at emitOne (events.js:77:13)                                                                                                                                                                        
gyp ERR! stack     at Socket.emit (events.js:169:7)                                                                                                                                                                    
gyp ERR! stack     at Pipe._onclose (net.js:477:12)                                                                                                                                                                    
gyp ERR! System Linux 4.10.1-1-MANJARO                                                                                                                                                                                 
gyp ERR! command "/usr/share/atom/resources/app/apm/bin/node" "/usr/share/atom/resources/app/apm/node_modules/.bin/node-gyp" "rebuild"
gyp ERR! cwd /tmp/apm-install-dir-117214-7034-190qczt/node_modules/git-blame/node_modules/runas
gyp ERR! node -v v4.4.5
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok 
[...]

Reproduces how often: Always

Versions

$ apm --version
apm  1.15.3
npm  3.10.5
node 4.4.5 x64
python 3.6.0
git 2.12.0
$ atom --version
Atom    : 1.15.0
Electron: 1.3.13
Chrome  : 52.0.2743.82
Node    : 6.5.0

OS: Manjaro (based on Arch-Linux)

Additional Information

Dirty workaround: Uncomment export PYTHON="${binDir}/python-interceptor.sh" in /usr/bin/apm, this yields a working build-chain with:

$ apm --version
apm  1.15.3
npm  3.10.5
node 4.4.5 x64
python 2.7.13
git 2.12.0

Suggested fix Make python-interceptor.sh use the python-executable set via environment variable instead of hard-coding it to python.

Or read the value from the --python switch, such that the fix matches the one given by node-gyp. :blush:

Hufschmidt avatar Mar 14 '17 08:03 Hufschmidt

This also occurs when building Atom from source. In the Arch section of the the build instructions for Linux it says one should export PYTHON=/usr/bin/python2. However because this environment variable is ignored by the mentioned python-interceptor.sh script, It will still use /usr/bin/python which under Arch Linux links to /usr/bin/python3. I could work around this problem by changing /usr/bin/python from linking to /usr/bin/python3 to link to /usr/bin/python2. But this no real solution.

How to reproduce this

  1. Make /usr/bin/python link to something other then python2 (like it is on Arch Linux)
  2. Set the PYTHON environment variable to the real location of python2
  3. Build Atom from source

This will cause an error like this one:

$ git clone https://github.com/atom/atom.git
$ cd atom
$ export PYTHON=/usr/bin/python2
$ script/build
Node:	v6.10.1
Npm:	v4.4.4
Installing script dependencies
prebuild-install info begin Prebuild-install version 2.1.1
prebuild-install info looking for local prebuild @ prebuilds/leveldown-v1.6.0-node-v48-linux-x64.tar.gz
prebuild-install info looking for cached prebuild @ /home/moritz/.npm/_prebuilds/https-github.com-level-leveldown-releases-download-v1.6.0-leveldown-v1.6.0-node-v48-linux-x64.tar.gz
prebuild-install info found cached prebuild 
prebuild-install info unpacking @ /home/moritz/.npm/_prebuilds/https-github.com-level-leveldown-releases-download-v1.6.0-leveldown-v1.6.0-node-v48-linux-x64.tar.gz
prebuild-install info unpack resolved to /home/moritz/code/atom/atom/script/node_modules/leveldown/build/Release/leveldown.node
prebuild-install info unpack required /home/moritz/code/atom/atom/script/node_modules/leveldown/build/Release/leveldown.node successfully
prebuild-install info install Prebuild successfully installed!
Installing apm
../src/onig-string.cc: In Konstruktor »OnigString::OnigString(v8::Local<v8::String>)«:
../src/onig-string.cc:25:40: Warnung: Vergleich zwischen vorzeichenbehafteten und vorzeichenlosen Ganzzahlausdrücken [-Wsign-compare]
   hasMultiByteChars = (value->Length() != utf8_length_);
                        ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
../deps/libgit2/deps/zlib/inflate.c: In Funktion »inflateMark«:
../deps/libgit2/deps/zlib/inflate.c:1507:61: Warnung: left shift of negative value [-Wshift-negative-value]
     if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16;
                                                             ^~
gyp ERR! configure error 
gyp ERR! stack Error: Command failed: /home/moritz/code/atom/atom/apm/node_modules/atom-package-manager/bin/python-interceptor.sh -c import platform; print(platform.python_version());
gyp ERR! stack /home/moritz/code/atom/atom/apm/node_modules/atom-package-manager/bin/python-interceptor.sh: Zeile 40: exec: python: Nicht gefunden.
gyp ERR! stack 
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:206:12)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at maybeClose (internal/child_process.js:877:16)
gyp ERR! stack     at Socket.<anonymous> (internal/child_process.js:334:11)
gyp ERR! stack     at emitOne (events.js:96:13)
gyp ERR! stack     at Socket.emit (events.js:188:7)
gyp ERR! stack     at Pipe._handle.close [as _onclose] (net.js:498:12)
gyp ERR! System Linux 4.10.6-1-ARCH
gyp ERR! command "/home/moritz/code/atom/atom/apm/node_modules/atom-package-manager/bin/node" "/home/moritz/code/atom/atom/apm/node_modules/atom-package-manager/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/moritz/code/atom/atom/apm/node_modules/atom-package-manager/node_modules/oniguruma
gyp ERR! node -v v6.9.5
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok 

npm ERR! Linux 4.10.6-1-ARCH
npm ERR! argv "/home/moritz/code/atom/atom/apm/node_modules/atom-package-manager/bin/node" "/home/moritz/code/atom/atom/apm/node_modules/atom-package-manager/node_modules/.bin/npm" "rebuild"
npm ERR! node v6.9.5
npm ERR! npm  v3.10.5
npm ERR! code ELIFECYCLE
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the oniguruma package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs oniguruma
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls oniguruma
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/moritz/code/atom/atom/apm/node_modules/atom-package-manager/npm-debug.log
module.js:471
    throw err;
    ^

Error: Cannot find module 'node-gyp/bin/node-gyp'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.resolve (internal/module.js:27:19)
    at Install.module.exports.Install.installNode (/home/moritz/code/atom/atom/apm/node_modules/atom-package-manager/lib/install.js:103:67)
    at /home/moritz/code/atom/atom/apm/node_modules/atom-package-manager/lib/install.js:3:59
    at fn (/home/moritz/code/atom/atom/apm/node_modules/atom-package-manager/node_modules/async/lib/async.js:582:34)
    at Immediate.<anonymous> (/home/moritz/code/atom/atom/apm/node_modules/atom-package-manager/node_modules/async/lib/async.js:498:34)
    at runCallback (timers.js:649:20)
    at tryOnImmediate (timers.js:622:5)
    at processImmediate [as _immediateCallback] (timers.js:594:5)
child_process.js:504
    throw err;
    ^

Error: Command failed: /home/moritz/code/atom/atom/apm/node_modules/atom-package-manager/bin/apm --loglevel=error install
    at checkExecSyncError (child_process.js:481:13)
    at Object.execFileSync (child_process.js:501:13)
    at module.exports (/home/moritz/code/atom/atom/script/lib/install-atom-dependencies.js:15:16)
    at Object.<anonymous> (/home/moritz/code/atom/atom/script/bootstrap:28:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)

MoritzKn avatar Apr 01 '17 14:04 MoritzKn

Arch user here as well. I was able to work around this by applying the following patch:

diff --git a/bin/python-interceptor.sh b/bin/python-interceptor.sh
index 7ce1965..12cc72f 100755
--- a/bin/python-interceptor.sh
+++ b/bin/python-interceptor.sh
@@ -34,9 +34,9 @@ case $1 in
       ARGS+=("--format=safemake.py")
     fi
 
-    exec python "${ARGS[@]}"
+    exec python2 "${ARGS[@]}"
     ;;
   *)
-    exec python "$@"
+    exec python2 "$@"
     ;;
 esac

and then also patching atom so it installs my locally patched apm (obviously replace file:///path/to/patched/apm with your actual path):

diff --git a/apm/package.json b/apm/package.json
index 732ab20..0e75319 100644
--- a/apm/package.json
+++ b/apm/package.json
@@ -6,6 +6,6 @@
     "url": "https://github.com/atom/atom.git"
   },
   "dependencies": {
-    "atom-package-manager": "1.16.1"
+    "atom-package-manager": "file:///path/to/patched/apm"
   }
 }

jaromero avatar Apr 13 '17 07:04 jaromero

This is still happening - it looks like setting ${PYTHON} isn't actually enough for all node-gyp builds.

smashwilson avatar Mar 05 '18 16:03 smashwilson

I believe this can be closed now. As of https://github.com/atom/apm/pull/887, apm has Node-gyp 5.1, which supports both Python 2 and Python 3.

DeeDeeG avatar Aug 11 '20 23:08 DeeDeeG