-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from FredHutch/womtool-pythonize
Womtool and Cromwell test run pythonize
- Loading branch information
Showing
8 changed files
with
158 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
version 1.0 | ||
## This is a test workflow that fails against womtool. | ||
## From https://github.com/broadinstitute/cromwell | ||
#### WORKFLOW DEFINITION | ||
workflow oops { | ||
call oopsie | ||
} | ||
|
||
#### TASK DEFINITIONS | ||
task oopsie { | ||
input { | ||
String str | ||
} | ||
command { echo ${str} } | ||
runtime { docker: docker_image } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ requires-python = ">=3.13" | |
dependencies = [ | ||
"httpx>=0.28.1", | ||
"pytest>=8.3.4", | ||
"sh>=2.1.0", | ||
"tenacity>=9.0.0", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import pytest | ||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
"--wdl-path", | ||
action="store", | ||
default="default_value", | ||
help="Path to a directory with a WDL file to test" | ||
) | ||
|
||
@pytest.fixture | ||
def wdl_path(pytestconfig): | ||
return pytestconfig.getoption("--wdl-path") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from utils import CromwellJava | ||
|
||
cromwell = CromwellJava() | ||
|
||
|
||
def test_cromwell_run(wdl_path): | ||
is_valid = cromwell.run(wdl_path) | ||
if wdl_path.startswith("bad"): | ||
assert not is_valid | ||
else: | ||
assert is_valid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from utils import Womtool | ||
|
||
wom = Womtool() | ||
|
||
|
||
def test_womtool_validate(wdl_path): | ||
is_valid = wom.validate(wdl_path) | ||
if wdl_path.startswith("bad"): | ||
assert not is_valid | ||
else: | ||
assert is_valid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
import sh | ||
|
||
|
||
class Womtool(object): | ||
"""Womtool class""" | ||
|
||
def __init__(self): | ||
self.womtool_path = os.getenv("WOMTOOL_PATH") | ||
if not self.womtool_path: | ||
raise Exception("failed setting WOMTOOL_PATH") | ||
self.womtool = sh.Command("java").bake("-jar", self.womtool_path) | ||
|
||
def has_inputs(self, wdl_path): | ||
path = Path(f"{wdl_path}/inputs.json") | ||
if path.exists(): | ||
self.womtool = self.womtool.bake(i=str(path)) | ||
|
||
def validate(self, wdl_path, show_cmd=False): | ||
try: | ||
self.womtool = self.womtool.bake( | ||
"validate", | ||
f"{wdl_path}/{wdl_path}.wdl", | ||
) | ||
self.has_inputs(wdl_path) | ||
if show_cmd: | ||
print(self.womtool) | ||
self.womtool() | ||
except sh.ErrorReturnCode as e: | ||
print(f"Command {e.full_cmd} exited with {e.exit_code}") | ||
return False | ||
|
||
return True | ||
|
||
class CromwellJava(object): | ||
"""Cromwell Java class - run Cromwell Java jar""" | ||
|
||
def __init__(self): | ||
self.cromwell_path = os.getenv("CROMWELL_PATH") | ||
if not self.cromwell_path: | ||
raise Exception("failed setting CROMWELL_PATH") | ||
self.cromwell = sh.Command("java").bake("-jar", self.cromwell_path) | ||
|
||
def has_inputs(self, wdl_path): | ||
path = Path(f"{wdl_path}/inputs.json") | ||
if path.exists(): | ||
self.cromwell = self.cromwell.bake(i=str(path)) | ||
|
||
def has_options(self, wdl_path): | ||
path = Path(f"{wdl_path}/options.json") | ||
if path.exists(): | ||
self.cromwell = self.cromwell.bake(o=str(path)) | ||
|
||
def run(self, wdl_path, show_cmd=False): | ||
try: | ||
self.cromwell = self.cromwell.bake( | ||
"run", | ||
f"{wdl_path}/{wdl_path}.wdl", | ||
) | ||
self.has_inputs(wdl_path) | ||
self.has_options(wdl_path) | ||
if show_cmd: | ||
print(self.cromwell) | ||
self.cromwell() | ||
except sh.ErrorReturnCode as e: | ||
print(f"Command {e.full_cmd} exited with {e.exit_code}") | ||
return False | ||
|
||
return True |