From 5bf28b71124f6e6a9aa1f07420f3560363cb4be1 Mon Sep 17 00:00:00 2001 From: Preocts Date: Fri, 30 May 2025 02:41:38 -0400 Subject: [PATCH 1/4] Create lint session for nox Move black, flake8, and isort actions into the `noxfile.py` alongside the existing mypy session. This will give the dev control over when these checks are run, allowing pre-commit to be optional in the local environment. There is a speed drawback as pre-commit runs on edited files only and nox will run on all file. The pre-commit config will remain and is always an option locally and in pre-commit.ci. --- noxfile.py | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/noxfile.py b/noxfile.py index 658df4c..2e191af 100644 --- a/noxfile.py +++ b/noxfile.py @@ -13,7 +13,8 @@ TESTS_PATH = "tests" COVERAGE_FAIL_UNDER = 50 DEFAULT_PYTHON = "3.12" -VENV_PATH = ".venv" +VENV_PATH = "./.venv" +LINT_PATH = "./src" REQUIREMENTS_PATH = "./requirements" # What we allowed to clean (delete) @@ -33,10 +34,7 @@ # Define the default sessions run when `nox` is called on the CLI nox.options.default_venv_backend = "virtualenv" -nox.options.sessions = [ - "test", - "mypy", -] +nox.options.sessions = ["lint", "test"] @nox.session(python=False) @@ -104,15 +102,30 @@ def coverage_combine(session: nox.Session) -> None: coverage("json") -@nox.session(python=DEFAULT_PYTHON) -def mypy(session: nox.Session) -> None: - """Run mypy against package and all required dependencies.""" +@nox.session(name="lint") +def run_linters_and_formatters(session: nox.Session) -> None: + """Run code formatters, linters, and type checking against all files.""" print_standard_logs(session) - session.install(".") - session.install("-r", "requirements/requirements.txt") - session.install("-r", "requirements/requirements-dev.txt") - session.run("mypy", "-p", MODULE_NAME, "--no-incremental") + session.install(".", "-r", f"{REQUIREMENTS_PATH}/requirements-dev.txt") + + python = partial(session.run, "python", "-m") + + # Handle anything tool that applies corrections first. + python( + "isort", + "--force-single-line-imports", + "--profile", + "black", + "--add-import", + "from __future__ import annotations", + LINT_PATH, + ) + python("black", "--verbose", LINT_PATH) + + # Linters: aka, things that yell but want you to fix things + python("flake8", "--show-source", "--verbose", LINT_PATH) + python("mypy", "--no-incremental", "--package", MODULE_NAME) @nox.session(python=DEFAULT_PYTHON) From 4b6c8828de23fe84353940743e0e45e3e972ff46 Mon Sep 17 00:00:00 2001 From: Preocts Date: Fri, 30 May 2025 02:45:31 -0400 Subject: [PATCH 2/4] Update CI to use nox lint session --- .github/workflows/python-tests.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 4aeed51..6bfe283 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -87,8 +87,8 @@ jobs: echo "TOTAL=$TOTAL" >> $GITHUB_ENV echo "### Total coverage: ${TOTAL}%" >> $GITHUB_STEP_SUMMARY - mypy-check: - name: "mypy strict enforcement" + linting: + name: "Check linting and formatting requirements" runs-on: "ubuntu-latest" steps: - name: "Repo checkout" @@ -101,8 +101,8 @@ jobs: - name: "Install nox" run: | - python -m pip install --upgrade pip nox + python -m pip install --upgrade nox - - name: "Enforce strict type annotations with mypy" + - name: "Run formatters and linters" run: | - nox --session mypy + nox --session lint From c65c64203cbc26f9fb735a7f648dfb8a6dc485b5 Mon Sep 17 00:00:00 2001 From: Preocts Date: Fri, 30 May 2025 02:45:52 -0400 Subject: [PATCH 3/4] Remove black config --- pyproject.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2ac4a93..c5a51de 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,10 +30,6 @@ homepage = "https://github.com/[ORG NAME]/[REPO NAME]" [tool.setuptools_scm] # Purposely left empty -[tool.black] -line-length = 100 -target-version = ['py39'] - [tool.setuptools.package-data] "module_name" = ["py.typed"] From cc8520e295e43c9742421c97d88672d995cfc765 Mon Sep 17 00:00:00 2001 From: Preocts Date: Fri, 30 May 2025 02:51:11 -0400 Subject: [PATCH 4/4] Add verbose flag to isort run --- noxfile.py | 1 + 1 file changed, 1 insertion(+) diff --git a/noxfile.py b/noxfile.py index 2e191af..85c5963 100644 --- a/noxfile.py +++ b/noxfile.py @@ -114,6 +114,7 @@ def run_linters_and_formatters(session: nox.Session) -> None: # Handle anything tool that applies corrections first. python( "isort", + "--verbose", "--force-single-line-imports", "--profile", "black",