Skip to content

Commit 53d7653

Browse files
committed
Add a setup-python-uv composite action and integrate just for CI and development tasks. Add a just recipe to install/uninstall a pre-push hook to run the same recipe locally that runs in CI. Put some dev notes in the README.
1 parent c7826af commit 53d7653

File tree

4 files changed

+141
-47
lines changed

4 files changed

+141
-47
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Setup Python with uv
2+
description: Install uv, set up Python, and install project dependencies
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Restore .venv cache
8+
uses: actions/cache@v4
9+
with:
10+
path: .venv
11+
key: venv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
12+
restore-keys: |
13+
venv-${{ runner.os }}-
14+
15+
- name: Install uv
16+
uses: astral-sh/setup-uv@v7
17+
with:
18+
enable-cache: true
19+
cache-dependency-glob: "uv.lock"
20+
21+
- name: Set up Python 3.14
22+
shell: bash
23+
run: uv python install
24+
# Uses version from .python-version
25+
26+
- name: Install dependencies
27+
shell: bash
28+
run: uv sync --frozen

.github/workflows/ci.yml

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,19 @@ on: [push, pull_request]
44

55
jobs:
66
ci_tests:
7-
name: python
7+
name: python 3.14
88
runs-on: ubuntu-latest
9+
timeout-minutes: 30
910

1011
steps:
1112
- uses: actions/checkout@v4
1213

13-
- name: Set up Python 3.14.0-rc.2
14-
uses: actions/setup-python@v5
15-
with:
16-
python-version: 3.14.0-rc.2
14+
- name: Setup Python 3.14 and uv
15+
uses: ./.github/actions/setup-python-uv
1716

18-
- name: Install uv
19-
uses: astral-sh/setup-uv@v6
17+
- name: Install just
18+
run: |
19+
curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin
2020
21-
- name: Lint
22-
run: uv run ruff check
23-
24-
- name: Check formatting
25-
run: uv run ruff format --check
26-
27-
- name: Type check
28-
run: uv run pyright
29-
30-
- name: Run tests
31-
run: uv run pytest -v
21+
- name: Run CI checks
22+
run: just ci-checks

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@ If you have [Astral's `uv`](https://docs.astral.sh/uv/) you can easily try `tdom
3030
uv run --with tdom --python 3.14 python
3131
```
3232

33+
## Development
34+
35+
This project uses [`just`](https://just.systems/) for task automation and [`uv`](https://docs.astral.sh/uv/) for dependency management.
36+
37+
### Setup
38+
39+
Install `just` and `uv`, then run:
40+
41+
```bash
42+
just install
43+
```
44+
45+
### Common Tasks
46+
47+
```bash
48+
just # Show all available tasks
49+
just test # Run tests
50+
just lint # Check code for issues
51+
just fmt # Format code
52+
just typecheck # Run type checker
53+
just ci-checks # Run all checks (CI pipeline)
54+
```
55+
3356
## Usage
3457

3558
`tdom` leverages Python 3.14's

justfile

Lines changed: 81 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,101 @@
1-
default: lint format_check type_check test
1+
# Justfile for tdom
2+
# Requires: just, uv, Python 3.14
3+
# All tasks use uv to ensure isolated, reproducible runs.
24

3-
lint:
4-
uv run ruff check
5+
# Default recipe shows help
6+
default:
7+
@just --list
58

6-
format_check:
7-
uv run ruff format --check
9+
# Print environment info
10+
info:
11+
@echo "Python: $(python --version)"
12+
@uv --version
813

9-
format_docs:
10-
npx prettier --write "**/*.md"
14+
# Install project and dev dependencies
15+
install:
16+
uv sync --all-groups
1117

12-
type_check:
13-
uv run pyright
18+
# Alias for install (better discoverability)
19+
setup: install
1420

15-
test:
16-
uv run pytest
21+
# Run tests (sequential)
22+
test *ARGS:
23+
uv run pytest {{ ARGS }}
1724

18-
watch:
19-
# Watch for changes and run tests.
20-
uv run ptw tdom/
25+
# Run tests (parallel)
26+
test-parallel *ARGS:
27+
uv run pytest -n auto {{ ARGS }}
2128

22-
build_docs:
23-
cd docs && uv run sphinx-build . _build
29+
# Lint code (check for issues)
30+
lint *ARGS:
31+
uv run ruff check {{ ARGS }} .
2432

25-
clean_docs:
26-
rm -rf docs/_build
33+
# Format code (auto-format)
34+
fmt *ARGS:
35+
uv run ruff format {{ ARGS }} .
2736

28-
build_package:
29-
uv build
37+
# Check formatting without modifying files (for CI)
38+
fmt-check *ARGS:
39+
uv run ruff format --check {{ ARGS }} .
3040

31-
clean_package:
32-
rm -rf dist/
41+
# Lint and auto-fix
42+
lint-fix:
43+
uv run ruff check --fix .
3344

34-
build: build_docs build_package
45+
# Type checking
46+
typecheck *ARGS:
47+
uv run pyright {{ ARGS }}
3548

36-
clean: clean_docs clean_package
49+
# Build the documentation site
50+
docs:
51+
uv run sphinx-build -b html docs docs/_build/html
3752

38-
reports:
39-
uv run pytest --cov=tdom --cov-report=xml:reports/coverage.xml --cov-report=term --cov-report=html:reports/coverage --junitxml=reports/pytest.xml --html=reports/pytest.html
53+
# Format markdown files
54+
fmt-docs:
55+
npx prettier --write "**/*.md"
56+
57+
# Watch for changes and run tests
58+
watch:
59+
uv run ptw tdom/
60+
61+
# Build sdist/wheel
62+
build:
63+
uv build
4064

41-
clean_reports:
65+
# Clean build and cache artifacts
66+
clean:
67+
rm -rf .pytest_cache .ruff_cache .pyright .mypy_cache build dist
68+
find docs/_build -mindepth 1 -maxdepth 1 -not -name ".gitkeep" -exec rm -rf {} + || true
4269
rm -rf reports/
4370

71+
# Run all quality checks with fail-fast behavior
72+
ci-checks:
73+
just install && just lint && just fmt-check && just typecheck && just test-parallel
74+
75+
# Generate reports for badges
76+
reports:
77+
uv run pytest --cov=tdom --cov-report=xml:reports/coverage.xml --cov-report=term --cov-report=html:reports/coverage --junitxml=reports/pytest.xml --html=reports/pytest.html
78+
79+
# Generate badge SVGs from reports
4480
badges:
4581
uv run genbadge tests -i reports/pytest.xml -v -o reports/pytest.svg
4682
uv run genbadge coverage -i reports/coverage.xml -v -o reports/coverage.svg
4783

48-
clean_badges:
49-
rm -rf reports/*.svg
84+
# Enable pre-push hook to run ci-checks before pushing
85+
enable-pre-push:
86+
@echo "Installing pre-push hook..."
87+
@echo '#!/bin/sh' > .git/hooks/pre-push
88+
@echo '' >> .git/hooks/pre-push
89+
@echo '# Run quality checks before push' >> .git/hooks/pre-push
90+
@echo 'echo "Running quality checks before push..."' >> .git/hooks/pre-push
91+
@echo 'if ! just ci-checks; then' >> .git/hooks/pre-push
92+
@echo ' echo "Pre-push check failed! Push aborted."' >> .git/hooks/pre-push
93+
@echo ' exit 1' >> .git/hooks/pre-push
94+
@echo 'fi' >> .git/hooks/pre-push
95+
@chmod +x .git/hooks/pre-push
96+
@echo "Pre-push hook installed! Use 'just disable-pre-push' to disable."
97+
98+
# Disable pre-push hook
99+
disable-pre-push:
100+
@chmod -x .git/hooks/pre-push 2>/dev/null || true
101+
@echo "Pre-push hook disabled. Use 'just enable-pre-push' to re-enable."

0 commit comments

Comments
 (0)