Skip to content

Commit 876c0fc

Browse files
authored
Fix serializing Directory[] on command line. (#190)
* Fix serializing Directory[] on command line. Also handle Directory[] in generate_parser.
1 parent 17fcf8d commit 876c0fc

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

cwltool/builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def generate_arg(self, binding): # type: (Dict[Text,Any]) -> List[Text]
155155
if binding.get("itemSeparator"):
156156
l = [binding["itemSeparator"].join([self.tostr(v) for v in value])]
157157
elif binding.get("valueFrom"):
158-
value = [v["path"] if isinstance(v, dict) and v.get("class") == "File" else v for v in value]
158+
value = [self.tostr(v) for v in value]
159159
return ([prefix] if prefix else []) + value
160160
elif prefix:
161161
return [prefix]

cwltool/main.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -237,45 +237,30 @@ def output_callback(out, processStatus):
237237
return final_output[0]
238238

239239

240-
class FileAction(argparse.Action):
240+
class FSAction(argparse.Action):
241+
objclass = None # type: Text
241242

242243
def __init__(self, option_strings, dest, nargs=None, **kwargs):
243244
# type: (List[Text], Text, Any, **Any) -> None
244245
if nargs is not None:
245246
raise ValueError("nargs not allowed")
246-
super(FileAction, self).__init__(option_strings, dest, **kwargs)
247+
super(FSAction, self).__init__(option_strings, dest, **kwargs)
247248

248249
def __call__(self, parser, namespace, values, option_string=None):
249250
# type: (argparse.ArgumentParser, argparse.Namespace, Union[AnyStr, Sequence[Any], None], AnyStr) -> None
250251
setattr(namespace,
251252
self.dest, # type: ignore
252-
{"class": "File",
253+
{"class": self.objclass,
253254
"location": "file://%s" % os.path.abspath(cast(AnyStr, values))})
254255

255-
256-
class DirectoryAction(argparse.Action):
256+
class FSAppendAction(argparse.Action):
257+
objclass = None # type: Text
257258

258259
def __init__(self, option_strings, dest, nargs=None, **kwargs):
259260
# type: (List[Text], Text, Any, **Any) -> None
260261
if nargs is not None:
261262
raise ValueError("nargs not allowed")
262-
super(DirectoryAction, self).__init__(option_strings, dest, **kwargs)
263-
264-
def __call__(self, parser, namespace, values, option_string=None):
265-
# type: (argparse.ArgumentParser, argparse.Namespace, Union[AnyStr, Sequence[Any], None], AnyStr) -> None
266-
setattr(namespace,
267-
self.dest, # type: ignore
268-
{"class": "Directory",
269-
"location": "file://%s" % os.path.abspath(cast(AnyStr, values))})
270-
271-
272-
class FileAppendAction(argparse.Action):
273-
274-
def __init__(self, option_strings, dest, nargs=None, **kwargs):
275-
# type: (List[Text], Text, Any, **Any) -> None
276-
if nargs is not None:
277-
raise ValueError("nargs not allowed")
278-
super(FileAppendAction, self).__init__(option_strings, dest, **kwargs)
263+
super(FSAppendAction, self).__init__(option_strings, dest, **kwargs)
279264

280265
def __call__(self, parser, namespace, values, option_string=None):
281266
# type: (argparse.ArgumentParser, argparse.Namespace, Union[AnyStr, Sequence[Any], None], AnyStr) -> None
@@ -288,9 +273,20 @@ def __call__(self, parser, namespace, values, option_string=None):
288273
self.dest, # type: ignore
289274
g)
290275
g.append(
291-
{"class": "File",
276+
{"class": self.objclass,
292277
"location": "file://%s" % os.path.abspath(cast(AnyStr, values))})
293278

279+
class FileAction(FSAction):
280+
objclass = "File"
281+
282+
class DirectoryAction(FSAction):
283+
objclass = "Directory"
284+
285+
class FileAppendAction(FSAppendAction):
286+
objclass = "File"
287+
288+
class DirectoryAppendAction(FSAppendAction):
289+
objclass = "Directory"
294290

295291
def generate_parser(toolparser, tool, namemap):
296292
# type: (argparse.ArgumentParser, Process, Dict[Text, Text]) -> argparse.ArgumentParser
@@ -330,6 +326,8 @@ def generate_parser(toolparser, tool, namemap):
330326
elif isinstance(inptype, dict) and inptype["type"] == "array":
331327
if inptype["items"] == "File":
332328
action = cast(argparse.Action, FileAppendAction)
329+
elif inptype["items"] == "Directory":
330+
action = cast(argparse.Action, DirectoryAppendAction)
333331
else:
334332
action = "append"
335333
elif isinstance(inptype, dict) and inptype["type"] == "enum":

0 commit comments

Comments
 (0)