Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require certain ERT env variables before running #109

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/fmu/sumo/sim2sumo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import argparse
import logging
from os import environ

from .grid3d import upload_simulation_runs
from .tables import upload_tables
Expand Down Expand Up @@ -54,9 +55,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"Required environment variable {envVar} is not set.")
missing += 1

if missing > 0:
print("Required ERT environment variables not found. This can happen if sim2sumo was called outside the ERT context. Stopping.")
exit()

args = parse_args()
logger.debug("Running with arguments %s", args)

Expand Down