Skip to content

Commit b85fba5

Browse files
committed
chore(scripts): enhance error handling and update dependency management docs
1 parent adabdb5 commit b85fba5

3 files changed

Lines changed: 37 additions & 5 deletions

File tree

scripts/README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Various scripts for CI/CD, release automation, and development tasks.
66

77
### Setup
88

9-
Install dependencies (all pinned and CVE-free):
9+
Install direct dependencies (hashed, no transitive deps):
1010

1111
```bash
12-
pip install -r requirements.txt
12+
python3 -m pip install --require-hashes --no-deps -r scripts/requirements.txt
1313
```
1414

1515
### Available Scripts
@@ -29,7 +29,7 @@ It's recommended to use a virtual environment:
2929
```bash
3030
python3 -m venv venv
3131
source venv/bin/activate # On macOS/Linux
32-
pip install -r requirements.txt
32+
python3 -m pip install --require-hashes --no-deps -r scripts/requirements.txt
3333
```
3434

3535
To deactivate: `deactivate`
@@ -39,7 +39,7 @@ To deactivate: `deactivate`
3939
To verify everything works:
4040

4141
```bash
42-
./test_python_scripts.sh
42+
./scripts/test_python_scripts.sh
4343
```
4444

4545
This creates a temporary environment, installs dependencies, runs tests, and cleans up automatically.
@@ -52,3 +52,27 @@ The `requirements.txt` includes **4 direct dependencies** (all pinned to specifi
5252
- **PyYAML** - YAML parsing for release notes
5353
- **Jinja2** - Template rendering for changelog files
5454
- **requests** - HTTP client for GitHub API interactions
55+
56+
## Updating requirements.txt hashes
57+
58+
If `./scripts/test_python_scripts.sh` fails with a `--require-hashes` error, regenerate hashes using a temporary no-hash file:
59+
60+
```bash
61+
cp scripts/requirements.txt /tmp/requirements-no-hash.txt
62+
python3 - <<'PY'
63+
import re, pathlib
64+
path = pathlib.Path('/tmp/requirements-no-hash.txt')
65+
text = path.read_text()
66+
text = re.sub(r"\s+--hash=sha256:[a-f0-9]+", "", text)
67+
path.write_text(text)
68+
print("Wrote", path)
69+
PY
70+
71+
mkdir -p /tmp/pip-hashes
72+
python3 -m pip download --no-deps -r /tmp/requirements-no-hash.txt -d /tmp/pip-hashes --quiet
73+
python3 -m pip hash /tmp/pip-hashes/* | sed 's/^.*--hash=/--hash=/'
74+
rm -rf /tmp/pip-hashes
75+
rm /tmp/requirements-no-hash.txt
76+
```
77+
78+
Add the pinned versions and hashes from the output to `scripts/requirements.txt` (direct dependencies only).

scripts/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ PyNaCl==1.6.2 --hash=sha256:c949ea47e4206af7c8f604b8278093b674f7c79ed0d4719cc836
99

1010
# Required by: scripts/ci/render-notes.py
1111
# YAML parser for release notes
12-
PyYAML==6.0.1 --hash=sha256:f003ed9ad21d6a4713f0a9b5a7a0a79e08dd0f221aff4525a2be4c346ee60aab
12+
PyYAML==6.0.1 --hash=sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43
1313

1414
# Required by: scripts/ci/render-notes.py
1515
# Template engine for rendering changelog files

scripts/test_python_scripts.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@ cleanup() {
1414
fi
1515
}
1616

17+
# Print guidance when dependency installs fail under --require-hashes.
18+
on_install_error() {
19+
echo ""
20+
echo "Dependency install failed. See scripts/README.md for updating requirements.txt hashes."
21+
}
22+
1723
# Ensure cleanup happens on exit
1824
trap cleanup EXIT
25+
# Print instructions if a command fails (e.g., missing hashes).
26+
trap on_install_error ERR
1927

2028
echo "Python Scripts Test"
2129
echo "==================="

0 commit comments

Comments
 (0)