From bb453db103475f4730a745f331187afde7316f0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Sch=C3=BCtt?= Date: Tue, 25 Aug 2020 22:05:32 +0200 Subject: [PATCH] precommit: Fix check for data/POTENTIAL file --- tools/precommit/Dockerfile | 3 +-- tools/precommit/precommit.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tools/precommit/Dockerfile b/tools/precommit/Dockerfile index 9fdb333dbc..e833c45ead 100644 --- a/tools/precommit/Dockerfile +++ b/tools/precommit/Dockerfile @@ -10,14 +10,13 @@ RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true && \ clang-format \ git \ less \ + nano \ npm \ - make \ python3 \ python3-pip \ python3-wheel \ python3-setuptools \ shellcheck \ - vim \ && rm -rf /var/lib/apt/lists/* # Install MarkdownLint. diff --git a/tools/precommit/precommit.py b/tools/precommit/precommit.py index 47cda35c13..e709d86b55 100755 --- a/tools/precommit/precommit.py +++ b/tools/precommit/precommit.py @@ -103,7 +103,9 @@ def main(): candidate_file_list += [os.path.join(root, fn) for fn in files] # Find eligible files and sort by size as larger ones will take longer to process. - eligible_file_pattern = re.compile(r".*(_POTENTIALS|(\.(F|fypp|c|cu|h|py|md)))$") + eligible_file_pattern = re.compile( + r"(./data/.*POTENTIALS?)|(.*\.(F|fypp|c|cu|h|py|md))$" + ) file_list = [fn for fn in candidate_file_list if eligible_file_pattern.match(fn)] file_list.sort(reverse=True, key=lambda fn: os.path.getsize(fn)) @@ -190,8 +192,8 @@ def process_file(fn, allow_modifications): elif re.match(r".*\.md$", fn): run_remote_tool("markdownlint", fn) - elif re.match(r".*_POTENTIALS$", fn): - run_local_tool("make", "data/POTENTIAL") + elif re.match(r"./data/.*POTENTIALS?$", fn): + check_data_files() else: raise Exception("Unknown file extension: " + fn) @@ -234,6 +236,14 @@ def run_analyze_src(fn): ) +# ====================================================================================== +def check_data_files(): + potential_files = [f"./data/{x}_POTENTIALS" for x in ("GTH", "HF", "NLCC", "ALL")] + expected_content = "".join([Path(fn).read_text() for fn in potential_files]) + if Path("./data/POTENTIAL").read_text() != expected_content: + raise Exception("The data files are out of sync - please run `make data`.") + + # ====================================================================================== def run_local_tool(*cmd, timeout=20): p = subprocess.run(cmd, timeout=timeout, stdout=PIPE, stderr=STDOUT)