2014-04-02 00:00:30 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# This tool can be used to install a new package into MicroPython
|
|
|
|
# library location (for unix port, default behavior), or produce
|
|
|
|
# complete library snapshot to be deployed on a device for baremetal
|
|
|
|
# ports (if PIP_MICROPY_DEST environment var is set).
|
|
|
|
#
|
2015-06-13 19:39:57 +01:00
|
|
|
# Note: this tool is deprecated in favor of "upip" native MicroPython
|
|
|
|
# package manager, which is bundled with MicroPython unix binary
|
|
|
|
# as a frozen module and can be run as "micropython -u pip" or installed
|
|
|
|
# from PyPI package "micropython-upip". This utility is left for
|
|
|
|
# reference, regression testing, debugging, etc.
|
|
|
|
#
|
2014-04-02 00:00:30 +01:00
|
|
|
|
2014-04-06 21:46:18 +01:00
|
|
|
if [ "$1" != "install" ]; then
|
|
|
|
echo "Only install command is supported currently"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
shift
|
|
|
|
|
2014-04-15 00:32:41 +01:00
|
|
|
if [ -z "$TMPDIR" ]; then
|
2014-04-14 12:26:12 +01:00
|
|
|
TMPDIR=/tmp
|
|
|
|
fi
|
|
|
|
TMPVENV="$TMPDIR/pip-micropy-venv"
|
|
|
|
|
2014-08-27 00:53:06 +01:00
|
|
|
if [ -n "$PIP_MICROPY_DEST" ]; then
|
2014-04-02 00:00:30 +01:00
|
|
|
dest="$PIP_MICROPY_DEST"
|
|
|
|
echo "Destination snapshot directory: $dest"
|
|
|
|
elif [ -n "$MICROPYPATH" ]; then
|
|
|
|
libdest=$(echo "$MICROPYPATH" | awk -F: ' {print $1}')
|
|
|
|
echo "Destination library directory: $libdest"
|
|
|
|
else
|
|
|
|
echo "Warning: MICROPYPATH is not set, assuming default value"
|
2014-04-14 22:26:34 +01:00
|
|
|
libdest=~/.micropython/lib
|
2014-04-02 00:00:30 +01:00
|
|
|
echo "Destination library directory: $libdest"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Due to bugs in pip, installation should happen with active virtualenv
|
|
|
|
# The issue (at least with pip 1.0 which is still what's shipped with many
|
|
|
|
# distros) is that even if --ignore-installed is used, package is not
|
|
|
|
# installed if it's already installed for main python distribution.
|
2014-04-14 12:26:12 +01:00
|
|
|
if [ ! -d "$TMPVENV" ]; then
|
|
|
|
virtualenv --no-site-packages "$TMPVENV"
|
2014-04-12 21:18:06 +01:00
|
|
|
# distutils, setuptools, pip are buggy and allow target packages affect
|
|
|
|
# their execution environment. For example, if distribution they install
|
|
|
|
# has re.py, they will import that instead of system re. So, we need
|
|
|
|
# to remove current dir from sys.path, but that appear to be quite uneasy
|
|
|
|
# with CPython, so we hook __import__ and exterminate it persistently.
|
|
|
|
# See also https://bitbucket.org/pypa/setuptools/issue/187/
|
2014-04-14 12:26:12 +01:00
|
|
|
cat > $(ls -1d "$TMPVENV"/lib/python*/)/sitecustomize.py <<EOF
|
2014-04-12 21:18:06 +01:00
|
|
|
import sys
|
|
|
|
import __builtin__
|
|
|
|
old_imp = __import__
|
|
|
|
def new_imp(*a, **kw):
|
|
|
|
if not sys.path[0]: sys.path.pop(0)
|
|
|
|
return old_imp(*a, **kw)
|
|
|
|
__builtin__.__import__ = new_imp
|
|
|
|
EOF
|
2014-04-02 00:00:30 +01:00
|
|
|
fi
|
2014-04-14 12:26:12 +01:00
|
|
|
. "$TMPVENV"/bin/activate
|
2014-04-02 00:00:30 +01:00
|
|
|
|
|
|
|
# We need to specify --record to override this switch as passed by pip
|
|
|
|
# pip will try to parse this file (at the location in specifies), and try to
|
|
|
|
# access files as specified in it. But paths there will be relative to --root
|
|
|
|
# we pass, so it won't find files and crash. However, if it won't find the
|
|
|
|
# file, it will just issue a warning and continue.
|
|
|
|
if [ -n "$dest" ]; then
|
|
|
|
pip install "$@" \
|
|
|
|
--install-option="--install-base=." \
|
|
|
|
--install-option="--install-purelib=lib" \
|
|
|
|
--install-option="--install-platlib=lib" \
|
|
|
|
--install-option="--install-scripts=." \
|
|
|
|
--install-option="--install-headers=headers" \
|
|
|
|
--install-option="--install-data=lib" \
|
2014-04-14 12:26:12 +01:00
|
|
|
--install-option="--record=$TMPDIR/setuptools-record.txt" \
|
2014-04-02 00:00:30 +01:00
|
|
|
--install-option="--no-compile" \
|
|
|
|
--install-option="--root=$dest"
|
|
|
|
else
|
|
|
|
# Here we assume that base dir is lib dir, and install scripts a level
|
2014-04-14 22:26:34 +01:00
|
|
|
# higher. For default value of ~/.micropython/lib/ , this should give
|
2014-04-02 00:00:30 +01:00
|
|
|
# reasonable behavior, though better would make it overridable (or
|
2014-04-14 22:26:34 +01:00
|
|
|
# go bold and use ~/bin ?)
|
2014-04-02 00:00:30 +01:00
|
|
|
pip install "$@" \
|
|
|
|
--install-option="--install-base=." \
|
|
|
|
--install-option="--install-purelib=." \
|
|
|
|
--install-option="--install-platlib=." \
|
|
|
|
--install-option="--install-scripts=.." \
|
|
|
|
--install-option="--install-headers=../headers" \
|
|
|
|
--install-option="--install-data=." \
|
2014-04-14 12:26:12 +01:00
|
|
|
--install-option="--record=$TMPDIR/setuptools-record.txt" \
|
2014-04-02 00:00:30 +01:00
|
|
|
--install-option="--no-compile" \
|
|
|
|
--install-option="--root=$libdest"
|
|
|
|
fi
|