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

Alien pip3 support #23

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
13 changes: 9 additions & 4 deletions bin/Alien
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ fi

mode="$1"
prog="$2"
alientype="${prog%%:*}"
alienpkg="${prog#*:}"
if [[ -z "$alientype" || -z "$alienpkg" ]]
if [[ ! $prog =~ ^.+:.+$ ]]
then
echo "Error: missing program name"
echo "Error: missing program name, format shoud be 'AlienType:program'"
exit 1
fi
alientype="${prog%%:*}"
alienpkg="${prog#*:}"
shift 2
if [[ ! -x /System/Index/bin/Alien-$alientype ]]
then
echo "Error: $alientype is not a valid alientype"
exit 1
fi
exec Alien-$alientype $mode $alienpkg "$@"
94 changes: 72 additions & 22 deletions bin/Alien-PIP
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,75 @@
. ScriptFunctions
Import Alien

PYTHON=${ALIEN_PYTHON:-python2}
case ${ALIEN_PYTHON:-python2} in
"python2")
PYTHONVER=$(python2 --version 2>&1 | awk {'print $2'} | cut -b1-3)
ALIEN_PYTHON=python2
ALIEN_PIP=pip2
MANAGER_RULE="PIP >= 7.0.0"
;;
"python3")
PYTHONVER=$(python3 --version 2>&1 | awk {'print $2'} | cut -b1-3)
ALIEN_PYTHON=python3
ALIEN_PIP="python3 -m pip"
MANAGER_RULE="Python >= 3.5.0"
;;
*)
exit 1
;;
esac

PYTHON="PYTHONPATH=$goboSystem/Aliens/PIP/lib/python${PYTHONVER}/site-packages $ALIEN_PYTHON"
PIP="PYTHONPATH=$goboSystem/Aliens/PIP/lib/python${PYTHONVER}/site-packages $ALIEN_PIP"

hasmanager() {
case ${ALIEN_PYTHON} in
"python2")
which $ALIEN_PIP > /dev/null 2>&1
;;
"python3")
which $ALIEN_PYTHON > /dev/null 2>&1
;;
*)
return 1
esac
return $?
}

getversion() {

local prog=$(echo "$1" | sed 's,\(.*\),\L\1,g')
local proginfo=$(pip list | sed 's,\(.*\),\L\1,g' | grep "^${prog} ")
local proginfo=$(eval ${PIP} list 2>/dev/null | sed 's,\(.*\),\L\1,g' | grep "^${prog} ")
if [ -z "$proginfo" ]
then exit 1
else echo "$proginfo | cut -d\( -f2 | cut -d\) -f1"
else echo "$proginfo" | cut -d\( -f2 | cut -d\) -f1
fi
}

getinstallversion() {
prog="$1"
versions=($(python - << EOF
import json, urllib2
from distutils.version import StrictVersion
versions=($(eval ${PYTHON} - << EOF
import json
from packaging.version import Version
try:
from urllib2 import urlopen, Request
def load_json(res):
return json.load(res)
except ModuleNotFoundError:
from urllib.request import urlopen, Request
def load_json(res):
return json.loads('\n'.join([l.decode() for l in res.readlines()]))
def available_versions(prog):
try:
url = "https://pypi.python.org/pypi/%s/json" %prog
data = json.load(urllib2.urlopen(urllib2.Request(url)))
versions = data["releases"].keys()
versions.sort(key=StrictVersion)
return versions
except:
return ''
print "\n".join(available_versions("$prog"))
url = "https://pypi.python.org/pypi/%s/json" %prog
data = load_json(urlopen(Request(url)))
versions = list(data["releases"].keys())
versions.sort(key=Version, reverse=True)
return versions
except Exception as e:
return []
print("\n".join(available_versions("$prog")))
EOF
))
for V in ${versions[@]}
Expand All @@ -55,17 +100,17 @@ install() {
then
mkdir -p "$target" || { echo "Failed to create $target."; exit 1; }
fi
pip install --upgrade --prefix=$target --src=$srcdir "$prog" $ver

Symlink_Aliens "$goboExecutables" "$goboSystem"/Aliens/PIP/bin
[ ! -z $ver ] && prog_with_ver="$prog==$ver" || prog_with_ver="$prog"
eval ${PIP} install --upgrade --prefix=$target --src=$srcdir "$prog_with_ver" && \
Symlink_Aliens "$goboExecutables" "$goboSystem"/Aliens/PIP/bin
}

remove() {
local prog="$1"
local ver="$2"

pip uninstall "$prog" $ver
eval ${PIP} uninstall "$prog" $ver

Cleanup_Aliens
}

Expand All @@ -74,9 +119,14 @@ prog="$2"

case "$command" in
--getversion)
echo $(getversion "$2")
ver=$(getversion "$2")
[ $? -eq 0 ] && echo $ver || exit $? # propagate the error
;;
--getinstallversion)
[ -z $(getversion "packaging") ] && {
echo "pip module 'packaging' (see PEP440) not found, installing it first"
install packaging || exit 1
}
echo $(getinstallversion "$2" "$3" "$4")
;;
--greater-than)
Expand All @@ -89,13 +139,13 @@ case "$command" in
lower="$3"
upper="$4"
ver=$(getversion "$2")
In_Version_Range "$lower" "$ver" "$upper"
In_Version_Range "$lower" "$ver" "$upper"
;;
--have-manager)
which pip >/dev/null 2>&1 || exit 1
hasmanager || exit 1
;;
--get-manager-rule)
echo "PIP >= 7.0.0"
echo $MANAGER_RULE
;;
--install)
install "$2" "$3"
Expand Down
10 changes: 10 additions & 0 deletions bin/Alien-PIP3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

# Shell script implementing the Aliens interface for PIP3.
# Packages are installed onto /System/Aliens/PIP. The Python module search path
# must include that directory, either through PYTHONPATH or through a .pth file.
#
# Copyright 2017 Aitor P. Iturri.
# Released under the GNU GPL 2 or later.

exec env ALIEN_PYTHON=python3 Alien-PIP $@