Skip to content

Commit 8ed9511

Browse files
Patrick Kidger Botpatrick-kidger
authored andcommitted
Use dependency groups, uv, and local pre-commit hooks
1 parent dd091fa commit 8ed9511

8 files changed

Lines changed: 77 additions & 62 deletions

File tree

.github/workflows/build_docs.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,18 @@ jobs:
1616
- name: Checkout code
1717
uses: actions/checkout@v2
1818

19-
- name: Set up Python ${{ matrix.python-version }}
20-
uses: actions/setup-python@v2
19+
- name: Install the latest version of uv
20+
uses: astral-sh/setup-uv@v7
2121
with:
2222
python-version: ${{ matrix.python-version }}
2323

2424
- name: Install dependencies
2525
run: |
26-
python -m pip install --upgrade pip
27-
python -m pip install '.[docs]'
26+
uv run echo done
2827
2928
- name: Build docs
3029
run: |
31-
mkdocs build
30+
uv run mkdocs build
3231
3332
- name: Upload docs
3433
uses: actions/upload-artifact@v4

.github/workflows/release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ jobs:
1313
uses: patrick-kidger/action_update_python_project@v8
1414
with:
1515
python-version: "3.11"
16+
# Uninstall and reinstall pytest to work around the fact that it doesn't get put into `bin` otherwise.
1617
test-script: |
1718
cp -r ${{ github.workspace }}/tests ./tests
1819
cp ${{ github.workspace }}/pyproject.toml ./pyproject.toml
19-
uv sync --extra tests --no-install-project --inexact
20+
uv pip uninstall pytest
21+
uv sync --no-install-project --inexact
2022
uv run --no-sync pytest
2123
pypi-token: ${{ secrets.pypi_token }}
2224
github-user: patrick-kidger

.github/workflows/run_tests.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,23 @@ jobs:
1515
- name: Checkout code
1616
uses: actions/checkout@v2
1717

18-
- name: Set up Python ${{ matrix.python-version }}
19-
uses: actions/setup-python@v2
18+
- name: Install the latest version of uv
19+
uses: astral-sh/setup-uv@v7
2020
with:
2121
python-version: ${{ matrix.python-version }}
2222

2323
- name: Install dependencies
2424
run: |
25-
python -m pip install --upgrade pip
26-
python -m pip install '.[dev,docs,tests]'
25+
uv run echo done
2726
2827
- name: Checks with pre-commit
2928
run: |
30-
pre-commit run --all-files
29+
uv run prek run --all-files
3130
3231
- name: Test with pytest
3332
run: |
34-
pytest
33+
uv run pytest
3534
3635
- name: Check that documentation can be built.
3736
run: |
38-
mkdocs build
37+
uv run mkdocs build

.pre-commit-config.yaml

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
1+
fail_fast: true
12
repos:
3+
- repo: meta
4+
hooks:
5+
- id: check-hooks-apply
6+
- id: check-useless-excludes
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v4.4.0
9+
hooks:
10+
- id: trailing-whitespace
11+
exclude: \.md$
12+
- id: check-toml
13+
- id: mixed-line-ending
214
- repo: local
315
hooks:
4-
- id: sort_pyproject
5-
name: sort_pyproject
6-
entry: toml-sort -i --sort-table-keys --sort-inline-tables
7-
language: python
16+
- id: sort-pyproject
17+
name: sort pyproject
818
files: ^pyproject\.toml$
9-
additional_dependencies: ["toml-sort==0.23.1"]
10-
- repo: https://github.com/astral-sh/ruff-pre-commit
11-
rev: v0.13.0
12-
hooks:
13-
- id: ruff-format # formatter
19+
language: system
20+
entry: uv run -- toml-sort -i --sort-table-keys --sort-inline-tables
21+
- id: ruff-format
22+
name: ruff format
1423
types_or: [python, pyi, jupyter, toml]
15-
- id: ruff # linter
24+
language: system
25+
entry: uv run -- ruff format --
26+
require_serial: true
27+
- id: ruff-lint
28+
name: ruff lint
1629
types_or: [python, pyi, jupyter, toml]
17-
args: [--fix]
18-
- repo: https://github.com/RobertCraigie/pyright-python
19-
rev: v1.1.405
20-
hooks:
30+
language: system
31+
entry: uv run -- ruff check --fix --
32+
require_serial: true
2133
- id: pyright
22-
additional_dependencies:
23-
[pytest]
34+
name: pyright
35+
types_or: [python]
36+
language: system
37+
entry: uv run -- pyright
38+
require_serial: true

CONTRIBUTING.md

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,24 @@ Contributions (pull requests) are very welcome! Here's how to get started.
44

55
---
66

7-
**Getting started**
7+
### Getting started
88

9-
First fork the library on GitHub.
10-
11-
Then clone and install the library:
9+
[We assume that you have `uv` installed.](https://docs.astral.sh/uv/) Now fork the library on GitHub. Then clone and install the library:
1210

1311
```bash
1412
git clone https://github.com/your-username-here/tinyio.git
1513
cd tinyio
16-
pip install -e '.[dev]'
17-
pre-commit install # `pre-commit` is installed by `pip` on the previous line
14+
uv run prek install # Creates a local venv + installs dependencies + installs pre-commit hooks.
1815
```
1916

2017
---
2118

22-
**If you're making changes to the code:**
23-
24-
Now make your changes. Make sure to include additional tests if necessary.
19+
### If you're making changes to the code
2520

26-
Next verify the tests all pass:
21+
Now make your changes. Make sure to include additional tests if necessary. Next verify the tests all pass:
2722

2823
```bash
29-
pip install -e '.[tests]'
30-
pytest # `pytest` is installed by `pip` on the previous line.
24+
uv run pytest
3125
```
3226

3327
Then push your changes back to your fork of the repository:
@@ -40,14 +34,12 @@ Finally, open a pull request on GitHub!
4034

4135
---
4236

43-
**If you're making changes to the documentation:**
37+
### If you're making changes to the documentation
4438

4539
Make your changes. You can then build the documentation by doing
4640

4741
```bash
48-
pip install -e '.[docs]'
49-
mkdocs serve
42+
uv run mkdocs serve
5043
```
5144

5245
You can then see your local copy of the documentation by navigating to `localhost:8000` in a web browser.
53-

docs/_static/mathjax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ window.MathJax = {
1111
}
1212
};
1313

14-
document$.subscribe(() => {
14+
document$.subscribe(() => {
1515
MathJax.typesetPromise()
1616
})

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ edit_uri: ""
4242

4343
strict: true # Don't allow warnings during the build process
4444

45-
extra_javascript:
45+
extra_javascript:
4646
# The below two make MathJax work, see https://squidfunk.github.io/mkdocs-material/reference/mathjax/
4747
- _static/mathjax.js
4848
- https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js

pyproject.toml

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22
build-backend = "hatchling.build"
33
requires = ["hatchling"]
44

5+
[dependency-groups]
6+
dev = [
7+
"prek==0.3.9",
8+
"pyright==1.1.405",
9+
"ruff==0.13.0",
10+
"toml-sort==0.23.1"
11+
]
12+
docs = [
13+
"hippogriffe==0.2.2",
14+
"griffe==1.7.3",
15+
"mkdocs==1.6.1",
16+
"mkdocs-include-exclude-files==0.1.0",
17+
"mkdocs-material==9.6.7",
18+
"mkdocstrings==0.28.3",
19+
"mkdocstrings-python==1.16.8",
20+
"pygments==2.20.0",
21+
"pymdown-extensions==10.21.2"
22+
]
23+
tests = ["pytest", "trio"]
24+
525
[project]
626
authors = [
727
{email = "contact@kidger.site", name = "Patrick Kidger"}
@@ -22,21 +42,6 @@ requires-python = ">=3.11"
2242
urls = {repository = "https://github.com/patrick-kidger/tinyio"}
2343
version = "0.4.0"
2444

25-
[project.optional-dependencies]
26-
dev = ["prek"]
27-
docs = [
28-
"hippogriffe==0.2.2",
29-
"griffe==1.7.3",
30-
"mkdocs==1.6.1",
31-
"mkdocs-include-exclude-files==0.1.0",
32-
"mkdocs-material==9.6.7",
33-
"mkdocstrings==0.28.3",
34-
"mkdocstrings-python==1.16.8",
35-
"pygments==2.20.0",
36-
"pymdown-extensions==10.21.2"
37-
]
38-
tests = ["pytest", "trio"]
39-
4045
[tool.hatch.build]
4146
include = ["tinyio/*"]
4247
reportFunctionMemberAccess = false
@@ -66,3 +71,6 @@ combine-as-imports = true
6671
extra-standard-library = ["typing_extensions"]
6772
lines-after-imports = 2
6873
order-by-type = true
74+
75+
[tool.uv]
76+
default-groups = ["dev", "docs", "tests"]

0 commit comments

Comments
 (0)