Skip to content
Draft
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
5 changes: 3 additions & 2 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/runtimeverification/python-project-template.git",
"commit": "70e5fe42fbddd7b0f89c56219ac9012c75028b84",
"commit": "7a095b4dd0a51916da0a728b8fdd9adf7e469a68",
"checkout": null,
"context": {
"cookiecutter": {
Expand All @@ -11,7 +11,8 @@
"description": "kup is a tool for managing installations of the K framework along with the different available semantics",
"author_name": "Runtime Verification, Inc.",
"author_email": "contact@runtimeverification.com",
"_template": "https://github.com/runtimeverification/python-project-template.git"
"_template": "https://github.com/runtimeverification/python-project-template.git",
"_commit": "7a095b4dd0a51916da0a728b8fdd9adf7e469a68"
}
},
"directory": null
Expand Down
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[flake8]
max-line-length = 120
extend-select = B9
extend-select = B9, TC1
extend-ignore = B950,E,W1,W2,W3,W4,W5
per-file-ignores =
*/__init__.py: F401
type-checking-strict = true
26 changes: 17 additions & 9 deletions .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,30 @@ jobs:
install_url: https://releases.nixos.org/nix/nix-2.32.0/install
extra_nix_config:
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}

- uses: cachix/cachix-action@v12
with:
name: k-framework
signingKey: '${{ secrets.CACHIX_PUBLIC_TOKEN }}'
skipPush: true
- uses: actions/setup-python@v4
- name: 'Install Python'
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: 'Install Poetry'
python-version: '3.10'
- name: 'Get uv release'
id: uv_release
run: |
curl -sSL https://install.python-poetry.org | python3 -
poetry --version
- name: 'Formatting and Type Checking'
run: make
echo uv_version=$(cat deps/uv_release) >> "${GITHUB_OUTPUT}"
- name: 'Install uv'
uses: astral-sh/setup-uv@v7
with:
version: ${{ steps.uv_release.outputs.uv_version }}
- name: 'Run code quality checks'
run: make check
- name: 'Run pyupgrade'
run: make pyupgrade
- name: 'Run unit tests'
run: make cov-unit
- name: 'Kup list works'
run: poetry run kup list
run: uv run kup list
- name: 'Build via Nix'
run: nix build
20 changes: 15 additions & 5 deletions .github/workflows/update-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,29 @@ jobs:
run: |
git config user.name devops
git config user.email devops@runtimeverification.com
- name: 'Install Poetry'
uses: Gr1N/setup-poetry@v9
- name: 'Install Python'
uses: actions/setup-python@v6
with:
python-version: '3.10'
- name: 'Get uv release'
id: uv_release
run: |
echo uv_version=$(cat deps/uv_release) >> "${GITHUB_OUTPUT}"
- name: 'Install uv'
uses: astral-sh/setup-uv@v7
with:
version: ${{ steps.uv_release.outputs.uv_version }}
- name: 'Install Nix'
uses: cachix/install-nix-action@v31.7.0
with:
install_url: https://releases.nixos.org/nix/nix-2.32.0/install
extra_nix_config: |
substituters = http://cache.nixos.org https://hydra.iohk.io
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=
- name: 'Update Poetry files'
- name: 'Update uv files'
run: |
poetry update
git add . && git commit -m "Sync Poetry files" || true
uv lock --upgrade
git add uv.lock && git commit -m "Sync uv lock file" || true
- name: 'Update Nix flake inputs'
run: |
RV_NIX_TOOLS_VERSION=$(cat deps/rv-nix-tools)
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/dist/
__pycache__/
.coverage
103 changes: 73 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,57 +1,100 @@
.PHONY: default all clean build install \
poetry-install \
test test-unit \
format isort autoflake black \
check check-isort check-autoflake check-black check-flake8 check-mypy
UV := uv
UV_RUN := $(UV) run --


default: check test-unit

all: check cov

.PHONY: clean
clean:
rm -rf dist .mypy_cache
rm -rf dist .coverage cov-* .mypy_cache .pytest_cache
find -type d -name __pycache__ -prune -exec rm -rf {} \;

.PHONY: build
build:
poetry build
$(UV) build

poetry-install:
poetry install

POETRY_RUN := poetry run
# Tests

TEST_ARGS :=

# Tests
test: test-all

.PHONY: test-all
test-all:
$(UV_RUN) pytest src/tests --maxfail=1 --verbose --durations=0 --numprocesses=4 --dist=worksteal $(TEST_ARGS)

.PHONY: test-unit
test-unit:
$(UV_RUN) pytest src/tests/unit --maxfail=1 --verbose $(TEST_ARGS)

.PHONY: test-integration
test-integration:
$(UV_RUN) pytest src/tests/integration --maxfail=1 --verbose --durations=0 --numprocesses=4 --dist=worksteal $(TEST_ARGS)


# Coverage

test: test-unit
COV_ARGS :=

test-unit: poetry-install
$(POETRY_RUN) python -m unittest discover tests --failfast --verbose
cov: cov-all

cov-%: TEST_ARGS += --cov=kup --no-cov-on-fail --cov-branch --cov-report=term

cov-all: TEST_ARGS += --cov-report=html:cov-all-html $(COV_ARGS)
cov-all: test-all

cov-unit: TEST_ARGS += --cov-report=html:cov-unit-html $(COV_ARGS)
cov-unit: test-unit

cov-integration: TEST_ARGS += --cov-report=html:cov-integration-html $(COV_ARGS)
cov-integration: test-integration


# 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
.PHONY: check-flake8
check-flake8:
$(UV_RUN) flake8 src

.PHONY: check-mypy
check-mypy:
$(UV_RUN) mypy src

.PHONY: autoflake
autoflake:
$(UV_RUN) autoflake --quiet --in-place src

.PHONY: check-autoflake
check-autoflake:
$(UV_RUN) autoflake --quiet --check src

.PHONY: isort
isort:
$(UV_RUN) isort src

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

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

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

isort: poetry-install
$(POETRY_RUN) isort src

check-isort: poetry-install
$(POETRY_RUN) isort --check src
# Optional tools

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

check-black: poetry-install
$(POETRY_RUN) black --check src
.PHONY: pyupgrade
pyupgrade:
$(UV_RUN) pyupgrade --py310-plus $(SRC_FILES)
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ etc.

## For Developers

Prerequsites: `python >= 3.10`, [`uv`](https://docs.astral.sh/uv/).

Use `make` to run common tasks (see the [Makefile](Makefile) for a complete list of available targets).

* `make build`: Build wheel
* `make check`: Check code style
* `make format`: Format code
* `make test-unit`: Run unit tests
* `make test-integration`: Run integration tests

For interactive use, spawn a shell with `poetry shell` (after `poetry install`), then run an interpreter.
1 change: 1 addition & 0 deletions deps/uv_release
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.9.22
3 changes: 3 additions & 0 deletions nix/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Notes
#### git submodules
If you use git submodules that are not required for building the project with `nix`, then you should add these directories to the `gitignoreSourcePure` list in `nix/kup/default.nix`, see the respective left-over `TODO` in the nix file. Otherwise, the nix build that is uploaded to the nix binary cache by CI might not match the version that is requested by `kup`, in case this project is offered as a package by `kup`. This is due to weird behaviour in regards to git submodules by `git` and `nix`, where a submodule directory might exist and be empty or instead not exist, which impacts the resulting nix hash, which is of impartance when offering/downloading cached nix derivations. See [runtimeverification/k/pull/4804](https://github.com/runtimeverification/k/pull/4804) for more information.
22 changes: 22 additions & 0 deletions nix/kup/build-systems-overlay.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
final: prev:
let
inherit (final) resolveBuildSystem;
inherit (builtins) mapAttrs;

# Build system dependencies specified in the shape expected by resolveBuildSystem
# The empty lists below are lists of optional dependencies.
#
# A package `foo` with specification written as:
# `setuptools-scm[toml]` in pyproject.toml would be written as
# `foo.setuptools-scm = [ "toml" ]` in Nix
buildSystemOverrides = {
# add dependencies here, e.g.:
# pyperclip.setuptools = [ ];
};
in
mapAttrs (
name: spec:
prev.${name}.overrideAttrs (old: {
nativeBuildInputs = old.nativeBuildInputs ++ resolveBuildSystem spec;
})
) buildSystemOverrides
55 changes: 55 additions & 0 deletions nix/kup/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
lib,
callPackage,
nix-gitignore,

pyproject-nix,
pyproject-build-systems,
uv2nix,

python
}:
let
pyproject-util = callPackage pyproject-nix.build.util {};
pyproject-packages = callPackage pyproject-nix.build.packages {
inherit python;
};

# load a uv workspace from a workspace root
workspace = uv2nix.lib.workspace.loadWorkspace {
workspaceRoot = lib.cleanSource (nix-gitignore.gitignoreSourcePure [
../../.gitignore
".github/"
"result*"
# do not include submodule directories that might be initilized empty or non-existent due to nix/git
# otherwise cachix build might not match the version that is requested by `kup`
# TODO: for new projects, add your submodule directories that are not required for nix builds here!
# e.g., `"/docs/external-computation"` with `external-computation` being a git submodule directory
# "/docs/external-computation"
] ../..
);
};

# create overlay
lockFileOverlay = workspace.mkPyprojectOverlay {
# prefer "wheel" over "sdist" due to maintance overhead
# there is no bundled set of overlays for "sdist" in uv2nix, in contrast to poetry2nix
sourcePreference = "wheel";
};

buildSystemsOverlay = import ./build-systems-overlay.nix;

# construct package set
pythonSet = pyproject-packages.overrideScope (lib.composeManyExtensions [
# make build tools available by default as these are not necessarily specified in python lock files
pyproject-build-systems.overlays.default
# include all packages from the python lock file
lockFileOverlay
# add build system overrides to certain python packages
buildSystemsOverlay
]);
in pyproject-util.mkApplication {
# default dependancy group enables no optional dependencies and no dependency-groups
venv = pythonSet.mkVirtualEnv "kup-env" workspace.deps.default;
package = pythonSet.kup;
}
Loading
Loading