Debian Codegraph @

scripts/setup-pylibs

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 set -euo pipefail
4
5 PROJECT_ROOT="$(realpathscip-shell system . . realpath. "$(dirnamescip-shell system . . dirname. "$0")/..")"
6
7 # Which requirements.txt to pass to pip
8 REQUIREMENTS_FILE="${PROJECT_ROOT}/requirements.txt"
9
10 # Where to put the final output in
11 PYLIBS_DIR="${PROJECT_ROOT}/pylibs"
12
13 # Distinguish Ubuntu Touch versions
14 UT_FRAMEWORK="${SDK_FRAMEWORK:-''}"
15
16 if [[ -n "$UT_FRAMEWORK" ]]; then
17 PYLIBS_DIR="${PROJECT_ROOT}/pylibs-${UT_FRAMEWORK}"
18 REQUIREMENTS_FILE="${PROJECT_ROOT}/requirements-${UT_FRAMEWORK}.txt"
19 fi
20
21 echoscip-shell system . . echo. "Using $REQUIREMENTS_FILE for resolving dependencies"
22
23 # List the glob patterns of files/directories you want in the qml plugin
24 # The idea here is to only declare what's _required_ to reduce our size a bit
25 PYTHON_INCLUDED_PATTERNS=(
26 "soupsieve"
27 "markdown"
28 "jinja2"
29 "markupsafe"
30 "bs4"
31 "cssutils"
32 "encutils"
33 # "pynliner" # we include our own instead
34 "pygments"
35 "html2text"
36 "importlib_metadata"
37 "zipp"
38 "typing_extensions*"
39 )
40
41 # Remove something from the copied-over modules, to improve final size
42 PYTHON_EXCLUDED_PATHS=(
43 # cssutils comes with a large test suite
44 # which we don't really need in the snap
45 # it saves us about 1MB
46 "cssutils/tests"
47 )
48
49 if [scip-shell system . . `[`. ! -f "${REQUIREMENTS_FILE}" ]; then
50 echoscip-shell system . . echo. "${REQUIREMENTS_FILE} does not exist!" >&2
51 exit 1
52 fi
53
54 if ! command -v pip3; then
55 echoscip-shell system . . echo. "pip3 binary not found!" >&2
56 exit 1
57 fi
58
59 # Clear our output dir
60 rmscip-shell system . . rm. -vfr "${PYLIBS_DIR}"
61 mkdirscip-shell system . . mkdir. -vp "${PYLIBS_DIR}"
62
63 PYTHONUSERBASE="$(mktempscip-shell system . . mktemp. -d)"
64 echoscip-shell system . . echo. "Set temporary PYTHONUSERBASE to: ${PYTHONUSERBASE}"
65 export PYTHONUSERBASE
66
67 echoscip-shell system . . echo. "Installing required modules via pip..."
68 pip3scip-shell system . . pip3. install --upgrade -r "${REQUIREMENTS_FILE}" --user
69 PYTHON_PACKAGES_DIR="$(python3scip-shell system . . python3. -m site --user-site)"
70 echoscip-shell system . . echo. "Python packages were installed to: ${PYTHON_PACKAGES_DIR}"
71 echoscip-shell system . . echo. "Installation done."
72
73 echoscip-shell system . . echo. "Copying over requested python modules..."
74 for pattern in "${PYTHON_INCLUDED_PATTERNS[@]}"; do
75 cpscip-shell system . . cp. -vr "${PYTHON_PACKAGES_DIR}/"${pattern} "${PYLIBS_DIR}/"
76 done
77 echoscip-shell system . . echo. "Copying done."
78
79 echoscip-shell system . . echo. "Trimming unneeded things from the modules..."
80 for excludedPath in "${PYTHON_EXCLUDED_PATHS[@]}"; do
81 rmscip-shell system . . rm. -vr "${PYLIBS_DIR}/${excludedPath:?entry in PYTHON_EXCLUDED_PATHS is null or unset}"
82 done
83 echoscip-shell system . . echo. "Trimming done."
84
85 echoscip-shell system . . echo. "Cleaning up pip data..."
86 rmscip-shell system . . rm. -vr "${PYTHONUSERBASE}"
87 echoscip-shell system . . echo. "Cleaning done."
88
89 echoscip-shell system . . echo. "Done! Data has been installed to: ${PYLIBS_DIR}"