forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-pip-compile.sh
executable file
·62 lines (58 loc) · 2.39 KB
/
post-pip-compile.sh
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
#!/usr/bin/env bash
set -e
# Remove any cruft from a requirements file generated by pip-tools which we don't want to keep
function show_help {
echo "Usage: post-pip-compile.sh file ..."
echo "Remove any cruft left behind by pip-compile in the given requirements file(s)."
echo ""
echo "Removes devstack-specific pip options and \"-e\" prefixes which were"
echo "added to GitHub URLs only so that pip-compile could process them"
echo "correctly."
}
function clean_file {
FILE_PATH=$1
TEMP_FILE=${FILE_PATH}.tmp
# pip-compile captures the devpi-related settings from devstack's pip.conf, remove them
sed '/^--index-url/d' ${FILE_PATH} > ${TEMP_FILE}
mv ${TEMP_FILE} ${FILE_PATH}
sed '/^--trusted-host/d' ${FILE_PATH} > ${TEMP_FILE}
mv ${TEMP_FILE} ${FILE_PATH}
# If an editable VCS URL has a version number suffix, it was only editable for pip-compile's benefit;
# this is a workaround for https://github.com/jazzband/pip-tools/issues/355
sed 's/-e \(.*==.*\)/\1/' ${FILE_PATH} > ${TEMP_FILE}
mv ${TEMP_FILE} ${FILE_PATH}
# Workaround for https://github.com/jazzband/pip-tools/issues/204 -
# change absolute paths for local editable packages back to relative ones
FILE_CONTENT=$(<${FILE_PATH})
FILE_URL_REGEX="-e (file:///[^'$'\n'']*)/common/lib/symmath"
if [[ "${FILE_CONTENT}" =~ ${FILE_URL_REGEX} ]]; then
BASE_FILE_URL=${BASH_REMATCH[1]}
sed "s|$BASE_FILE_URL/||" ${FILE_PATH} > ${TEMP_FILE}
mv ${TEMP_FILE} ${FILE_PATH}
sed "s|$BASE_FILE_URL|.|" ${FILE_PATH} > ${TEMP_FILE}
mv ${TEMP_FILE} ${FILE_PATH}
fi
# Code sandbox local package installs must be non-editable due to file
# permissions issues. edxapp ones must stay editable until assorted
# packaging bugs are fixed.
if [[ "${FILE_PATH}" == "requirements/edx-sandbox/base.txt" ]]; then
sed "s|-e common/lib/|common/lib/|" ${FILE_PATH} > ${TEMP_FILE}
mv ${TEMP_FILE} ${FILE_PATH}
fi
# Replace the instructions for regenerating the output file.
INPUT_FILE=${FILE_PATH/\.txt/\.in}
sed "s/pip-compile --output-file.*/make upgrade/" ${FILE_PATH} > ${TEMP_FILE}
mv ${TEMP_FILE} ${FILE_PATH}
}
for i in "$@"; do
case ${i} in
-h|--help)
# help or unknown option
show_help
exit 0
;;
*)
clean_file ${i}
;;
esac
done