Skip to content

Commit

Permalink
drop black and flake8 dependencies (#4181)
Browse files Browse the repository at this point in the history
* drop black and flake8 dependencies

* use pre-commit for ci

* added additional whatsnew entry

* review actions

* review actions - align hooks cli
  • Loading branch information
bjlittle authored Jun 22, 2021
1 parent 1572e18 commit af13e14
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 87 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
18 changes: 9 additions & 9 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,24 +17,24 @@ 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", "docs", "lib", "noxfile.py", "setup.py"]
- repo: https://github.com/pycqa/isort
rev: 5.9.1
rev: "5.9.1"
hooks:
- id: isort
# Align CLI usage with other hooks, rather than use isort "src_paths" option
# in the pyproject.toml configuration.
name: isort
args: ["--filter-files"]
args: ["--filter-files", "--check", "docs", "lib", "noxfile.py", "setup.py"]
- repo: https://github.com/asottile/blacken-docs
rev: v1.8.0
hooks:
Expand Down
7 changes: 5 additions & 2 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ This document explains the changes made to Iris for this release
🔗 Dependencies
===============

#. N/A
#. `@bjlittle`_ dropped both `black`_ and `flake8`_ package dependencies
from our `conda`_ YAML and ``setup.cfg`` PyPI requirements. (:pull:`4181`)


📚 Documentation
Expand Down Expand Up @@ -128,7 +129,6 @@ This document explains the changes made to Iris for this release
they render better in the published documentation. See :issue:`4085`.
(:pull:`4100`)


💼 Internal
===========

Expand Down Expand Up @@ -187,6 +187,9 @@ This document explains the changes made to Iris for this release
#. `@bjlittle`_ added the `blacken-docs`_ ``pre-commit`` hook to automate
``black`` linting of documentation code blocks. (:pull:`4205`)

#. `@bjlittle`_ consolidated `nox`_ ``black``, ``flake8`` and ``isort`` sessions
into one ``lint`` session using ``pre-commit``. (:pull:`4181`)

.. comment
Whatsnew author names (@github name) in alphabetical order. Note that,
core dev names are automatically included by the common_links.inc:
Expand Down
64 changes: 8 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,12 @@ 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.
cmd = ["pre-commit", "run", "--all-files"]
hooks = ["black", "blacken-docs", "flake8", "isort"]
for hook in hooks:
session.run(*cmd, hook)


@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"
2 changes: 0 additions & 2 deletions requirements/ci/py37.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ dependencies:

# Test dependencies.
- asv
- black=21.5b2
- filelock
- flake8
- imagehash>=4.0
- nose
- pillow<7
Expand Down
2 changes: 0 additions & 2 deletions requirements/ci/py38.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ dependencies:

# Test dependencies.
- asv
- black=21.5b2
- filelock
- flake8
- imagehash>=4.0
- nose
- pillow<7
Expand Down
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ docs =
sphinx-panels
test =
asv
black==21.5b2
filelock
flake8
imagehash>=4.0
nose
pillow<7
Expand Down

0 comments on commit af13e14

Please sign in to comment.