-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Restructure the python code (#211)
- Renames `pyrs` → `tket2`. Closes #207. - Adds a poetry configuration and makes sure all commands can be run from the root. - Expands the justfile and other development docs. `poetry run just pytest` will take care of everything. - Enables ruff checks (lints and format) on CI. - Fixes rust binding imports requiring duplicated `import pyrs.pyrs`. Closes #208. This was caused by the python `__init__.py` overriding the one [generated by maturin](https://www.maturin.rs/project_layout.html#mixed-rustpython-project).
- Loading branch information
Showing
34 changed files
with
181 additions
and
102 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 |
---|---|---|
|
@@ -29,14 +29,22 @@ jobs: | |
with: | ||
components: rustfmt, clippy | ||
- uses: mozilla-actions/[email protected] | ||
- name: Check formatting | ||
- name: Check rust formatting | ||
run: cargo fmt -- --check | ||
- name: Check python formatting | ||
uses: chartboost/ruff-action@v1 | ||
with: | ||
args: format --check | ||
- name: Run clippy | ||
run: cargo clippy --all-targets --all-features --workspace -- -D warnings | ||
- name: Build docs | ||
run: cargo doc --no-deps --all-features | ||
env: | ||
RUSTDOCFLAGS: "-Dwarnings" | ||
- name: Python lints | ||
uses: chartboost/ruff-action@v1 | ||
with: | ||
args: check | ||
|
||
benches: | ||
# Not required, we can ignore it for the merge queue check. | ||
|
@@ -101,14 +109,11 @@ jobs: | |
cache: 'pip' | ||
- name: Build pyo3 bindings | ||
run: | | ||
pip install -r requirements.txt | ||
cd pyrs | ||
pip install -r dev-requirements.txt | ||
maturin build | ||
pip install ../target/wheels/*.whl | ||
pip install target/wheels/*.whl | ||
- name: Test pyo3 bindings | ||
run: | | ||
cd pyrs | ||
pytest | ||
run: pytest | ||
|
||
coverage: | ||
if: github.event_name != 'merge_group' | ||
|
@@ -149,15 +154,12 @@ jobs: | |
cache: 'pip' | ||
- name: Build pyo3 bindings | ||
run: | | ||
pip install -r requirements.txt | ||
pip install -r dev-requirements.txt | ||
pip install pytest-cov | ||
cd pyrs | ||
maturin build | ||
pip install ../target/wheels/*.whl | ||
pip install target/wheels/*.whl | ||
- name: Run python tests with coverage instrumentation | ||
run: | | ||
cd pyrs | ||
pytest --cov=./ --cov-report=xml | ||
run: pytest --cov=./ --cov-report=xml | ||
- name: Upload python coverage to codecov.io | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
|
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 was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
# Use common dependencies | ||
# Runtime requirements | ||
-r requirements.txt | ||
|
||
# Development requirements | ||
maturin # Build wheels | ||
black # Code formatting | ||
pytest # Unit testing | ||
ruff # Code formatting | ||
pytket # TKET1 | ||
jupyterlab # For running the examples | ||
graphviz # Visualisation of Hugrs in the notebooks |
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
Submodule symengine.rs
deleted from
05ae9c
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,8 +1,32 @@ | ||
# List the available commands | ||
help: | ||
@just --list --justfile {{justfile()}} | ||
|
||
# Run all the rust tests | ||
test: | ||
cargo test | ||
cargo test --all-features | ||
|
||
# Auto-fix all clippy warnings | ||
fix: | ||
cargo clippy --fix --allow-staged | ||
cargo clippy --all-targets --all-features --workspace --fix --allow-staged | ||
|
||
# Build the python package wheels | ||
pybuild: | ||
maturin build --release | ||
|
||
# Build the python package for local development | ||
pydevelop: | ||
maturin develop | ||
|
||
# Run the python tests | ||
pytest: pydevelop | ||
pytest | ||
|
||
# Run the pre-commit checks | ||
check: | ||
./.github/pre-commit | ||
|
||
ptest: | ||
(cd pyrs && maturin develop && pytest) | ||
# Format the code | ||
format: | ||
cargo fmt | ||
ruff format . |
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,46 @@ | ||
[tool.poetry] | ||
name = "tket2-py" | ||
version = "0.1.0" | ||
description = "pytket extension for the tket 2 compiler" | ||
classifiers = [] # TODO | ||
authors = [] # TODO | ||
maintainers = [] # TODO | ||
include = ["pyproject.toml"] | ||
license = "Apache-2.0" | ||
readme = "README.md" | ||
|
||
packages = [{ include = "tket2-py" }] | ||
|
||
[tool.poetry.dependencies] | ||
python = ">=3.10" | ||
|
||
[tool.poetry.dev-dependencies] | ||
maturin = "^1.3.0" | ||
pytket = "*" | ||
pytest = "^7.1.2" | ||
ruff = "^0.1.3" | ||
|
||
[build-system] | ||
requires = ["maturin~=1.3"] | ||
build-backend = "maturin" | ||
|
||
[project] | ||
name = "tket2" | ||
version = "0.1.0" | ||
description = "pytket extension for the tket 2 compiler" | ||
authors = [] # TODO | ||
classifiers = [] # TODO | ||
requires-python = ">=3.10" | ||
license = "Apache-2.0" | ||
|
||
[project.urls] | ||
homepage = "https://github.com/CQCL/tket2" | ||
repository = "https://github.com/CQCL/tket2" | ||
|
||
[tool.maturin] | ||
manifest-path = "tket2-py/Cargo.toml" | ||
python-source = "tket2-py" | ||
|
||
[tool.pytest.ini_options] | ||
# Lark throws deprecation warnings for `src_parse` and `src_constants`. | ||
filterwarnings = "ignore::DeprecationWarning:lark.*" |
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
Oops, something went wrong.