Skip to content

Commit

Permalink
doc: Add DEVELOPMENT.md
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Oct 20, 2023
1 parent e826a2c commit 53f05d3
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

# A pre-push hook for rust codebases that checks formatting, clippy, and tests

set -eu

if [[ "${IGNORE_RUSTHOOKS:=0}" -ne 0 ]]; then
echo "Ignoring rusthooks"
exit 0
fi

if ! cargo fmt -- --check
then
echo "There are some code style issues."
echo "Run cargo fmt first."
exit 1
fi

if ! cargo clippy --all-targets --all-features --workspace -- -D warnings
then
echo "There are some clippy issues."
exit 1
fi

if ! cargo test --all-features
then
echo "There are some test issues."
exit 1
fi

exit 0
86 changes: 86 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Welcome to the portgraph development guide <!-- omit in toc -->

This guide is intended to help you get started with developing portgraph.

If you find any errors or omissions in this document, please [open an issue](https://github.com/CQCL/portgraph/issues/new)!

## #️⃣ Setting up the development environment

You can setup the development environment you will need:

- Rust: https://www.rust-lang.org/tools/install

You can use the git hook in [`.github/pre-commit`](.github/pre-commit) to automatically run the test and check formatting before committing.
To install it, run:

```bash
ln -s .github/pre-commit .git/hooks/pre-commit
# Or, to check before pushing instead
ln -s .github/pre-commit .git/hooks/pre-push
```

## 🏃 Running the tests

To compile and test the rust code, run:

```bash
cargo build
cargo test
```

Run the benchmarks with:

```bash
cargo bench
```

Finally, if you have rust nightly installed, you can run `miri` to detect
undefined behaviour in the code.

```bash
cargo +nightly miri test
```

## 💅 Coding Style

The rustfmt tool is used to enforce a consistent rust coding style. The CI will fail if the code is not formatted correctly.

To format your code, run:

```bash
# Format rust code
cargo fmt
```

We also check for clippy warnings, which are a set of linting rules for rust. To run clippy, run:

```bash
cargo clippy --all-targets
```

## 🌐 Contributing to portgraph

We welcome contributions to portgraph! Please open [an issue](https://github.com/CQCL/portgraph/issues/new) or [pull request](https://github.com/CQCL/portgraph/compare) if you have any questions or suggestions.

PRs should be made against the `main` branch, and should pass all CI checks before being merged. This includes using the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) format for the PR title.

The general format of a contribution title should be:

```
<type>(<scope>)!: <description>
```

Where the scope is optional, and the `!` is only included if this is a semver breaking change that requires a major version bump.

We accept the following contribution types:

- feat: New features.
- fix: Bug fixes.
- docs: Improvements to the documentation.
- style: Formatting, missing semi colons, etc; no code change.
- refactor: Refactoring code without changing behaviour.
- perf: Code refactoring focused on improving performance.
- test: Adding missing tests, refactoring tests; no production code change.
- ci: CI related changes. These changes are not published in the changelog.
- chore: Updating build tasks, package manager configs, etc. These changes are not published in the changelog.
- revert: Reverting previous commits.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Please read the [API documentation here][].
See [CHANGELOG][] for a list of changes. The minimum supported rust
version will only change on major releases.

## Development

See [DEVELOPMENT.md](DEVELOPMENT.md) for instructions on setting up the development environment.

## License

This project is licensed under Apache License, Version 2.0 ([LICENSE][] or http://www.apache.org/licenses/LICENSE-2.0).
Expand Down

0 comments on commit 53f05d3

Please sign in to comment.