Skip to content

Commit

Permalink
Add missing utils to Python package
Browse files Browse the repository at this point in the history
  • Loading branch information
pinkwah committed Jan 13, 2021
1 parent 1b67181 commit 8d223db
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 17 deletions.
15 changes: 4 additions & 11 deletions python/ecl/bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
import sys


def _exec(prog):
prog_path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".bin", prog))
os.execl(prog_path, prog_path, *sys.argv[1:])


def ecl_pack():
_exec("ecl_pack.x")


def ecl_unpack():
_exec("ecl_unpack.x")
def main():
prog = os.path.basename(sys.argv[0])
path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".bin", prog))
os.execl(path, path, *sys.argv[1:])
35 changes: 35 additions & 0 deletions python/tests/test_bin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import sys
import pytest
import subprocess
import signal


@pytest.mark.skipif(
sys.platform != "linux", reason="ecl utils are only available on Linux at this time"
)
@pytest.mark.parametrize(
"name,returncode,stderr",
[
("CF_dump", -signal.SIGSEGV, b""),
("convert.x", 1, b"Usage: convert.x"),
("ecl_pack.x", 0, b""),
("ecl_unpack.x", 1, b"ecl_unpack UNIFIED_FILE1"),
("grdecl_grid", -signal.SIGABRT, b"util_fopen: failed to open:(null)"),
("grdecl_test.x", -signal.SIGABRT, b"util_fopen: failed to open:(null)"),
("grid_dump.x", 1, b"grid_dump.x: filename"),
("grid_dump_ascii.x", 1, b"grid_dump_ascii.x: filename"),
("grid_info.x", 1, b"grid_info.x: filename"),
("kw_extract", 0, b"src_file target_file kw1 kw2 kw3"),
("kw_list.x", 0, b""),
("load_test.x", 0, b""),
("make_grid", 1, b"make_grid: basename nx ny nz"),
("ri_well_test", 1, b""),
("segment_info", -signal.SIGSEGV, b""),
("select_test.x", 0, b""),
("summary.x", 1, b""),
],
)
def test_exec(name: str, returncode: int, stderr: str) -> None:
status = subprocess.run([name], stderr=subprocess.PIPE)
assert status.returncode == returncode
assert stderr in status.stderr
41 changes: 35 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
import sys
import skbuild
import setuptools
from setuptools_scm import get_version
Expand All @@ -11,6 +11,38 @@
long_description = f.read()


def utility_wrappers():
"""
Wrappers around ecl's "application" utilities. These are only supported on
Linux at this time so only create the wrapper when on Linux.
"""
if sys.platform != "linux":
return []

return [
name + " = ecl.bin:main"
for name in (
"CF_dump",
"convert.x",
"ecl_pack.x",
"ecl_unpack.x",
"grdecl_grid",
"grdecl_test.x",
"grid_dump.x",
"grid_dump_ascii.x",
"grid_info.x",
"kw_extract",
"kw_list.x",
"load_test.x",
"make_grid",
"ri_well_test",
"segment_info",
"select_test.x",
"summary.x",
)
]


skbuild.setup(
name="ecl",
author="Equinor ASA",
Expand All @@ -34,14 +66,11 @@
"six"
],
entry_points={
"console_scripts": [
"ecl_pack.x = ecl.bin:ecl_pack",
"ecl_unpack.x = ecl.bin:ecl_unpack",
]
"console_scripts": utility_wrappers()
},
cmake_args=[
"-DECL_VERSION=" + version,
"-DBUILD_APPLICATIONS=ON",
"-DBUILD_APPLICATIONS=" + ("ON" if sys.platform == "linux" else "OFF"),
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON",
"-DCMAKE_INSTALL_BINDIR=python/ecl/.bin",
"-DCMAKE_INSTALL_LIBDIR=python/ecl/.libs",
Expand Down

0 comments on commit 8d223db

Please sign in to comment.