Skip to content

Commit b26f844

Browse files
authored
Convert to uv workflow (#203)
* remove external requirement files * update project metadata - Use uv build system - static version - list dependencies - list dependency groups with developer dependencies * Remove unused samples * Rewrite noxfile for uv workflow - Simplify session names `dev`, `test`, `lint`, etc - Use uv in all calls - Move linting and formatting into noxfile session * pin python version for uv config * create uv.lock file * Update github actions workflow - Upgrade all action versions - Dynamically pull default python version from `.python-versoin` file - Update nox sessions to match new noxfile * Correct copy paste error * Use uvx in actions instead of uv run * noxfile enforces frozen lockfile * checkout repo for file reading * output a json report with the html * Ensure steps wait for settings to be completed * Update development setup for uv * update FAQ * Split linter and formatter groups * Split linting and formatting sessions * Remove verbose from formatters and linters * Do not install all groups for dev environ * Don't build python sessions Embrace the uv tool and allow it to manage dependencies in the project root. * Replace requests with httpx * Remove tool group * extract common sync args * Use hatch backend and dynamic versioning * Allow mypy to use incremental cache * adjust greedy ignore * Remove version from init values
1 parent ba6aac3 commit b26f844

File tree

16 files changed

+813
-292
lines changed

16 files changed

+813
-292
lines changed

.github/workflows/python-tests.yml

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
name: "python tests and coverage"
22
# Uses:
3-
# https://github.com/actions/setup-python : a26af69be951a213d495a4c3e4e4022e16d87065
4-
# https://github.com/actions/checkout : 11bd71901bbe5b1630ceea73d27597364c9af683
5-
# https://github.com/actions/download-artifact : d3f86a106a0bac45b974a628896c90dbdf5c8093
6-
# https://github.com/actions/upload-artifact : ea165f8d65b6e75b540449e92b4886f43607fa02
3+
# https://github.com/actions/setup-python : v5.6.0 a26af69be951a213d495a4c3e4e4022e16d87065
4+
# https://github.com/actions/checkout : v4.2.2 11bd71901bbe5b1630ceea73d27597364c9af683
5+
# https://github.com/actions/download-artifact : v5.0.0 634f93cb2916e3fdff6788551b99b062d0335ce0
6+
# https://github.com/actions/upload-artifact : v4.6.2 ea165f8d65b6e75b540449e92b4886f43607fa02
7+
# https://github.com/astral-sh/setup-uv : v6.4.3 e92bafb6253dcd438e0484186d7669ea7a8ca1cc
78

89
on:
910
pull_request:
@@ -13,26 +14,31 @@ on:
1314
branches:
1415
- "main"
1516

17+
env:
18+
UV_PYTHON_PREFERENCE: "only-system"
19+
1620
jobs:
1721
settings:
1822
runs-on: "ubuntu-latest"
1923
name: "Define workflow settings"
20-
outputs:
21-
default-python-version: "3.12"
2224
steps:
25+
- name: "Repo checkout"
26+
uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683"
27+
2328
- name: "Define settings"
24-
run: ""
29+
run: |
30+
echo "python_version=$(<.python-version)" >> $GITHUB_OUTPUT
2531
2632
run-tests-and-coverage:
27-
name: "Run pytest with coverage."
28-
needs: ["settings"]
33+
name: "Run nox for tests and coverage"
34+
needs: "settings"
2935
runs-on: "${{ matrix.os }}"
3036
strategy:
3137
fail-fast: false
3238
matrix:
3339
os:
34-
- "macos-latest"
35-
- "windows-latest"
40+
# - "macos-latest"
41+
# - "windows-latest"
3642
- "ubuntu-latest"
3743
python-version:
3844
- "3.9"
@@ -52,13 +58,15 @@ jobs:
5258
python-version: "${{ matrix.python-version }}"
5359
allow-prereleases: true
5460

55-
- name: "Install nox"
56-
run: |
57-
python -m pip install --upgrade nox
61+
- name: "Install the latest version of uv"
62+
uses: "astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc"
63+
with:
64+
version: "latest"
65+
python-version: "${{ matrix.python-version }}"
66+
enable-cache: true
5867

5968
- name: "Run tests and coverage via nox"
60-
run: |
61-
nox --session test -- partial-coverage
69+
run: "uvx nox --session test -- partial-coverage no-config"
6270

6371
- name: "Save coverage artifact"
6472
uses: "actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02"
@@ -69,8 +77,8 @@ jobs:
6977
include-hidden-files: true
7078

7179
coverage-compile:
72-
name: "Compile coverage reports."
73-
needs: ["settings", "run-tests-and-coverage"]
80+
name: "coverage compile"
81+
needs: "run-tests-and-coverage"
7482
runs-on: "ubuntu-latest"
7583
steps:
7684
- name: "Repo checkout"
@@ -79,28 +87,33 @@ jobs:
7987
- name: "Set up Python"
8088
uses: "actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065"
8189
with:
82-
python-version: "${{ needs.settings.outputs.default-python-version }}"
90+
python-version: ${{ steps.settings.outputs.python_version }}
8391

84-
- name: "Install nox"
85-
run: |
86-
python -m pip install --upgrade nox
92+
- name: "Install the latest version of uv"
93+
uses: "astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc"
94+
with:
95+
version: "latest"
96+
python-version: ${{ steps.settings.outputs.python_version }}
97+
enable-cache: true
8798

8899
- name: "Download coverage artifacts"
89-
uses: "actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093"
100+
uses: "actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0"
90101
with:
91102
pattern: "coverage-artifact-*"
92103
merge-multiple: true
93104

94-
- name: "Compile coverage data, print report"
105+
- name: "Compile coverage data"
106+
run: "uvx nox --session combine"
107+
108+
- name: "Post summary to step summary."
95109
run: |
96-
nox --session coverage_combine
97110
export TOTAL=$(python -c "import json;print(json.load(open('coverage.json'))['totals']['percent_covered_display'])")
98111
echo "TOTAL=$TOTAL" >> $GITHUB_ENV
99112
echo "### Total coverage: ${TOTAL}%" >> $GITHUB_STEP_SUMMARY
100113
101-
linting:
102-
name: "Check linting and formatting requirements"
103-
needs: ["settings"]
114+
linters-and-formatters:
115+
name: "linters and formattrs"
116+
needs: "settings"
104117
runs-on: "ubuntu-latest"
105118
steps:
106119
- name: "Repo checkout"
@@ -109,12 +122,14 @@ jobs:
109122
- name: "Set up Python"
110123
uses: "actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065"
111124
with:
112-
python-version: "${{ needs.settings.outputs.default-python-version }}"
125+
python-version: ${{ steps.settings.outputs.python_version }}
113126

114-
- name: "Install nox"
115-
run: |
116-
python -m pip install --upgrade nox
127+
- name: "Install the latest version of uv"
128+
uses: "astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc"
129+
with:
130+
version: "latest"
131+
python-version: ${{ steps.settings.outputs.python_version }}
132+
enable-cache: true
117133

118-
- name: "Run formatters and linters"
119-
run: |
120-
nox --session lint
134+
- name: "Enforce strict type annotations with mypy"
135+
run: "uvx nox --session lint"

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ htmlcov
1111
coverage.*
1212

1313
.venv*
14-
temp*
14+
temp_*
1515
.env

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.9

CONTRIBUTING.md

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -42,70 +42,74 @@ The following steps outline how to install this repo for local development.
4242

4343
## Prerequisites
4444

45-
### Clone repo
45+
### [Install uv](https://docs.astral.sh/uv/getting-started/installation/)
4646

47-
```bash
48-
git clone https://github.com/[ORG NAME]/[REPO NAME]
47+
uv is required to use the provided noxfile sessions for developer setup,
48+
linting, and tests. Using nox is completely optional, all sessions can be
49+
manually recreated. These instructions will not cover those cases.
4950

50-
cd [REPO NAME]
51-
```
51+
## Nox Sessions
5252

53-
### [Install nox](https://nox.thea.codes/en/stable/index.html)
53+
### Developer Install
5454

55-
It is recommended to use a tool such as `pipx` or `uvx` to install nox. nox is
56-
needed to run the provided sessions for developer setup, linting, tests, and
57-
dependency management. It is optional, but these instructions will not cover
58-
manually steps outside of nox.
55+
This builds the `/.venv`, installs the editable package, and installs
56+
pre-commit.
5957

58+
```console
59+
uvx nox -s dev
60+
```
6061

61-
## Nox Sessions
62+
### Run tests and display coverage
6263

63-
### Developer Install
64+
```console
65+
uvx nox -s test
66+
```
6467

65-
This builds the `/.venv`, installs the editable
66-
package, and installs all dependency files.
68+
Passing extra arguements to pytest:
6769

68-
```bash
69-
nox -s dev
70+
```console
71+
uvx nos -s test -- -vvv -x --full-trace
7072
```
7173

72-
### Run tests with coverage
74+
### Run linters
7375

74-
```bash
75-
nox -s test
76+
```console
77+
uvx nox -s lint
7678
```
7779

78-
### Run formatters and linters
80+
### Run formatters
7981

80-
```bash
81-
nox -s lint
82+
```console
83+
uvx nox -s format
84+
```
85+
86+
### Run all checks
87+
88+
```console
89+
uvx nox
8290
```
8391

8492
### Build dist
8593

86-
```bash
87-
nox -s build
94+
```console
95+
uvx nox -s build
8896
```
8997

9098
---
9199

92100
## Updating dependencies
93101

94-
New dependencys can be added to the `requirements-*.txt` file. It is recommended
95-
to only use pins when specific versions or upgrades beyond a certain version are
96-
to be avoided. Otherwise, allow `pip-compile` to manage the pins in the
97-
generated `constraints.txt` file.
98-
99-
Once updated following the steps below, the package can be installed if needed.
102+
New dependencies should be added with the uv cli command `uv add
103+
[package-name]`. This will ensure the `uv.lock` file is updated as well.
100104

101-
### Update the generated files with changes
105+
### Upgrade an existing package to latest
102106

103-
```bash
104-
nox -s update-deps
107+
```console
108+
uvx nox -s upgrade-package -- package-name
105109
```
106110

107-
### Upgrade all generated dependencies
111+
### Upgrade all packages to latest
108112

109-
```bash
110-
nox -s upgrade-deps
113+
```console
114+
uvx nox -s upgrade
111115
```

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[![Python 3.9 | 3.10 | 3.11 | 3.12 | 3.13](https://img.shields.io/badge/Python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue)](https://www.python.org/downloads)
22
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
3+
[![Nox](https://img.shields.io/badge/%F0%9F%A6%8A-Nox-D85E00.svg)](https://github.com/wntrblm/nox)
34

45
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/Preocts/python-src-template/main.svg)](https://results.pre-commit.ci/latest/github/Preocts/python-src-template/main)
56
[![Python tests](https://github.com/Preocts/python-src-template/actions/workflows/python-tests.yml/badge.svg?branch=main)](https://github.com/Preocts/python-src-template/actions/workflows/python-tests.yml)
@@ -11,8 +12,7 @@
1112

1213
---
1314

14-
A template I use for most projects and is setup to jive with my environment at
15-
the company I work with.
15+
A template I use for most projects.
1616

1717
This is not the one-shot solution to project structure or packaging. This is
1818
just what works well for one egg on the Internet. Feel free to use it as you see
@@ -25,14 +25,12 @@ fit.
2525
one-size-fits-most template I've put together. Use what you want how you
2626
want.
2727

28-
- **Q:** Why not put the requirements into the `pyproject.toml`?
29-
- **A:** Mostly because `pip-compile` does all the work for me and doesn't
30-
target the `pyproject.toml` dependency groups yet.
31-
3228
- **Q:** Why does this template change so often?
3329
- **A:** I'm constantly finding new tweaks that make the template fit just a
3430
little better. I'm also open to ideas and suggestions so please drop an
3531
issue if you have one.
3632

37-
- **Q:** Have I heard of uv?
38-
- **A:** Yes. I'm already exploring a uv driven workflow for this template.
33+
- **Q:** Why nox?
34+
- **A:** Duplicatable workflows that are platform agnostic. Whether locally,
35+
in a container, in a github action, or on your machine; there is one
36+
official way workflows are run.

init_template.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
class ProjectData:
3030
name: str = "module-name"
3131
module: str = "module_name"
32-
version: str = "0.1.0"
3332
description: str = "Module Description"
3433
author_email: str = "yourname@email.invalid"
3534
author_name: str = "[YOUR NAME]"

0 commit comments

Comments
 (0)