Skip to content
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

Python syntax error in dynamically generated 'build/gyp-mac-tool' file when python3 on the PATH is < 3.6 #2351

Closed
DeeDeeG opened this issue Mar 24, 2021 · 14 comments · Fixed by #2362

Comments

@DeeDeeG
Copy link
Contributor

DeeDeeG commented Mar 24, 2021

  • Node Version: Latest 10, 12, 14 and 15 (10.24.0, 12.21.0, 14.16.0, 15.12.0)
  • Platform: macOS "Catalina" 10.15.7
  • Compiler: Apple clang version 12.0.0 (clang-1200.0.32.29)
  • Module: git-utils, leveldown, superstring
Verbose output (from node-gyp rebuild --verbose):
% /Users/[user]/node-gyp/bin/node-gyp.js rebuild --verbose
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli   '/Users/[user]/n-prefix/bin/node',
gyp verb cli   '/Users/[user]/node-gyp/bin/node-gyp.js',
gyp verb cli   'rebuild',
gyp verb cli   '--verbose'
gyp verb cli ]
gyp info using [email protected]
gyp info using [email protected] | darwin | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb find Python Python is not set from command line or npm configuration
gyp verb find Python Python is not set from environment variable PYTHON
gyp verb find Python checking if "python3" can be used
gyp verb find Python - executing "python3" to get executable path
gyp verb find Python - executable path is "/Library/Frameworks/Python.framework/Versions/3.10/bin/python3"
gyp verb find Python - executing "/Library/Frameworks/Python.framework/Versions/3.10/bin/python3" to get version
gyp verb find Python - version is "3.10.0"
gyp info find Python using Python version 3.10.0 found at "/Library/Frameworks/Python.framework/Versions/3.10/bin/python3"
gyp verb get node dir no --target version specified, falling back to host node version: 15.12.0
gyp verb command install [ '15.12.0' ]
gyp verb install input version string "15.12.0"
gyp verb install installing version: 15.12.0
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 15.12.0
gyp verb build dir attempting to create "build" dir: /Users/[user]/github/node_modules/superstring/build
gyp verb build dir "build" dir needed to be created? /Users/[user]/github/node_modules/superstring/build
gyp verb build/config.gypi creating config file
gyp verb build/config.gypi writing out config file: /Users/[user]/github/node_modules/superstring/build/config.gypi
gyp verb config.gypi checking for gypi file: /Users/[user]/github/node_modules/superstring/config.gypi
gyp verb common.gypi checking for gypi file: /Users/[user]/github/node_modules/superstring/common.gypi
gyp verb gyp gyp format was not specified; forcing "make"
gyp info spawn /Library/Frameworks/Python.framework/Versions/3.10/bin/python3
gyp info spawn args [
gyp info spawn args   '/Users/[user]/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/[user]/github/node_modules/superstring/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/[user]/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/[user]/Library/Caches/node-gyp/15.12.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/[user]/Library/Caches/node-gyp/15.12.0',
gyp info spawn args   '-Dnode_gyp_dir=/Users/[user]/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/[user]/Library/Caches/node-gyp/15.12.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/[user]/github/node_modules/superstring',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
gyp verb command build []
gyp verb build type Release
gyp verb architecture x64
gyp verb node dev dir /Users/[user]/Library/Caches/node-gyp/15.12.0
gyp verb `which` succeeded for `make` /usr/bin/make
gyp info spawn make
gyp info spawn args [ 'V=1', 'BUILDTYPE=Release', '-C', 'build' ]
  c++ -o Release/obj.target/superstring_core/src/core/encoding-conversion.o ../src/core/encoding-conversion.cc '-DNODE_GYP_MODULE_NAME=superstring_core' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DPCRE2_CODE_UNIT_WIDTH=16' -I/Users/[user]/Library/Caches/node-gyp/15.12.0/include/node -I/Users/[user]/Library/Caches/node-gyp/15.12.0/src -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/config -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/openssl/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/uv/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/zlib -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/v8/include -I../vendor/libcxx -I../vendor/pcre/include  -O3 -gdwarf-2 -mmacosx-version-min=10.13 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++1y -stdlib=libc++ -fno-rtti -fno-exceptions -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/superstring_core/src/core/encoding-conversion.o.d.raw   -c
  c++ -o Release/obj.target/superstring_core/src/core/marker-index.o ../src/core/marker-index.cc '-DNODE_GYP_MODULE_NAME=superstring_core' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DPCRE2_CODE_UNIT_WIDTH=16' -I/Users/[user]/Library/Caches/node-gyp/15.12.0/include/node -I/Users/[user]/Library/Caches/node-gyp/15.12.0/src -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/config -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/openssl/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/uv/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/zlib -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/v8/include -I../vendor/libcxx -I../vendor/pcre/include  -O3 -gdwarf-2 -mmacosx-version-min=10.13 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++1y -stdlib=libc++ -fno-rtti -fno-exceptions -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/superstring_core/src/core/marker-index.o.d.raw   -c
  c++ -o Release/obj.target/superstring_core/src/core/patch.o ../src/core/patch.cc '-DNODE_GYP_MODULE_NAME=superstring_core' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DPCRE2_CODE_UNIT_WIDTH=16' -I/Users/[user]/Library/Caches/node-gyp/15.12.0/include/node -I/Users/[user]/Library/Caches/node-gyp/15.12.0/src -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/config -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/openssl/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/uv/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/zlib -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/v8/include -I../vendor/libcxx -I../vendor/pcre/include  -O3 -gdwarf-2 -mmacosx-version-min=10.13 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++1y -stdlib=libc++ -fno-rtti -fno-exceptions -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/superstring_core/src/core/patch.o.d.raw   -c
  c++ -o Release/obj.target/superstring_core/src/core/point.o ../src/core/point.cc '-DNODE_GYP_MODULE_NAME=superstring_core' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DPCRE2_CODE_UNIT_WIDTH=16' -I/Users/[user]/Library/Caches/node-gyp/15.12.0/include/node -I/Users/[user]/Library/Caches/node-gyp/15.12.0/src -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/config -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/openssl/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/uv/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/zlib -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/v8/include -I../vendor/libcxx -I../vendor/pcre/include  -O3 -gdwarf-2 -mmacosx-version-min=10.13 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++1y -stdlib=libc++ -fno-rtti -fno-exceptions -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/superstring_core/src/core/point.o.d.raw   -c
  c++ -o Release/obj.target/superstring_core/src/core/range.o ../src/core/range.cc '-DNODE_GYP_MODULE_NAME=superstring_core' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DPCRE2_CODE_UNIT_WIDTH=16' -I/Users/[user]/Library/Caches/node-gyp/15.12.0/include/node -I/Users/[user]/Library/Caches/node-gyp/15.12.0/src -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/config -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/openssl/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/uv/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/zlib -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/v8/include -I../vendor/libcxx -I../vendor/pcre/include  -O3 -gdwarf-2 -mmacosx-version-min=10.13 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++1y -stdlib=libc++ -fno-rtti -fno-exceptions -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/superstring_core/src/core/range.o.d.raw   -c
  c++ -o Release/obj.target/superstring_core/src/core/regex.o ../src/core/regex.cc '-DNODE_GYP_MODULE_NAME=superstring_core' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DPCRE2_CODE_UNIT_WIDTH=16' -I/Users/[user]/Library/Caches/node-gyp/15.12.0/include/node -I/Users/[user]/Library/Caches/node-gyp/15.12.0/src -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/config -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/openssl/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/uv/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/zlib -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/v8/include -I../vendor/libcxx -I../vendor/pcre/include  -O3 -gdwarf-2 -mmacosx-version-min=10.13 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++1y -stdlib=libc++ -fno-rtti -fno-exceptions -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/superstring_core/src/core/regex.o.d.raw   -c
  c++ -o Release/obj.target/superstring_core/src/core/text.o ../src/core/text.cc '-DNODE_GYP_MODULE_NAME=superstring_core' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DPCRE2_CODE_UNIT_WIDTH=16' -I/Users/[user]/Library/Caches/node-gyp/15.12.0/include/node -I/Users/[user]/Library/Caches/node-gyp/15.12.0/src -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/config -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/openssl/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/uv/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/zlib -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/v8/include -I../vendor/libcxx -I../vendor/pcre/include  -O3 -gdwarf-2 -mmacosx-version-min=10.13 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++1y -stdlib=libc++ -fno-rtti -fno-exceptions -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/superstring_core/src/core/text.o.d.raw   -c
  c++ -o Release/obj.target/superstring_core/src/core/text-buffer.o ../src/core/text-buffer.cc '-DNODE_GYP_MODULE_NAME=superstring_core' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DPCRE2_CODE_UNIT_WIDTH=16' -I/Users/[user]/Library/Caches/node-gyp/15.12.0/include/node -I/Users/[user]/Library/Caches/node-gyp/15.12.0/src -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/config -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/openssl/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/uv/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/zlib -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/v8/include -I../vendor/libcxx -I../vendor/pcre/include  -O3 -gdwarf-2 -mmacosx-version-min=10.13 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++1y -stdlib=libc++ -fno-rtti -fno-exceptions -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/superstring_core/src/core/text-buffer.o.d.raw   -c
  c++ -o Release/obj.target/superstring_core/src/core/text-slice.o ../src/core/text-slice.cc '-DNODE_GYP_MODULE_NAME=superstring_core' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DPCRE2_CODE_UNIT_WIDTH=16' -I/Users/[user]/Library/Caches/node-gyp/15.12.0/include/node -I/Users/[user]/Library/Caches/node-gyp/15.12.0/src -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/config -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/openssl/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/uv/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/zlib -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/v8/include -I../vendor/libcxx -I../vendor/pcre/include  -O3 -gdwarf-2 -mmacosx-version-min=10.13 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++1y -stdlib=libc++ -fno-rtti -fno-exceptions -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/superstring_core/src/core/text-slice.o.d.raw   -c
  c++ -o Release/obj.target/superstring_core/src/core/text-diff.o ../src/core/text-diff.cc '-DNODE_GYP_MODULE_NAME=superstring_core' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DPCRE2_CODE_UNIT_WIDTH=16' -I/Users/[user]/Library/Caches/node-gyp/15.12.0/include/node -I/Users/[user]/Library/Caches/node-gyp/15.12.0/src -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/config -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/openssl/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/uv/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/zlib -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/v8/include -I../vendor/libcxx -I../vendor/pcre/include  -O3 -gdwarf-2 -mmacosx-version-min=10.13 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++1y -stdlib=libc++ -fno-rtti -fno-exceptions -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/superstring_core/src/core/text-diff.o.d.raw   -c
  c++ -o Release/obj.target/superstring_core/src/core/libmba-diff.o ../src/core/libmba-diff.cc '-DNODE_GYP_MODULE_NAME=superstring_core' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DPCRE2_CODE_UNIT_WIDTH=16' -I/Users/[user]/Library/Caches/node-gyp/15.12.0/include/node -I/Users/[user]/Library/Caches/node-gyp/15.12.0/src -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/config -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/openssl/openssl/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/uv/include -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/zlib -I/Users/[user]/Library/Caches/node-gyp/15.12.0/deps/v8/include -I../vendor/libcxx -I../vendor/pcre/include  -O3 -gdwarf-2 -mmacosx-version-min=10.13 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++1y -stdlib=libc++ -fno-rtti -fno-exceptions -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/superstring_core/src/core/libmba-diff.o.d.raw   -c
  rm -f Release/superstring_core.a && ./gyp-mac-tool filter-libtool libtool  -static -o Release/superstring_core.a Release/obj.target/superstring_core/src/core/encoding-conversion.o Release/obj.target/superstring_core/src/core/marker-index.o Release/obj.target/superstring_core/src/core/patch.o Release/obj.target/superstring_core/src/core/point.o Release/obj.target/superstring_core/src/core/range.o Release/obj.target/superstring_core/src/core/regex.o Release/obj.target/superstring_core/src/core/text.o Release/obj.target/superstring_core/src/core/text-buffer.o Release/obj.target/superstring_core/src/core/text-slice.o Release/obj.target/superstring_core/src/core/text-diff.o Release/obj.target/superstring_core/src/core/libmba-diff.o
  File "./gyp-mac-tool", line 252
    fp.write(f"{package_type}{signature_code}")
                                             ^
SyntaxError: invalid syntax
make: *** [Release/superstring_core.a] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/[user]/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (node:events:369:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
gyp ERR! System Darwin 19.6.0
gyp ERR! command "/Users/[user]/n-prefix/bin/node" "/Users/[user]/node-gyp/bin/node-gyp.js" "rebuild" "--verbose"
gyp ERR! cwd /Users/[user]/github/node_modules/superstring
gyp ERR! node -v v15.12.0
gyp ERR! node-gyp -v v7.1.2
gyp ERR! not ok 

More info:

Only node-gyp from git master is affected; The latest release to the npm package registry 7.1.2 is unaffected.

The error looks like this:

  File "./gyp-mac-tool", line 252
    fp.write(f"{package_type}{signature_code}")
                                             ^
SyntaxError: invalid syntax
make: *** [Release/superstring_core.a] Error 1

When this error occurs, it's always the same syntax error at line 252 of gyp-mac-tool. Some (most?) packages appear to be unaffected, but I've found a few packages which are affected: git-utils, leveldown, and superstring.

(Maybe this has to do with the gyp-next v0.7.0 or v0.8.0 upgrades?)

@cclauss
Copy link
Contributor

cclauss commented Mar 24, 2021

f-strings are a syntax error only on Python < 3.6. Given that we plan to drop those versions, I do not see the problem.

After a closer look... gyp verb find Python - version is "3.10.0"

This run was executed on a pre-release version of Python 3.10 -- We should not support pre-release software.

@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Mar 24, 2021

It occurs with stable Python 3 as well. Such as Python 3.8.2 currently shipped with command line tools for Xcode.

I admit it was careless and a bit misleading of me to include Python 3.10 in my verbose output, but in my testing the behavior is the same with stable Python versions.

For example: It occurs with stable Python 3.8.2 (which I believe is currently shipped with command line tools for Xcode).

With Python 3.8.2, I can use fstrings in general.

For example, I can run this file, which I named test.py:

package_type = 'a'
signature_code = 'b'
print(f"{package_type}{signature_code}")
% /usr/bin/python3 test.py
ab
% /usr/bin/python3 --version
Python 3.8.2

@richardlau
Copy link
Member

#!/usr/bin/env python
has a #!/usr/bin/env python header so maybe it's not using the version of Python you're expecting it to.

@cclauss
Copy link
Contributor

cclauss commented Mar 24, 2021

I always use #!/usr/bin/env python3 now that Py2 is dead.

@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Mar 24, 2021

@richardlau that seems to have been the problem.

The problem goes away if that shebang line is changed to #!/usr/bin/env python3, or if I make python on my PATH point to Python 3 (Python 3.8.2 in my case).

macOS Catalina users still have Python 2.7.16 as python in the PATH by default. (I think this is still true for macOS Big Sur as well: https://apple.stackexchange.com/a/406703)

The shebang lines are updated in gyp-next master (as of nodejs/gyp-next#94), and included in the gyp-next 0.8.1 release, so perhaps that updated gyp-next (0.8.1) should be used in node-gyp.

@cclauss
Copy link
Contributor

cclauss commented Mar 24, 2021

Modifying all shebang lines to add the 3 seems like the safest approach.

@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Mar 24, 2021

I humbly suggest updating to use gyp-next 0.8.1, where the shebang lines have already been updated. (Was done (by me!) in nodejs/gyp-next#94).

I think ./update-gyp v0.8.1 does it? I can submit a Pull Request for that if desired...

UPDATE: I opened a pull request. See: #2355.

@cclauss cclauss changed the title Python syntax error in dynamically generated 'build/gyp-mac-tool' file, for certain packages Python syntax error in dynamically generated 'build/gyp-mac-tool' file when run on Python < 3.6 Mar 24, 2021
@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Mar 24, 2021

It also seems prudent to use the same Python that lib/find-python.js uses, or at least do a semver check like that file does. python3 on the PATH might not be the same as what find-python.js picks.

It seems to me that the Makefile gyp generates runs gyp-mac-tool as ./gyp-mac-tool. For example:

cmd_mac_tool = ./gyp-mac-tool $(4) $< "$@"

That's why the Python that is run is whatever is found by the shebang line in gyp-mac-tool.

Thorough solutions (allowing use of newer Python language features and protecting users from this bug):

Change the Makefile to work better for node-gyp: It would be good for node-gyp's use-case if these lines in the Makefile were $PYTHON_FROM_FIND_PYTHON_DOT_JS ./gyp-mac-tool.

(We could change this in gyp-next's main brach... Or we could maintain a separate branch there with patches for node-gyp, or carry a patch here in the node-gyp repo to make gyp-next work better for node-gyp.)

Workaround the problem by manipulating the environment: We could manipulate the environment such that the Python we want is the first on the PATH. (Maybe using a Python venv.) Something like that.

Simpler solutions:

Don't fix this bug: Hope (and require) that macOS users' python3 on the PATH is 3.6 or greater. (Makes the more-sophisticated and more end-user-configurable Python detection and version checking in lib/find-python.js moot/pointless when building certain packages...)

Older Python support in gyp-mac-tool: Drop the use of f-string in gyp-mac-tool, so that older Python 3 can still run the file. Covers the off chance that lib/find-python.js picks something other than the first python3 on the PATH. (Such as from the PYTHON env var or the --python command-line flag.)

@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Mar 27, 2021

Even if gyp-next is bumped to 0.8.1 (which would fix this issue for users with recent Python 3 first on their PATH), there is the corner case where python3 on the PATH is something old like Python 3.4, and lib/find-python.js finds a usable Python despite this. Users would be surprised that we pick a valid Python version in find-python.js which is then ignored by gyp-mac-tool, causing the build to fail.

I have a tentative fix for this corner case. (DeeDeeG@8250dec) It records the full path to the Python binary located by find-python.js in the Makefile. So gyp-mac-tool is run with a new enough Python binary.

It's pretty specific to node-gyp, but I suppose I could investigate what impact this would/wouldn't have in the node build process? (Are there any other gyp-next users to worry about?) So I'm not sure whether to try to land this in gyp-next directly or float it as a patch here?

Lots of details & my thoughts on where to land this (click to expand):
Implementation notes (click to expand):

I changed gyp/pylib/gyp/generator/make.py so that the generated Makefile includes the absolute PATH to Python that lib/find-python.js found. I recorded this as a Makefile variable CONFIG_PYTHON. But I also made the logic check if that Python executable still exists on disk; if not, I had it fall back to the Python specified in the shebang line of gyp-mac-tool. (CONFIG_PYTHON is an empty string if the Python executable no-longer exists on the disk.)

So in the end we have: $(CONFIG_PYTHON) ./gyp-mac-tool rather than simply ./gyp-mac-tool.

The reason I didn't just hard-code a Python path found by find-python.js is, I realized that the Makefile is generated during node-gyp configure, and any arbitrary amount of time could pass before running node-gyp build. In the time that passes between these commands, someone could uninstall a version of Python in order to upgrade to a new Python, they could reinstall their OS but preserve the built package in their home directory, or they copy-pasting their repository to a new machine... So to avoid regressing on that and introducing a new common failure mode, I made sure to fall back to the shebang Python if the Python find-python.js found once upon a time is no-longer on the disk.

Caveat: This relies on reading the PYTHON env var that is set during node-gyp configure, based on the result of find-python.js. This fix is only relevant to/tested properly for node-gyp, where we can rely on the PYTHON env var being set to a helpful value by lib/find-python.js. And in fact, other projects might be using the PYTHON env var for a different purpose, so this change might be disruptive for other projects in general. So I'm not sure exactly where to land this fix. Landing it in gyp-next's main branch seems a bit questionable.

Some options:

  • Land this in the main branch of gyp-next, despite it not being relevant to everyone and potentially being disruptive.
    • I'd prefer not to do this on gyp-next's main branch, since I don't think other projects would need this outside of node-gyp, but maybe the implementation could be less disruptive by using a more specific and unlikely to overlap env var like GYP_MAC_CONFIG_PYTHON or NODE_GYP_FOUND_PYTHON?
  • Land this in an alternative branch at the gyp-next repository for node-gyp specific tweaks.
    • Implies that the gyp-next maintainers tag two new releases each time, a node-gyp-specific variant and a general-purpose one.
  • I could set up ./update-python in this project to automatically cherry-pick this fix after every sync with the gyp-next repo.
    • Introduce a very basic system to this repo for curating and automatically applying patches to gyp.

Caveat 2: I'm not really sure about the flock changes in my commit, since the packages I've tried this with don't actually generate the ./gyp-mac-tool flock stuff in the Makefile.

@DeeDeeG DeeDeeG mentioned this issue Mar 29, 2021
2 tasks
@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Mar 30, 2021

I did a little research on how the nodejs/node repository handles this.

They actually do their own Python detection, looking for python3.9 ... python3.6 or python2.7... And whichever they find first, they symlink to ./out/tools/bin/python. They have a Makefile for the overall node repo that puts this symlinked Python on the PATH, sets an env var (if not yet defined) PYTHON=python (which means the symlinked python is used if the user doesn't specify a PYTHON env var before running make).

If we could set up a similar Python symlink in the build dir for packages we're building, during node-gyp configure, and have that respected during node-gyp build, that would be great.


In general, I think we need to either:

  • Write a full Python path to a file, or
  • Make a Python symlink

And commit that to disk during node-gyp configure, so that said path or symlink can be used during node-gyp build.

Any advice on an implementation approach would be much appreciated. If I don't get any advice, I suppose I'll keep improvising and see what I can come up with.

I think patching gyp is an easy-to-author but less-easy-to-maintain option, so I'm continuing to look to alternatives that don't involve patching gyp. If folks here are comfortable maintaining patches to gyp specifically for node-gyp, please do let me know, as I have a solution in the form of patching node-gyp gyp that's ready to go. I even figured out a system to float the patches and automatically cherry-pick them on top of each new upstream gyp-next release. Any interest/input/advice from maintainers would help me pick a specific direction to pursue here. I'd really like to fix this bug. Thanks.

@cclauss
Copy link
Contributor

cclauss commented Mar 31, 2021

Awesome detective work @DeeDeeG Thanks much for digging into the details.

It would be great if Node.js and gyp shared a common method for finding the right Python to use. Unless others have objections, I believe that creating a symlink at a well known path is the best approach. That would be easiest to reason about and easiest to test.

@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Mar 31, 2021

I have two WIP implementations (both fully working, but code style could be cleaned up a bit), and a third idea that also probably would not be that hard to do.

  • Add a Python symlink in the build folder and add that to PATH for builds: DeeDeeG@b2251a8
  • Patch gyp's Makefile generator to record the absolute Python path validated by lib/find-python.js in the Makefile: DeeDeeG@a68d184
  • I reckon it wouldn't be hard to record the absolute Python path in config.gypi and read that at build time, like we already do for a handful of other variables and paths and so on.

Any comment or preference among these from node-gyp and/or nodejs folks would be much appreciated.

Speaking from my personal opinion, I feel like this bug is very fixable in time for the upcoming v8.0.0 release of node-gyp. (But regardless, I would be happy to work on it for a subsequent release if this doesn't quite make it in time.)

P.S. my thoughts: I'm leaning toward the symlinks, because we wouldn't have to patch gyp. IMO patching gyp implies checking with the nodejs/node folks and seeing if they're okay with it, and/or potentially having to float gyp patches at this repository. Doing it in config.gypi might make the configure code slightly cleaner, I suppose? But I haven't really tried that approach yet.

@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Mar 31, 2021

Re: @cclauss

It would be great if Node.js and gyp shared a common method for finding the right Python to use.

If you mean full code deduplication across these two projects, some of the duplicate code in either repository could be moved into gyp itself. Although I am not so versed in Python to be able to fluently code this feature in Python, my Makefile generator patch is an example of at least recording the absolute Python path, achieved within the gyp codebase. Somehow the "find the right Python to use" part seems odd to me to include in gyp directly, but it should still be possible if that's what you meant.

If you meant we should use a similar algorithm or perform the same checks to find a usable Python binary/decide which Python is the right Python to use, even if technically the code is still duplicated, then I don't see why not. At least we should "compare notes". For example, their idea of checking python3.9 ... python3.6 is neat, and we could use that as the fallback check on Unix, similar to the default install paths we currently check on Windows...

nodejs/node's checks are here: https://github.com/nodejs/node/blob/v15.13.0/configure

(EDIT: We could steal borrow their code (with credit given). I presume it is under a fairly liberal license. It would have to be lightly adapted so we can retain the ability to change our supported Python versions before they do, since we are to an extent an upstream project of the nodejs/node build process, via npm.)

(If you just meant we should roughly copy their symlinking method, then see DeeDeeG@b2251a8 as mentioned in my previous comment.)

@DeeDeeG DeeDeeG changed the title Python syntax error in dynamically generated 'build/gyp-mac-tool' file when run on Python < 3.6 Python syntax error in dynamically generated 'build/gyp-mac-tool' file when python3 on the PATH is < 3.6 Oct 10, 2021
@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Oct 10, 2021

Now that the shebangs in gyp-next are python3 I updated the issue title.

This issue now affects anyone with python3 older than 3.6 first on their PATH... who were able to supply the path to Python >= 3.6 for use earlier in node-gyp's run. Such as with the PYTHON env var, or the npm config item npm_config_python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants