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/.git-blame-ignore-revs b/.git-blame-ignore-revs index 593947014..dd25b1ca4 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -1,2 +1,4 @@ -# Formatted entire CMake code base with cmake-format -45b43632309cff022326472a8be0fdd5efc8f5c8 +# Formatted entire codebase (#337) +db7044f9c85b9675b0447d2162001f32b61e0e84 +cc0f75b44d536fd10fa0556474926e58bfbb3f4f +71520f8bcc8af9611e2a0f70eb3278fcc3064343 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 # diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a4f49cf5f..20db12cdd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,18 @@ +ci: + autofix_prs: false + autoupdate_branch: develop + 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: @@ -12,3 +26,15 @@ 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/psf/black-pre-commit-mirror + rev: 24.10.0 + hooks: + - id: black + - repo: https://github.com/csachs/pyproject-flake8 + rev: v7.0.0 + hooks: + - id: pyproject-flake8 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 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/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..920a32dae --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[tool.isort] +profile = "black" + +[tool.black] + +[tool.flake8] +max-line-length = 88 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(