Skip to content

Commit

Permalink
🚜 Noxifcation and adds pre-commit support (#192)
Browse files Browse the repository at this point in the history
* 🚜 Refactors nox and streamlines pipelines

* ⚙️ Adds pre-commit and lint just command

* ⚙️ Fix ~= handling of the install

* ⚙️ Update actions to support cancel-in-progress

---------

Co-authored-by: Jeffrey Triplett <[email protected]>
  • Loading branch information
jefftriplett and Jeffrey Triplett authored Sep 28, 2023
1 parent 8ad1fd8 commit 6dee914
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 12 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
branches:
- main

concurrency:
group: test-${{ github.head_ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
Expand All @@ -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
Expand Down
47 changes: 47 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 12 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
29 changes: 23 additions & 6 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ zip_safe = False
tests_require = django-friendship[test]

[options.extras_require]
lint =
pre-commit
test =
black
pytest
Expand Down

0 comments on commit 6dee914

Please sign in to comment.