Skip to content

Commit c4f380d

Browse files
authored
Small updates (#184)
* Udpate .gitignore Simply and clean. Also moving to the default ./venv to ./.venv * Tidy pyproject.toml * Simplify noxfile session names * Update documentation
1 parent 9029316 commit c4f380d

File tree

6 files changed

+50
-48
lines changed

6 files changed

+50
-48
lines changed

.github/workflows/python-tests.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
4848
- name: "Run tests and coverage via nox"
4949
run: |
50-
nox --session tests_with_coverage-${{ matrix.python-version }}
50+
nox --session version_coverage-${{ matrix.python-version }}
5151
5252
- name: "Save coverage artifact"
5353
uses: "actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b"
@@ -82,7 +82,7 @@ jobs:
8282

8383
- name: "Compile coverage data, print report"
8484
run: |
85-
nox --session coverage_combine_and_report
85+
nox --session coverage_combine
8686
export TOTAL=$(python -c "import json;print(json.load(open('coverage.json'))['totals']['percent_covered_display'])")
8787
echo "TOTAL=$TOTAL" >> $GITHUB_ENV
8888
echo "### Total coverage: ${TOTAL}%" >> $GITHUB_STEP_SUMMARY
@@ -105,4 +105,4 @@ jobs:
105105
106106
- name: "Enforce strict type annotations with mypy"
107107
run: |
108-
nox --session mypy_check
108+
nox --session mypy

.gitignore

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
temp_*
2-
.env
3-
venv/
41
*egg-info/
5-
.nox/
6-
.coverage
7-
.coverage.*
8-
coverage.xml
9-
coverage.json
10-
htmlcov/
11-
build/
12-
dist/
13-
__pycache__/
14-
.vscode/
2+
*.pyc
3+
4+
build
5+
dist
6+
7+
.vscode
8+
.nox
9+
htmlcov
10+
.coverage*
11+
coverage.*
12+
13+
.venv*
14+
temp*
15+
.env

CONTRIBUTING.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ the desired version while creating the `venv`. (e.g. `python3` or `python3.12`)
7272
### Create the `venv`:
7373

7474
```console
75-
python -m venv venv
75+
python -m venv .venv
7676
```
7777

7878
Activate the `venv`:
7979

8080
```console
8181
# Linux/Mac
82-
. venv/bin/activate
82+
. .venv/bin/activate
8383

8484
# Windows
85-
venv\Scripts\activate
85+
.venv\Scripts\activate
8686
```
8787

8888
The command prompt should now have a `(venv)` prefix on it. `python` will now

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ fit.
2121
one-size-fits-most template I've put together. Use what you want how you
2222
want.
2323

24-
- **Q:** Why do you hard pin your development and test requirements?
25-
- **A:** For control over the environment used to develop on the package. It
26-
is also beneficial in many of the areas I work where artifactory proxies are
27-
between `pip` and the pypi public index. Versions remaining hard pinned
28-
ensure the package is always cleared for use through the artifactory.
29-
3024
- **Q:** Why not put the requirements into the `pyproject.toml`?
3125
- **A:** Mostly because `pip-compile` does all the work for me and doesn't
3226
target the `pyproject.toml`. Partly because many of my projects need to be
@@ -37,3 +31,10 @@ fit.
3731
- **A:** I'm constantly finding new tweaks that make the template fit just a
3832
little better. I'm also open to ideas and suggestions so please drop an
3933
issue if you have one.
34+
35+
- **Q:** Have I heard of uv?
36+
- **A:** Yes. I'm already exploring a uv driven workflow for this template.
37+
You can see it on the `uv-workflow` branch. I will be waiting until the
38+
April 2025 release of pip for support of
39+
[dependency-groups](https://packaging.python.org/en/latest/specifications/dependency-groups/)
40+
before committing to any changes.

noxfile.py

+17-16
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
COVERAGE_FAIL_UNDER = 50
1414
DEFAULT_PYTHON_VERSION = "3.12"
1515
PYTHON_MATRIX = ["3.9", "3.10", "3.11", "3.12", "3.13"]
16-
VENV_PATH = "venv"
16+
VENV_BACKEND = "venv"
17+
VENV_PATH = ".venv"
1718
REQUIREMENT_IN_FILES = [
1819
pathlib.Path("requirements/requirements.in"),
1920
]
@@ -36,23 +37,23 @@
3637

3738
# Define the default sessions run when `nox` is called on the CLI
3839
nox.options.sessions = [
39-
"tests_with_coverage",
40-
"coverage_combine_and_report",
41-
"mypy_check",
40+
"version_coverage",
41+
"coverage_combine",
42+
"mypy",
4243
]
4344

4445

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

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

5354

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

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

6667

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

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

7677

77-
@nox.session(python=False)
78+
@nox.session(python=False, venv_backend=VENV_BACKEND)
7879
def coverage(session: nox.Session) -> None:
7980
"""Generate a coverage report. Does not use a venv."""
8081
session.run("coverage", "erase")
8182
session.run("coverage", "run", "-m", "pytest", TESTS_PATH)
8283
session.run("coverage", "report", "-m")
8384

8485

85-
@nox.session(python=DEFAULT_PYTHON_VERSION)
86+
@nox.session(python=DEFAULT_PYTHON_VERSION, venv_backend=VENV_BACKEND)
8687
def build(session: nox.Session) -> None:
8788
"""Build distribution files."""
8889
print_standard_logs(session)
@@ -91,7 +92,7 @@ def build(session: nox.Session) -> None:
9192
session.run("python", "-m", "build")
9293

9394

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

118119

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

128129

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

138139

139-
@nox.session(python=False)
140+
@nox.session(python=False, venv_backend=VENV_BACKEND)
140141
def clean(_: nox.Session) -> None:
141142
"""Clean cache, .pyc, .pyo, and test/build artifact files from project."""
142143
count = 0

pyproject.toml

+6-7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ classifiers = [
2121
]
2222
dynamic = ["dependencies", "optional-dependencies", "version"]
2323

24+
[project.urls]
25+
homepage = "https://github.com/[ORG NAME]/[REPO NAME]"
26+
27+
# [project.scripts]
28+
# python-src-example = "module_name.sample:main"
29+
2430
[tool.setuptools_scm]
2531
# Purposely left empty
2632

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

34-
[project.urls]
35-
homepage = "https://github.com/[ORG NAME]/[REPO NAME]"
36-
37-
# CLI scripts if needed
38-
# [project.scripts]
39-
# python-src-example = "module_name.sample:main"
40-
4140
[tool.black]
4241
line-length = 100
4342
target-version = ['py39']

0 commit comments

Comments
 (0)