alessandro trinca tornidor
commited on
Commit
·
e5face2
1
Parent(s):
803d9c7
ci: add bash/zsh script to automate requirements*.txt files
Browse files
scripts/create_requirements.sh
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
|
| 3 |
+
SCRIPT=$(realpath "$0")
|
| 4 |
+
REQUIREMENTS_NO_VERSION=$(realpath "$1") | $(realpath "./requirements_no_versions.txt")
|
| 5 |
+
SCRIPT_FOLDER=$(dirname "$SCRIPT")
|
| 6 |
+
ROOT_FOLDER=${SCRIPT_FOLDER}/../
|
| 7 |
+
echo "# REQUIREMENTS_NO_VERSION: ${REQUIREMENTS_NO_VERSION} #"
|
| 8 |
+
|
| 9 |
+
mkdir -p tmp
|
| 10 |
+
rm ./tmp/requirements_tmp.txt || echo "./tmp/requirements_tmp.txt not found!"
|
| 11 |
+
|
| 12 |
+
echo "start requirements.txt preparation: pip freeze..."
|
| 13 |
+
pip freeze > ./tmp/freeze.txt
|
| 14 |
+
echo "grep python dependencies into freeze.txt..."
|
| 15 |
+
for f in $(ls requirements_no_versions*.txt); do
|
| 16 |
+
for x in $(cat ./$f); do
|
| 17 |
+
echo "# $x #"
|
| 18 |
+
grep $x ./tmp/freeze.txt >> ./tmp/${f}_tmp.txt
|
| 19 |
+
echo "# done line '$x' #"
|
| 20 |
+
done
|
| 21 |
+
echo "# file '$f' ##" >> ./tmp/requirements_tmp.txt
|
| 22 |
+
sort -u ./tmp/${f}_tmp.txt >> ./tmp/requirements_tmp.txt
|
| 23 |
+
echo "# processed file '$f' ##" >> ./tmp/requirements_tmp.txt
|
| 24 |
+
echo "# ==================== #" >> ./tmp/requirements_tmp.txt
|
| 25 |
+
done
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
echo "cat ${ROOT_FOLDER}/tmp/requirements_tmp.txt"
|
| 29 |
+
cat ${ROOT_FOLDER}/tmp/requirements_tmp.txt
|
| 30 |
+
echo -e "\n"
|
| 31 |
+
|
| 32 |
+
[[ "$(echo -n 'Promote && sort "${ROOT_FOLDER}/tmp/requirements_tmp.txt" as new requirements.txt? [y/N]> ' >&2; read; echo $REPLY)" == [Yy]* ]] \
|
| 33 |
+
&& echo "copy requirements_tmp.txt to root project..." \
|
| 34 |
+
|| exit 0
|
| 35 |
+
|
| 36 |
+
cp ${ROOT_FOLDER}/tmp/requirements_tmp.txt ${ROOT_FOLDER}/requirements.txt
|
| 37 |
+
|
| 38 |
+
echo "Fix any discrepancy within the new requirements.txt, bye!"
|
| 39 |
+
|
| 40 |
+
exit 0
|