Skip to content

Commit 065c8cf

Browse files
authored
Correct Python scripts (#547)
* Show formatting diffs if test fails * Fix python scripts formatting (per black v26) * Add a logfile for the python format test
1 parent 8d74c0c commit 065c8cf

4 files changed

Lines changed: 16 additions & 18 deletions

File tree

build/fix_mechanism_fac.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import sys
3838
import re
3939

40-
4140
# =========================== FUNCTIONS =========================== #
4241

4342

build/kpp_conversion.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import sys
2323
import re
2424

25-
2625
# =========================== FUNCTIONS =========================== #
2726

2827

build/mech_converter.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,9 @@ def separate_stoichiometry(input_species):
177177
else: # if there is no coefficient then output an assumed coefficient of 1
178178
return (1.0, pat_match[2])
179179
else:
180-
raise Exception(
181-
f"""Reaction species does not match the correct
180+
raise Exception(f"""Reaction species does not match the correct
182181
format: '{input_species}'. Note that species names should
183-
not begin with numerical characters."""
184-
)
182+
not begin with numerical characters.""")
185183

186184

187185
# ======================================================
@@ -643,8 +641,7 @@ def convert_to_fortran(mechFile, configDir, sharedDir, mcmV):
643641

644642
# Combine mechanism rates and RO2 sum files.
645643
with open(os.path.join(sharedDir, "mechanism.f90"), "a") as mech_rates_coeff_file:
646-
mech_rates_coeff_file.write(
647-
"""
644+
mech_rates_coeff_file.write("""
648645
module mechanism_mod
649646
use, intrinsic :: iso_c_binding
650647
implicit none
@@ -657,8 +654,7 @@ def convert_to_fortran(mechFile, configDir, sharedDir, mcmV):
657654
integer, parameter :: DP = selected_real_kind( p = 15, r = 307 )
658655
real(c_double), intent(inout) :: p(*), q(*)
659656
real(c_double), intent(in) :: t, TEMP, N2, O2, M, RH, H2O, BLHEIGHT, DEC, JFAC, DILUTE, ROOFOPEN, ASA, J(*), RO2
660-
"""
661-
)
657+
""")
662658

663659
# Write out 'Generic Rate Coefficients' and 'Complex reactions'.
664660
for item in mechanism_rates_coeff_list:
@@ -667,12 +663,10 @@ def convert_to_fortran(mechFile, configDir, sharedDir, mcmV):
667663
# Write out 'Reaction definitions'.
668664
for r in mech_rates_list:
669665
mech_rates_coeff_file.write(r)
670-
mech_rates_coeff_file.write(
671-
"""
666+
mech_rates_coeff_file.write("""
672667
end subroutine update_p
673668
end module mechanism_mod
674-
"""
675-
)
669+
""")
676670

677671
# -------------------------------------------------
678672

tests/python_format_test.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,24 @@ if [ $? -ne 0 ] ; then
2323
exit 1
2424
fi
2525

26-
printf "\nExecuting Python format test:\n"
26+
LOG_FILE=tests/pythontest.log
27+
28+
printf "==> Executing Python format test...\n"
2729

2830
test_total=0
2931
test_fail=0
3032

33+
printf "Python format test\n\n" > "$LOG_FILE"
34+
3135
find build/ tools/ -name "*.py" | {
3236
while IFS= read -r file; do
3337
test_total=$((test_total + 1))
34-
black --check "$file" > /dev/null 2>&1
38+
black -q --check "$file"
3539
if [ $? -eq 0 ] ; then
36-
printf "[PASS] %s\n" "$file"
40+
printf "[PASS] %s\n" "$file" >> "$LOG_FILE"
3741
else
38-
printf "[FAIL] %s\n" "$file"
42+
printf "[FAIL] %s\n" "$file" >> "$LOG_FILE"
43+
black -q --diff "$file" >> $LOG_FILE
3944
test_fail=$((test_fail + 1))
4045
fi
4146
done
@@ -49,5 +54,6 @@ find build/ tools/ -name "*.py" | {
4954
test_script_pass=1
5055
fi
5156

57+
printf "==> Python format test logfile: %s\n" "$LOG_FILE"
5258
exit $test_script_pass
5359
}

0 commit comments

Comments
 (0)