44 lines
1.1 KiB
Bash
Executable File
44 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Extract the dependencies from the setup.py files
|
|
# and save the result to requirements.txt.
|
|
#
|
|
# You can filter any extra require by adding the name as argument.
|
|
#
|
|
# Examples:
|
|
# tools/extract-requirements.sh
|
|
# tools/extract-requirements.sh dev
|
|
|
|
set -u
|
|
|
|
error() {
|
|
echo >&2 "error: $*"
|
|
exit 1
|
|
}
|
|
|
|
command -v python3 > /dev/null || error "python3 command not found!"
|
|
command -v sed > /dev/null || error "sed command not found!"
|
|
|
|
for setup_path in */setup.py; do
|
|
path="$(dirname "$setup_path")"
|
|
|
|
# Build egg
|
|
python3 "$setup_path" egg_info > /dev/null 2>&1 || true
|
|
egg_path="$(echo "$path"/*.egg-info)"
|
|
|
|
# Remove entire extra section from require file
|
|
for arg in "$@"; do
|
|
sed --in-place "/^\[$arg\]/,/^\[/d" -- "$egg_path/requires.txt"
|
|
done
|
|
|
|
# Generate requirements.txt
|
|
cat << EOF > "$path/requirements.txt"
|
|
# This file is auto-generated by tools/extract-requirements.sh.
|
|
# Please do not edit this file, edit the setup.py file!
|
|
EOF
|
|
|
|
cat -- "$egg_path/requires.txt" |
|
|
sed '/^$/d' |
|
|
LC_ALL=en_US.UTF-8 sort >> "$path/requirements.txt"
|
|
done
|