From 6dee914002666c847aa667f0f07afd418543ca7e Mon Sep 17 00:00:00 2001 From: Jeff Triplett Date: Thu, 28 Sep 2023 08:28:23 -0500 Subject: [PATCH] :tractor: Noxifcation and adds pre-commit support (#192) * :tractor: Refactors nox and streamlines pipelines * :gear: Adds pre-commit and lint just command * :gear: Fix ~= handling of the install * :gear: Update actions to support cancel-in-progress --------- Co-authored-by: Jeffrey Triplett --- .github/workflows/actions.yml | 8 +++--- .pre-commit-config.yaml | 47 +++++++++++++++++++++++++++++++++++ justfile | 15 ++++++++--- noxfile.py | 29 ++++++++++++++++----- setup.cfg | 2 ++ 5 files changed, 89 insertions(+), 12 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 1ba3540..6dddc93 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -6,6 +6,10 @@ on: branches: - main +concurrency: + group: test-${{ github.head_ref }} + cancel-in-progress: true + jobs: test: runs-on: ubuntu-latest @@ -24,9 +28,7 @@ jobs: - "3.11" steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 1 + - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v4 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..1c7c5c3 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,47 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-json + - id: check-merge-conflict + - id: check-symlinks + - id: check-toml + - id: check-yaml + - id: end-of-file-fixer + alias: autoformat + - id: trailing-whitespace + alias: autoformat +- repo: https://github.com/asottile/pyupgrade + rev: v3.13.0 + hooks: + - id: pyupgrade + args: [--py36-plus] +- repo: https://github.com/psf/black + rev: 23.9.1 + hooks: + - id: black + args: [ + "." + ] + alias: autoformat + additional_dependencies: ['click==8.0.4'] +- repo: https://github.com/asottile/blacken-docs + rev: 1.16.0 + hooks: + - id: blacken-docs + alias: autoformat + additional_dependencies: ['black==22.1.0', 'click==8.0.4'] +- repo: https://github.com/charliermarsh/ruff-pre-commit + # Ruff version. + rev: 'v0.0.291' + hooks: + - id: ruff + # Respect `exclude` and `extend-exclude` settings. + args: + - "--fix" + exclude: /migrations/ + alias: autoformat diff --git a/justfile b/justfile index c1acdc1..035581c 100644 --- a/justfile +++ b/justfile @@ -5,13 +5,22 @@ just --fmt --unstable @nox *ARGS: - nox --no-install --reuse-existing-virtualenvs {{ ARGS }} + python -m nox --no-install --reuse-existing-virtualenvs {{ ARGS }} @pip-compile: - pip-compile --resolver=backtracking + python -m piptools compile --resolver=backtracking @pre-commit: git ls-files -- . | xargs pre-commit run --config=.pre-commit-config.yaml --files @test *ARGS: - nox --reuse-existing-virtualenvs {{ ARGS }} + python -m nox --reuse-existing-virtualenvs \ + --session "test_django_version" \ + {{ ARGS }} + + python -m nox --reuse-existing-virtualenvs \ + --session "test_python_version" \ + {{ ARGS }} + +lint: + python -m nox --reuse-existing-virtualenvs --session "lint" diff --git a/noxfile.py b/noxfile.py index 00f7ecf..953c16c 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,29 +1,46 @@ import nox +# DJANGO_STABLE_VERSION should be set to the latest Django LTS version +# and should *not* appear in DJANGO_VERSIONS -DJANGO_STABLE_VERSION = ["4.2"] +DJANGO_STABLE_VERSION = "4.2" DJANGO_VERSIONS = ["3.2", "4.1", "main"] -PYTHON_STABLE_VERSION = ["3.11"] +# PYTHON_STABLE_VERSION should be set to the latest stable Python version +# and should *not* appear in PYTHON_VERSIONS + +PYTHON_STABLE_VERSION = "3.11" PYTHON_VERSIONS = ["3.8", "3.9", "3.10"] -@nox.session(python=PYTHON_STABLE_VERSION, tags=["django"]) +@nox.session +def lint(session): + session.install(".[lint]") + session.run("python", "-m", "pre_commit", "run", "--all-files") + + +@nox.session(python=[PYTHON_STABLE_VERSION], tags=["django"]) @nox.parametrize("django", DJANGO_VERSIONS) def test_django_version(session: nox.Session, django: str) -> None: + if django == DJANGO_STABLE_VERSION: + session.skip() + session.install(".[test]") if django == "main": session.install("https://github.com/django/django/archive/refs/heads/main.zip") else: - session.install(f"django~={django}") + session.install(f"django~={django}.0") session.run("pytest", *session.posargs) @nox.session(python=PYTHON_VERSIONS, tags=["python"]) -@nox.parametrize("django", DJANGO_STABLE_VERSION) +@nox.parametrize("django", [DJANGO_STABLE_VERSION]) def test_python_version(session: nox.Session, django: str) -> None: + if session.python == PYTHON_STABLE_VERSION: + session.skip() + session.install(".[test]") - session.install(f"django~={django}") + session.install(f"django~={django}.0") session.run("pytest", *session.posargs) diff --git a/setup.cfg b/setup.cfg index 2ba4939..732ed3d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -36,6 +36,8 @@ zip_safe = False tests_require = django-friendship[test] [options.extras_require] +lint = + pre-commit test = black pytest