From b70fd3aa67b6d0b683f7683f5df371daa6c492a9 Mon Sep 17 00:00:00 2001 From: zmoon Date: Tue, 14 Jan 2025 12:29:07 -0600 Subject: [PATCH 1/3] Update findent hook and pin findent version --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2fd94da6..3d3c40d7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,10 +13,10 @@ repos: - id: check-yaml - repo: https://github.com/zmoon/findent-pre-commit - rev: "65627b8" + rev: "17b1b07" hooks: - # NOTE: doesn't work on Windows currently - id: findent-pypi + additional_dependencies: [findent==4.3.1] args: ['-i3'] exclude: | (?x)^( From 25b97d9608b6852cd385bdf82fa5a5f2d585840d Mon Sep 17 00:00:00 2001 From: zmoon Date: Tue, 14 Jan 2025 12:47:43 -0600 Subject: [PATCH 2/3] Switch to gersemi CMake formatter --- .pre-commit-config.yaml | 13 +++---- CMakeLists.txt | 27 ++++++++++----- src/api/CMakeLists.txt | 5 ++- src/core/CMakeLists.txt | 41 ++++++++++++---------- src/external/CMakeLists.txt | 11 ++++-- src/process/drydep/CMakeLists.txt | 5 ++- src/process/dust/CMakeLists.txt | 14 ++++++-- src/process/plumerise/CMakeLists.txt | 12 +++++-- src/process/seasalt/CMakeLists.txt | 15 ++++++-- tests/CMakeLists.txt | 52 ++++++++++++++++++++-------- 10 files changed, 133 insertions(+), 62 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3d3c40d7..024c26d5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,16 +29,11 @@ repos: src/external/GOCART/.* )$ - - repo: https://github.com/cheshirekow/cmake-format-precommit - rev: v0.6.13 + - repo: https://github.com/BlankSpruce/gersemi + rev: "0.18.1" hooks: - - id: cmake-format - additional_dependencies: [PyYAML] - exclude: (?x)^( - cmake/FindNetCDF.cmake - )$ - - id: cmake-lint - additional_dependencies: [PyYAML] + - id: gersemi + args: [--in-place, --indent=2] exclude: (?x)^( cmake/FindNetCDF.cmake )$ diff --git a/CMakeLists.txt b/CMakeLists.txt index aa5bf496..9bdf6c4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,6 @@ cmake_minimum_required(VERSION 3.5) -project( - CATChem - VERSION 0.1.0 - LANGUAGES Fortran) +project(CATChem VERSION 0.1.0 LANGUAGES Fortran) include(CMakePrintHelpers) @@ -13,9 +10,16 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) endif() -cmake_print_variables(CMAKE_Fortran_COMPILER CMAKE_Fortran_COMPILER_ID CMAKE_BUILD_TYPE) +cmake_print_variables( + CMAKE_Fortran_COMPILER + CMAKE_Fortran_COMPILER_ID + CMAKE_BUILD_TYPE +) set(_catchem_compiler_options "") -if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU|G95" AND CMAKE_BUILD_TYPE MATCHES "Debug") +if( + CMAKE_Fortran_COMPILER_ID MATCHES "GNU|G95" + AND CMAKE_BUILD_TYPE MATCHES "Debug" +) list( APPEND _catchem_compiler_options @@ -26,8 +30,12 @@ if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU|G95" AND CMAKE_BUILD_TYPE MATCHES "Deb -fcheck=all -ffpe-trap=invalid,zero,overflow -fbacktrace - -fmax-errors=0) -elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel" AND CMAKE_BUILD_TYPE MATCHES "Debug") + -fmax-errors=0 + ) +elseif( + CMAKE_Fortran_COMPILER_ID MATCHES "Intel" + AND CMAKE_BUILD_TYPE MATCHES "Debug" +) list( APPEND _catchem_compiler_options @@ -42,7 +50,8 @@ elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel" AND CMAKE_BUILD_TYPE MATCHES "D -error-limit 0 -diag-disable - 6379,10448) + 6379,10448 + ) endif() add_subdirectory(src) diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index b0c1f82a..5f42f33c 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -8,5 +8,8 @@ target_link_libraries(${_lib} PUBLIC CATChem_process_dust) target_link_libraries(${_lib} PUBLIC CATChem_process_seasalt) target_link_libraries(${_lib} PUBLIC CATChem_process_plumerise) target_link_libraries(${_lib} PUBLIC CATChem_process_drydep) -set_target_properties(${_lib} PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include) +set_target_properties( + ${_lib} + PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include +) target_compile_options(${_lib} PRIVATE ${_catchem_compiler_options}) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 4e6aa138..87bf3d1f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,21 +1,26 @@ -set(_srcs - charpak_mod.F90 - chemstate_mod.F90 - cmn_size_mod.F90 - config_mod.F90 - config_opt_mod.F90 - constants.F90 - diagstate_mod.F90 - emisstate_mod.F90 - error_mod.F90 - gridstate_mod.F90 - init_mod.F90 - metstate_mod.F90 - precision_mod.F90 - qfyaml_mod.F90 - species_mod.F90 - state_mod.F90) +set( + _srcs + charpak_mod.F90 + chemstate_mod.F90 + cmn_size_mod.F90 + config_mod.F90 + config_opt_mod.F90 + constants.F90 + diagstate_mod.F90 + emisstate_mod.F90 + error_mod.F90 + gridstate_mod.F90 + init_mod.F90 + metstate_mod.F90 + precision_mod.F90 + qfyaml_mod.F90 + species_mod.F90 + state_mod.F90 +) add_library(CATChem_core ${_srcs}) -set_target_properties(CATChem_core PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include) +set_target_properties( + CATChem_core + PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include +) target_compile_options(CATChem_core PRIVATE ${_catchem_compiler_options}) diff --git a/src/external/CMakeLists.txt b/src/external/CMakeLists.txt index 99a9e5e5..04aa3c8d 100644 --- a/src/external/CMakeLists.txt +++ b/src/external/CMakeLists.txt @@ -1,4 +1,8 @@ -set(_srcs GOCART/Process_Library/GOCART2G_Process.F90 GOCART/Process_Library/GOCART2G_MieMod.F90) +set( + _srcs + GOCART/Process_Library/GOCART2G_Process.F90 + GOCART/Process_Library/GOCART2G_MieMod.F90 +) set(_lib GOCART2G) add_library(${_lib} ${_srcs}) @@ -11,4 +15,7 @@ find_package(NetCDF REQUIRED COMPONENTS Fortran) target_link_libraries(${_lib} NetCDF::NetCDF_Fortran) # target_link_libraries(${_lib} PUBLIC CATChem_core) -set_target_properties(${_lib} PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include) +set_target_properties( + ${_lib} + PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include +) diff --git a/src/process/drydep/CMakeLists.txt b/src/process/drydep/CMakeLists.txt index 1b3ba745..ba0e7f9c 100644 --- a/src/process/drydep/CMakeLists.txt +++ b/src/process/drydep/CMakeLists.txt @@ -6,4 +6,7 @@ add_library(${_lib} ${_srcs}) target_link_libraries(${_lib} PUBLIC CATChem_core) target_link_libraries(${_lib} PUBLIC GOCART2G) -set_target_properties(${_lib} PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include) +set_target_properties( + ${_lib} + PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include +) diff --git a/src/process/dust/CMakeLists.txt b/src/process/dust/CMakeLists.txt index 44fc1c88..602c75cf 100644 --- a/src/process/dust/CMakeLists.txt +++ b/src/process/dust/CMakeLists.txt @@ -1,8 +1,16 @@ -set(_srcs CCPr_Dust_Mod.F90 ccpr_dust_common_mod.F90 ccpr_scheme_fengsha_mod.F90 - ccpr_scheme_ginoux_mod.F90) +set( + _srcs + CCPr_Dust_Mod.F90 + ccpr_dust_common_mod.F90 + ccpr_scheme_fengsha_mod.F90 + ccpr_scheme_ginoux_mod.F90 +) set(_lib CATChem_process_dust) add_library(${_lib} ${_srcs}) target_link_libraries(${_lib} PUBLIC CATChem_core) -set_target_properties(${_lib} PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include) +set_target_properties( + ${_lib} + PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include +) diff --git a/src/process/plumerise/CMakeLists.txt b/src/process/plumerise/CMakeLists.txt index 41d45113..53c731e3 100644 --- a/src/process/plumerise/CMakeLists.txt +++ b/src/process/plumerise/CMakeLists.txt @@ -1,7 +1,15 @@ -set(_srcs CCPr_Plumerise_Mod.F90 CCPr_Scheme_Briggs_mod.F90 CCPr_Scheme_Sofiev_mod.F90) +set( + _srcs + CCPr_Plumerise_Mod.F90 + CCPr_Scheme_Briggs_mod.F90 + CCPr_Scheme_Sofiev_mod.F90 +) set(_lib CATChem_process_plumerise) add_library(${_lib} ${_srcs}) target_link_libraries(${_lib} PUBLIC CATChem_core) -set_target_properties(${_lib} PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include) +set_target_properties( + ${_lib} + PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include +) diff --git a/src/process/seasalt/CMakeLists.txt b/src/process/seasalt/CMakeLists.txt index 3cfa6b71..42f5d551 100644 --- a/src/process/seasalt/CMakeLists.txt +++ b/src/process/seasalt/CMakeLists.txt @@ -1,8 +1,17 @@ -set(_srcs CCPr_SeaSalt_Mod.F90 ccpr_seasalt_common_mod.F90 ccpr_scheme_gong03_mod.F90 - ccpr_scheme_gong97_mod.F90 ccpr_scheme_geos12_mod.F90) +set( + _srcs + CCPr_SeaSalt_Mod.F90 + ccpr_seasalt_common_mod.F90 + ccpr_scheme_gong03_mod.F90 + ccpr_scheme_gong97_mod.F90 + ccpr_scheme_geos12_mod.F90 +) set(_lib CATChem_process_seasalt) add_library(${_lib} ${_srcs}) target_link_libraries(${_lib} PUBLIC CATChem_core) -set_target_properties(${_lib} PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include) +set_target_properties( + ${_lib} + PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include +) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 79456ebb..1dcb34a1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,26 +1,34 @@ +include(CTest) + add_compile_options(${_catchem_compiler_options}) add_library(testing testing_mod.f90) target_link_libraries(testing PRIVATE CATChem_core) -set_target_properties(testing PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include) - -enable_testing() +set_target_properties( + testing + PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include +) add_executable(test_main test_main.F90) target_link_libraries(test_main PRIVATE CATChem_core) target_link_libraries(test_main PRIVATE CATChem) target_link_libraries(test_main PRIVATE testing) -set_target_properties(test_main PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include) +set_target_properties( + test_main + PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include +) add_test( NAME test_main COMMAND test_main - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) add_test( NAME test_main_missing_config COMMAND test_main - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} +) set_property(TEST test_main_missing_config PROPERTY WILL_FAIL TRUE) add_executable(test_dust test_dust.f90) @@ -28,43 +36,59 @@ target_link_libraries(test_dust PRIVATE CATChem_core) target_link_libraries(test_dust PRIVATE CATChem) target_link_libraries(test_dust PRIVATE CATChem_process_dust) target_link_libraries(test_dust PRIVATE testing) -set_target_properties(test_dust PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include) +set_target_properties( + test_dust + PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include +) add_test( NAME test_ccpr_dust COMMAND test_dust - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) add_executable(test_seasalt test_seasalt.F90) target_link_libraries(test_seasalt PRIVATE CATChem_core) target_link_libraries(test_seasalt PRIVATE CATChem) target_link_libraries(test_seasalt PRIVATE CATChem_process_seasalt) target_link_libraries(test_seasalt PRIVATE testing) -set_target_properties(test_seasalt PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include) +set_target_properties( + test_seasalt + PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include +) add_test( NAME test_ccpr_seasalt COMMAND test_seasalt - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) add_executable(test_prise test_plumerise.F90) target_link_libraries(test_prise PRIVATE CATChem_core) target_link_libraries(test_prise PRIVATE CATChem) target_link_libraries(test_prise PRIVATE testing) -set_target_properties(test_prise PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include) +set_target_properties( + test_prise + PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include +) add_test( NAME test_plumerise COMMAND test_prise - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) add_executable(test_drydep test_drydep.f90) target_link_libraries(test_drydep PRIVATE CATChem_core) target_link_libraries(test_drydep PRIVATE CATChem) target_link_libraries(test_drydep PRIVATE testing) -set_target_properties(test_drydep PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include) +set_target_properties( + test_drydep + PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include +) add_test( NAME test_drydep COMMAND test_drydep - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) From a3ada054427e344477eb969cf3f287e0b04e15ae Mon Sep 17 00:00:00 2001 From: zmoon Date: Tue, 14 Jan 2025 12:49:53 -0600 Subject: [PATCH 3/3] Update other hooks --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 024c26d5..7f9d8108 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: - id: check-useless-excludes - repo: https://github.com/pre-commit/pre-commit-hooks - rev: "v4.6.0" + rev: "v5.0.0" hooks: - id: trailing-whitespace args: ['--markdown-linebreak-ext=md,markdown']