This guide is intended to help you get started with developing tket2.
If you find any errors or omissions in this document, please open an issue!
You can setup the development environment in two ways:
The easiest way to setup the development environment is to use the provided
devenv.nix
file. This will setup a development shell with all the
required dependencies.
To use this, you will need to install devenv. Once you have it running, open a shell with:
devenv shell
All the required dependencies should be available. You can automate loading the shell by setting up direnv.
To setup the environment manually you will need:
-
Python 3.10+: https://www.python.org/downloads/
It is advisable to use a virtual environment for keeping the python environment isolated, see
venv
for more details.Install the python development dependencies with:
pip install -r pyrs/dev-requirements.txt
If you are testing the tkcxx
feature to bind to TKET-1, you will need to setup
the tket-rs
bindings. This requires configuring conan
for the project, see
the TKET-rs readme for more
details.
You can use the git hook in .github/pre-commit
to automatically run the test and check formatting before commiting.
To install it, run:
cp .github/pre-commit .git/hooks/pre-commit
# Or, to check before pushing instead
cp .github/pre-commit .git/hooks/pre-push
To compile and test the rust code, run:
cargo build
cargo test
Run the benchmarks with:
cargo bench
Finally, if you have rust nightly installed, you can run miri
to detect
undefined behaviour in the code. Note that the devenv shell only has rust
stable available.
cargo +nightly miri test
To run the python tests, run:
cd pyrs
maturin develop
pytest
The rustfmt tool is used to enforce a consistent rust coding style. The CI will fail if the code is not formatted correctly. Python code is formatted with black.
To format your code, run:
# Format rust code
cargo fmt
# Format python code
black .
We also check for clippy warnings, which are a set of linting rules for rust. To run clippy, run:
cargo clippy
# Include code not compiled in the main build
cargo clippy --all-targets