-
Notifications
You must be signed in to change notification settings - Fork 2
/
getpylib
executable file
·54 lines (44 loc) · 1.14 KB
/
getpylib
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
#!/bin/bash
# find dynamic libraries needed by python packages
#
# Ruoshi Sun
# 2020-09-09
if [ $# -lt 2 ]; then
echo "Usage: `basename $0` image /path/to/site-packages [python_cmd] [module]"
exit 1
fi
IMG=$1
DIR=$2
PYTHON="python"
if [ $# -ge 3 ]; then
PYTHON=$3
fi
if [ $# -eq 4 ]; then
shift 3
MODULES=($@)
fi
# check for lsof
docker run --rm --entrypoint lsof $IMG &> /dev/null
if [ $? -ne 0 ]; then
echo "Please install lsof in $IMG"
exit 1
fi
# python module list
if [ -z "$MODULES" ]; then
MODULES=($(docker run --rm $IMG ls -1 $DIR | \
grep -vE "dist-info|^_|\.|README"))
fi
BEFORE=$(mktemp)
AFTER=$(mktemp)
ALL=$(mktemp)
docker run --rm $IMG $PYTHON -c "import os; pid=os.getpid(); os.system('lsof -p %d -Fn' % pid)" | \
sed -n 's/^n//p' >$BEFORE
N=${#MODULES[@]}
for i in "${!MODULES[@]}"; do
echo "${MODULES[$i]} ($((i+1))/$N)"
docker run --rm $IMG $PYTHON -c "import os; pid=os.getpid(); import ${MODULES[$i]}; os.system('lsof -p %d -Fn' % pid)" | \
sed -n 's/^n//p' >$AFTER
diff $BEFORE $AFTER | sed -n 's/^> //p' >>$ALL
done
awk '{print $1}' $ALL|sort|uniq
rm $BEFORE $AFTER $ALL