Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ env:
# Increment the build number to force new pip cache upload.
PIP_CACHE_BUILD: "0"
# Pip packages to be upgraded/installed.
PIP_CACHE_PACKAGES: "nox pip setuptools wheel"
PIP_CACHE_PACKAGES: "nox pip pyyaml setuptools wheel"
# Conda packages to be installed.
CONDA_CACHE_PACKAGES: "nox pip"
# Git commit hash for iris test data.
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ repos:
hooks:
- id: black
pass_filenames: false
args: [--config=./pyproject.toml, --check, .]
args: [--config=./pyproject.toml, .]

- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
Expand All @@ -46,7 +46,7 @@ repos:
hooks:
- id: isort
types: [file, python]
args: [--filter-files, --check]
args: [--filter-files]

- repo: https://github.com/asottile/blacken-docs
rev: v1.10.0
Expand Down
31 changes: 27 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import hashlib
import os
from pathlib import Path
from tempfile import NamedTemporaryFile
from urllib.parse import unquote, urlsplit

import nox
from nox.logger import logger
Expand Down Expand Up @@ -173,13 +175,34 @@ def lint(session: nox.sessions.Session):
A `nox.sessions.Session` object.

"""
import yaml

# Pip install the session requirements.
session.install("pre-commit")
# Execute the pre-commit linting tasks.
cmd = ["pre-commit", "run", "--all-files"]
hooks = ["black", "blacken-docs", "flake8", "isort"]

# Load the pre-commit configuration YAML file.
with open(".pre-commit-config.yaml", "r") as fi:
config = yaml.load(fi, Loader=yaml.FullLoader)

# Ensure black and isort only perform a status check
# with a custom pre-commit configuration.
hooks = []
for entry in config["repos"]:
hook = Path(urlsplit(unquote(entry["repo"])).path).name
hooks.append(hook)
if hook in ["black", "isort"]:
# Enforce a "--check" for the hook.
entry["hooks"][0]["args"].insert(0, "--check")

with NamedTemporaryFile(mode="w+t", delete=False) as temp:
yaml.dump(config, temp)

# Execute the pre-commit linting tasks with the custom
# pre-commit configuration.
cmd = ["pre-commit", "run", "--all-files", f"--config={temp.name}"]
for hook in hooks:
session.run(*cmd, hook)
if hook != "pre-commit-hooks":
session.run(*cmd, hook)


@nox.session(python=PY_VER, venv_backend="conda")
Expand Down