Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8ce63e8
remove external requirement files
Preocts Aug 9, 2025
be56f5b
update project metadata
Preocts Aug 9, 2025
d0db51f
Remove unused samples
Preocts Aug 9, 2025
d6e29b1
Rewrite noxfile for uv workflow
Preocts Aug 9, 2025
374327b
pin python version for uv config
Preocts Aug 9, 2025
6b84026
create uv.lock file
Preocts Aug 9, 2025
1bba75d
Update github actions workflow
Preocts Aug 9, 2025
4e82697
Correct copy paste error
Preocts Aug 9, 2025
e7657e6
Use uvx in actions instead of uv run
Preocts Aug 9, 2025
c619129
noxfile enforces frozen lockfile
Preocts Aug 9, 2025
ff4e904
checkout repo for file reading
Preocts Aug 9, 2025
33bbd50
output a json report with the html
Preocts Aug 9, 2025
4dd2eb3
Ensure steps wait for settings to be completed
Preocts Aug 9, 2025
ffad9cc
Update development setup for uv
Preocts Aug 9, 2025
e145e28
update FAQ
Preocts Aug 9, 2025
117217b
Split linter and formatter groups
Preocts Aug 9, 2025
698eb90
Split linting and formatting sessions
Preocts Aug 9, 2025
1b01938
Remove verbose from formatters and linters
Preocts Aug 9, 2025
c4e4156
Do not install all groups for dev environ
Preocts Aug 9, 2025
065e77c
Don't build python sessions
Preocts Aug 9, 2025
b6d097c
Replace requests with httpx
Preocts Aug 9, 2025
ab9fc4d
Remove tool group
Preocts Aug 9, 2025
ae4eb89
extract common sync args
Preocts Aug 9, 2025
71bdd40
Use hatch backend and dynamic versioning
Preocts Aug 9, 2025
4b596d4
Allow mypy to use incremental cache
Preocts Aug 9, 2025
7c46836
adjust greedy ignore
Preocts Aug 9, 2025
2cf139e
Remove version from init values
Preocts Aug 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 50 additions & 35 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: "python tests and coverage"
# Uses:
# https://github.com/actions/setup-python : a26af69be951a213d495a4c3e4e4022e16d87065
# https://github.com/actions/checkout : 11bd71901bbe5b1630ceea73d27597364c9af683
# https://github.com/actions/download-artifact : d3f86a106a0bac45b974a628896c90dbdf5c8093
# https://github.com/actions/upload-artifact : ea165f8d65b6e75b540449e92b4886f43607fa02
# https://github.com/actions/setup-python : v5.6.0 a26af69be951a213d495a4c3e4e4022e16d87065
# https://github.com/actions/checkout : v4.2.2 11bd71901bbe5b1630ceea73d27597364c9af683
# https://github.com/actions/download-artifact : v5.0.0 634f93cb2916e3fdff6788551b99b062d0335ce0
# https://github.com/actions/upload-artifact : v4.6.2 ea165f8d65b6e75b540449e92b4886f43607fa02
# https://github.com/astral-sh/setup-uv : v6.4.3 e92bafb6253dcd438e0484186d7669ea7a8ca1cc

on:
pull_request:
Expand All @@ -13,26 +14,31 @@ on:
branches:
- "main"

env:
UV_PYTHON_PREFERENCE: "only-system"

jobs:
settings:
runs-on: "ubuntu-latest"
name: "Define workflow settings"
outputs:
default-python-version: "3.12"
steps:
- name: "Repo checkout"
uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683"

- name: "Define settings"
run: ""
run: |
echo "python_version=$(<.python-version)" >> $GITHUB_OUTPUT

run-tests-and-coverage:
name: "Run pytest with coverage."
needs: ["settings"]
name: "Run nox for tests and coverage"
needs: "settings"
runs-on: "${{ matrix.os }}"
strategy:
fail-fast: false
matrix:
os:
- "macos-latest"
- "windows-latest"
# - "macos-latest"
# - "windows-latest"
- "ubuntu-latest"
python-version:
- "3.9"
Expand All @@ -52,13 +58,15 @@ jobs:
python-version: "${{ matrix.python-version }}"
allow-prereleases: true

- name: "Install nox"
run: |
python -m pip install --upgrade nox
- name: "Install the latest version of uv"
uses: "astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc"
with:
version: "latest"
python-version: "${{ matrix.python-version }}"
enable-cache: true

- name: "Run tests and coverage via nox"
run: |
nox --session test -- partial-coverage
run: "uvx nox --session test -- partial-coverage no-config"

- name: "Save coverage artifact"
uses: "actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02"
Expand All @@ -69,8 +77,8 @@ jobs:
include-hidden-files: true

coverage-compile:
name: "Compile coverage reports."
needs: ["settings", "run-tests-and-coverage"]
name: "coverage compile"
needs: "run-tests-and-coverage"
runs-on: "ubuntu-latest"
steps:
- name: "Repo checkout"
Expand All @@ -79,28 +87,33 @@ jobs:
- name: "Set up Python"
uses: "actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065"
with:
python-version: "${{ needs.settings.outputs.default-python-version }}"
python-version: ${{ steps.settings.outputs.python_version }}

- name: "Install nox"
run: |
python -m pip install --upgrade nox
- name: "Install the latest version of uv"
uses: "astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc"
with:
version: "latest"
python-version: ${{ steps.settings.outputs.python_version }}
enable-cache: true

- name: "Download coverage artifacts"
uses: "actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093"
uses: "actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0"
with:
pattern: "coverage-artifact-*"
merge-multiple: true

- name: "Compile coverage data, print report"
- name: "Compile coverage data"
run: "uvx nox --session combine"

- name: "Post summary to step summary."
run: |
nox --session coverage_combine
export TOTAL=$(python -c "import json;print(json.load(open('coverage.json'))['totals']['percent_covered_display'])")
echo "TOTAL=$TOTAL" >> $GITHUB_ENV
echo "### Total coverage: ${TOTAL}%" >> $GITHUB_STEP_SUMMARY

linting:
name: "Check linting and formatting requirements"
needs: ["settings"]
linters-and-formatters:
name: "linters and formattrs"
needs: "settings"
runs-on: "ubuntu-latest"
steps:
- name: "Repo checkout"
Expand All @@ -109,12 +122,14 @@ jobs:
- name: "Set up Python"
uses: "actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065"
with:
python-version: "${{ needs.settings.outputs.default-python-version }}"
python-version: ${{ steps.settings.outputs.python_version }}

- name: "Install nox"
run: |
python -m pip install --upgrade nox
- name: "Install the latest version of uv"
uses: "astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc"
with:
version: "latest"
python-version: ${{ steps.settings.outputs.python_version }}
enable-cache: true

- name: "Run formatters and linters"
run: |
nox --session lint
- name: "Enforce strict type annotations with mypy"
run: "uvx nox --session lint"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ htmlcov
coverage.*

.venv*
temp*
temp_*
.env
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9
76 changes: 40 additions & 36 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,70 +42,74 @@ The following steps outline how to install this repo for local development.

## Prerequisites

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

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

cd [REPO NAME]
```
## Nox Sessions

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

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

```console
uvx nox -s dev
```

## Nox Sessions
### Run tests and display coverage

### Developer Install
```console
uvx nox -s test
```

This builds the `/.venv`, installs the editable
package, and installs all dependency files.
Passing extra arguements to pytest:

```bash
nox -s dev
```console
uvx nos -s test -- -vvv -x --full-trace
```

### Run tests with coverage
### Run linters

```bash
nox -s test
```console
uvx nox -s lint
```

### Run formatters and linters
### Run formatters

```bash
nox -s lint
```console
uvx nox -s format
```

### Run all checks

```console
uvx nox
```

### Build dist

```bash
nox -s build
```console
uvx nox -s build
```

---

## Updating dependencies

New dependencys can be added to the `requirements-*.txt` file. It is recommended
to only use pins when specific versions or upgrades beyond a certain version are
to be avoided. Otherwise, allow `pip-compile` to manage the pins in the
generated `constraints.txt` file.

Once updated following the steps below, the package can be installed if needed.
New dependencies should be added with the uv cli command `uv add
[package-name]`. This will ensure the `uv.lock` file is updated as well.

### Update the generated files with changes
### Upgrade an existing package to latest

```bash
nox -s update-deps
```console
uvx nox -s upgrade-package -- package-name
```

### Upgrade all generated dependencies
### Upgrade all packages to latest

```bash
nox -s upgrade-deps
```console
uvx nox -s upgrade
```
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![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)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Nox](https://img.shields.io/badge/%F0%9F%A6%8A-Nox-D85E00.svg)](https://github.com/wntrblm/nox)

[![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)
[![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)
Expand All @@ -11,8 +12,7 @@

---

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

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

- **Q:** Why not put the requirements into the `pyproject.toml`?
- **A:** Mostly because `pip-compile` does all the work for me and doesn't
target the `pyproject.toml` dependency groups yet.

- **Q:** Why does this template change so often?
- **A:** I'm constantly finding new tweaks that make the template fit just a
little better. I'm also open to ideas and suggestions so please drop an
issue if you have one.

- **Q:** Have I heard of uv?
- **A:** Yes. I'm already exploring a uv driven workflow for this template.
- **Q:** Why nox?
- **A:** Duplicatable workflows that are platform agnostic. Whether locally,
in a container, in a github action, or on your machine; there is one
official way workflows are run.
1 change: 0 additions & 1 deletion init_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
class ProjectData:
name: str = "module-name"
module: str = "module_name"
version: str = "0.1.0"
description: str = "Module Description"
author_email: str = "yourname@email.invalid"
author_name: str = "[YOUR NAME]"
Expand Down
Loading