From 506627704c63a451529fa1d0db9f011017fdd12d Mon Sep 17 00:00:00 2001 From: Sergey Kosukhin Date: Mon, 6 Jan 2025 19:52:24 +0100 Subject: [PATCH 01/14] Remove invalid entry from .git-blame-ignore-revs --- .git-blame-ignore-revs | 2 -- 1 file changed, 2 deletions(-) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 593947014..e69de29bb 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -1,2 +0,0 @@ -# Formatted entire CMake code base with cmake-format -45b43632309cff022326472a8be0fdd5efc8f5c8 From ff0fd6062e6ae70c60a9883ea4a0e5c02b642978 Mon Sep 17 00:00:00 2001 From: Sergey Kosukhin Date: Mon, 6 Jan 2025 19:53:35 +0100 Subject: [PATCH 02/14] Update .git-blame-ignore-revs --- .git-blame-ignore-revs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index e69de29bb..dd25b1ca4 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -0,0 +1,4 @@ +# Formatted entire codebase (#337) +db7044f9c85b9675b0447d2162001f32b61e0e84 +cc0f75b44d536fd10fa0556474926e58bfbb3f4f +71520f8bcc8af9611e2a0f70eb3278fcc3064343 From 86ce5e2da40fd8e8546169a5dbf08350f0e8df00 Mon Sep 17 00:00:00 2001 From: Sergey Kosukhin Date: Mon, 6 Jan 2025 19:54:09 +0100 Subject: [PATCH 03/14] Add isort configuration --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..5d7bf33d9 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.isort] +profile = "black" From 31074f3fc94928ce6a091e1b0c24c4150dde16fe Mon Sep 17 00:00:00 2001 From: Sergey Kosukhin Date: Mon, 6 Jan 2025 19:58:16 +0100 Subject: [PATCH 04/14] Add flake8 configuration --- .flake8 | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 000000000..2bcd70e39 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 88 From 37b415e1077fbbe3c7c2050709f262e81764d44a Mon Sep 17 00:00:00 2001 From: Sergey Kosukhin Date: Mon, 6 Jan 2025 20:00:17 +0100 Subject: [PATCH 05/14] Make flake8 happy --- .cmake-format.py | 6 +++--- examples/all-sky/make_problem_size_loop.py | 6 +++--- tests/validation-plots.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.cmake-format.py b/.cmake-format.py index f6ee981d9..90fe35cdf 100644 --- a/.cmake-format.py +++ b/.cmake-format.py @@ -1,13 +1,13 @@ -with section("parse"): +with section("parse"): # noqa: F821 additional_commands = {"check_python3_package": {"pargs": 1, "kwargs": {"CODE": 1}}} -with section("format"): +with section("format"): # noqa: F821 dangle_parens = True max_lines_hwrap = 0 keyword_case = "upper" autosort = True -with section("lint"): +with section("lint"): # noqa: F821 # The formatter sometimes fails to fit the code into the line limit (C0301) and can # disagree with the linter regarding the indentation (C0307): disabled_codes = ["C0301", "C0307"] diff --git a/examples/all-sky/make_problem_size_loop.py b/examples/all-sky/make_problem_size_loop.py index 8b72e788b..9f0ed7627 100644 --- a/examples/all-sky/make_problem_size_loop.py +++ b/examples/all-sky/make_problem_size_loop.py @@ -76,10 +76,10 @@ raise AssertionError("Need to supply cloud optics if providing aerosol optics") # Every combo of ncol, nlay - for l in args.nlay: - for i in args.ncol: + for ll in args.nlay: + for ii in args.ncol: print( - f"{args.executable} {i:6d} {l:4d} {args.nloops:3d} " + f"{args.executable} {ii:6d} {ll:4d} {args.nloops:3d} " + f"{args.output_file} {args.k_distribution} " + f"{args.cloud_optics} {args.aerosol_optics} " ) diff --git a/tests/validation-plots.py b/tests/validation-plots.py index 3a9fd40a8..45baa7f0b 100755 --- a/tests/validation-plots.py +++ b/tests/validation-plots.py @@ -111,11 +111,11 @@ def main(): try: try: urllib.request.urlretrieve(construct_lbl_esgf_root(v), v + lbl_suffix) - except: + except Exception: urllib.request.urlretrieve( construct_lbl_esgf_root(v, esgf_node="dkrz"), v + lbl_suffix ) - except: + except Exception: raise Exception("Failed to download {0}".format(v + lbl_suffix)) lbl = xr.open_mfdataset([v + lbl_suffix for v in fluxes], combine="by_coords").sel( From b34cc2f785d3daf0a8e5ad972d1d42d549c53fb1 Mon Sep 17 00:00:00 2001 From: Sergey Kosukhin Date: Tue, 14 Jan 2025 14:17:44 +0100 Subject: [PATCH 06/14] Switch to pyproject-flake8 --- .flake8 | 2 -- pyproject.toml | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 2bcd70e39..000000000 --- a/.flake8 +++ /dev/null @@ -1,2 +0,0 @@ -[flake8] -max-line-length = 88 diff --git a/pyproject.toml b/pyproject.toml index 5d7bf33d9..5e30d41ba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,5 @@ [tool.isort] profile = "black" + +[tool.flake8] +max-line-length = 88 From 9dec0506c0b3d85c19c843abf80179bf0ece4f40 Mon Sep 17 00:00:00 2001 From: Sergey Kosukhin Date: Tue, 14 Jan 2025 14:22:54 +0100 Subject: [PATCH 07/14] Placeholder for black in pyproject.toml --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 5e30d41ba..920a32dae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,7 @@ [tool.isort] profile = "black" +[tool.black] + [tool.flake8] max-line-length = 88 From a0e151cc0042d6b4a891233711d9eb718166a82e Mon Sep 17 00:00:00 2001 From: Sergey Kosukhin Date: Tue, 14 Jan 2025 14:25:27 +0100 Subject: [PATCH 08/14] Extend pre-commit config with pyproject-flake8 --- .pre-commit-config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a4f49cf5f..c87395c77 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,3 +12,7 @@ repos: name: cmake-lint (templates) types: [file] files: \.cmake\.in$ + - repo: https://github.com/csachs/pyproject-flake8 + rev: v7.0.0 + hooks: + - id: pyproject-flake8 From 1cff7b4279015d6bc12aabfd429e9828740041a2 Mon Sep 17 00:00:00 2001 From: Sergey Kosukhin Date: Tue, 14 Jan 2025 14:27:57 +0100 Subject: [PATCH 09/14] Extend pre-commit config with isort --- .pre-commit-config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c87395c77..c23acad13 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,6 +12,10 @@ repos: name: cmake-lint (templates) types: [file] files: \.cmake\.in$ + - repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort - repo: https://github.com/csachs/pyproject-flake8 rev: v7.0.0 hooks: From c49b89b77225faed3ea9e577e04deed1f3ffec21 Mon Sep 17 00:00:00 2001 From: Sergey Kosukhin Date: Tue, 14 Jan 2025 14:37:29 +0100 Subject: [PATCH 10/14] Extend pre-commit config with black --- .pre-commit-config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c23acad13..a19dd0756 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,6 +16,10 @@ repos: rev: 5.13.2 hooks: - id: isort + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 24.10.0 + hooks: + - id: black - repo: https://github.com/csachs/pyproject-flake8 rev: v7.0.0 hooks: From 3a38a0dc4a38f25e5c9f7de643d9d585ce03da46 Mon Sep 17 00:00:00 2001 From: Robert Pincus Date: Tue, 14 Jan 2025 15:56:29 +0100 Subject: [PATCH 11/14] Extend the pre-commit configuration --- .pre-commit-config.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a19dd0756..4b86f1cb8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,14 @@ repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/rhysd/actionlint + rev: v1.7.6 + hooks: + - id: actionlint - repo: https://github.com/cheshirekow/cmake-format-precommit rev: v0.6.13 hooks: From e1c04da5a7e6c33cd647415f026e8913e7f797b5 Mon Sep 17 00:00:00 2001 From: Sergey Kosukhin Date: Tue, 14 Jan 2025 15:59:39 +0100 Subject: [PATCH 12/14] Prepare for pre-commit CI --- .pre-commit-config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4b86f1cb8..20db12cdd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,7 @@ +ci: + autofix_prs: false + autoupdate_branch: develop + repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 From 5dd4ffad726de83d0370b3cb23875590b9bb4ee6 Mon Sep 17 00:00:00 2001 From: Sergey Kosukhin Date: Tue, 14 Jan 2025 16:19:00 +0100 Subject: [PATCH 13/14] Make actionlint happy --- .github/workflows/check-api.yml | 2 +- .github/workflows/containerized-ci.yml | 2 +- .github/workflows/continuous-integration.yml | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-api.yml b/.github/workflows/check-api.yml index 4b50a0355..61e78836d 100644 --- a/.github/workflows/check-api.yml +++ b/.github/workflows/check-api.yml @@ -33,5 +33,5 @@ jobs: $FC --version cmake -S . -B build \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ - -DKERNEL_MODE=$RTE_KERNELS + -DKERNEL_MODE="$RTE_KERNELS" cmake --build build diff --git a/.github/workflows/containerized-ci.yml b/.github/workflows/containerized-ci.yml index cf6ffad2d..926f17d4e 100644 --- a/.github/workflows/containerized-ci.yml +++ b/.github/workflows/containerized-ci.yml @@ -83,7 +83,7 @@ jobs: run: | cmake -S . -B build -G "Ninja" \ -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \ - -DRTE_ENABLE_SP=`test 'x${{ matrix.fpmodel }}' = xSP && echo ON || echo OFF` \ + -DRTE_ENABLE_SP="$(test '${{ matrix.fpmodel }}' = SP && echo ON || echo OFF)" \ -DKERNEL_MODE=${{ matrix.rte-kernels }} \ -DBUILD_TESTING=ON cmake --build build diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index baff11923..ee14cb039 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -101,7 +101,7 @@ jobs: if: matrix.gfortran-from == 'conda' run: | conda install -c conda-forge gfortran=${{ matrix.gfortran-version }} -y - echo "FC=gfortran" >> $GITHUB_ENV + echo "FC=gfortran" >> "$GITHUB_ENV" # # Install dependencies # @@ -112,7 +112,7 @@ jobs: # - name: Adjust toolchain if: matrix.os == 'windows-2022' - run: echo "FC=${FC}.exe" >> $GITHUB_ENV + run: echo "FC=${FC}.exe" >> "$GITHUB_ENV" # # Build libraries, examples, and tests # @@ -120,7 +120,7 @@ jobs: run: | cmake -S . -B build -G "Ninja" \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ - -DRTE_ENABLE_SP=`test 'x${{ matrix.fpmodel }}' = xSP && echo ON || echo OFF` \ + -DRTE_ENABLE_SP="$(test '${{ matrix.fpmodel }}' = SP && echo ON || echo OFF)" \ -DBUILD_TESTING=ON cmake --build build # From f44db57a6dc604c2b206a926b374e72a47476a8d Mon Sep 17 00:00:00 2001 From: Sergey Kosukhin Date: Tue, 14 Jan 2025 16:53:33 +0100 Subject: [PATCH 14/14] Add pre-commit to environment-dev.yml --- environment-dev.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/environment-dev.yml b/environment-dev.yml index 5b46be5b8..b42277aa7 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -21,6 +21,7 @@ dependencies: - netcdf-fortran - cmake - ninja + - pre-commit variables: FC: gfortran # Debugging flags below