Skip to content

Commit

Permalink
Add precommit hooks for ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
bachase committed Feb 10, 2025
1 parent b5d3814 commit 0891ee7
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 5 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ jobs:
pip install poetry
- name: Install dependencies & ucc
run: |
poetry install
run: poetry install

- name: Run linter
run: poetry run ruff check

- name: Run formatter check
run: poetry run ruff format --check

- name: Run tests
run: poetry run pytest ucc --verbose
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version (keep in sync with the version in pyproject.toml)
rev: v0.9.4
hooks:
# Run the linter first, as fixing will change files that need to be
# formatted after
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
9 changes: 8 additions & 1 deletion docs/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The rest of this document describes the technical details of getting set up to d
Setting up your development environment
---------------------------------------

We leverage `poetry <https://python-poetry.org/>` for packaging and dependency management.
We leverage `poetry <https://python-poetry.org/>` for packaging and dependency management.
After installing poetry, run the following commands to clone the repository, create a poetry managed virtual environment for development, and install dependencies.

.. code:: bash
Expand All @@ -37,6 +37,13 @@ and build the documentation by changing to the ``docs/source`` directory where y
The built documentation will then live in ``ucc/docs/source/_build/html``.

We also use `pre-commit <https://pre-commit.com/>` to run code formatting and linting checks before each commit.
To enable the pre-commit hooks, run

.. code:: bash
pre-commit install
.. tip::

Remember to run the tests and build the documentation before opening a pull request to ensure a smoother pull request review.
Expand Down
129 changes: 127 additions & 2 deletions poetry.lock

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

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ packages = [{include = "ucc"}]
pytest = ">=6.0"
pytest-cov = ">=2.10"
ruff = "^0.9.4"
pre-commit = "^4.1.0"

[tool.poetry.group.doc.dependencies]
sphinx = ">=8.1.3"
Expand Down

0 comments on commit 0891ee7

Please sign in to comment.