Skip to content

Commit

Permalink
initialize maturin package
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-codecov committed Aug 28, 2024
1 parent 595a8df commit e54e900
Show file tree
Hide file tree
Showing 14 changed files with 327 additions and 5 deletions.
55 changes: 52 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ concurrency:

jobs:
lint:
name: Lint (rustfmt + clippy)
name: Lint Rust (rustfmt + clippy)
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -28,6 +28,23 @@ jobs:
cargo fmt --all --check
cargo clippy
lint-python:
name: Lint Python (ruff, mypy)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-python@v3
with:
python-version: '3.12'
- name: Install requirements
run: pip install -r requirements.dev.txt
- name: Run lint
run: |
ruff check
ruff format
mypy
build:
name: Build
runs-on: ubuntu-latest
Expand All @@ -43,6 +60,14 @@ jobs:
- name: Run build
run: |
cargo build
- uses: actions/setup-python@v3
with:
python-version: '3.12'
- name: Install Python requirements
run: pip install -r requirements.dev.txt
- name: Build Python bindings
run: maturin build

test:
name: Test
runs-on: ubuntu-latest
Expand All @@ -55,9 +80,21 @@ jobs:
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly
- name: Run tests
- name: Run Rust tests
run: |
cargo test
- uses: actions/setup-python@v3
with:
python-version: '3.12'
- name: Run Python tests
run: |
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.dev.txt
maturin develop
pytest
# This job runs tests, generates coverage data, and generates JUnit test
# results in a single test invocation and then uploads it all to Codecov.
# However, it doesn't print test results to stdout. If Codecov's failed test
Expand All @@ -81,6 +118,18 @@ jobs:
run: |
cargo install cargo2junit
cargo llvm-cov --lcov --output-path lcov.info -- -Z unstable-options --format json --report-time | cargo2junit > results.xml
- uses: actions/setup-python@v3
with:
python-version: '3.12'
- name: Run Python tests
run: |
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.dev.txt
maturin develop
pytest --cov --junitxml=junit.xml
- name: Upload coverage data to Codecov
if: ${{ !cancelled() }}
uses: codecov/codecov-action@v4
Expand All @@ -90,6 +139,6 @@ jobs:
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
file: ./results.xml
files: ./results.xml,./junit.xml
token: ${{ secrets.CODECOV_ORG_TOKEN }}
verbose: true
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,13 @@ target/
# Vim swapfiles
.*.sw*

# Python junk
__pycache__/
*.py[cod]
*$py.class

# Native extensions for Python
*.so

.git
lcov.info
21 changes: 20 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
- repo: local
hooks:
- id: format
- id: rustfmt
name: cargo fmt
entry: cargo fmt
args: ["--check", "--"]
Expand All @@ -16,3 +16,22 @@ repos:
pass_filenames: false
types: [rust]
language: system
- id: ruffcheck
name: ruff check
entry: ruff check
require_serial: true
types: [python]
language: system
- id: rufffmt
name: ruff format
entry: ruff format
require_serial: true
types: [python]
language: system
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.10.0'
hooks:
- id: mypy
verbose: true
entry: bash -c 'mypy "$@" || true' --
types: [python]
116 changes: 116 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[workspace]

resolver = "2"
members = ["core"]
members = ["bindings", "core"]
default-members = ["core"]

[profile.release]

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Install lint hooks with `pip install pre-commit && pre-commit install`.
### Repository structure

- `core/`: Rust crate with all of the core coverage-processing functionality
- `bindings/`: Rust crate with PyO3 bindings for `core/`

### Writing new parsers

Expand Down
17 changes: 17 additions & 0 deletions bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "codecov-rs-bindings"
version = "0.1.0"
publish = false
edition = "2021"

[lib]
name = "_bindings"
crate-type = ["cdylib"]

[dependencies]
codecov-rs = { path = "../core" }

pyo3 = { version = "0.22.2", features = [
"extension-module",
"abi3-py311",
] }
6 changes: 6 additions & 0 deletions bindings/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use pyo3::prelude::*;

#[pymodule]
fn _bindings(_py: Python, _m: Bound<PyModule>) -> PyResult<()> {
Ok(())
}
27 changes: 27 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
comment:
layout: "condensed_header, diff, condensed_files, components, condensed_footer"

component_management:
default_rules:
statuses:
- type: project
target: auto
branches:
- "!main"
- type: patch
target: auto
branches:
- "!main"
individual_components:
- component_id: rust_core
name: core
paths:
- core/**
- component_id: rust_bindings
name: bindings
paths:
- bindings/**
- component_id: python_package
name: python
paths:
- python/codecov_rs/**
Loading

0 comments on commit e54e900

Please sign in to comment.