Skip to content

2025-02-04 Update #5

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 6 commits into from
Feb 5, 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
26 changes: 13 additions & 13 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ jobs:
os: ["ubuntu"]
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip"
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand All @@ -25,27 +28,24 @@ jobs:
components: llvm-tools-preview
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- uses: Swatinem/rust-cache@v1
- uses: Swatinem/rust-cache@v2
with:
key: coverage-cargo-${{ matrix.os }}
continue-on-error: true
- name: Setup virtual environment
run: |
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
uv sync
- name: Run coverage
run: |
source venv/bin/activate
source <(cargo llvm-cov show-env --export-prefix)
export CARGO_TARGET_DIR=$CARGO_LLVM_COV_TARGET_DIR
export CARGO_INCREMENTAL=1
cargo llvm-cov clean --workspace
cargo test
maturin develop
pytest tests --cov=foobar --cov-report xml
cargo llvm-cov --no-run --lcov --output-path coverage.lcov
- uses: codecov/codecov-action@v3
uv run -- maturin develop --uv
uv run -- pytest tests --cov=foobar --cov-report xml
cargo llvm-cov report --lcov --output-path coverage.lcov
- uses: codecov/codecov-action@v5
with:
files: coverage.lcov,coverage.xml
name: ${{ matrix.os }}
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "foobar"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.16.1", features = ["extension-module"] }
pyo3 = { version = "0.23.3", features = ["extension-module"] }

[package.metadata.maturin]
python-source = "python"
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ system. This installs `pytest`, which is able to measure the coverage of the
Python only sections and also exercise the PyO3 bound Rust code.

```
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
uv sync
```

The Rust tests use `cargo test`. To measure the full Rust coverage from Python
Expand Down Expand Up @@ -86,9 +84,9 @@ measurements.
```
cargo llvm-cov clean --workspace
cargo test
maturin develop
pytest tests --cov=foobar --cov-report xml
cargo llvm-cov --no-run --lcov --output-path coverage.lcov
uv run -- maturin develop --uv
uv run -- pytest tests --cov=foobar --cov-report xml
cargo llvm-cov report --lcov --output-path coverage.lcov
```

First the `cargo llvm-cov clean` command removes any previous profiling
Expand Down
19 changes: 14 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
[build-system]
requires = ["maturin>=0.12,<0.13"]
build-backend = "maturin"

[project]
name = "foobar"
requires-python = ">=3.6"
version = "0.1.1"
requires-python = ">=3.9"
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
"pytest>=8.3.4",
"pytest-cov>=6.0.0",
"maturin>=1.8.1",
]

[build-system]
requires = ["maturin>=1.0,<2.0"]
build-backend = "maturin"

[tool.maturin]
python-source = "python"
module-name = "foobar._foobar"
2 changes: 1 addition & 1 deletion python/foobar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .foobar import pyo3_sum
from ._foobar import pyo3_sum

def py_sum(a, b):
"""Returns the sum of two numbers (Python only)"""
Expand Down
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn pyo3_sum(a: usize, b: usize) -> PyResult<usize> {

/// A Python module implemented in Rust.
#[pymodule]
fn foobar(_py: Python, m: &PyModule) -> PyResult<()> {
fn _foobar(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(pyo3_sum, m)?)?;
Ok(())
}
Expand Down
230 changes: 230 additions & 0 deletions uv.lock

Large diffs are not rendered by default.

Loading