Skip to content

Commit aa0ffeb

Browse files
authored
Add CMake style checker (parflow#733)
Add style checker gersemi for CMake files, will be part of the style check CI test.
1 parent a2725bd commit aa0ffeb

58 files changed

Lines changed: 5787 additions & 4427 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 642 additions & 495 deletions
Large diffs are not rendered by default.

CONTRIBUTING.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ error prone.
215215

216216
ParFlow uses automated code formatters to check code as one of the
217217
checks in our CI system. Incorrectly formatted code will fail the
218-
check and won't be merged. The check is done using Uncrustify for C
219-
and Black for Python. A script is provided to automatically reformat
220-
code and do the check.
218+
check and won't be merged. The check is done using Uncrustify for
219+
C/C++, Black for Python and gersemi for CMake. A script is provided
220+
to automatically reformat code and do the check.
221221

222222
To check if the coding style is correct run the pfformat script at the
223223
root of the PF source tree:
@@ -234,19 +234,17 @@ cd parflow
234234
./bin/pfformat
235235
```
236236

237-
You must have installed **Uncrustify version 0.79.0** in order for this to
238-
work. For Python, ParFlow uses the **Black code formatter pinned to
239-
version 26.3.1**. Black is installed into the ParFlow Python
240-
environment during installation, so you normally don't need to install
241-
it manually, but if you do you should ensure that you are using
242-
**Black 26.3.1** to match the version used in CI.
237+
The pfformat command uses an installed Python environment and
238+
should get the correct versions of the formatting tools.
243239

244240
Information and source on these tools can be found here:
245241

246242
[Uncrustify](https://github.com/uncrustify/uncrustify)
247243

248244
[Black](https://github.com/psf/black)
249245

246+
[gersemi](https://github.com/BlankSpruce/gersemi)
247+
250248
### Why auto code formatting?
251249

252250
Enforcing a common code indentation and other style format is fairly

bin/pfformat

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function main() {
128128
do
129129
if $check
130130
then
131-
if output=$(uncrustify --check -c bin/parflow.cfg $i)
131+
if output=$(uncrustify --check -c bin/parflow.cfg $i 2>&1)
132132
then
133133
log 'pfformat PASSED %s\n' $i
134134
else
@@ -140,10 +140,9 @@ function main() {
140140
fi
141141
done
142142

143-
# Disable this for now while Python is being refactored.
144143
if $check
145144
then
146-
if output=$($PARFLOW_DIR/bin/pfpython -m black . --check)
145+
if output=$($PARFLOW_DIR/bin/pfpython -m black . --check 2>&1)
147146
then
148147
log 'pfformat PASSED %s\n' $i
149148
else
@@ -154,6 +153,19 @@ function main() {
154153
$PARFLOW_DIR/bin/pfpython -m black .
155154
fi
156155

156+
if $check
157+
then
158+
if output=$($PARFLOW_DIR/bin/pfpython -m gersemi . --check 2>&1)
159+
then
160+
log 'pfformat PASSED %s\n' $i
161+
else
162+
printf 'pfFormat FAILED\nCMake style checker gersemi output was «%s»\n' "$output\n"
163+
failed=true
164+
fi
165+
else
166+
$PARFLOW_DIR/bin/pfpython -m gersemi --in-place .
167+
fi
168+
157169
if $check
158170
then
159171
if $failed ;

0 commit comments

Comments
 (0)