Skip to content

Commit 604cb14

Browse files
authored
Merge pull request #1 from Trojan3877/copilot/make-python-dev-dependencies-reproducible
Make Python dev dependencies reproducible with pip-tools hashed lock file
2 parents 2902c21 + 08ad602 commit 604cb14

File tree

4 files changed

+790
-1
lines changed

4 files changed

+790
-1
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: CI Pipeline
2+
3+
on:
4+
push:
5+
branches: ["main", "master"]
6+
pull_request:
7+
branches: ["main", "master"]
8+
9+
jobs:
10+
lint-and-test:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v3
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: "3.11"
23+
cache: "pip"
24+
25+
- name: Install pip-tools
26+
run: python -m pip install --upgrade pip pip-tools
27+
28+
- name: Install dev dependencies from lock file
29+
run: pip-sync requirements-dev.lock
30+
31+
- name: Lint with flake8
32+
run: flake8 .
33+
34+
- name: Check formatting with black
35+
run: black --check .
36+
37+
- name: Type-check with mypy
38+
run: mypy . || true
39+
40+
- name: Run tests
41+
run: pytest --cov=services tests/

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ logs:
88
docker-compose logs -f
99

1010
test:
11-
pytest --cov=services tests/
11+
pytest --cov=services tests/
12+
13+
lock-dev:
14+
pip-compile --generate-hashes requirements-dev.txt --output-file requirements-dev.lock
15+
16+
sync-dev:
17+
pip-sync requirements-dev.lock

docs/dev-dependencies.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Developer Dependencies
2+
3+
This project uses [pip-tools](https://github.com/jazzband/pip-tools) to keep
4+
dev dependencies reproducible.
5+
6+
| File | Purpose |
7+
|------|---------|
8+
| `requirements-dev.txt` | Human-maintained input: list of top-level dev packages |
9+
| `requirements-dev.lock` | Auto-generated lock file with pinned versions **and SHA-256 hashes** |
10+
11+
---
12+
13+
## Prerequisites
14+
15+
Install pip-tools once into your virtual environment:
16+
17+
```bash
18+
python -m pip install pip-tools
19+
```
20+
21+
---
22+
23+
## Compiling the lock file
24+
25+
Re-generate `requirements-dev.lock` from `requirements-dev.txt`:
26+
27+
```bash
28+
make lock-dev
29+
# equivalent: pip-compile --generate-hashes requirements-dev.txt --output-file requirements-dev.lock
30+
```
31+
32+
Commit the updated `requirements-dev.lock` along with any changes to
33+
`requirements-dev.txt`.
34+
35+
---
36+
37+
## Installing / syncing from the lock file
38+
39+
Install the exact locked versions (removes any packages not in the lock file):
40+
41+
```bash
42+
make sync-dev
43+
# equivalent: pip-sync requirements-dev.lock
44+
```
45+
46+
---
47+
48+
## Updating dependencies (minor/patch)
49+
50+
To pull in the latest compatible minor/patch releases:
51+
52+
```bash
53+
pip-compile --upgrade --generate-hashes requirements-dev.txt --output-file requirements-dev.lock
54+
```
55+
56+
Or upgrade a single package (e.g. `pytest`):
57+
58+
```bash
59+
pip-compile --upgrade-package pytest --generate-hashes requirements-dev.txt --output-file requirements-dev.lock
60+
```
61+
62+
After compiling, sync your environment:
63+
64+
```bash
65+
make sync-dev
66+
```
67+
68+
Then commit both `requirements-dev.txt` (if changed) and `requirements-dev.lock`.

0 commit comments

Comments
 (0)