Skip to content

Commit 55d0403

Browse files
Initial commit
0 parents  commit 55d0403

16 files changed

Lines changed: 350 additions & 0 deletions

File tree

Makefile

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
UV := uv
2+
UV_RUN := $(UV) run --
3+
4+
5+
default: check test-unit
6+
7+
all: check cov
8+
9+
.PHONY: clean
10+
clean:
11+
rm -rf dist .coverage cov-* .mypy_cache .pytest_cache
12+
find -type d -name __pycache__ -prune -exec rm -rf {} \;
13+
14+
.PHONY: build
15+
build:
16+
$(UV) build
17+
18+
19+
# Tests
20+
21+
TEST_ARGS :=
22+
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
39+
40+
COV_ARGS :=
41+
42+
cov: cov-all
43+
44+
cov-%: TEST_ARGS += --cov=komet_node --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
54+
55+
56+
# Checks and formatting
57+
58+
format: autoflake isort black
59+
check: check-flake8 check-mypy check-autoflake check-isort check-black
60+
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
80+
81+
.PHONY: check-isort
82+
check-isort:
83+
$(UV_RUN) isort --check src
84+
85+
.PHONY: black
86+
black:
87+
$(UV_RUN) black src
88+
89+
.PHONY: check-black
90+
check-black:
91+
$(UV_RUN) black --check src
92+
93+
94+
# Optional tools
95+
96+
SRC_FILES := $(shell find src -type f -name '*.py')
97+
98+
.PHONY: pyupgrade
99+
pyupgrade:
100+
$(UV_RUN) pyupgrade --py310-plus $(SRC_FILES)

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# komet-node
2+
3+
4+
## Installation
5+
6+
Prerequsites: `python >= 3.10`, [`uv`](https://docs.astral.sh/uv/).
7+
8+
```bash
9+
make build
10+
pip install dist/*.whl
11+
```
12+
13+
14+
## For Developers
15+
16+
Use `make` to run common tasks (see the [Makefile](Makefile) for a complete list of available targets).
17+
18+
* `make build`: Build wheel
19+
* `make check`: Check code style
20+
* `make format`: Format code
21+
* `make test-unit`: Run unit tests
22+
* `make test-integration`: Run integration tests
23+

flake.nix

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
description = "komet-node - Local development testnet for Stellar based on K semantics";
3+
inputs = {
4+
nixpkgs.url = "nixpkgs/nixos-25.05";
5+
flake-utils.url = "github:numtide/flake-utils";
6+
uv2nix.url = "github:pyproject-nix/uv2nix/680e2f8e637bc79b84268949d2f2b2f5e5f1d81c";
7+
# stale nixpkgs is missing the alias `lib.match` -> `builtins.match`
8+
# therefore point uv2nix to a patched nixpkgs, which introduces this alias
9+
# this is a temporary solution until nixpkgs us up-to-date again
10+
uv2nix.inputs.nixpkgs.url = "github:runtimeverification/nixpkgs/libmatch";
11+
# inputs.nixpkgs.follows = "nixpkgs";
12+
pyproject-build-systems.url = "github:pyproject-nix/build-system-pkgs/7dba6dbc73120e15b558754c26024f6c93015dd7";
13+
pyproject-build-systems = {
14+
inputs.nixpkgs.follows = "uv2nix/nixpkgs";
15+
inputs.uv2nix.follows = "uv2nix";
16+
inputs.pyproject-nix.follows = "uv2nix/pyproject-nix";
17+
};
18+
pyproject-nix.follows = "uv2nix/pyproject-nix";
19+
};
20+
outputs = { self, nixpkgs, flake-utils, pyproject-nix, pyproject-build-systems, uv2nix }:
21+
let
22+
pythonVer = "310";
23+
in flake-utils.lib.eachSystem [
24+
"x86_64-linux"
25+
"x86_64-darwin"
26+
"aarch64-linux"
27+
"aarch64-darwin"
28+
] (system:
29+
let
30+
# due to the nixpkgs that we use in this flake being outdated, uv is also heavily outdated
31+
# we can instead use the binary release of uv provided by uv2nix for now
32+
uvOverlay = final: prev: {
33+
uv = uv2nix.packages.${final.system}.uv-bin;
34+
};
35+
komet-nodeOverlay = final: prev: {
36+
komet-node = final.callPackage ./nix/komet-node {
37+
inherit pyproject-nix pyproject-build-systems uv2nix;
38+
python = final."python${pythonVer}";
39+
};
40+
};
41+
pkgs = import nixpkgs {
42+
inherit system;
43+
overlays = [
44+
uvOverlay
45+
komet-nodeOverlay
46+
];
47+
};
48+
python = pkgs."python${pythonVer}";
49+
in {
50+
devShells.default = pkgs.mkShell {
51+
name = "uv develop shell";
52+
buildInputs = [
53+
python
54+
pkgs.uv
55+
];
56+
env = {
57+
# prevent uv from managing Python downloads and force use of specific
58+
UV_PYTHON_DOWNLOADS = "never";
59+
UV_PYTHON = python.interpreter;
60+
};
61+
shellHook = ''
62+
unset PYTHONPATH
63+
'';
64+
};
65+
packages = rec {
66+
inherit (pkgs) komet-node;
67+
default = komet-node;
68+
};
69+
}) // {
70+
overlays.default = final: prev: {
71+
inherit (self.packages.${final.system}) komet-node;
72+
};
73+
};
74+
}

nix/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Notes
2+
#### git submodules
3+
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/komet-node/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.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
final: prev:
2+
let
3+
inherit (final) resolveBuildSystem;
4+
inherit (builtins) mapAttrs;
5+
6+
# Build system dependencies specified in the shape expected by resolveBuildSystem
7+
# The empty lists below are lists of optional dependencies.
8+
#
9+
# A package `foo` with specification written as:
10+
# `setuptools-scm[toml]` in pyproject.toml would be written as
11+
# `foo.setuptools-scm = [ "toml" ]` in Nix
12+
buildSystemOverrides = {
13+
# add dependencies here, e.g.:
14+
# pyperclip.setuptools = [ ];
15+
};
16+
in
17+
mapAttrs (
18+
name: spec:
19+
prev.${name}.overrideAttrs (old: {
20+
nativeBuildInputs = old.nativeBuildInputs ++ resolveBuildSystem spec;
21+
})
22+
) buildSystemOverrides

nix/komet-node/default.nix

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
lib,
3+
callPackage,
4+
nix-gitignore,
5+
6+
pyproject-nix,
7+
pyproject-build-systems,
8+
uv2nix,
9+
10+
python
11+
}:
12+
let
13+
pyproject-util = callPackage pyproject-nix.build.util {};
14+
pyproject-packages = callPackage pyproject-nix.build.packages {
15+
inherit python;
16+
};
17+
18+
# load a uv workspace from a workspace root
19+
workspace = uv2nix.lib.workspace.loadWorkspace {
20+
workspaceRoot = lib.cleanSource (nix-gitignore.gitignoreSourcePure [
21+
../../.gitignore
22+
".github/"
23+
"result*"
24+
# do not include submodule directories that might be initilized empty or non-existent due to nix/git
25+
# otherwise cachix build might not match the version that is requested by `kup`
26+
# TODO: for new projects, add your submodule directories that are not required for nix builds here!
27+
# e.g., `"/docs/external-computation"` with `external-computation` being a git submodule directory
28+
# "/docs/external-computation"
29+
] ../..
30+
);
31+
};
32+
33+
# create overlay
34+
lockFileOverlay = workspace.mkPyprojectOverlay {
35+
# prefer "wheel" over "sdist" due to maintance overhead
36+
# there is no bundled set of overlays for "sdist" in uv2nix, in contrast to poetry2nix
37+
sourcePreference = "wheel";
38+
};
39+
40+
buildSystemsOverlay = import ./build-systems-overlay.nix;
41+
42+
# construct package set
43+
pythonSet = pyproject-packages.overrideScope (lib.composeManyExtensions [
44+
# make build tools available by default as these are not necessarily specified in python lock files
45+
pyproject-build-systems.overlays.default
46+
# include all packages from the python lock file
47+
lockFileOverlay
48+
# add build system overrides to certain python packages
49+
buildSystemsOverlay
50+
]);
51+
in pyproject-util.mkApplication {
52+
# default dependancy group enables no optional dependencies and no dependency-groups
53+
venv = pythonSet.mkVirtualEnv "komet-node-env" workspace.deps.default;
54+
package = pythonSet.komet-node;
55+
}

pyproject.toml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "komet-node"
7+
version = "0.1.0"
8+
description = "Local development testnet for Stellar based on K semantics"
9+
readme = "README.md"
10+
requires-python = "~=3.10"
11+
dependencies = []
12+
13+
[[project.authors]]
14+
name = "Runtime Verification, Inc."
15+
email = "contact@runtimeverification.com"
16+
17+
[project.scripts]
18+
komet-node = "komet-node.__main__:main"
19+
20+
[dependency-groups]
21+
dev = [
22+
"autoflake",
23+
"black",
24+
"flake8",
25+
"flake8-bugbear",
26+
"flake8-comprehensions",
27+
"flake8-quotes",
28+
"flake8-type-checking",
29+
"isort",
30+
"mypy",
31+
"pep8-naming",
32+
"pytest",
33+
"pytest-cov",
34+
"pytest-mock",
35+
"pytest-xdist",
36+
"pyupgrade",
37+
]
38+
39+
[tool.hatch.metadata]
40+
allow-direct-references = true
41+
42+
[tool.isort]
43+
profile = "black"
44+
line_length = 120
45+
46+
[tool.autoflake]
47+
recursive = true
48+
expand-star-imports = true
49+
remove-all-unused-imports = true
50+
ignore-init-module-imports = true
51+
remove-duplicate-keys = true
52+
remove-unused-variables = true
53+
54+
[tool.black]
55+
line-length = 120
56+
skip-string-normalization = true
57+
58+
[tool.mypy]
59+
disallow_untyped_defs = true

src/komet_node/__init__.py

Whitespace-only changes.

src/komet_node/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def main() -> None:
2+
print('Hello world!')

src/komet_node/hello.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def hello(name: str) -> str:
2+
return f'Hello, {name}!'

0 commit comments

Comments
 (0)