-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_pip_reqs.sh
61 lines (55 loc) · 1.58 KB
/
gen_pip_reqs.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
#!/usr/bin/env bash
# Set default output file name
output_file="requirements.txt"
# help message
usage() {
echo "Usage: $0 [--all] [--with <group1,group2,...>] [--output <file_name>]"
echo "Export Python package requirements using poetry"
echo ""
echo "Options:"
echo " --all Export packages from all groups"
echo " --with <group1,group2> Export packages only from specified groups (comma-separated)"
echo " --output <file_name> Save output to specified file (default: requirements.txt)"
exit 1
}
groups_specified=false
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-w | --with)
groups+=("${2}")
groups_specified=true
shift 2
;;
-a | --all)
all_groups=true
groups_specified=true
shift
;;
-o | --output)
output_file="${2}"
shift 2
;;
-h | --help)
usage
;;
*)
echo "Unknown option: $1"
usage
;;
esac
done
# If --all was specified, get all the groups from the pyproject.toml file
if [ "$all_groups" = true ]; then
groups=($(grep -E "^\[tool\.poetry\.group\.[^]]+\]$" pyproject.toml | cut -d "." -f 4))
fi
# Generate requirements.txt file
# whether to use the --with flag
if [ "$groups_specified" = true ]; then
poetry export --without-hashes $(printf -- "--with %s " "${groups[@]}") -f requirements.txt -o "$output_file"
else
poetry export --without-hashes -f requirements.txt -o "$output_file"
fi
# add local package information to the end of the file
echo "# local package" >> "$output_file"
echo "-e ." >> "$output_file"