|
| 1 | +#!/bin/sh |
| 2 | +# |
| 3 | +# This tool can be used to install a new package into MicroPython |
| 4 | +# library location (for unix port, default behavior), or produce |
| 5 | +# complete library snapshot to be deployed on a device for baremetal |
| 6 | +# ports (if PIP_MICROPY_DEST environment var is set). |
| 7 | +# |
| 8 | + |
| 9 | +if [ -n "$PIP_MICROPY_DEST" ]; then |
| 10 | + dest="$PIP_MICROPY_DEST" |
| 11 | + echo "Destination snapshot directory: $dest" |
| 12 | +elif [ -n "$MICROPYPATH" ]; then |
| 13 | + libdest=$(echo "$MICROPYPATH" | awk -F: ' {print $1}') |
| 14 | + echo "Destination library directory: $libdest" |
| 15 | +else |
| 16 | + echo "Warning: MICROPYPATH is not set, assuming default value" |
| 17 | + libdest=~/.micropython/lib |
| 18 | + echo "Destination library directory: $libdest" |
| 19 | +fi |
| 20 | + |
| 21 | +# Due to bugs in pip, installation should happen with active virtualenv |
| 22 | +# The issue (at least with pip 1.0 which is still what's shipped with many |
| 23 | +# distros) is that even if --ignore-installed is used, package is not |
| 24 | +# installed if it's already installed for main python distribution. |
| 25 | +if [ ! -d /tmp/pip-micropy-venv ]; then |
| 26 | + virtualenv --no-site-packages /tmp/pip-micropy-venv |
| 27 | +fi |
| 28 | +. /tmp/pip-micropy-venv/bin/activate |
| 29 | + |
| 30 | +# We need to specify --record to override this switch as passed by pip |
| 31 | +# pip will try to parse this file (at the location in specifies), and try to |
| 32 | +# access files as specified in it. But paths there will be relative to --root |
| 33 | +# we pass, so it won't find files and crash. However, if it won't find the |
| 34 | +# file, it will just issue a warning and continue. |
| 35 | +if [ -n "$dest" ]; then |
| 36 | +pip install "$@" \ |
| 37 | + --install-option="--install-base=." \ |
| 38 | + --install-option="--install-purelib=lib" \ |
| 39 | + --install-option="--install-platlib=lib" \ |
| 40 | + --install-option="--install-scripts=." \ |
| 41 | + --install-option="--install-headers=headers" \ |
| 42 | + --install-option="--install-data=lib" \ |
| 43 | + --install-option="--record=/tmp/setuptools-record.txt" \ |
| 44 | + --install-option="--no-compile" \ |
| 45 | + --install-option="--root=$dest" |
| 46 | +else |
| 47 | +# Here we assume that base dir is lib dir, and install scripts a level |
| 48 | +# higher. For default value of ~/micropython/lib/ , this should give |
| 49 | +# reasonable behavior, though better would make it overridable (or |
| 50 | +# go bold and use ~/bin ?) |
| 51 | +pip install "$@" \ |
| 52 | + --install-option="--install-base=." \ |
| 53 | + --install-option="--install-purelib=." \ |
| 54 | + --install-option="--install-platlib=." \ |
| 55 | + --install-option="--install-scripts=.." \ |
| 56 | + --install-option="--install-headers=../headers" \ |
| 57 | + --install-option="--install-data=." \ |
| 58 | + --install-option="--record=/tmp/setuptools-record.txt" \ |
| 59 | + --install-option="--no-compile" \ |
| 60 | + --install-option="--root=$libdest" |
| 61 | +fi |
0 commit comments