Skip to content

Commit 3befe5a

Browse files
authored
Migrate to uv (#183)
* feat: use idiomatic version configs * fix: apply linter suggestions * feat: upgrade python from 3.11 to 3.13 * feat: replace pip with uv * feat: makefile overhaul * chore: update snapshots
1 parent 6dd4710 commit 3befe5a

File tree

16 files changed

+303
-127
lines changed

16 files changed

+303
-127
lines changed

.flake8

Lines changed: 0 additions & 5 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,41 +34,21 @@ jobs:
3434

3535
- uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
3636
with:
37-
node-version: 24
37+
node-version-file: ".node-version"
38+
cache: "npm"
3839

3940
- uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
4041
id: setup-python
4142
with:
42-
python-version: "3.14"
43+
python-version-file: ".python-version"
4344

44-
- name: python - setup dependency cache
45-
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
45+
- name: python - setup uv
46+
uses: astral-sh/setup-uv@ed21f2f24f8dd64503750218de024bcf64c7250a # v7.1.5
4647
with:
47-
key: venv-${{ runner.os }}-${{ steps.setup_python.outputs.python-version}}-${{ hashFiles('requirements.txt') }}
48-
path: .venv
48+
enable-cache: true
4949

50-
- name: python - install dependencies
51-
run: |
52-
python -m venv .venv
53-
source .venv/bin/activate
54-
python -m pip install -r requirements.txt
55-
echo "$VIRTUAL_ENV/bin" >> $GITHUB_PATH
56-
echo "VIRTUAL_ENV=$VIRTUAL_ENV" >> $GITHUB_ENV
57-
58-
- name: python - lint
59-
run: make py-lint
60-
61-
- name: python - test
62-
run: make py-test
63-
64-
- name: npm - install dependencies
65-
run: npm ci
66-
67-
- name: npm - lint
68-
run: make npm-lint
69-
70-
- name: npm - test
71-
run: make npm-test
50+
- name: build and verify
51+
run: make ci
7252

7353
- name: conditionally semantic release
7454
if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}

.github/workflows/update-snapshots.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,10 @@ jobs:
6666

6767
- uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
6868
with:
69-
node-version: 24
69+
node-version-file: ".node-version"
7070

71-
- name: Install dependencies
72-
run: npm ci
73-
74-
- name: Update CDK and Jest snapshots
75-
run: make snapshots
71+
- name: Build and update snapshots
72+
run: make build
7673

7774
- name: Check for snapshot changes
7875
id: check_changes

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
24.11.1

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

.tool-versions

Lines changed: 0 additions & 2 deletions
This file was deleted.

Makefile

Lines changed: 114 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,135 @@
1-
VENV = .venv/bin
2-
31
.PHONY: all
4-
all: install-deps build fmt lint test
2+
all: build
53

6-
.PHONY: install-deps
7-
install-deps:
8-
@echo "=== Running target: install-deps ==="
9-
npm install --ignore-scripts
10-
python3 -m venv .venv && \
11-
$(VENV)/pip install -r requirements.txt
4+
###########################
5+
# Composite targets
6+
# ###########################
127

138
.PHONY: build
14-
build:
15-
@echo "=== Running target: build ==="
16-
npm run build # runs build through prepare-script
9+
build: install lint-fix fmt npm-build snapshots
10+
11+
.PHONY: ci
12+
ci: install lint fmt-check npm-build test
13+
14+
.PHONY: install
15+
install: py-install npm-install
16+
17+
.PHONY: lint
18+
lint: py-lint-check npm-lint-check
19+
20+
.PHONY: lint-fix
21+
lint-fix: py-lint-fix npm-lint-fix
22+
23+
.PHONY: fmt
24+
fmt: py-fmt-fix npm-fmt-fix
25+
26+
.PHONY: fmt-check
27+
fmt-check: py-fmt-check npm-fmt-check
1728

1829
.PHONY: test
19-
test: npm-test py-test
30+
test: py-test npm-test
31+
32+
.PHONY: snapshots
33+
snapshots: npm-test-update
34+
35+
.PHONY: clean
36+
clean: npm-clean py-clean
37+
38+
.PHONY: clean-all
39+
clean-all: npm-clean-all py-clean-all
40+
41+
42+
###########################
43+
# NPM targets
44+
###########################
45+
.PHONY: npm-install
46+
npm-install:
47+
ifeq ($(CI),true)
48+
npm ci
49+
else
50+
npm install --ignore-scripts
51+
endif
52+
53+
.PHONY: npm-build
54+
npm-build:
55+
npm run build
56+
57+
.PHONY: npm-fmt-fix
58+
npm-fmt-fix:
59+
npm run fmt
60+
61+
.PHONY: npm-fmt-check
62+
npm-fmt-check:
63+
npm run fmt:check
64+
65+
.PHONY: npm-upgrade-deps
66+
npm-upgrade-deps:
67+
npm run upgrade-dependencies
2068

69+
.PHONY: npm-biome-migrate
70+
npm-biome-migrate:
71+
npm run biome-migrate
72+
73+
.PHONY: npm-test
2174
npm-test:
22-
@echo "=== Running target: npm-test ==="
2375
npm run test
2476

25-
py-test:
26-
@echo "=== Running target: py-test ==="
27-
TARGET_BUCKET_URL=s3://dummy/web \
28-
EXPIRE_SECONDS=86400 \
29-
DEPLOY_LOG_BUCKET_URL=s3://dummy/deployments.log \
30-
$(VENV)/python -m unittest discover webapp_deploy
77+
.PHONY: npm-test-update
78+
npm-test-update:
79+
npm run test:update
3180

32-
.PHONY: fmt
33-
fmt:
81+
.PHONY: npm-lint-check
82+
npm-lint-check:
83+
npm run lint
84+
85+
.PHONY: npm-lint-fix
86+
npm-lint-fix:
3487
npm run lint:fix
35-
$(VENV)/black webapp_deploy
3688

37-
.PHONY: npm-fmt
38-
npm-fmt:
39-
@echo "=== Running target: npm-fmt ==="
40-
npm run format
89+
.PHONY: npm-clean
90+
npm-clean:
91+
rm -rf dist/ lib/
4192

42-
.PHONY: py-fmt
43-
py-fmt:
44-
@echo "=== Running target: py-fmt ==="
45-
$(VENV)/black webapp_deploy
93+
.PHONY: npm-clean-all
94+
npm-clean-all: npm-clean
95+
rm -rf node_modules/
4696

47-
.PHONY: lint
48-
lint: npm-lint py-lint
4997

50-
.PHONY: npm-lint
51-
npm-lint:
52-
@echo "=== Running target: npm-lint ==="
53-
npm run lint
98+
###########################
99+
## Python targets
100+
###########################
101+
.PHONY: py-install
102+
py-install:
103+
uv sync
54104

55-
.PHONY: py-lint
56-
py-lint:
57-
@echo "=== Running target: py-lint ==="
58-
$(VENV)/flake8 --exclude .venv webapp_deploy
59-
$(VENV)/black --check webapp_deploy
105+
.PHONY: py-lint-check
106+
py-lint-check:
107+
uv run ruff check webapp_deploy
60108

61-
.PHONY: snapshots
62-
snapshots:
63-
@echo "=== Running target: snapshots ==="
64-
npm test -- --updateSnapshot
109+
.PHONY: py-lint-fix
110+
py-lint-fix:
111+
uv run ruff check --fix webapp_deploy
65112

66-
.PHONY: clean
67-
clean:
68-
rm -rf dist/ lib/
113+
.PHONY: py-fmt-fix
114+
py-fmt-fix:
115+
uv run ruff format webapp_deploy
69116

70-
.PHONY: upgrade-deps
71-
upgrade-deps:
72-
@echo "=== Running target: upgrade-deps ==="
73-
npm run upgrade-dependencies
117+
.PHONY: py-fmt-check
118+
py-fmt-check:
119+
uv run ruff format --check webapp_deploy
74120

75-
.PHONY: biome-migrate
76-
biome-migrate:
77-
@echo "=== Running target: biome-migrate ==="
78-
npm run biome-migrate
121+
.PHONY: py-test
122+
py-test:
123+
TARGET_BUCKET_URL=s3://dummy/web \
124+
EXPIRE_SECONDS=86400 \
125+
DEPLOY_LOG_BUCKET_URL=s3://dummy/deployments.log \
126+
uv run python -m unittest discover webapp_deploy
127+
128+
.PHONY: py-clean
129+
py-clean:
130+
uv run ruff clean
131+
uv clean
132+
133+
.PHONY: py-clean-all
134+
py-clean-all: py-clean
135+
rm -rf venv

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,16 @@ aws lambda invoke \
5555
Testing locally:
5656

5757
```bash
58-
python3 -m venv .venv
59-
source .venv/bin/activate
60-
pip install -r requirements.txt
58+
$ uv sync
6159

6260
# Adjust to your project. See config.py for full list.
63-
export TARGET_BUCKET_URL=s3://my-website/web
64-
export EXPIRE_SECONDS=86400
65-
export DEPLOY_LOG_BUCKET_URL=s3://my-website/deployments.log
66-
export CF_DISTRIBUTION_ID=EKJ2IPY1KTEAR1
61+
$ export TARGET_BUCKET_URL=s3://my-website/web
62+
$ export EXPIRE_SECONDS=86400
63+
$ export DEPLOY_LOG_BUCKET_URL=s3://my-website/deployments.log
64+
$ export CF_DISTRIBUTION_ID=EKJ2IPY1KTEAR1
6765

6866
# Adjust artifact path.
69-
python -m webapp_deploy.main s3://my-bucket/my-release.tgz
67+
$ uv run python -m webapp_deploy.main s3://my-bucket/my-release.tgz
7068
```
7169

7270
## Notes

build.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,3 @@ cp -r webapp_deploy dist/
88
if [ -e dist/webapp_deploy/__pycache__ ]; then
99
rm -rf dist/webapp_deploy/__pycache__
1010
fi
11-
12-
# We currently do not install requirements.txt as the
13-
# items are already present in lambda runtime.

mise.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[settings]
2+
idiomatic_version_file_enable_tools = ["python", "node"]
3+
4+
[tools]
5+
uv = "0.9.16"

0 commit comments

Comments
 (0)