Skip to content

Commit

Permalink
Extend pre-commit configuration (#339)
Browse files Browse the repository at this point in the history
* Update .git-blame-ignore-revs
* Add pyproject.toml with configurations for isort, black and flake8
* Extend pre-commit configuration with isort, black, pyproject-flake8,
  check-yaml, end-of-file-fixer, trailing-whitespace and actionlint
* Address issues identified by flake8 and actionlint
* Prepare for pre-commit CI
* Add pre-commit to environment-dev.yml

---------

Co-authored-by: Robert Pincus <[email protected]>
  • Loading branch information
skosukhin and RobertPincus authored Jan 14, 2025
1 parent 0d5be57 commit 9507fea
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 15 deletions.
6 changes: 3 additions & 3 deletions .cmake-format.py
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
6 changes: 4 additions & 2 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Formatted entire CMake code base with cmake-format
45b43632309cff022326472a8be0fdd5efc8f5c8
# Formatted entire codebase (#337)
db7044f9c85b9675b0447d2162001f32b61e0e84
cc0f75b44d536fd10fa0556474926e58bfbb3f4f
71520f8bcc8af9611e2a0f70eb3278fcc3064343
2 changes: 1 addition & 1 deletion .github/workflows/check-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/containerized-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -112,15 +112,15 @@ 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
#
- name: Build libraries and tests
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
#
Expand Down
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
1 change: 1 addition & 0 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies:
- netcdf-fortran
- cmake
- ninja
- pre-commit
variables:
FC: gfortran
# Debugging flags below
Expand Down
6 changes: 3 additions & 3 deletions examples/all-sky/make_problem_size_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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} "
)
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[tool.isort]
profile = "black"

[tool.black]

[tool.flake8]
max-line-length = 88
4 changes: 2 additions & 2 deletions tests/validation-plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 9507fea

Please sign in to comment.