-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #410 from Chia-Network/pre-commit
introduce pre-commit
- Loading branch information
Showing
4 changed files
with
153 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# See https://pre-commit.com for more information | ||
# See https://pre-commit.com/hooks.html for more hooks | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v3.2.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: check-yaml | ||
- id: check-added-large-files | ||
- repo: local | ||
hooks: | ||
- id: fmt | ||
name: fmt | ||
description: run cargo fmt on the workspace | ||
entry: cargo fmt --all -- --color always | ||
language: system | ||
pass_filenames: false | ||
- id: clippy | ||
name: clippy | ||
description: run cargo clippy on the workspace | ||
stages: [pre-push] | ||
entry: cargo clippy --workspace --all-features -- -Dwarnings | ||
language: system | ||
pass_filenames: false | ||
- id: build | ||
name: build | ||
description: run cargo build on the workspace | ||
stages: [pre-push] | ||
entry: cargo build --all-features --workspace | ||
language: system | ||
pass_filenames: false | ||
- id: benchmarks | ||
name: build benchmarks | ||
description: run cargo bench on the workspace | ||
stages: [pre-push] | ||
entry: cargo bench --no-run --workspace | ||
language: system | ||
pass_filenames: false | ||
- id: tests | ||
name: run tests | ||
description: run cargo test on the workspace | ||
stages: [pre-push] | ||
entry: cargo test --workspace | ||
language: system | ||
pass_filenames: false | ||
- id: wheel | ||
name: build wheel | ||
description: run maturin develop on the wheel | ||
stages: [pre-push] | ||
entry: sh -c "cd wheel && maturin develop" | ||
language: system | ||
pass_filenames: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,102 @@ | ||
This cargo workspace contains code useful for working with the Chia network. | ||
|
||
It contains a rust crate `chia` (here), a python wheel api `chia_rs` (in `wheel`), and web assembly (in `wasm`). | ||
# Tests | ||
|
||
To run tests: | ||
|
||
``` | ||
cargo test --all | ||
``` | ||
|
||
Some slow tests are only enabled in optimized builds, so it may also be a good | ||
idea to run the tests in release mode: | ||
|
||
``` | ||
cargo test --all --release | ||
``` | ||
|
||
You may need a python virtual environment activated for the tests to link. | ||
This seems to be caused by the pyo3 dependency in the `wheel`. | ||
|
||
# Benchmarks | ||
|
||
To run benchmarks for a specific crate: | ||
|
||
``` | ||
cargo bench -- --save-baseline before | ||
<make change> | ||
cargo bench -- --save-baseline after | ||
critcmp after before | ||
``` | ||
|
||
You can also run all the benchmarks by including `--workspace` on the command | ||
line. | ||
|
||
# pre-commit | ||
|
||
This repository has a pre-commit configuration, which is hooked into git by | ||
running: | ||
|
||
``` | ||
pre-commit install --hook-type pre-commit --hook-type pre-push | ||
``` | ||
|
||
It runs `cargo fmt` on all crates on every commit, and runs clippy and builds on | ||
push. | ||
|
||
To run all checks explicitly (without pushing), run: | ||
|
||
``` | ||
pre-commit run --all --hook-stage pre-push | ||
``` | ||
|
||
# python bindings | ||
|
||
The `wheel` crate is a single python wheel that exports the functionality of | ||
all crates in the repository. | ||
|
||
It's built with `maturin`. You need to have activated a python virtual | ||
environment for the build to work. | ||
|
||
``` | ||
pip install maturin | ||
cd wheel | ||
maturin develop | ||
``` | ||
|
||
Once built, the python tests can be run, from the root of the repository. Note | ||
that the tests require that `chia-blockchain` and `blspy` wheels are installed. | ||
|
||
``` | ||
pytest tests | ||
``` | ||
|
||
# Fuzzers | ||
|
||
Fuzzers can't be run or listed for the whole workspace, but only for individual | ||
crates. There is a tool to generate a fuzzing corpus from a blockchain database. | ||
It's run like this: | ||
|
||
``` | ||
cd chia-tools | ||
cargo run --release --bin gen-corpus -- --help | ||
``` | ||
|
||
The following crates have fuzzers: | ||
|
||
* chia-bls | ||
* chia-protocol | ||
* chia-wallet | ||
* clvm-utils | ||
* chia (the root crate) | ||
|
||
To list and run fuzzers: | ||
|
||
``` | ||
cargo fuzz list | ||
``` | ||
|
||
``` | ||
cargo fuzz run <name-of-fuzzer> | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters