From af4c01ff26b104fd565ed0a4f7e7aa885fb55551 Mon Sep 17 00:00:00 2001 From: Runar Ask Johannessen Date: Wed, 16 Oct 2024 11:14:32 +0200 Subject: [PATCH] Require certain ERT env variables before running --- src/fmu/sumo/sim2sumo/main.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/fmu/sumo/sim2sumo/main.py b/src/fmu/sumo/sim2sumo/main.py index f1ef401..36daa6b 100644 --- a/src/fmu/sumo/sim2sumo/main.py +++ b/src/fmu/sumo/sim2sumo/main.py @@ -2,6 +2,7 @@ import argparse import logging +from os import environ from .grid3d import upload_simulation_runs from .tables import upload_tables @@ -64,9 +65,24 @@ def parse_args(): return args +# fmu-dataio needs these when creating metadata +REQUIRED_ENV_VARS = ["_ERT_EXPERIMENT_ID", "_ERT_RUNPATH"] + + def main(): """Main function to be called""" logger = logging.getLogger(__file__ + ".main") + + missing = 0 + for envVar in REQUIRED_ENV_VARS: + if environ.get(envVar) is None: + print(f"{envVar} is not set.") + missing += 1 + + if missing > 0: + print("Missing required environment variables. Stopping.") + exit() + args = parse_args() logger.debug("Running with arguments %s", args) if args.help_on != "No help":