Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

- name: "Run tests and coverage via nox"
run: |
nox --session tests_with_coverage-${{ matrix.python-version }}
nox --session version_coverage-${{ matrix.python-version }}

- name: "Save coverage artifact"
uses: "actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b"
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:

- name: "Compile coverage data, print report"
run: |
nox --session coverage_combine_and_report
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
Expand All @@ -105,4 +105,4 @@ jobs:

- name: "Enforce strict type annotations with mypy"
run: |
nox --session mypy_check
nox --session mypy
27 changes: 14 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
temp_*
.env
venv/
*egg-info/
.nox/
.coverage
.coverage.*
coverage.xml
coverage.json
htmlcov/
build/
dist/
__pycache__/
.vscode/
*.pyc

build
dist

.vscode
.nox
htmlcov
.coverage*
coverage.*

.venv*
temp*
.env
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ the desired version while creating the `venv`. (e.g. `python3` or `python3.12`)
### Create the `venv`:

```console
python -m venv venv
python -m venv .venv
```

Activate the `venv`:

```console
# Linux/Mac
. venv/bin/activate
. .venv/bin/activate

# Windows
venv\Scripts\activate
.venv\Scripts\activate
```

The command prompt should now have a `(venv)` prefix on it. `python` will now
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ fit.
one-size-fits-most template I've put together. Use what you want how you
want.

- **Q:** Why do you hard pin your development and test requirements?
- **A:** For control over the environment used to develop on the package. It
is also beneficial in many of the areas I work where artifactory proxies are
between `pip` and the pypi public index. Versions remaining hard pinned
ensure the package is always cleared for use through the artifactory.

- **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`. Partly because many of my projects need to be
Expand All @@ -37,3 +31,10 @@ fit.
- **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.
You can see it on the `uv-workflow` branch. I will be waiting until the
April 2025 release of pip for support of
[dependency-groups](https://packaging.python.org/en/latest/specifications/dependency-groups/)
before committing to any changes.
33 changes: 17 additions & 16 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
COVERAGE_FAIL_UNDER = 50
DEFAULT_PYTHON_VERSION = "3.12"
PYTHON_MATRIX = ["3.9", "3.10", "3.11", "3.12", "3.13"]
VENV_PATH = "venv"
VENV_BACKEND = "venv"
VENV_PATH = ".venv"
REQUIREMENT_IN_FILES = [
pathlib.Path("requirements/requirements.in"),
]
Expand All @@ -36,23 +37,23 @@

# Define the default sessions run when `nox` is called on the CLI
nox.options.sessions = [
"tests_with_coverage",
"coverage_combine_and_report",
"mypy_check",
"version_coverage",
"coverage_combine",
"mypy",
]


@nox.session(python=PYTHON_MATRIX)
def tests_with_coverage(session: nox.Session) -> None:
@nox.session(python=PYTHON_MATRIX, venv_backend=VENV_BACKEND)
def version_coverage(session: nox.Session) -> None:
"""Run unit tests with coverage saved to partial file."""
print_standard_logs(session)

session.install(".[test]")
session.run("coverage", "run", "-p", "-m", "pytest", TESTS_PATH)


@nox.session(python=DEFAULT_PYTHON_VERSION)
def coverage_combine_and_report(session: nox.Session) -> None:
@nox.session(python=DEFAULT_PYTHON_VERSION, venv_backend=VENV_BACKEND)
def coverage_combine(session: nox.Session) -> None:
"""Combine all coverage partial files and generate JSON report."""
print_standard_logs(session)

Expand All @@ -64,8 +65,8 @@ def coverage_combine_and_report(session: nox.Session) -> None:
session.run("python", "-m", "coverage", "json")


@nox.session(python=DEFAULT_PYTHON_VERSION)
def mypy_check(session: nox.Session) -> None:
@nox.session(python=DEFAULT_PYTHON_VERSION, venv_backend=VENV_BACKEND)
def mypy(session: nox.Session) -> None:
"""Run mypy against package and all required dependencies."""
print_standard_logs(session)

Expand All @@ -74,15 +75,15 @@ def mypy_check(session: nox.Session) -> None:
session.run("mypy", "-p", MODULE_NAME, "--no-incremental")


@nox.session(python=False)
@nox.session(python=False, venv_backend=VENV_BACKEND)
def coverage(session: nox.Session) -> None:
"""Generate a coverage report. Does not use a venv."""
session.run("coverage", "erase")
session.run("coverage", "run", "-m", "pytest", TESTS_PATH)
session.run("coverage", "report", "-m")


@nox.session(python=DEFAULT_PYTHON_VERSION)
@nox.session(python=DEFAULT_PYTHON_VERSION, venv_backend=VENV_BACKEND)
def build(session: nox.Session) -> None:
"""Build distribution files."""
print_standard_logs(session)
Expand All @@ -91,7 +92,7 @@ def build(session: nox.Session) -> None:
session.run("python", "-m", "build")


@nox.session(python=False)
@nox.session(python=False, venv_backend=VENV_BACKEND)
def install(session: nox.Session) -> None:
"""Setup a development environment. Uses active venv if available, builds one if not."""
# Use the active environement if it exists, otherwise create a new one
Expand All @@ -116,7 +117,7 @@ def install(session: nox.Session) -> None:
session.log(f"\n\nRun '{activate_command}' to enter the virtual environment.\n")


@nox.session(python=DEFAULT_PYTHON_VERSION)
@nox.session(python=DEFAULT_PYTHON_VERSION, venv_backend=VENV_BACKEND)
def update(session: nox.Session) -> None:
"""Process requirement*.in files, updating only additions/removals."""
print_standard_logs(session)
Expand All @@ -126,7 +127,7 @@ def update(session: nox.Session) -> None:
session.run("pip-compile", "--no-emit-index-url", str(filename))


@nox.session(python=DEFAULT_PYTHON_VERSION)
@nox.session(python=DEFAULT_PYTHON_VERSION, venv_backend=VENV_BACKEND)
def upgrade(session: nox.Session) -> None:
"""Process requirement*.in files and upgrade all libraries as possible."""
print_standard_logs(session)
Expand All @@ -136,7 +137,7 @@ def upgrade(session: nox.Session) -> None:
session.run("pip-compile", "--no-emit-index-url", "--upgrade", str(filename))


@nox.session(python=False)
@nox.session(python=False, venv_backend=VENV_BACKEND)
def clean(_: nox.Session) -> None:
"""Clean cache, .pyc, .pyo, and test/build artifact files from project."""
count = 0
Expand Down
13 changes: 6 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ classifiers = [
]
dynamic = ["dependencies", "optional-dependencies", "version"]

[project.urls]
homepage = "https://github.com/[ORG NAME]/[REPO NAME]"

# [project.scripts]
# python-src-example = "module_name.sample:main"

[tool.setuptools_scm]
# Purposely left empty

Expand All @@ -31,13 +37,6 @@ file = ["requirements/requirements.txt"]
dev = { file = ["requirements/requirements-dev.txt"] }
test = { file = ["requirements/requirements-test.txt"] }

[project.urls]
homepage = "https://github.com/[ORG NAME]/[REPO NAME]"

# CLI scripts if needed
# [project.scripts]
# python-src-example = "module_name.sample:main"

[tool.black]
line-length = 100
target-version = ['py39']
Expand Down