Skip to content

Commit e924c5d

Browse files
authored
chore: Configure poetry for managing python dependencies (zxcalc#18)
- Configures poetry for managing the dependencies. - Configures `maturin` (part of the pyo3 project) for building the python bindings. - Adds a `pre-commit` config file with the lints and tests that we will require in CI. - Adds a `CONTRIBUTING.md` file with instructions on how to run the project.
1 parent 5d5d538 commit e924c5d

File tree

15 files changed

+2897
-189
lines changed

15 files changed

+2897
-189
lines changed

.pre-commit-config.yaml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.5.0 # Use the ref you want to point at
4+
hooks:
5+
- id: check-added-large-files
6+
- id: check-case-conflict
7+
- id: check-executables-have-shebangs
8+
- id: check-merge-conflict
9+
- id: check-toml
10+
- id: check-vcs-permalinks
11+
- id: check-yaml
12+
- id: detect-private-key
13+
#- id: end-of-file-fixer
14+
#- id: trailing-whitespace
15+
- id: fix-byte-order-marker
16+
- id: mixed-line-ending
17+
# Python-specific
18+
- id: check-ast
19+
- id: check-docstring-first
20+
- id: debug-statements
21+
22+
- repo: local
23+
hooks:
24+
- id: cargo-fmt
25+
name: cargo format
26+
description: Format rust code with `cargo fmt`.
27+
entry: cargo fmt --all -- --check
28+
language: system
29+
files: \.rs$
30+
pass_filenames: false
31+
- id: cargo-check
32+
name: cargo check
33+
description: Check rust code with `cargo check`.
34+
entry: cargo check --all --all-features --workspace
35+
language: system
36+
files: \.rs$
37+
pass_filenames: false
38+
- id: cargo-test
39+
name: cargo test
40+
description: Run tests with `cargo test`.
41+
entry: cargo test --all-features -p quizx
42+
language: system
43+
files: \.rs$
44+
pass_filenames: false
45+
- id: cargo-clippy
46+
name: cargo clippy
47+
description: Run clippy lints with `cargo clippy`.
48+
entry: cargo clippy --all-features --workspace -- -D warnings
49+
language: system
50+
files: \.rs$
51+
pass_filenames: false
52+
- id: ruff format
53+
name: ruff format
54+
description: Format python code with `ruff format`.
55+
entry: poetry run ruff format
56+
language: system
57+
files: \.py$
58+
pass_filenames: false
59+
- id: ruff lint
60+
name: ruff lint
61+
description: Lint python code with `ruff lint`.
62+
entry: poetry run ruff check
63+
language: system
64+
files: \.py$
65+
pass_filenames: false
66+
- id: mypy
67+
name: mypy
68+
description: Run mypy type checker.
69+
entry: poetry run mypy pybindings
70+
language: system
71+
files: \.py$
72+
pass_filenames: false

CONTRIBUTING.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Welcome to the quizx development guide <!-- omit in toc -->
2+
3+
This guide is intended to help you get started with developing quizx.
4+
5+
If you find any errors or omissions in this document, please [open an issue](https://github.com/Quantomatic/quizx/issues/new)!
6+
7+
## #️⃣ Setting up the development environment
8+
9+
To develop the rust library, you will need to have the rust toolchain installed. You can install it by following the instructions at [https://www.rust-lang.org/tools/install](https://www.rust-lang.org/tools/install).
10+
11+
If you are using VSCode, you can install the `rust-analyzer` extension to get code completion and other features.
12+
13+
To develop the python library, you will additionally need the Poetry package manager. You can install it by following the instructions at [https://python-poetry.org/docs/](https://python-poetry.org/docs/).
14+
15+
Finally, we provide a `just` file to help manage the common development workflow. You can install `just` by following the instructions at [https://just.systems/](https://just.systems/).
16+
17+
Once you have these installed, run `just setup` to download the necessary dependencies and set up some pre-commit hooks.
18+
19+
Run `just` to see all available commands.
20+
21+
## 🚀 Building the project
22+
23+
There is a miscellaneous collection of rust programs written using the library,
24+
found in `src/bin`. To execute these programs, run:
25+
26+
```bash
27+
cargo run --release --bin <program_name>
28+
```
29+
30+
To build the python library, run:
31+
32+
```bash
33+
# Ensure you have all the necessary dependencies installed
34+
poetry install
35+
# Enter the environment with the installed dependencies
36+
poetry shell
37+
# Build the python library
38+
maturin develop
39+
# The library will now be available for import in python
40+
python -c "import quizx"
41+
```
42+
43+
## 🏃 Running the tests
44+
45+
To compile and test the code, run:
46+
47+
```bash
48+
just test
49+
# or, to test only the rust code or the python code
50+
just test rust
51+
just test python
52+
```
53+
54+
## 💅 Coding Style
55+
56+
The `rustfmt` and `ruff` tools are used to enforce a consistent coding for rust
57+
and python code, respectively. The CI will fail if the code is not formatted
58+
correctly.
59+
60+
To format your code, run:
61+
62+
```bash
63+
just format
64+
```
65+
66+
We also use various linters to catch common mistakes and enforce best practices. To run these, use:
67+
68+
```bash
69+
just check
70+
```
71+
72+
To quickly fix common issues, run:
73+
74+
```bash
75+
just fix
76+
# or, to fix only the rust code or the python code
77+
just fix rust
78+
just fix python
79+
```
80+
81+
## 🌐 Contributing to quizx
82+
83+
We welcome contributions to quizx! Please open [an issue](https://github.com/CQCL/hugr/issues/new) or [pull request](https://github.com/CQCL/hugr/compare) if you have any questions or suggestions.
84+
85+
PRs should be made against the `master` branch, and should pass all CI checks before being merged.
86+
87+
Please title your PRs using the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) format;
88+
```
89+
<type>(<scope>)!: <description>
90+
```
91+
Where the scope is optional, and the `!` is only included if this is a semver breaking change that requires a major version bump.
92+
93+
We accept the following contribution types:
94+
95+
- feat: New features.
96+
- fix: Bug fixes.
97+
- docs: Improvements to the documentation.
98+
- style: Formatting, missing semi colons, etc; no code change.
99+
- refactor: Refactoring code without changing behaviour.
100+
- perf: Code refactoring focused on improving performance.
101+
- test: Adding missing tests, refactoring tests; no production code change.
102+
- ci: CI related changes. These changes are not published in the changelog.
103+
- chore: Updating build tasks, package manager configs, etc. These changes are not published in the changelog.
104+
- revert: Reverting previous commits.
105+

0 commit comments

Comments
 (0)