-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathrequirements.sh
More file actions
executable file
·45 lines (34 loc) · 940 Bytes
/
requirements.sh
File metadata and controls
executable file
·45 lines (34 loc) · 940 Bytes
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
#!/usr/bin/env bash
set -e
if [ ! -f pyproject.toml ]; then
echo "pyproject.toml not found!"
exit 1
fi
echo "Generating clean requirements.txt with direct dependencies..."
> requirements.txt
awk '
/^\[tool\.poetry\.dependencies\]/ {section="deps"; next}
/^\[tool\.poetry\.dev-dependencies\]/ {section="dev"; next}
/^\[/ {section=""; next}
section!="" && NF>0 {
if ($1 ~ /^python/) next
gsub(/"/, "", $0)
gsub(/ /, "", $0)
split($0, a, "=")
pkg=a[1]
ver=a[2]
# Leave hyphens as-is (do not convert to underscores)
if(ver=="" || ver=="*") {
print pkg
} else {
# Remove ^ or ~ for pip-friendly pin
gsub(/\^|~/, "", ver)
# Add == only if not already present
if(index(ver, "==")==0) {
print pkg "==" ver
} else {
print pkg ver
}
}
}' pyproject.toml > requirements.txt
echo "Done! requirements.txt created."