Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion bin/apm
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,26 @@ binDir=`pwd -P`
maybe_node_gyp_path="$binDir"/../node_modules/.bin/node-gyp
if [ -e "$maybe_node_gyp_path" ]
then
# Prevent vars like NODE_CONFIG_NODE_GYP from messing this up
for var in $(env | grep -i ^npm_config_node_gyp=)
do
unset ${var%%=*}
done

export npm_config_node_gyp="$maybe_node_gyp_path"
fi

export PYTHON="${binDir}/python-interceptor.sh"
export ATOM_APM_ORIGINAL_PYTHON="${PYTHON:-}"

# Assumption: env iterates through environment variables in the same order that
# process.env iterates through properties within npm. So, we take the last match.
for var in $(env | grep -i ^npm_config_python=)
do
ATOM_APM_ORIGINAL_PYTHON="${var#*=}"
unset ${var%%=*}
done

export npm_config_python="${SCRIPT_DIR}/python-interceptor.sh"

builtin cd "$initialCwd"
"$binDir/$nodeBin" "$binDir/../lib/cli.js" "$@"
21 changes: 20 additions & 1 deletion bin/npm
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,30 @@
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export PATH="$SCRIPT_DIR:$PATH"

export PYTHON="${SCRIPT_DIR}/python-interceptor.sh"
export ATOM_APM_ORIGINAL_PYTHON="${PYTHON:-}"

# Assumption: env iterates through environment variables in the same order that
# process.env iterates through properties within npm. So, we take the last match.
for var in $(env | grep -i ^npm_config_python=)
do
ATOM_APM_ORIGINAL_PYTHON="${var#*=}"
done
if [ -z "${ATOM_APM_ORIGINAL_PYTHON}" ] && [ -n "${PYTHON:-}" ]
then
ATOM_APM_ORIGINAL_PYTHON="${PYTHON}"
fi

export npm_config_python="${SCRIPT_DIR}/python-interceptor.sh"

maybe_node_gyp_path="$SCRIPT_DIR"/../node_modules/.bin/node-gyp
if [ -e "$maybe_node_gyp_path" ]
then
# Prevent vars like NODE_CONFIG_NODE_GYP from messing this up
for var in $(env | grep -i ^npm_config_node_gyp=)
do
unset ${var%%=*}
done

export npm_config_node_gyp="$maybe_node_gyp_path"
fi

Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/fake-python-1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "fake-python-1 called" >&2
exit 1
4 changes: 4 additions & 0 deletions spec/fixtures/fake-python-2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "fake-python-2 called" >&2
exit 1
43 changes: 43 additions & 0 deletions spec/install-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,46 @@ describe 'apm install', ->

makefileContent = fs.readFileSync(path.join(testModuleDirectory, 'build', 'Makefile'), {encoding: 'utf-8'})
expect(makefileContent).toMatch('node_modules/with\\ a\\ space/addon.gypi')

describe "configurable Python binaries", ->
nodeModules = fs.realpathSync(path.join(__dirname, '..', 'node_modules'))
[originalPython, originalNpmConfigPython] = []

beforeEach ->
originalPython = process.env.PYTHON
originalNpmConfigPython = process.env.npm_config_python
delete process.env.PYTHON
delete process.env.npm_config_python

afterEach ->
process.env.PYTHON = originalPython
process.env.npm_config_python = originalNpmConfigPython

it 'respects ${PYTHON} if set', ->
process.env.PYTHON = path.join __dirname, 'fixtures', 'fake-python-1.sh'

callback = jasmine.createSpy('callback')
apm.run(['install', 'native-package'], callback)

waitsFor 'waiting for install to fail', 600000, ->
callback.callCount is 1

runs ->
errorText = callback.mostRecentCall.args[0]
expect(errorText).not.toBeNull()
expect(errorText).toMatch('fake-python-1 called')

it 'respects ${npm_config_python} if set', ->
process.env.npm_config_python = path.join __dirname, 'fixtures', 'fake-python-2.sh'
process.env.PYTHON = path.join __dirname, 'fixtures', 'fake-python-1.sh'

callback = jasmine.createSpy('callback')
apm.run(['install', 'native-package'], callback)

waitsFor 'waiting for install to fail', 600000, ->
callback.callCount is 1

runs ->
errorText = callback.mostRecentCall.args[0]
expect(errorText).not.toBeNull()
expect(errorText).toMatch('fake-python-2 called')