From 9a064854b8b65aaa3a9f61944c9d80bf0d2c99ca Mon Sep 17 00:00:00 2001 From: Bill Little Date: Thu, 24 Jun 2021 15:24:38 +0100 Subject: [PATCH] optimise pre-commit (#4208) --- .pre-commit-config.yaml | 34 ++++++++++++++++++++++---------- lib/iris/tests/test_std_names.py | 23 +++++++++++++++------ pyproject.toml | 28 +++----------------------- 3 files changed, 44 insertions(+), 41 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 846b833241..bce7091376 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,8 +1,18 @@ # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks + +files: | + (?x)( + noxfile\.py| + setup\.py| + docs\/.+\.py| + lib\/.+\.py + ) +minimum_pre_commit_version: 1.21.0 + 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 @@ -16,27 +26,31 @@ repos: - id: debug-statements # 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 pass_filenames: false - args: ["--config=./pyproject.toml", "--check", "docs", "lib", "noxfile.py", "setup.py"] + args: [--config=./pyproject.toml, --check, .] + - repo: https://github.com/PyCQA/flake8 - rev: "3.9.2" + rev: 3.9.2 hooks: - id: flake8 - args: ["--config=./setup.cfg", "docs", "lib", "noxfile.py", "setup.py"] + types: [file, python] + args: [--config=./setup.cfg] + - 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", "--check", "docs", "lib", "noxfile.py", "setup.py"] + types: [file, python] + args: [--filter-files, --check] + - repo: https://github.com/asottile/blacken-docs rev: v1.8.0 hooks: - id: blacken-docs + types: [file, rst] additional_dependencies: [black==21.6b0] diff --git a/lib/iris/tests/test_std_names.py b/lib/iris/tests/test_std_names.py index 3321fd7708..2093d14bf8 100644 --- a/lib/iris/tests/test_std_names.py +++ b/lib/iris/tests/test_std_names.py @@ -26,14 +26,25 @@ def test_standard_names(self): # Check for some known standard names valid_nameset = set(["air_density", "northward_wind", "wind_speed"]) - self.assertTrue(valid_nameset.issubset(keyset), "Known standard name missing from STD_NAMES") + self.assertTrue( + valid_nameset.issubset(keyset), + "Known standard name missing from STD_NAMES", + ) # Check for some invalid standard names - invalid_nameset = set(["invalid_air_density", "invalid_northward_wind", - "invalid_wind_speed", - "stratiform_snowfall_rate"]) - self.assertSetEqual(invalid_nameset - keyset, invalid_nameset, - "\nInvalid standard name(s) present in STD_NAMES") + invalid_nameset = set( + [ + "invalid_air_density", + "invalid_northward_wind", + "invalid_wind_speed", + "stratiform_snowfall_rate", + ] + ) + self.assertSetEqual( + invalid_nameset - keyset, + invalid_nameset, + "\nInvalid standard name(s) present in STD_NAMES", + ) if __name__ == "__main__": diff --git a/pyproject.toml b/pyproject.toml index 89af0f5fd2..58ce1daba1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,34 +13,18 @@ build-backend = "setuptools.build_meta" line-length = 79 target-version = ['py37', 'py38'] include = '\.pyi?$' -exclude = ''' - +extend-exclude = ''' ( /( - \.eggs # exclude a few common directories in the - | \.git # root of the project - | \.hg - | \.mypy_cache - | \.tox - | \.venv - | _build - | buck-out - | build - | compiled_krb - | dist - | etc - | iris_image_test_output + | pyke_rules | sphinxext | tools )/ - | gitwash_dumper.py - | _ff_cross_references.py # auto-generated files - | std_names.py + | _ff_cross_references.py | um_cf_map.py ) ''' - [tool.isort] force_sort_within_sections = "True" known_first_party = "iris" @@ -55,10 +39,4 @@ extend_skip = [ "tools", ] skip_gitignore = "True" -src_paths = [ - "docs", - "lib", - "noxfile.py", - "setup.py", -] verbose = "False"