-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpypkgver
executable file
·81 lines (72 loc) · 1.86 KB
/
pypkgver
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
# find latest python packages
#
# Ruoshi Sun
# 2020-08-14
if [[ $# -lt 2 || $# -gt 4 ]]; then
echo "Usage: `basename $0` c[onda] \"CHANNELS_LIST\" \"PACKAGES_LIST\" [eb]"
echo " `basename $0` p[ip] \"PACKAGES_LIST\" [eb]"
echo "Adding \"eb\" as the last argument will print the result in easyconfig format."
exit 1
fi
EB=false
MANAGER=$1
if [[ $MANAGER =~ ^c ]]; then
CHANNELS="$2"
PACKAGES="$3"
if [ $# -eq 4 ]; then
EB=true
fi
elif [[ $MANAGER =~ ^p ]]; then
PACKAGES="$2"
if [ $# -eq 3 ]; then
EB=true
fi
else
echo "Invalid package manager $MANAGER"
exit 1
fi
# sort packages
PACKAGES_SORTED=$(echo "$PACKAGES" | tr ' ' '\n' | sort | tr '\n' ' ')
function search_conda {
CONDA_CMD_PREFIX="conda search"
for c in $CHANNELS; do
CONDA_CMD_PREFIX+=" -c $c"
done
for i in $PACKAGES_SORTED; do
CONDA_CMD="$CONDA_CMD_PREFIX -f $i"
if [ "$EB" = "true" ]; then
eval $CONDA_CMD | tail -1 | awk '{printf "requirements += \"%s=%s \"\n", $1, $2}'
else
eval $CONDA_CMD | tail -1
fi
done
}
function search_pip {
TMP=$(mktemp)
for i in $PACKAGES_SORTED; do
if [ "$EB" = "true" ]; then
pip search $i | tail -n +1 | awk '{
if(NR==1) {
gsub(/[()]/,"")
printf "requirements += \"%s==%s \"\n", $1, $2
}
}'
else
pip search $i >$TMP
awk -v i=$i '{
if ($1==i) {
gsub(/[()]/,"")
printf "%s==%s\n", $1, $2
exit
}
}' $TMP
fi
done
}
module load anaconda/2019.10-py3.7 2>/dev/null
if [[ $MANAGER =~ ^c ]]; then
search_conda $PACKAGES_SORTED
else
search_pip $PACKAGES_SORTED
fi