Skip to content

Commit 1d33304

Browse files
authored
Merge pull request #28 from danielcristho/main
Add pre-commit to github actions & create justfile
2 parents 996745a + 347571d commit 1d33304

File tree

5 files changed

+259
-32
lines changed

5 files changed

+259
-32
lines changed

.github/workflows/check.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Pre-Commit
2+
3+
on:
4+
workflow_call:
5+
workflow_dispatch:
6+
push:
7+
branches: [main]
8+
pull_request:
9+
branches: [main]
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
jobs:
16+
pre-commit:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v6.0.1
22+
23+
- name: Setup Python
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: "3.14"
27+
28+
- name: Add uv
29+
uses: astral-sh/setup-uv@v7
30+
31+
- name: Install dependencies
32+
run: uv sync --dev
33+
34+
- name: Run pre-commit
35+
uses: pre-commit/action@v3.0.0

.github/workflows/test.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: PyTest
2+
on:
3+
workflow_call:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
paths:
10+
- ".github/workflows/test.yml"
11+
- "render_engine_api/**"
12+
- "tests/**"
13+
- "pyproject.toml"
14+
- "requirements.txt"
15+
16+
jobs:
17+
gen-coverage-badge:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v6
21+
- uses: astral-sh/setup-uv@v7
22+
with:
23+
python-version: "3.14"
24+
enable-cache: true
25+
26+
- name: run coverage and generate cov-report
27+
run: |
28+
uv run --dev pytest --cov-report xml
29+
- name: genbadge coverage
30+
run: |
31+
uvx --with "genbadge[coverage]" genbadge coverage -i coverage.xml
32+
- name: Commit Badge
33+
uses: stefanzweifel/git-auto-commit-action@v7
34+
with:
35+
commit_message: Update coverage badge [skip ci]
36+
file_pattern: coverage.svg
37+
38+
test-against-python-matrix:
39+
# Only test all the supported versions when a pull request is made or the workflow is called
40+
if: ${{github.event_name == 'workflow_call'}} || ${{github.event_name == 'pull_request'}}
41+
runs-on: ubuntu-latest
42+
strategy:
43+
matrix:
44+
python-version: ["3.10", "3.11", "3.12", "3.13"]
45+
fail-fast: true
46+
steps:
47+
- uses: actions/checkout@v6.0.1
48+
- name: Install uv
49+
uses: astral-sh/setup-uv@v7
50+
with:
51+
python-version: ${{ matrix.python-version }}
52+
enable-cache: true # caching dependencies
53+
- name: Run tests
54+
run: |
55+
uv run --dev pytest tests
56+
57+
test-against-latest-os:
58+
# Always run against the latest version on both Windows, Linux, MacOS
59+
if: github.event.pull_request.user.login != 'dependabot[bot]'
60+
strategy:
61+
matrix:
62+
os: [windows-latest, macos-latest]
63+
fail-fast: true
64+
runs-on: ${{ matrix.os }}
65+
steps:
66+
- uses: actions/checkout@v6.0.1
67+
- name: Install uv
68+
uses: astral-sh/setup-uv@v7
69+
with:
70+
python-version: "3.14"
71+
enable-cache: true # caching dependencies
72+
- name: run tests
73+
run: uv run --dev pytest tests

.pre-commit-config.yaml

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
repos:
2-
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v2.3.0
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v6.0.0
44
hooks:
5-
- id: check-yaml
6-
- id: end-of-file-fixer
7-
- id: trailing-whitespace
8-
- repo: https://github.com/astral-sh/ruff-pre-commit
9-
# Ruff version.
10-
rev: v0.15.1
11-
hooks:
12-
# Run the linter.
13-
- id: ruff-check
14-
args: [ --fix ]
15-
# Run the formatter.
16-
- id: ruff-format
17-
- repo: https://github.com/allganize/ty-pre-commit
18-
# Ty version.
19-
rev: v0.0.17
20-
hooks:
21-
# Run the type checker.
22-
- id: ty-check
23-
- repo: https://github.com/DavidAnson/markdownlint-cli2
24-
rev: v0.6.0
25-
hooks:
26-
- id: markdownlint-cli2
27-
- repo: local
28-
hooks:
29-
- id: deptry
30-
name: deptry
31-
entry: uv run deptry .
32-
language: system
33-
always_run: true
34-
pass_filenames: false
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- repo: https://github.com/astral-sh/ruff-pre-commit
9+
# Ruff version.
10+
rev: v0.15.4
11+
hooks:
12+
# Run the linter.
13+
- id: ruff-check
14+
args: [--fix]
15+
# Run the formatter.
16+
- id: ruff-format
17+
- repo: https://github.com/allganize/ty-pre-commit
18+
# Ty version.
19+
rev: v0.0.20
20+
hooks:
21+
# Run the type checker.
22+
- id: ty-check
23+
- repo: https://github.com/DavidAnson/markdownlint-cli2
24+
rev: v0.21.0
25+
hooks:
26+
- id: markdownlint-cli2
27+
- repo: local
28+
hooks:
29+
- id: deptry
30+
name: deptry
31+
entry: uv run deptry .
32+
language: system
33+
always_run: true
34+
pass_filenames: false

CONTRIBUTING.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Contributing to the Render Engine Projects
2+
3+
Render Engine API is a unifying API layer for managing and working with [render-engine][render-engine].
4+
The [CLI][cli], [TUI][tui], and custom tools can use this module as a shared API layer. Please refer to
5+
the main [CONTRIBUTING.md](https://github.com/render-engine/render-engine/blob/main/CONTRIBUTING.md)
6+
for more details on how to contribute.
7+
8+
## Render Engine API Specific Topics
9+
10+
Render Engine API is a `uv` based project. For more information on installing `uv` and using it
11+
please see the [uv documentation](https://docs.astral.sh/uv/#installation). To get started, fork
12+
this repository and check out your fork.
13+
14+
```shell
15+
git clone <url to fork>
16+
```
17+
18+
Once you have checked out the repository, run `uv sync --dev` and then activate the `venv` that was
19+
created:
20+
21+
```shell
22+
uv sync --dev
23+
source .venv/bin/activate
24+
```
25+
26+
Once you have done this you will be in the virtual environment and ready to work. It is recommended
27+
that you do a local, editable install of the API in your virtual environment so that you can easily
28+
work with the changes you have made.
29+
30+
```shell
31+
uv pip install -e .
32+
```
33+
34+
This will allow you to test your changes locally.
35+
36+
[render-engine]: https://github.com/render-engine/render-engine
37+
[cli]: https://github.com/render-engine/render-engine-cli
38+
[tui]: https://github.com/render-engine/render-engine-tui

justfile

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Render Engine API - Just recipes
2+
# Run tasks with: just <task-name>
3+
4+
DEFAULT_PYTHON_VERSION := "3.14"
5+
6+
# Default recipe to display available commands
7+
default:
8+
@just --list
9+
10+
# Sync dependencies using uv
11+
sync:
12+
uv sync --dev
13+
14+
# Run pytest
15+
test *FLAGS='':
16+
pytest {{ DEFAULT_PYTHON_VERSION }} {{ FLAGS }}
17+
18+
# Install pre-commit hooks
19+
pre-commit-install:
20+
uvx pre-commit install
21+
22+
# Run pre-commit on all files
23+
pre-commit:
24+
uvx pre-commit run --all-files
25+
26+
# Run pre-commit on staged files (default git behavior)
27+
pre-commit-run:
28+
uvx pre-commit run
29+
30+
# Update pre-commit hook versions
31+
pre-commit-update:
32+
uvx pre-commit autoupdate
33+
34+
# Run tests in arbitrary Python version.
35+
pytest VERSION *FLAGS='':
36+
uv run -p {{ VERSION }} --dev pytest {{ FLAGS }}
37+
38+
# Run pytest with coverage report (defaults to XML)
39+
test-cov-report REPORT='xml':
40+
uv run --dev pytest --cov-report={{ REPORT }}
41+
42+
# Run all nox sessions
43+
nox:
44+
uvx nox
45+
46+
# Run ruff linter without fixing
47+
lint DIRECTORY='.':
48+
uvx ruff check {{ DIRECTORY }}
49+
50+
# Run ruff linter with auto-fix
51+
lint-fix DIRECTORY='.':
52+
uvx ruff check --fix {{ DIRECTORY }}
53+
54+
# Run ruff formatter as check
55+
format DIRECTORY='.':
56+
uvx ruff format --check {{ DIRECTORY }}
57+
58+
# Run ruff formatter and fix issues
59+
format-fix DIRECTORY='.':
60+
uvx ruff format --check {{ DIRECTORY }}
61+
62+
ruff: lint format
63+
64+
# Run both linter and formatter, fixing issues.
65+
ruff-fix DIRECTORY='.':
66+
@# Prefacing with `-` to ignore any errors that might be fixed by formatting.
67+
-uvx ruff check --fix {{ DIRECTORY }}
68+
uvx ruff format {{ DIRECTORY }}
69+
uvx ruff check {{ DIRECTORY }}
70+
@echo "\nEverything looks good!"
71+
72+
# Run ty type checker
73+
ty PATH='src':
74+
uv run ty check {{ PATH }} # For the moment we have way too many issues in ty so not having it fail.
75+
76+
# Generate coverage badge
77+
badge: (test-cov-report 'xml')
78+
uvx --with "genbadge[coverage]" genbadge coverage -i coverage.xml
79+
80+
# Run full CI workflow (sync, lint, test, badge)
81+
ci: sync nox ruff ty badge

0 commit comments

Comments
 (0)