Skip to content

Migrate to using uv for build system #537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions .github/actions/with-docker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,27 @@ runs:
TAG=runtimeverificationinc/${CONTAINER_NAME}
K_COMMIT=$(grep -Po '[0-9.]+' ./deps/k_release)

docker build . --tag ${TAG} --build-arg K_COMMIT=${K_COMMIT} --file .github/workflows/Dockerfile
USER=github-user
GROUP=${USER}
USER_ID=1000
GROUP_ID=${USER_ID}

docker run \
--name ${CONTAINER_NAME} \
--rm \
--interactive \
--tty \
--detach \
-v ${PWD}:${PWD} \
--workdir ${PWD} \
docker build . --tag ${TAG} \
--file .github/workflows/Dockerfile \
--build-arg K_COMMIT=${K_COMMIT} \
--build-arg USER=${USER} \
--build-arg GROUP=${GROUP} \
--build-arg USER_ID=${USER_ID} \
--build-arg GROUP_ID=${GROUP_ID}

docker run \
--name ${CONTAINER_NAME} \
--rm \
--interactive \
--tty \
--detach \
--workdir /home/${USER}/workspace \
${TAG}

docker cp . ${CONTAINER_NAME}:/home/${USER}/workspace
docker exec --user root ${CONTAINER_NAME} chown -R ${USER}:${GROUP} /home/${USER}
13 changes: 11 additions & 2 deletions .github/workflows/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ RUN apt-get update \
&& apt-get upgrade --yes \
&& apt-get install --yes \
curl
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/usr python3 - --version 2.0.1

ARG USER=user
ARG GROUP
ARG USER_ID=1000
ARG GROUP_ID=1000
RUN groupadd -g $GROUP_ID user && useradd -m -u $USER_ID -s /bin/sh -g user user
RUN groupadd -g ${GROUP_ID} ${GROUP} && useradd -m -u ${USER_ID} -s /bin/sh -g ${GROUP} ${USER}
USER ${USER}:${GROUP}

RUN mkdir /home/${USER}/workspace
WORKDIR /home/${USER}/workspace

ENV PATH=/home/${USER}/.local/bin:${PATH}
RUN curl -LsSf https://astral.sh/uv/install.sh | sh && uv --version
20 changes: 8 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ jobs:
steps:
- name: 'Check out code'
uses: actions/checkout@v4
- name: 'Install Poetry'
uses: Gr1N/setup-poetry@v8
with:
poetry-version: 2.0.1
- name: 'Install uv'
uses: astral-sh/setup-uv@v5
- name: 'Run code quality checks'
run: make check

Expand All @@ -52,10 +50,8 @@ jobs:
steps:
- name: 'Check out code'
uses: actions/checkout@v4
- name: 'Install Poetry'
uses: Gr1N/setup-poetry@v8
with:
poetry-version: 2.0.1
- name: 'Install uv'
uses: astral-sh/setup-uv@v5
- name: 'Run unit tests'
run: make test-unit

Expand All @@ -74,9 +70,9 @@ jobs:
with:
container-name: mir-semantics-ci-${{ github.sha }}
- name: 'Build kmir'
run: docker exec --user user mir-semantics-ci-${GITHUB_SHA} make build
run: docker exec --user github-user mir-semantics-ci-${GITHUB_SHA} make build
- name: 'Run integration tests'
run: docker exec --user user mir-semantics-ci-${GITHUB_SHA} make test-integration
run: docker exec --user github-user mir-semantics-ci-${GITHUB_SHA} make test-integration
- name: 'Tear down Docker'
if: always()
run: docker stop --time 0 mir-semantics-ci-${GITHUB_SHA}
Expand Down Expand Up @@ -115,10 +111,10 @@ jobs:
container-name: mir-smir-ci-${{ github.sha }}

- name: 'Build kmir (within docker)'
run: docker exec --user user mir-smir-ci-${GITHUB_SHA} make build
run: docker exec --user github-user mir-smir-ci-${GITHUB_SHA} make build

- name: 'Run parser tests (within docker)'
run: make smir-parse-tests POETRY_RUN='docker exec --user user mir-smir-ci-${GITHUB_SHA} poetry -C kmir run'
run: docker exec --user github-user mir-smir-ci-${GITHUB_SHA} make smir-parse-tests

- name: 'Tear down Docker'
if: always()
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/update-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ jobs:
uses: actions/checkout@v4
with:
token: ${{ secrets.JENKINS_GITHUB_PAT }}
- name: 'Install Poetry'
- name: 'Install uv'
run: |
curl -sSL https://install.python-poetry.org | python3 - --version 1.3.2
curl -LsSf https://astral.sh/uv/install.sh | sh
echo ${HOME}/.local/bin >> $GITHUB_PATH
uv --version
- name: 'Update pyk release tag'
run: |
K_VERSION=$(cat ./deps/k_release)
cd kmir
sed -i 's!kframework = "[0-9\.]*"!kframework = "'${K_VERSION}'"!' pyproject.toml
poetry update -vvv
git add pyproject.toml poetry.lock
git commit -m 'kmir/{pyproject.toml,poetry.lock}: sync Poetry files' || true
sed -i 's! "kframework==v[0-9\.]*",! "kframework==v'${K_VERSION}',"!' pyproject.toml
uv lock --upgrade
git add pyproject.toml uv.lock
git commit -m 'kmir/{pyproject.toml,uv.lock}: sync uv files, K version '${K_VERSION} || true
- name: 'Update Nix flake inputs'
run: |
K_VERSION=$(cat deps/k_release)
Expand Down
63 changes: 30 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
POETRY := poetry -C kmir
POETRY_RUN := $(POETRY) run
UV := uv --directory kmir
UV_RUN := $(UV) run

TOP_DIR := $(shell pwd)

default: build
default: check build

build: poetry-install
$(POETRY) run kdist -v build mir-semantics.\* -j4
build:
$(UV_RUN) kdist -v build mir-semantics\.* -j4

.PHONY: test
test: test-unit test-integration smir-parse-tests
Expand All @@ -31,7 +31,7 @@ smir-parse-tests: # build # commented out for CI's sake
&& echo -n "smir-ed " \
|| report "$$source" "SMIR ERROR!"; \
if [ -s $${target} ]; then \
${POETRY_RUN} parse $$(realpath $${target}) Pgm > /dev/null \
${UV_RUN} parse $$(realpath $${target}) Pgm > /dev/null \
&& (echo "and parsed!"; rm $${target}) \
|| report "$$source" "PARSE ERROR!"; \
fi; \
Expand All @@ -41,45 +41,41 @@ smir-parse-tests: # build # commented out for CI's sake
##################################################
# Targets operating in the `kmir` directory

.PHONY: poetry-install
poetry-install:
$(POETRY) install

test-unit: poetry-install # build # commented out for CI's sake
$(POETRY_RUN) pytest $(TOP_DIR)/kmir/src/tests/unit --maxfail=1 --verbose $(TEST_ARGS)
test-unit:
$(UV_RUN) pytest $(TOP_DIR)/kmir/src/tests/unit --maxfail=1 --verbose $(TEST_ARGS)

test-integration: build
$(POETRY_RUN) pytest $(TOP_DIR)/kmir/src/tests/integration --maxfail=1 --verbose \
$(UV_RUN) pytest $(TOP_DIR)/kmir/src/tests/integration --maxfail=1 --verbose \
--durations=0 --numprocesses=4 --dist=worksteal $(TEST_ARGS)

# Checks and formatting

format: autoflake isort black
check: check-flake8 check-mypy check-autoflake check-isort check-black

check-flake8: poetry-install
$(POETRY_RUN) flake8 src
check-flake8:
$(UV_RUN) flake8 src

check-mypy: poetry-install
$(POETRY_RUN) mypy src
check-mypy:
$(UV_RUN) mypy src

autoflake: poetry-install
$(POETRY_RUN) autoflake --quiet --in-place src
autoflake:
$(UV_RUN) autoflake --quiet --in-place src

check-autoflake: poetry-install
$(POETRY_RUN) autoflake --quiet --check src
check-autoflake:
$(UV_RUN) autoflake --quiet --check src

isort: poetry-install
$(POETRY_RUN) isort src
isort:
$(UV_RUN) isort src

check-isort: poetry-install
$(POETRY_RUN) isort --check src
check-isort:
$(UV_RUN) isort --check src

black: poetry-install
$(POETRY_RUN) black src
black:
$(UV_RUN) black src

check-black: poetry-install
$(POETRY_RUN) black --check src
check-black:
$(UV_RUN) black --check src

# Coverage

Expand All @@ -106,14 +102,15 @@ clean:
rm -rf kmir/dist kmir/.coverage kmir/cov-* kmir/.mypy_cache kmir/.pytest_cache
find kmir/ -type d -name __pycache__ -prune -exec rm -rf {} \;

.PHONY: pyupgrade
pyupgrade: SRC_FILES := $(shell find kmir/src -type f -name '*.py')
pyupgrade: poetry-install
$(POETRY_RUN) pyupgrade --py310-plus $(SRC_FILES)
pyupgrade:
$(UV_RUN) pyupgrade --py310-plus $(SRC_FILES)

# Update smir exec tests expectations
.PHONY: update-exec-smir
update-exec-smir: poetry-install
UPDATE_EXEC_SMIR=true $(POETRY_RUN) pytest -k test_exec_smir
update-exec-smir:
UPDATE_EXEC_SMIR=true $(UV_RUN) pytest -k test_exec_smir

# Update checked-in smir.json files (using stable-mir-json dependency and jq)
.PHONY: update-smir-json
Expand Down
Loading
Loading