Skip to content

Commit e9c6a38

Browse files
authored
Merge pull request #456 from jmchilton/galaxy_deps_toil_refactor
Tweak SoftwareRequirement handling for reuse in Toil.
2 parents 9900de0 + 8af03a6 commit e9c6a38

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

cwltool/builder.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def __init__(self): # type: () -> None
4242
self.pathmapper = None # type: PathMapper
4343
self.stagedir = None # type: Text
4444
self.make_fs_access = None # type: Type[StdFsAccess]
45-
self.build_job_script = None # type: Callable[[List[str]], Text]
4645
self.debug = False # type: bool
4746
self.mutation_manager = None # type: MutationManager
4847

@@ -51,6 +50,15 @@ def __init__(self): # type: () -> None
5150
self.loadListing = "deep_listing" # type: Union[None, str]
5251

5352
self.find_default_container = None # type: Callable[[], Text]
53+
self.job_script_provider = None # type: Any
54+
55+
def build_job_script(self, commands):
56+
# type: (List[str]) -> Text
57+
build_job_script_method = getattr(self.job_script_provider, "build_job_script", None) # type: Callable[[Builder, List[str]], Text]
58+
if build_job_script_method:
59+
return build_job_script_method(self, commands)
60+
else:
61+
return None
5462

5563
def bind_input(self, schema, datum, lead_pos=None, tail_pos=None):
5664
# type: (Dict[Text, Any], Any, Union[int, List[int]], List[int]) -> List[Dict[Text, Any]]

cwltool/job.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,19 @@ def _execute(self, runtime, env, rm_tmpdir=True, move_outputs="move"):
190190
os.makedirs(dn)
191191
stdout_path = absout
192192

193-
build_job_script = self.builder.build_job_script # type: Callable[[List[str]], Text]
193+
commands = [Text(x).encode('utf-8') for x in runtime + self.command_line]
194+
job_script_contents = None # type: Text
195+
builder = getattr(self, "builder", None) # type: Builder
196+
if builder is not None:
197+
job_script_contents = builder.build_job_script(commands)
194198
rcode = _job_popen(
195-
[Text(x).encode('utf-8') for x in runtime + self.command_line],
199+
commands,
196200
stdin_path=stdin_path,
197201
stdout_path=stdout_path,
198202
stderr_path=stderr_path,
199203
env=env,
200204
cwd=self.outdir,
201-
build_job_script=build_job_script,
205+
job_script_contents=job_script_contents,
202206
)
203207

204208
if self.successCodes and rcode in self.successCodes:
@@ -401,14 +405,9 @@ def _job_popen(
401405
env, # type: Union[MutableMapping[Text, Text], MutableMapping[str, str]]
402406
cwd, # type: Text
403407
job_dir=None, # type: Text
404-
build_job_script=None, # type: Callable[[List[str]], Text]
408+
job_script_contents=None, # type: Text
405409
):
406410
# type: (...) -> int
407-
408-
job_script_contents = None # type: Text
409-
if build_job_script:
410-
job_script_contents = build_job_script(commands)
411-
412411
if not job_script_contents and not FORCE_SHELLED_POPEN:
413412

414413
stdin = None # type: Union[IO[Any], int]

cwltool/main.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from schema_salad.sourceline import strip_dup_lineno
2222

2323
from . import draft2tool, workflow
24+
from .builder import Builder
2425
from .cwlrdf import printdot, printrdf
2526
from .errors import UnsupportedRequirement, WorkflowException
2627
from .load_tool import fetch_document, make_tool, validate_document, jobloaderctx
@@ -255,6 +256,9 @@ def output_callback(out, processStatus):
255256
try:
256257
for r in jobiter:
257258
if r:
259+
builder = kwargs.get("builder", None) # type: Builder
260+
if builder is not None:
261+
r.builder = builder
258262
if r.outdir:
259263
output_dirs.add(r.outdir)
260264
r.run(**kwargs)
@@ -728,10 +732,10 @@ def main(argsl=None, # type: List[str]
728732

729733
make_tool_kwds = vars(args)
730734

731-
build_job_script = None # type: Callable[[Any, List[str]], Text]
735+
job_script_provider = None # type: Callable[[Any, List[str]], Text]
732736
if conf_file or use_conda_dependencies:
733737
dependencies_configuration = DependenciesConfiguration(args) # type: DependenciesConfiguration
734-
make_tool_kwds["build_job_script"] = dependencies_configuration.build_job_script
738+
make_tool_kwds["job_script_provider"] = dependencies_configuration
735739

736740
make_tool_kwds["find_default_container"] = functools.partial(find_default_container, args)
737741

cwltool/process.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -598,12 +598,7 @@ def _init_job(self, joborder, **kwargs):
598598

599599
builder.resources = self.evalResources(builder, kwargs)
600600

601-
build_job_script = kwargs.get("build_job_script", None) # type: Callable[[Builder, List[str]], Text]
602-
curried_build_job_script = None # type: Callable[[List[str]], Text]
603-
if build_job_script:
604-
curried_build_job_script = lambda commands: build_job_script(builder, commands)
605-
builder.build_job_script = curried_build_job_script
606-
601+
builder.job_script_provider = kwargs.get("job_script_provider", None)
607602
return builder
608603

609604
def evalResources(self, builder, kwargs):

tests/test_deps_env/random-lines/1.0/env.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
# This shouldn't need to use bash-isms - but we don't know the full path to this file,
55
# so for testing it is setup this way. For actual deployments just using full paths
66
# directly would be preferable.
7-
PACKAGE_DIRECTORY="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/tests/test_deps_env/random-lines/1.0/"
7+
PACKAGE_DIRECTORY="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/"
88
export PATH=$PATH:$PACKAGE_DIRECTORY/scripts

0 commit comments

Comments
 (0)