From fa0810c5d3efe5580d01aa017d1d28d1e0525912 Mon Sep 17 00:00:00 2001 From: Nils Vu Date: Tue, 9 Apr 2024 16:34:38 -0700 Subject: [PATCH] CleanOutput.py: support glob patterns --- support/Pipelines/Bbh/InitialData.yaml | 3 +++ .../Poisson/ProductOfSinusoids1D.yaml | 7 +----- tests/tools/Test_CleanOutput.py | 4 ++-- tools/CleanOutput.py | 23 +++++++++++-------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/support/Pipelines/Bbh/InitialData.yaml b/support/Pipelines/Bbh/InitialData.yaml index 19e971dacfdd..c33f8cd7aca3 100644 --- a/support/Pipelines/Bbh/InitialData.yaml +++ b/support/Pipelines/Bbh/InitialData.yaml @@ -2,6 +2,9 @@ # See LICENSE.txt for details. Executable: SolveXcts +ExpectedOutput: + - BbhReductions.h5 + - BbhVolume*.h5 {% if evolve %} Next: Run: spectre.Pipelines.Bbh.Inspiral:start_inspiral diff --git a/tests/InputFiles/Poisson/ProductOfSinusoids1D.yaml b/tests/InputFiles/Poisson/ProductOfSinusoids1D.yaml index 3916588e254f..22e382018390 100644 --- a/tests/InputFiles/Poisson/ProductOfSinusoids1D.yaml +++ b/tests/InputFiles/Poisson/ProductOfSinusoids1D.yaml @@ -8,12 +8,7 @@ Testing: ExpectedOutput: - PoissonProductOfSinusoids1DReductions.h5 - PoissonProductOfSinusoids1DVolume0.h5 - - SubdomainMatrix_[B0,(L1I0)].txt - - SubdomainMatrix_[B0,(L1I1)].txt - - SubdomainMatrix_[B0,(L2I0)].txt - - SubdomainMatrix_[B0,(L2I1)].txt - - SubdomainMatrix_[B0,(L2I2)].txt - - SubdomainMatrix_[B0,(L2I3)].txt + - SubdomainMatrix*.txt OutputFileChecks: - Label: Discretization error Subfile: ErrorNorms.dat diff --git a/tests/tools/Test_CleanOutput.py b/tests/tools/Test_CleanOutput.py index bb822e283b52..c89e5d451966 100644 --- a/tests/tools/Test_CleanOutput.py +++ b/tests/tools/Test_CleanOutput.py @@ -27,7 +27,7 @@ def setUp(self): os.makedirs(self.test_dir, exist_ok=True) with open(self.input_file_path, "w") as open_file: yaml.safe_dump_all( - [{"ExpectedOutput": ["Reduction.h5", "Volume0.h5"]}, {}], + [{"ExpectedOutput": ["Reduction.h5", "Volume*.h5"]}, {}], open_file, ) @@ -48,7 +48,7 @@ def test_clean_output(self): ) with open(self.reduction_file_path, "w"): pass - with self.assertRaisesRegex(MissingExpectedOutputError, "Volume0.h5"): + with self.assertRaisesRegex(MissingExpectedOutputError, "Volume\*.h5"): clean_output( input_file=self.input_file_path, output_dir=self.test_dir, diff --git a/tools/CleanOutput.py b/tools/CleanOutput.py index 61bf5f91682a..6d994972a073 100644 --- a/tools/CleanOutput.py +++ b/tools/CleanOutput.py @@ -1,6 +1,7 @@ # Distributed under the MIT License. # See LICENSE.txt for details. +import glob import logging import os import shutil @@ -24,13 +25,14 @@ def clean_output(input_file, output_dir, force): Deletes output files specified in the `input_file` from the `output_dir`, raising an error if the expected output files were not found. - The `input_file` must list its expected output files in the metadata: + The `input_file` must list its expected output files in the metadata. + They may contain glob patterns: \b ```yaml ExpectedOutput: - Reduction.h5 - - Volume0.h5 + - Volume*.h5 ``` """ with open(input_file, "r") as open_input_file: @@ -52,14 +54,17 @@ def clean_output(input_file, output_dir, force): missing_files = [] for expected_output_file in expected_output: - expected_output_file = os.path.join(output_dir, expected_output_file) + found_output_files = glob.glob( + os.path.join(output_dir, expected_output_file) + ) logging.debug(f"Attempting to remove file {expected_output_file}...") - if os.path.exists(expected_output_file): - if os.path.isfile(expected_output_file): - os.remove(expected_output_file) - else: - shutil.rmtree(expected_output_file) - logging.info(f"Removed file {expected_output_file}.") + if len(found_output_files) > 0: + for expected_output_file in found_output_files: + if os.path.isfile(expected_output_file): + os.remove(expected_output_file) + else: + shutil.rmtree(expected_output_file) + logging.info(f"Removed file {expected_output_file}.") elif not force: missing_files.append(expected_output_file) logging.error(