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

Move ert config #17

Merged
merged 6 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
write_to = "src/fmu/sumo/sim2sumo/version.py"

[tool.black]
line-length = 79
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ where = src
[options.entry_points]
console_scripts =
sim2sumo = fmu.sumo.sim2sumo.sim2sumo:main
ert =
fmu_sumo_sim2sumo_jobs = fmu.sumo.sim2sumo.hook_implementations.jobs
1 change: 1 addition & 0 deletions src/fmu/sumo/sim2sumo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
Empty file.
65 changes: 65 additions & 0 deletions src/fmu/sumo/sim2sumo/hook_implementations/jobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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_sim2sumo"
) # pylint: disable=no-value-for-parameter
def installable_jobs():
return _get_jobs_from_directory("sumo/sim2sumo/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_sim2sumo"
) # 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,
}