Skip to content

Commit

Permalink
Minor improvements to benchmark data generation messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
trexfeathers committed Nov 21, 2022
1 parent a8e6a13 commit c3fa502
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion benchmarks/benchmarks/generate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from pathlib import Path
import re
from textwrap import dedent
from warnings import warn

from iris import load_cube
from iris.experimental.ugrid import PARSE_UGRID_ON_LOAD
Expand All @@ -35,15 +36,23 @@
error = "Env variable DATA_GEN_PYTHON not a runnable python executable path."
raise ValueError(error)

# The default location of data files used in benchmarks. Used by CI.
default_data_dir = (Path(__file__).parent.parent / ".data").resolve()
# Optionally override the default data location with environment variable.
BENCHMARK_DATA = Path(environ.get("BENCHMARK_DATA", default_data_dir))
if BENCHMARK_DATA == default_data_dir:
BENCHMARK_DATA.mkdir(exist_ok=True)
message = (
f"No BENCHMARK_DATA env var, defaulting to {BENCHMARK_DATA}. "
"Note that some benchmark files are GB in size."
)
warn(message)
elif not BENCHMARK_DATA.is_dir():
message = f"Not a directory: {BENCHMARK_DATA} ."
raise ValueError(message)

# Flag to allow the rebuilding of synthetic data.
# Manual flag to allow the rebuilding of synthetic data.
# False forces a benchmark run to re-make all the data files.
REUSE_DATA = True


Expand Down Expand Up @@ -74,6 +83,7 @@ def run_function_elsewhere(func_to_run, *args, **kwargs):
"""
func_string = dedent(getsource(func_to_run))
func_string = func_string.replace("@staticmethod\n", "")
func_call_term_strings = [repr(arg) for arg in args]
func_call_term_strings += [f"{name}={repr(val)}" for name, val in kwargs.items()]
func_call_string = (
Expand Down

0 comments on commit c3fa502

Please sign in to comment.