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 bd6fe6c commit dee6617
Show file tree
Hide file tree
Showing 16 changed files with 364 additions and 11 deletions.
70 changes: 66 additions & 4 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,25 @@ 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: Build and run lint
run: |
python3 -m venv .venv
source .venv/bin/activate
pip install -r python/requirements.dev.txt
maturin develop
ruff check
ruff format
mypy
build:
name: Build
runs-on: ubuntu-latest
Expand All @@ -43,6 +62,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 python/requirements.dev.txt
- name: Build Python bindings
run: maturin build

test:
name: Test
runs-on: ubuntu-latest
Expand All @@ -55,9 +82,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 python/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 @@ -80,16 +119,39 @@ jobs:
- name: Run tests
run: |
cargo install cargo2junit
cargo llvm-cov --lcov --output-path lcov.info -- -Z unstable-options --format json --report-time | cargo2junit > results.xml
cargo llvm-cov --lcov --output-path core.lcov -- -Z unstable-options --format json --report-time | cargo2junit > core-test-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
# Re-activate the venv in future steps
echo PATH=$PATH >> $GITHUB_ENV
pip install -r python/requirements.dev.txt
source <(cargo llvm-cov show-env --export-prefix)
cargo llvm-cov clean --workspace
maturin develop
pytest --cov --junitxml=python-test-results.xml
cargo llvm-cov --no-run --lcov --output-path bindings.lcov
- name: Upload coverage data to Codecov
if: ${{ !cancelled() }}
uses: codecov/codecov-action@v4
with:
files: ./core.lcov,./bindings.lcov,./.coverage
token: ${{ secrets.CODECOV_ORG_TOKEN }}
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
file: ./results.xml
files: ./core-test-results.xml,./python-test-results.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
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,29 @@ All details (e.g. SQLite schema, code interfaces) subject to breaking changes un

## Developing

At time of writing, `codecov-rs` requires the nightly compiler for niceties such as `#[feature(trait_alias)]` in the library itself.
Set up your development environment:
- Install the nightly compiler via [rustup](https://rustup.rs/). At time of writing, `codecov-rs` requires the nightly compiler for niceties such as `#[feature(trait_alias)]`.
- To work on the Python bindings, set up a virtualenv with your tool of choice and install our Python dependencies: `pip install -r python/requirements.dev.txt`.
- Install lint hooks with `pip install pre-commit && pre-commit install`.
- Large sample test reports are checked in using [Git LFS](https://git-lfs.com/) in `core/fixtures/**/large` directories (e.g. `core/fixtures/pyreport/large`). Tests and benchmarks may reference them so installing it yourself is recommended.

`codecov-rs` aims to serve as effective documentation for every flavor of every format it supports. To that end, the following are greatly appreciated in submissions:
- Thorough doc comments (`///` / `/**`). For parsers, include snippets that show what inputs look like
- Granular, in-module unit tests
- Integration tests with real-world samples (that are safe to distribute; don't send us data from your private repo)

Large sample test reports are checked in using [Git LFS](https://git-lfs.com/) in `core/fixtures/**/large` directories (e.g. `core/fixtures/pyreport/large`). Tests and benchmarks may reference them so installing it yourself is recommended.

The `examples/` directory contains runnable commands for developers including:
- `parse_pyreport`: converts a given pyreport into a SQLite report
- `sql_to_pyreport`: converts a given SQLite report into a pyreport (report JSON + chunks file)

You can run an example with `cargo run --example <example> <arguments>`. Consider following suit for your own new feature.

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/`
- `python/codecov_rs`: Python code using/typing the Rust crate in `bindings/`
- `python/tests`: Python tests

### Writing new parsers

Expand All @@ -58,7 +61,11 @@ Non-XML formats lack clean OOTB support for streaming so `codecov-rs` currently

Run tests with:
```
# Rust tests
$ cargo test
# Python tests
$ pytest
```

### Benchmarks
Expand Down
Loading

0 comments on commit dee6617

Please sign in to comment.