From e35c66345a8a1626dd46dc5f1ad5baa8afe35a65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85dne=20Jacobsen?= Date: Wed, 11 Oct 2023 12:47:39 +0200 Subject: [PATCH] ert implementation stuff --- setup.cfg | 4 ++ src/fmu/sumo/uploader/config_jobs/SUMO_UPLOAD | 23 +++++++ .../uploader/hook_implementations/__init__.py | 0 .../uploader/hook_implementations/jobs.py | 61 +++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 src/fmu/sumo/uploader/config_jobs/SUMO_UPLOAD create mode 100644 src/fmu/sumo/uploader/hook_implementations/__init__.py create mode 100644 src/fmu/sumo/uploader/hook_implementations/jobs.py diff --git a/setup.cfg b/setup.cfg index 80253ed..9893f36 100644 --- a/setup.cfg +++ b/setup.cfg @@ -58,3 +58,7 @@ test=pytest [options.entry_points] console_scripts = sumo_upload=fmu.sumo.uploader.scripts.sumo_upload:main +ert = + fmu_sumo_jobs = fmu.sumo.hook_implementations.jobs + sumo_upload = fmu.sumo.uploader.scripts.sumo_upload + diff --git a/src/fmu/sumo/uploader/config_jobs/SUMO_UPLOAD b/src/fmu/sumo/uploader/config_jobs/SUMO_UPLOAD new file mode 100644 index 0000000..b45b950 --- /dev/null +++ b/src/fmu/sumo/uploader/config_jobs/SUMO_UPLOAD @@ -0,0 +1,23 @@ +-- This is the forward model job which uploads data to Sumo +-- It is called from the ERT config file as a regular forward model + +-- Arguments: +-- SUMO_CASEPATH: The absolute path to the root of the case +-- e.g. // +-- SEARCHPATH: The searchpath relative to the realization root +-- e.g "share/results/maps/*.gri" +-- SUMO_ENV: The environment to upload to + +STDERR sumo_upload.stderr +STDOUT sumo_upload.stdout + +EXECUTABLE sumo_upload + + +ARGLIST + +MIN_ARG 2 +MAX_ARG 3 +ARG_TYPE 0 STRING +ARG_TYPE 1 STRING +ARG_TYPE 2 STRING diff --git a/src/fmu/sumo/uploader/hook_implementations/__init__.py b/src/fmu/sumo/uploader/hook_implementations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/fmu/sumo/uploader/hook_implementations/jobs.py b/src/fmu/sumo/uploader/hook_implementations/jobs.py new file mode 100644 index 0000000..29afadf --- /dev/null +++ b/src/fmu/sumo/uploader/hook_implementations/jobs.py @@ -0,0 +1,61 @@ +import importlib +import os +from pkg_resources import resource_filename + +from ert.shared.plugins.plugin_manager import hook_implementation +from ert.shared.plugins.plugin_response import plugin_response + + +def _get_jobs_from_directory(directory): + """Do a filesystem lookup in a directory to check + for available ERT forward models""" + resource_directory = resource_filename("fmu", directory) + + all_files = [ + os.path.join(resource_directory, f) + for f in os.listdir(resource_directory) + if os.path.isfile(os.path.join(resource_directory, f)) + ] + return {os.path.basename(path): path for path in all_files} + + +# pylint: disable=no-value-for-parameter +@hook_implementation +@plugin_response(plugin_name="fmu_sumo") # pylint: disable=no-value-for-parameter +def installable_jobs(): + return _get_jobs_from_directory("sumo/config_jobs") + + +def _get_module_variable_if_exists(module_name, variable_name, default=""): + try: + script_module = importlib.import_module(module_name) + except ImportError: + return default + + return getattr(script_module, variable_name, default) + + +@hook_implementation +@plugin_response(plugin_name="fmu_sumo") # pylint: disable=no-value-for-parameter +def job_documentation(job_name): + sumo_fmu_jobs = set(installable_jobs().data.keys()) + if job_name not in sumo_fmu_jobs: + return None + + module_name = "jobs.scripts.{}".format(job_name.lower()) + + description = _get_module_variable_if_exists( + module_name=module_name, variable_name="description" + ) + examples = _get_module_variable_if_exists( + module_name=module_name, variable_name="examples" + ) + category = _get_module_variable_if_exists( + module_name=module_name, variable_name="category", default="other" + ) + + return { + "description": description, + "examples": examples, + "category": category, + }