Skip to content

Commit

Permalink
use pre-commit for ci
Browse files Browse the repository at this point in the history
  • Loading branch information
bjlittle committed Jun 21, 2021
1 parent 0af4113 commit e386d89
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 78 deletions.
8 changes: 3 additions & 5 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,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: "pip setuptools wheel nox"
PIP_CACHE_PACKAGES: "nox pip setuptools wheel"
# Conda packages to be installed.
CONDA_CACHE_PACKAGES: "nox pip"
# Git commit hash for iris test data.
Expand Down Expand Up @@ -116,7 +116,7 @@ lint_task:
image: python:3.8
cpu: 2
memory: 4G
name: "${CIRRUS_OS}: black, flake8 and isort"
name: "${CIRRUS_OS}: linting"
pip_cache:
folder: ~/.cache/pip
fingerprint_script:
Expand All @@ -126,9 +126,7 @@ lint_task:
- pip list
- python -m pip install --retries 3 --upgrade ${PIP_CACHE_PACKAGES}
- pip list
- nox --session black
- nox --session flake8
- nox --session isort
- nox --session lint


#
Expand Down
15 changes: 7 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v4.0.1'
rev: "v4.0.1"
hooks:
# Prevent giant files from being committed.
- id: check-added-large-files
Expand All @@ -17,21 +17,20 @@ repos:
# Don't commit to main branch.
- id: no-commit-to-branch
- repo: https://github.com/psf/black
rev: '21.6b0'
rev: "21.6b0"
hooks:
- id: black
# Force black to run on whole repo, using settings from pyproject.toml
pass_filenames: false
args: [--config=./pyproject.toml, .]
args: ["--config=./pyproject.toml", "--check", "docs", "lib", "noxfile.py", "setup.py"]
- repo: https://github.com/PyCQA/flake8
rev: '3.9.2'
rev: "3.9.2"
hooks:
# Run flake8.
- id: flake8
args: [--config=./setup.cfg]
args: ["--config=./setup.cfg"]
- repo: https://github.com/pycqa/isort
rev: 5.8.0
rev: "5.8.0"
hooks:
- id: isort
name: isort
args: ["--profile", "black", "--filter-files"]
args: ["--filter-files", "--check"]
61 changes: 5 additions & 56 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
#: Default to reusing any pre-existing nox environments.
nox.options.reuse_existing_virtualenvs = True

#: Root directory.
ROOT_DIR = Path(__file__).resolve().parent

#: Name of the package to test.
PACKAGE = str(ROOT_DIR / "lib" / "iris")

#: Cirrus-CI environment variable hook.
PY_VER = os.environ.get("PY_VER", ["3.7", "3.8"])

Expand Down Expand Up @@ -162,49 +156,9 @@ def prepare_venv(session: nox.sessions.Session) -> None:


@nox.session
def flake8(session: nox.sessions.Session):
"""
Perform flake8 linting of iris.
Parameters
----------
session: object
A `nox.sessions.Session` object.
"""
# Pip install the session requirements.
session.install("flake8")
# Execute the flake8 linter on the package.
session.run("flake8", PACKAGE)
# Execute the flake8 linter on root Python files.
for fname in ROOT_DIR.glob("*.py"):
session.run("flake8", str(fname))


@nox.session
def black(session: nox.sessions.Session):
"""
Perform black format checking of iris.
Parameters
----------
session: object
A `nox.sessions.Session` object.
"""
# Pip install the session requirements.
session.install("black==21.5b2")
# Execute the black format checker on the package.
session.run("black", "--check", PACKAGE)
# Execute the black format checker on root Python files.
for fname in ROOT_DIR.glob("*.py"):
session.run("black", "--check", str(fname))


@nox.session
def isort(session: nox.sessions.Session):
def lint(session: nox.sessions.Session):
"""
Perform isort import checking of iris codebase.
Perform pre-commit linting of iris codebase.
Parameters
----------
Expand All @@ -213,14 +167,9 @@ def isort(session: nox.sessions.Session):
"""
# Pip install the session requirements.
session.install("isort")
# Execute the isort import checker on the package.
session.run("isort", "--check", str(PACKAGE))
# Execute the isort import checker on the documentation.
session.run("isort", "--check", str(ROOT_DIR / "docs"))
# Execute the isort import checker on the root Python files.
for fname in ROOT_DIR.glob("*.py"):
session.run("isort", "--check", str(fname))
session.install("pre-commit")
# Execute the pre-commit linting tasks.
session.run("pre-commit", "run", "--all-files")


@nox.session(python=PY_VER, venv_backend="conda")
Expand Down
26 changes: 17 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
[build-system]
# Defined by PEP 518
requires = [
"scitools-pyke",
"setuptools>=40.8.0",
"wheel",
]
# Defined by PEP 517
build-backend = "setuptools.build_meta"


[tool.black]
line-length = 79
target-version = ['py37', 'py38']
Expand Down Expand Up @@ -29,15 +40,6 @@ exclude = '''
)
'''

[build-system]
# Defined by PEP 518
requires = [
"scitools-pyke",
"setuptools>=40.8.0",
"wheel",
]
# Defined by PEP 517
build-backend = "setuptools.build_meta"

[tool.isort]
force_sort_within_sections = "True"
Expand All @@ -53,4 +55,10 @@ extend_skip = [
"tools",
]
skip_gitignore = "True"
src_paths = [
"docs",
"lib",
"noxfile.py",
"setup.py",
]
verbose = "False"

0 comments on commit e386d89

Please sign in to comment.