Skip to content

Commit

Permalink
pre-commit checks
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Nov 18, 2024
1 parent 1f04e28 commit 53b59bd
Show file tree
Hide file tree
Showing 9 changed files with 478 additions and 12 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Continuous integration
on:
push:
branches:
- main
- main
pull_request:
branches:
- main
Expand Down Expand Up @@ -71,10 +71,10 @@ jobs:
run: cargo test --verbose --no-default-features
- name: Tests with all features
run: cargo test --verbose --all-features

rs-semver-checks:
needs: [check]
if: ${{ github.event_name == 'pull_request' }}
uses: CQCL/hugrverse-actions/.github/workflows/rs-semver-checks.yml@main
secrets:
GITHUB_PAT: ${{ secrets.HUGRBOT_PAT }}
GITHUB_PAT: ${{ secrets.HUGRBOT_PAT }}
4 changes: 2 additions & 2 deletions .github/workflows/missing-ops.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Detect missing operation definitions
on:
push:
branches:
- main
- main
pull_request:
branches:
- main
Expand Down Expand Up @@ -69,4 +69,4 @@ jobs:
timeout-variable: "MISSING_OPS_MSG_SENT"
secrets:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
GITHUB_PAT: ${{ secrets.HUGRBOT_PAT }}
GITHUB_PAT: ${{ secrets.HUGRBOT_PAT }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# Python dirs
.pytest_cache
.venv
.venv
94 changes: 94 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0 # Use the ref you want to point at
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-toml
- id: check-vcs-permalinks
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
exclude: |
(?x)^(
tests/data/.*
)$
- id: trailing-whitespace
exclude: |
(?x)^(
tests/data/.*
)$
- id: fix-byte-order-marker
- id: mixed-line-ending
# Python-specific
- id: check-ast
- id: check-docstring-first
- id: debug-statements

- repo: local
hooks:
- id: ruff-format
name: ruff format
description: Format python code with `ruff`.
entry: uv run ruff format
language: system
files: \.py$
pass_filenames: false
- id: ruff-check
name: ruff
description: Check python code with `ruff`.
entry: uv run ruff check --fix --exit-non-zero-on-fix
language: system
files: \.py$
pass_filenames: false
- id: mypy-check
name: mypy
description: Check python code with `mypy`.
entry: uv run mypy .
language: system
files: \.py$
pass_filenames: false
- id: cargo-fmt
name: cargo format
description: Format rust code with `cargo fmt`.
entry: cargo fmt --all -- --check
language: system
files: \.rs$
pass_filenames: false
- id: cargo-check
name: cargo check
description: Check rust code with `cargo check`.
entry: cargo check --all --all-features --workspace
language: system
files: \.rs$
pass_filenames: false
- id: cargo-test
name: cargo test
description: Run tests with `cargo test`.
entry: cargo test --all-features --workspace
language: system
files: \.rs$
pass_filenames: false
- id: cargo-clippy
name: cargo clippy
description: Run clippy lints with `cargo clippy`.
entry: cargo clippy --all-targets --all-features --workspace -- -D warnings
language: system
files: \.rs$
pass_filenames: false
- id: cargo-doc
name: cargo doc
description: Generate documentation with `cargo doc`.
entry: sh -c "RUSTDOCFLAGS=-Dwarnings cargo doc --no-deps --all-features --workspace"
language: system
files: \.rs$
pass_filenames: false
- id: py-test
name: pytest
description: Run python tests
entry: uv run pytest
language: system
files: \.py$
pass_filenames: false
46 changes: 45 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion LICENCE
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
11 changes: 10 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
help:
@just --list --justfile {{justfile()}}

# Prepare the environment for development, installing all the dependencies and
# setting up the pre-commit hooks.
setup:
uv run pre-commit install -t pre-commit

# Run the pre-commit checks.
check:
HUGR_TEST_SCHEMA=1 uv run pre-commit run --all-files

# Run all the rust tests
test:
cargo test --all-features
Expand All @@ -13,4 +22,4 @@ fix:
# Check for missing optypes
check-optypes:
uv sync
uv run -- cargo test -- --ignored missing_optypes
uv run -- cargo test -- --ignored missing_optypes
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ authors = [
{ name = "TKET development team", email = "tket-support@quantinuum.com" },
]

[tool.uv]
dev-dependencies = ["pytket>=1.32"]
[dependency-groups]
# Default dev dependency group
dev = [{ include-group = "lint" }, { include-group = "test" }]
lint = ["pre-commit >=3.6.0,<4", "ruff >=0.6.2,<0.7", "mypy ==1.10.0"]
test = ["pytest >=6.2.4,<7", "pytket>=1.32"]
Loading

0 comments on commit 53b59bd

Please sign in to comment.