From 8dfa7134d14a5d7964fd096839094b14a2c7ff61 Mon Sep 17 00:00:00 2001 From: Preocts Date: Fri, 28 Feb 2025 01:27:21 -0500 Subject: [PATCH 1/4] Udpate .gitignore Simply and clean. Also moving to the default ./venv to ./.venv --- .gitignore | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 0f91802..e448f26 100644 --- a/.gitignore +++ b/.gitignore @@ -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 From 6957a5240029e1233b4d3763bdc9bff3cc4d055d Mon Sep 17 00:00:00 2001 From: Preocts Date: Fri, 28 Feb 2025 01:30:23 -0500 Subject: [PATCH 2/4] Tidy pyproject.toml --- pyproject.toml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2fd37ca..f8487b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 @@ -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'] From 4891c4f31a71c8a24439b8b7831af08e4ae5188c Mon Sep 17 00:00:00 2001 From: Preocts Date: Fri, 28 Feb 2025 02:00:13 -0500 Subject: [PATCH 3/4] Simplify noxfile session names --- .github/workflows/python-tests.yml | 6 +++--- noxfile.py | 33 +++++++++++++++--------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 20e7924..890e754 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -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" @@ -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 @@ -105,4 +105,4 @@ jobs: - name: "Enforce strict type annotations with mypy" run: | - nox --session mypy_check + nox --session mypy diff --git a/noxfile.py b/noxfile.py index f9088a7..e5224c5 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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"), ] @@ -36,14 +37,14 @@ # 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) @@ -51,8 +52,8 @@ def tests_with_coverage(session: nox.Session) -> None: 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) @@ -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) @@ -74,7 +75,7 @@ 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") @@ -82,7 +83,7 @@ def coverage(session: nox.Session) -> None: 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) @@ -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 @@ -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) @@ -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) @@ -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 From 02f05a5a65cb23586cc07f054128c23be5c4b905 Mon Sep 17 00:00:00 2001 From: Preocts Date: Fri, 28 Feb 2025 02:16:57 -0500 Subject: [PATCH 4/4] Update documentation --- CONTRIBUTING.md | 6 +++--- README.md | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b3083c4..e5392e6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/README.md b/README.md index 40312e7..5352c56 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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.