From f82eaf34a71bd81d463ae015533c183beaeb1af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Sch=C3=BCtt?= Date: Fri, 23 Jul 2021 22:16:57 +0200 Subject: [PATCH] precommit: Check file properties of all files again --- tools/docker/scripts/test_python.sh | 1 + tools/precommit/check_file_properties.py | 10 ++++++---- tools/precommit/precommit.py | 3 +-- tools/toolchain/scripts/stage8/install_sirius.sh | 12 ++++++------ 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tools/docker/scripts/test_python.sh b/tools/docker/scripts/test_python.sh index 535342ca7e..198fba125d 100755 --- a/tools/docker/scripts/test_python.sh +++ b/tools/docker/scripts/test_python.sh @@ -26,6 +26,7 @@ run_test ./tools/prettify/prettify_test.py run_test mypy --strict ./tools/dashboard/generate_dashboard.py run_test mypy --strict ./tools/regtesting/do_regtest.py run_test mypy --strict ./tools/regtesting/optimize_test_dirs.py +run_test mypy --strict ./tools/precommit/check_file_properties.py # Test generate_dashboard.py. Running it twice to also execute its caching. mkdir -p /workspace/artifacts/dashboard diff --git a/tools/precommit/check_file_properties.py b/tools/precommit/check_file_properties.py index 96d859e80c..89275969a4 100755 --- a/tools/precommit/check_file_properties.py +++ b/tools/precommit/check_file_properties.py @@ -98,14 +98,16 @@ C_FAMILY_EXTENSIONS = (".c", ".cu", ".cpp", ".h", ".hpp") @lru_cache(maxsize=None) -def get_install_txt(): +def get_install_txt() -> str: return CP2K_DIR.joinpath("INSTALL.md").read_text() @lru_cache(maxsize=None) -def get_flags_src(): +def get_flags_src() -> str: cp2k_info = CP2K_DIR.joinpath("src/cp2k_info.F").read_text() - return CP2K_FLAGS_RE.search(cp2k_info).group(1) + match = CP2K_FLAGS_RE.search(cp2k_info) + assert match + return match.group(1) def check_file(path: pathlib.Path) -> typing.List[str]: @@ -174,7 +176,7 @@ def check_file(path: pathlib.Path) -> typing.List[str]: continue # ignore aptly named inclusion guards flags.add(word) - flags = [flag for flag in flags if not FLAG_EXCEPTIONS_RE.match(flag)] + flags = {flag for flag in flags if not FLAG_EXCEPTIONS_RE.match(flag)} for flag in sorted(flags): if flag not in get_install_txt(): diff --git a/tools/precommit/precommit.py b/tools/precommit/precommit.py index 18aef56cf1..c29eb462b6 100755 --- a/tools/precommit/precommit.py +++ b/tools/precommit/precommit.py @@ -200,8 +200,7 @@ def process_file(fn, allow_modifications): if re.match(r"./data/.*POTENTIALS?$", fn): check_data_files() - if re.match(r".*\.(F|fypp|c|cu|cpp|h|hpp)$", fn): - run_check_file_properties(fn) + run_check_file_properties(fn) new_content = Path(fn).read_bytes() if new_content == orig_content: diff --git a/tools/toolchain/scripts/stage8/install_sirius.sh b/tools/toolchain/scripts/stage8/install_sirius.sh index c030378edd..061166904b 100755 --- a/tools/toolchain/scripts/stage8/install_sirius.sh +++ b/tools/toolchain/scripts/stage8/install_sirius.sh @@ -110,12 +110,12 @@ case "$with_sirius" in mkdir build cd build COMPILATION_OPTIONS="-DHDF5_DIR=${HDF5_DIR}" - #if [ -n "$ELPA_LIBS" ] ; then - # if [ -s "$ELPAROOT" ] ; then - # export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$ELPAROOT/lib/pkgconfig:$ELPAROOT/lib64/pkgconfig - # fi - # COMPILATION_OPTIONS="-DUSE_ELPA=ON -DELPA_INCLUDE_DIR=${ELPAROOT}/include/elpa-${ELPAVERSION} $COMPILATION_OPTIONS" - #fi + # if [ -n "$ELPA_LIBS" ] ; then + # if [ -s "$ELPAROOT" ] ; then + # export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$ELPAROOT/lib/pkgconfig:$ELPAROOT/lib64/pkgconfig + # fi + # COMPILATION_OPTIONS="-DUSE_ELPA=ON -DELPA_INCLUDE_DIR=${ELPAROOT}/include/elpa-${ELPAVERSION} $COMPILATION_OPTIONS" + # fi if [ -n "$SCALAPACK_LIBS" ]; then export SCALAPACK_LIB="$SCALAPACK_LIBS"