Skip to content

Commit 4a4811e

Browse files
Migrate from poetry to uv (#146)
Co-authored-by: Julian Kuners <julian.kuners@gmail.com>
1 parent 9ec9050 commit 4a4811e

28 files changed

Lines changed: 1523 additions & 889 deletions

.cruft.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"template": "https://github.com/runtimeverification/python-project-template.git",
3-
"commit": "70e5fe42fbddd7b0f89c56219ac9012c75028b84",
3+
"commit": "7a095b4dd0a51916da0a728b8fdd9adf7e469a68",
44
"checkout": null,
55
"context": {
66
"cookiecutter": {
@@ -11,7 +11,8 @@
1111
"description": "kup is a tool for managing installations of the K framework along with the different available semantics",
1212
"author_name": "Runtime Verification, Inc.",
1313
"author_email": "contact@runtimeverification.com",
14-
"_template": "https://github.com/runtimeverification/python-project-template.git"
14+
"_template": "https://github.com/runtimeverification/python-project-template.git",
15+
"_commit": "7a095b4dd0a51916da0a728b8fdd9adf7e469a68"
1516
}
1617
},
1718
"directory": null

.flake8

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[flake8]
22
max-line-length = 120
3-
extend-select = B9
3+
extend-select = B9, TC1
44
extend-ignore = B950,E,W1,W2,W3,W4,W5
55
per-file-ignores =
66
*/__init__.py: F401
7+
type-checking-strict = true

.github/workflows/test-pr.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,30 @@ jobs:
2222
install_url: https://releases.nixos.org/nix/nix-2.32.0/install
2323
extra_nix_config:
2424
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
25-
2625
- uses: cachix/cachix-action@v12
2726
with:
2827
name: k-framework
2928
signingKey: '${{ secrets.CACHIX_PUBLIC_TOKEN }}'
3029
skipPush: true
31-
- uses: actions/setup-python@v4
30+
- name: 'Install Python'
31+
uses: actions/setup-python@v6
3232
with:
33-
python-version: '3.11'
34-
- name: 'Install Poetry'
33+
python-version: '3.10'
34+
- name: 'Get uv release'
35+
id: uv_release
3536
run: |
36-
curl -sSL https://install.python-poetry.org | python3 -
37-
poetry --version
38-
- name: 'Formatting and Type Checking'
39-
run: make
37+
echo uv_version=$(cat deps/uv_release) >> "${GITHUB_OUTPUT}"
38+
- name: 'Install uv'
39+
uses: astral-sh/setup-uv@v7
40+
with:
41+
version: ${{ steps.uv_release.outputs.uv_version }}
42+
- name: 'Run code quality checks'
43+
run: make check
44+
- name: 'Run pyupgrade'
45+
run: make pyupgrade
46+
- name: 'Run unit tests'
47+
run: make cov-unit
4048
- name: 'Kup list works'
41-
run: poetry run kup list
49+
run: uv run kup list
4250
- name: 'Build via Nix'
4351
run: nix build

.github/workflows/update-version.yml

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ on:
33
push:
44
branches:
55
- '_update-deps/runtimeverification/rv-nix-tools'
6+
- '_update-deps-cron/uv2nix'
7+
- '_update-deps-cron/pyproject-build-systems'
68
workflow_dispatch:
79
concurrency:
810
group: ${{ github.workflow }}-${{ github.ref }}
@@ -23,22 +25,47 @@ jobs:
2325
run: |
2426
git config user.name devops
2527
git config user.email devops@runtimeverification.com
26-
- name: 'Install Poetry'
27-
uses: Gr1N/setup-poetry@v9
28+
- name: 'Install Python'
29+
uses: actions/setup-python@v6
30+
with:
31+
python-version: '3.10'
32+
# note: we install the same version of `uv` as used by `uv2nix` in order to match the nix derivation
33+
- name: 'Update uv release tag'
34+
id: uv_release
35+
run: |
36+
UV2NIX_VERSION=$(cat deps/uv2nix)
37+
UV_VERSION=$(curl -s https://raw.githubusercontent.com/pyproject-nix/uv2nix/$(cat deps/uv2nix)/pkgs/uv-bin/srcs.json | jq -r .version)
38+
[[ "$UV_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]
39+
echo $UV_VERSION > deps/uv_release
40+
git add deps/uv_release && git commit -m "Sync uv version: uv ${UV_VERSION}" || true
41+
echo uv_version=$UV_VERSION >> "${GITHUB_OUTPUT}"
42+
- name: 'Install uv'
43+
uses: astral-sh/setup-uv@v7
44+
with:
45+
version: ${{ steps.uv_release.outputs.uv_version }}
2846
- name: 'Install Nix'
2947
uses: cachix/install-nix-action@v31.7.0
3048
with:
3149
install_url: https://releases.nixos.org/nix/nix-2.32.0/install
3250
extra_nix_config: |
3351
substituters = http://cache.nixos.org https://hydra.iohk.io
3452
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=
35-
- name: 'Update Poetry files'
53+
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
54+
- uses: cachix/cachix-action@v16
55+
with:
56+
name: k-framework
57+
authToken: ${{ secrets.CACHIX_PUBLIC_TOKEN }}
58+
- name: 'Update uv files'
3659
run: |
37-
poetry update
38-
git add . && git commit -m "Sync Poetry files" || true
60+
uv lock --upgrade
61+
git add uv.lock && git commit -m "Sync uv lock file" || true
3962
- name: 'Update Nix flake inputs'
4063
run: |
64+
UV2NIX_VERSION=$(cat deps/uv2nix)
65+
PYPROJECT_BUILD_SYSTEMS_VERSION=$(cat deps/pyproject-build-systems)
4166
RV_NIX_TOOLS_VERSION=$(cat deps/rv-nix-tools)
67+
sed -i 's! uv2nix.url = "github:pyproject-nix/uv2nix/[a-z0-9\.]*"! uv2nix.url = "github:pyproject-nix/uv2nix/'"${UV2NIX_VERSION}"'"!' flake.nix
68+
sed -i 's! pyproject-build-systems.url = "github:pyproject-nix/build-system-pkgs/[a-z0-9\.]*"! pyproject-build-systems.url = "github:pyproject-nix/build-system-pkgs/'"${PYPROJECT_BUILD_SYSTEMS_VERSION}"'"!' flake.nix
4269
sed -i 's! rv-nix-tools.url = "github:runtimeverification/rv-nix-tools/[a-z0-9\.]*"! rv-nix-tools.url = "github:runtimeverification/rv-nix-tools/'"${RV_NIX_TOOLS_VERSION}"'"!' flake.nix
4370
nix flake update
4471
git add flake.nix flake.lock && git commit -m 'flake.{nix,lock}: update Nix derivations' || true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/dist/
22
__pycache__/
3+
.coverage

Makefile

Lines changed: 73 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,100 @@
1-
.PHONY: default all clean build install \
2-
poetry-install \
3-
test test-unit \
4-
format isort autoflake black \
5-
check check-isort check-autoflake check-black check-flake8 check-mypy
1+
UV := uv
2+
UV_RUN := $(UV) run --
3+
64

75
default: check test-unit
86

7+
all: check cov
8+
9+
.PHONY: clean
910
clean:
10-
rm -rf dist .mypy_cache
11+
rm -rf dist .coverage cov-* .mypy_cache .pytest_cache
1112
find -type d -name __pycache__ -prune -exec rm -rf {} \;
1213

14+
.PHONY: build
1315
build:
14-
poetry build
16+
$(UV) build
1517

16-
poetry-install:
17-
poetry install
1818

19-
POETRY_RUN := poetry run
19+
# Tests
2020

21+
TEST_ARGS :=
2122

22-
# Tests
23+
test: test-all
24+
25+
.PHONY: test-all
26+
test-all:
27+
$(UV_RUN) pytest src/tests --maxfail=1 --verbose --durations=0 --numprocesses=4 --dist=worksteal $(TEST_ARGS)
28+
29+
.PHONY: test-unit
30+
test-unit:
31+
$(UV_RUN) pytest src/tests/unit --maxfail=1 --verbose $(TEST_ARGS)
32+
33+
.PHONY: test-integration
34+
test-integration:
35+
$(UV_RUN) pytest src/tests/integration --maxfail=1 --verbose --durations=0 --numprocesses=4 --dist=worksteal $(TEST_ARGS)
36+
37+
38+
# Coverage
2339

24-
test: test-unit
40+
COV_ARGS :=
2541

26-
test-unit: poetry-install
27-
$(POETRY_RUN) python -m unittest discover tests --failfast --verbose
42+
cov: cov-all
43+
44+
cov-%: TEST_ARGS += --cov=kup --no-cov-on-fail --cov-branch --cov-report=term
45+
46+
cov-all: TEST_ARGS += --cov-report=html:cov-all-html $(COV_ARGS)
47+
cov-all: test-all
48+
49+
cov-unit: TEST_ARGS += --cov-report=html:cov-unit-html $(COV_ARGS)
50+
cov-unit: test-unit
51+
52+
cov-integration: TEST_ARGS += --cov-report=html:cov-integration-html $(COV_ARGS)
53+
cov-integration: test-integration
2854

2955

3056
# Checks and formatting
3157

3258
format: autoflake isort black
3359
check: check-flake8 check-mypy check-autoflake check-isort check-black
3460

35-
check-flake8: poetry-install
36-
$(POETRY_RUN) flake8 src
61+
.PHONY: check-flake8
62+
check-flake8:
63+
$(UV_RUN) flake8 src
64+
65+
.PHONY: check-mypy
66+
check-mypy:
67+
$(UV_RUN) mypy src
68+
69+
.PHONY: autoflake
70+
autoflake:
71+
$(UV_RUN) autoflake --quiet --in-place src
72+
73+
.PHONY: check-autoflake
74+
check-autoflake:
75+
$(UV_RUN) autoflake --quiet --check src
76+
77+
.PHONY: isort
78+
isort:
79+
$(UV_RUN) isort src
3780

38-
check-mypy: poetry-install
39-
$(POETRY_RUN) mypy src
81+
.PHONY: check-isort
82+
check-isort:
83+
$(UV_RUN) isort --check src
4084

41-
autoflake: poetry-install
42-
$(POETRY_RUN) autoflake --quiet --in-place src
85+
.PHONY: black
86+
black:
87+
$(UV_RUN) black src
4388

44-
check-autoflake: poetry-install
45-
$(POETRY_RUN) autoflake --quiet --check src
89+
.PHONY: check-black
90+
check-black:
91+
$(UV_RUN) black --check src
4692

47-
isort: poetry-install
48-
$(POETRY_RUN) isort src
4993

50-
check-isort: poetry-install
51-
$(POETRY_RUN) isort --check src
94+
# Optional tools
5295

53-
black: poetry-install
54-
$(POETRY_RUN) black src
96+
SRC_FILES := $(shell find src -type f -name '*.py')
5597

56-
check-black: poetry-install
57-
$(POETRY_RUN) black --check src
98+
.PHONY: pyupgrade
99+
pyupgrade:
100+
$(UV_RUN) pyupgrade --py310-plus $(SRC_FILES)

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ etc.
4343

4444
## For Developers
4545

46+
Prerequsites: `python >= 3.10`, [`uv`](https://docs.astral.sh/uv/).
47+
4648
Use `make` to run common tasks (see the [Makefile](Makefile) for a complete list of available targets).
4749

4850
* `make build`: Build wheel
4951
* `make check`: Check code style
5052
* `make format`: Format code
5153
* `make test-unit`: Run unit tests
54+
* `make test-integration`: Run integration tests
5255

53-
For interactive use, spawn a shell with `poetry shell` (after `poetry install`), then run an interpreter.

deps/uv2nix

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

deps/uv_release

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

0 commit comments

Comments
 (0)