Skip to content

Commit

Permalink
Merge pull request #112 from sondreso/hook-implemenation
Browse files Browse the repository at this point in the history
Use ERT plugin system
  • Loading branch information
berland authored May 26, 2020
2 parents 87f14ec + d7202af commit cf32697
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ before_script:
-DBUILD_SHARED_LIBS=ON
- make -j 4 install
- popd; popd
- git clone --branch master --depth 1 https://github.com/equinor/ert
- pushd ert
- source .libres_version
- rm -rf tests # Avoid running these tests.
- rm -rf test-data # Avoid running these tests.
- popd
- git clone --branch $LIBRES_VERSION --depth 1 https://github.com/equinor/libres
- pushd libres
- pip install -r requirements.txt --prefix=$INSTALL_DIR
- rm -rf python/tests # Avoid running these tests.
- rm -rf test-data # Avoid running these tests.
- popd
- bash ert/.build_install.sh libres
- pip install ert/ --prefix=$INSTALL_DIR

script:
- pip install .
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@
install_requires=[],
setup_requires=["setuptools >=28", "setuptools_scm", "pytest-runner"],
tests_require=["pytest"],
entry_points={"console_scripts": SSCRIPTS},
entry_points={
"console_scripts": SSCRIPTS,
"ert": ["subscript_jobs = subscript.hook_implementations.jobs"],
},
scripts=["src/subscript/legacy/" + scriptname for scriptname in LEGACYSCRIPTS],
use_scm_version={"write_to": "src/subscript/version.py"},
test_suite="tests",
Expand Down
6 changes: 6 additions & 0 deletions src/subscript/config_jobs/SUNSCH
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
EXECUTABLE ../sunsch/sunsch.py
ARGLIST <config>

MIN_ARG 1
MAX_ARG 1
ARG_TYPE 0 STRING
Empty file.
28 changes: 28 additions & 0 deletions src/subscript/hook_implementations/jobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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):
resource_directory = resource_filename("subscript", 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}


@hook_implementation
@plugin_response(plugin_name="subscript")
def installable_jobs():
return _get_jobs_from_directory("config_jobs")


@hook_implementation
@plugin_response(plugin_name="subscript")
def installable_workflow_jobs():
return {}
1 change: 1 addition & 0 deletions src/subscript/sunsch/sunsch.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python
"""
Tool for generating Eclipse Schedule files
Expand Down
31 changes: 31 additions & 0 deletions tests/test_hook_implementations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
import sys

import pytest

import subscript.hook_implementations.jobs
from ert_shared.plugins.plugin_manager import ErtPluginManager


@pytest.mark.skipif(sys.version_info.major < 3, reason="requires python3")
def test_hook_implementations():
pm = ErtPluginManager(plugins=[subscript.hook_implementations.jobs])

expected_jobs = {
"SUNSCH": "subscript/config_jobs/SUNSCH",
}
installable_jobs = pm.get_installable_jobs()
for wf_name, wf_location in expected_jobs.items():
assert wf_name in installable_jobs
assert installable_jobs[wf_name].endswith(wf_location)
assert os.path.isfile(installable_jobs[wf_name])

assert set(installable_jobs.keys()) == set(expected_jobs.keys())

expected_workflow_jobs = {}
installable_workflow_jobs = pm.get_installable_workflow_jobs()
for wf_name, wf_location in expected_workflow_jobs.items():
assert wf_name in installable_workflow_jobs
assert installable_workflow_jobs[wf_name].endswith(wf_location)

assert set(installable_workflow_jobs.keys()) == set(expected_workflow_jobs.keys())

0 comments on commit cf32697

Please sign in to comment.