Skip to content

Commit 4033326

Browse files
authored
add pre commit hook to run format tests (#118)
1 parent e004ed9 commit 4033326

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ jobs:
4545
e2e
4646
- name: Run isort
4747
uses: isort/isort-action@v1
48+
- name: Formatting hint
49+
if: failure()
50+
run: |
51+
echo "::notice::PROTIP: You can install pre-commit hooks to automatically format your code before each commit. Run 'uv run pre-commit install' and never have to resubmit a PR because of formatting errors! See CONTRIBUTING.md for more details."
4852
4953
5054
typing:

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.9.6
4+
hooks:
5+
- id: ruff
6+
args: [--fix]
7+
files: ^(pystemd|examples|tests|e2e)/
8+
- id: ruff-format
9+
files: ^(pystemd|examples|tests|e2e)/
10+
- repo: https://github.com/pycqa/isort
11+
rev: 6.0.0
12+
hooks:
13+
- id: isort

CONTRIBUTING.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,61 @@ possible.
66
We use GitHub issues to track public bugs. Please ensure your description is
77
clear and has sufficient instructions to be able to reproduce the issue.
88

9+
## Development setup
10+
11+
### Prerequisites
12+
Install [uv](https://docs.astral.sh/uv/getting-started/installation/) if you don't have it already:
13+
14+
15+
### Installing dependencies
16+
After cloning the repository, install the development dependencies:
17+
18+
```bash
19+
uv sync --all-extras
20+
```
21+
22+
### Running tests
23+
Run the unit tests with:
24+
25+
```bash
26+
uv run pytest tests
27+
```
28+
29+
Or with coverage:
30+
31+
```bash
32+
uv run pytest --cov=pystemd tests
33+
```
34+
35+
### Running E2E tests
36+
The E2E tests run in a systemd container using mkosi and are primarily designed
37+
for CI. To run them locally, you need `mkosi` and `systemd-container` installed.
38+
See `.github/workflows/e2e-tests.yml` for the full setup. For most contributions,
39+
unit tests are sufficient.
40+
41+
### Formatting code
42+
Format your code before submitting a pull request:
43+
44+
```bash
45+
uv run ruff check --fix pystemd examples tests e2e
46+
uv run ruff format pystemd examples tests e2e
47+
uv run isort .
48+
```
49+
50+
### Type checking
51+
We use [pyrefly](https://github.com/facebook/pyrefly) for type checking. Run it with:
52+
53+
```bash
54+
uv run pyrefly check pystemd examples tests
55+
```
56+
57+
Optionally, you can install pre-commit hooks to automatically format code on
58+
each commit:
59+
60+
```bash
61+
uv run pre-commit install
62+
```
63+
964
## Sending a pull request
1065
Have a fix or feature? Awesome! When you send the pull request we suggest you
1166
include a build output.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ lint = [
4646
"ruff",
4747
"pyrefly",
4848
"isort",
49+
"pre-commit",
4950
]
5051

5152
[project.urls]

0 commit comments

Comments
 (0)