Skip to content

Commit cf32697

Browse files
authored
Merge pull request #112 from sondreso/hook-implemenation
Use ERT plugin system
2 parents 87f14ec + d7202af commit cf32697

7 files changed

Lines changed: 84 additions & 1 deletion

File tree

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ before_script:
7878
-DBUILD_SHARED_LIBS=ON
7979
- make -j 4 install
8080
- popd; popd
81+
- git clone --branch master --depth 1 https://github.com/equinor/ert
82+
- pushd ert
83+
- source .libres_version
84+
- rm -rf tests # Avoid running these tests.
85+
- rm -rf test-data # Avoid running these tests.
86+
- popd
87+
- git clone --branch $LIBRES_VERSION --depth 1 https://github.com/equinor/libres
88+
- pushd libres
89+
- pip install -r requirements.txt --prefix=$INSTALL_DIR
90+
- rm -rf python/tests # Avoid running these tests.
91+
- rm -rf test-data # Avoid running these tests.
92+
- popd
93+
- bash ert/.build_install.sh libres
94+
- pip install ert/ --prefix=$INSTALL_DIR
8195

8296
script:
8397
- pip install .

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@
6464
install_requires=[],
6565
setup_requires=["setuptools >=28", "setuptools_scm", "pytest-runner"],
6666
tests_require=["pytest"],
67-
entry_points={"console_scripts": SSCRIPTS},
67+
entry_points={
68+
"console_scripts": SSCRIPTS,
69+
"ert": ["subscript_jobs = subscript.hook_implementations.jobs"],
70+
},
6871
scripts=["src/subscript/legacy/" + scriptname for scriptname in LEGACYSCRIPTS],
6972
use_scm_version={"write_to": "src/subscript/version.py"},
7073
test_suite="tests",

src/subscript/config_jobs/SUNSCH

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
EXECUTABLE ../sunsch/sunsch.py
2+
ARGLIST <config>
3+
4+
MIN_ARG 1
5+
MAX_ARG 1
6+
ARG_TYPE 0 STRING

src/subscript/hook_implementations/__init__.py

Whitespace-only changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import os
2+
from pkg_resources import resource_filename
3+
4+
from ert_shared.plugins.plugin_manager import hook_implementation
5+
from ert_shared.plugins.plugin_response import plugin_response
6+
7+
8+
def _get_jobs_from_directory(directory):
9+
resource_directory = resource_filename("subscript", directory)
10+
11+
all_files = [
12+
os.path.join(resource_directory, f)
13+
for f in os.listdir(resource_directory)
14+
if os.path.isfile(os.path.join(resource_directory, f))
15+
]
16+
return {os.path.basename(path): path for path in all_files}
17+
18+
19+
@hook_implementation
20+
@plugin_response(plugin_name="subscript")
21+
def installable_jobs():
22+
return _get_jobs_from_directory("config_jobs")
23+
24+
25+
@hook_implementation
26+
@plugin_response(plugin_name="subscript")
27+
def installable_workflow_jobs():
28+
return {}

src/subscript/sunsch/sunsch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python
12
"""
23
Tool for generating Eclipse Schedule files
34

tests/test_hook_implementations.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
import sys
3+
4+
import pytest
5+
6+
import subscript.hook_implementations.jobs
7+
from ert_shared.plugins.plugin_manager import ErtPluginManager
8+
9+
10+
@pytest.mark.skipif(sys.version_info.major < 3, reason="requires python3")
11+
def test_hook_implementations():
12+
pm = ErtPluginManager(plugins=[subscript.hook_implementations.jobs])
13+
14+
expected_jobs = {
15+
"SUNSCH": "subscript/config_jobs/SUNSCH",
16+
}
17+
installable_jobs = pm.get_installable_jobs()
18+
for wf_name, wf_location in expected_jobs.items():
19+
assert wf_name in installable_jobs
20+
assert installable_jobs[wf_name].endswith(wf_location)
21+
assert os.path.isfile(installable_jobs[wf_name])
22+
23+
assert set(installable_jobs.keys()) == set(expected_jobs.keys())
24+
25+
expected_workflow_jobs = {}
26+
installable_workflow_jobs = pm.get_installable_workflow_jobs()
27+
for wf_name, wf_location in expected_workflow_jobs.items():
28+
assert wf_name in installable_workflow_jobs
29+
assert installable_workflow_jobs[wf_name].endswith(wf_location)
30+
31+
assert set(installable_workflow_jobs.keys()) == set(expected_workflow_jobs.keys())

0 commit comments

Comments
 (0)