Skip to content

Commit 2f94e8a

Browse files
authored
Added test coverage. (#39)
1 parent 71b038d commit 2f94e8a

File tree

6 files changed

+283
-69
lines changed

6 files changed

+283
-69
lines changed

.github/workflows/test.yml

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: "Testing package"
22

33
on:
44
pull_request:
5+
push:
6+
branches:
7+
- master
58

69
jobs:
710
py-lint:
@@ -83,29 +86,39 @@ jobs:
8386
- uses: actions-rs/toolchain@v1
8487
with:
8588
toolchain: stable
86-
components: clippy
89+
components: llvm-tools-preview
8790
override: true
8891
- uses: actions/setup-python@v6
8992
with:
9093
python-version: 3.x
9194
- name: Install uv
9295
uses: astral-sh/setup-uv@v7
96+
- name: Install llvm-cov
97+
uses: taiki-e/install-action@v2
98+
with:
99+
tool: cargo-llvm-cov
93100
- id: prepare-container
94101
name: Prepare docker container
95102
run: docker compose up -d --wait
96103
- id: setup-venv
97104
name: Setup virtualenv
98-
run: python -m venv .venv
99-
- name: Build lib
100-
uses: PyO3/maturin-action@v1
101-
with:
102-
command: dev --uv
103-
sccache: true
105+
run: uv venv
104106
- name: Run pytest
105107
run: |
106108
set -e
107-
source .venv/bin/activate
108-
pytest -vv -n auto python/tests
109+
source <(cargo llvm-cov show-env --sh)
110+
export CARGO_TARGET_DIR="$CARGO_LLVM_COV_TARGET_DIR"
111+
export CARGO_INCREMENTAL="1"
112+
cargo llvm-cov clean --workspace
113+
uv run -- maturin dev --uv
114+
uv run -- pytest -vv python/tests --cov natsrpy --cov-report xml
115+
cargo llvm-cov report --lcov --output-path coverage.lcov
116+
- uses: codecov/codecov-action@v5
117+
with:
118+
fail_ci_if_error: false
119+
token: ${{ secrets.CODECOV_TOKEN }}
120+
files: coverage.lcov,coverage.xml
121+
verbose: true
109122
- name: Teardown docker
110123
if: always()
111124
run: docker compose down

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ repos:
7676
language: python
7777
additional_dependencies:
7878
- mypy
79+
- maturin
7980
entry: python ./scripts/stubtest.py
8081
pass_filenames: false
8182
always_run: true

Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@ thiserror = "2.0.18"
2727
time = "0.3.47"
2828
tokio = { version = "1.50.0", features = ["full"] }
2929

30+
[profile.dev]
31+
opt-level = 0
32+
lto = "off"
33+
incremental = true
34+
3035
[profile.release]
31-
lto = "fat"
32-
codegen-units = 1
3336
opt-level = 3
34-
strip = true
3537
debug = false
38+
strip = true
39+
lto = "fat"
3640
panic = "abort"
41+
codegen-units = 1

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,28 @@ As of for now, our documentation is only availabe in source code. You can see it
5656
## Development
5757

5858
We use stable rust and pyo3 for writing python extension module.
59+
In order to build the project, use uv and maturin.
5960

60-
In order to run the project use maturin:
61+
uv is used for all python-side dependencies (including dev deps).
62+
Maturin is used only for building rust-side.
6163

6264
```bash
6365
# To create .venv folder
6466
uv venv
67+
# Sync deps
68+
uv sync --locked
6569
# To build and install the package in a virtual environment
66-
maturin dev --uv
70+
uv run -- maturin dev --uv
6771
```
6872

73+
If you want to setup automatic rebuilds, use this command:
74+
75+
```bash
76+
uv run -- python -m maturin_import_hook site install
77+
```
78+
79+
It will force rebuild project when rust code changes.
80+
6981
For lints please use `pre-commit`.
7082

7183
```bash

pyproject.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ classifiers = [
1313
"Programming Language :: Rust",
1414
"Topic :: System :: Networking",
1515
]
16-
dynamic = ["version"]
1716
dependencies = [
18-
"typing-extensions>=4.14.0",
17+
"maturin-import-hook>=0.3.0",
18+
"typing-extensions>=4.14.0",
1919
]
20+
dynamic = ["version"]
2021

2122
[[project.authors]]
2223
name = "Pavel Kirilin"
@@ -25,16 +26,21 @@ email = "s3riussan@gmail.com"
2526
[dependency-groups]
2627
dev = [
2728
"anyio>=4,<5",
29+
"maturin>=1,<2",
2830
"mypy>=1.19.1,<2",
2931
"pre-commit>=4.5.1,<5",
3032
"pytest>=9,<10",
33+
"pytest-cov>=7,<8",
3134
"pytest-xdist>=3,<4",
3235
]
3336

3437
[build-system]
3538
requires = ["maturin>=1.12,<2.0"]
3639
build-backend = "maturin"
3740

41+
[tool.uv]
42+
package = false
43+
3844
[tool.maturin]
3945
bindings = "pyo3"
4046
features = ["pyo3/extension-module"]

0 commit comments

Comments
 (0)