Skip to content

Commit 0aac7ba

Browse files
committed
Make pip-micropython more portable
Replace /tmp with a $TMPDIR variable Replace multiple occurrences of /tmp/pip-micropy-venv with a $TMPVENV variable Replace ~ with $HOME
1 parent bbae42d commit 0aac7ba

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

tools/pip-micropython

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ if [ "$1" != "install" ]; then
1212
fi
1313
shift
1414

15+
if [ -n "$TMPDIR" ]; then
16+
TMPDIR=/tmp
17+
fi
18+
TMPVENV="$TMPDIR/pip-micropy-venv"
19+
1520
if [ -n "$PIP_MICROPY_DEST" ]; then
1621
dest="$PIP_MICROPY_DEST"
1722
echo "Destination snapshot directory: $dest"
@@ -20,23 +25,23 @@ elif [ -n "$MICROPYPATH" ]; then
2025
echo "Destination library directory: $libdest"
2126
else
2227
echo "Warning: MICROPYPATH is not set, assuming default value"
23-
libdest=~/.micropython/lib
28+
libdest=$HOME/.micropython/lib
2429
echo "Destination library directory: $libdest"
2530
fi
2631

2732
# Due to bugs in pip, installation should happen with active virtualenv
2833
# The issue (at least with pip 1.0 which is still what's shipped with many
2934
# distros) is that even if --ignore-installed is used, package is not
3035
# installed if it's already installed for main python distribution.
31-
if [ ! -d /tmp/pip-micropy-venv ]; then
32-
virtualenv --no-site-packages /tmp/pip-micropy-venv
36+
if [ ! -d "$TMPVENV" ]; then
37+
virtualenv --no-site-packages "$TMPVENV"
3338
# distutils, setuptools, pip are buggy and allow target packages affect
3439
# their execution environment. For example, if distribution they install
3540
# has re.py, they will import that instead of system re. So, we need
3641
# to remove current dir from sys.path, but that appear to be quite uneasy
3742
# with CPython, so we hook __import__ and exterminate it persistently.
3843
# See also https://bitbucket.org/pypa/setuptools/issue/187/
39-
cat > $(ls -1d /tmp/pip-micropy-venv/lib/python*/)/sitecustomize.py <<EOF
44+
cat > $(ls -1d "$TMPVENV"/lib/python*/)/sitecustomize.py <<EOF
4045
import sys
4146
import __builtin__
4247
old_imp = __import__
@@ -46,7 +51,7 @@ def new_imp(*a, **kw):
4651
__builtin__.__import__ = new_imp
4752
EOF
4853
fi
49-
. /tmp/pip-micropy-venv/bin/activate
54+
. "$TMPVENV"/bin/activate
5055

5156
# We need to specify --record to override this switch as passed by pip
5257
# pip will try to parse this file (at the location in specifies), and try to
@@ -61,22 +66,22 @@ pip install "$@" \
6166
--install-option="--install-scripts=." \
6267
--install-option="--install-headers=headers" \
6368
--install-option="--install-data=lib" \
64-
--install-option="--record=/tmp/setuptools-record.txt" \
69+
--install-option="--record=$TMPDIR/setuptools-record.txt" \
6570
--install-option="--no-compile" \
6671
--install-option="--root=$dest"
6772
else
6873
# Here we assume that base dir is lib dir, and install scripts a level
69-
# higher. For default value of ~/micropython/lib/ , this should give
74+
# higher. For default value of $HOME/.micropython/lib/ , this should give
7075
# reasonable behavior, though better would make it overridable (or
71-
# go bold and use ~/bin ?)
76+
# go bold and use $HOME/bin ?)
7277
pip install "$@" \
7378
--install-option="--install-base=." \
7479
--install-option="--install-purelib=." \
7580
--install-option="--install-platlib=." \
7681
--install-option="--install-scripts=.." \
7782
--install-option="--install-headers=../headers" \
7883
--install-option="--install-data=." \
79-
--install-option="--record=/tmp/setuptools-record.txt" \
84+
--install-option="--record=$TMPDIR/setuptools-record.txt" \
8085
--install-option="--no-compile" \
8186
--install-option="--root=$libdest"
8287
fi

0 commit comments

Comments
 (0)