Skip to content

Commit aa1b7c9

Browse files
committed
Refactor job script/dependency stuff to allow toil pickle-ing.
Does this look cleaner anyway? I suspect yes?
1 parent 9900de0 commit aa1b7c9

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

cwltool/builder.py

Lines changed: 9 additions & 1 deletion
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

Lines changed: 8 additions & 9 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,10 +728,10 @@ def main(argsl=None, # type: List[str]
728728

729729
make_tool_kwds = vars(args)
730730

731-
build_job_script = None # type: Callable[[Any, List[str]], Text]
731+
job_script_provider = None # type: Callable[[Any, List[str]], Text]
732732
if conf_file or use_conda_dependencies:
733733
dependencies_configuration = DependenciesConfiguration(args) # type: DependenciesConfiguration
734-
make_tool_kwds["build_job_script"] = dependencies_configuration.build_job_script
734+
make_tool_kwds["job_script_provider"] = dependencies_configuration
735735

736736
make_tool_kwds["find_default_container"] = functools.partial(find_default_container, args)
737737

cwltool/process.py

Lines changed: 1 addition & 6 deletions
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):

0 commit comments

Comments
 (0)