Skip to content

Commit

Permalink
cwl: ignore argument same as stream name
Browse files Browse the repository at this point in the history
(closes #154)
  • Loading branch information
jirikuncar committed May 24, 2018
1 parent 4bd112f commit 6a7315c
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions renku/models/cwl/command_line_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,11 @@ def validate_path(self, attribute, value):
if not value.exists():
raise ValueError('Directory must exist.')

def file_candidate(self, candidate):
def file_candidate(self, candidate, ignore=None):
"""Return a path instance if it exists in current directory."""
if ignore and candidate in ignore:
return

candidate = Path(candidate)

if not candidate.is_absolute():
Expand All @@ -241,15 +244,15 @@ def split_command_and_args(self):

return cmd, args

def guess_type(self, value):
def guess_type(self, value, ignore_filenames=None):
"""Return new value and CWL parameter type."""
try:
value = int(value)
return value, 'int', None
except ValueError:
pass

candidate = self.file_candidate(value)
candidate = self.file_candidate(value, ignore=ignore_filenames)
if candidate:
try:
return File(path=candidate.relative_to(self.directory)
Expand All @@ -270,6 +273,11 @@ def guess_inputs(self, *arguments):
position = 0
prefix = None

output_streams = {
getattr(self, stream_name)
for stream_name in ('stdout', 'stderr')
}

for index, argument in enumerate(arguments):
itemSeparator = None

Expand All @@ -286,7 +294,9 @@ def guess_inputs(self, *arguments):
if '=' in argument:
prefix, default = argument.split('=', 1)
prefix += '='
default, type, itemSeparator = self.guess_type(default)
default, type, itemSeparator = self.guess_type(
default, ignore_filenames=output_streams
)
# TODO can be output

position += 1
Expand All @@ -310,12 +320,14 @@ def guess_inputs(self, *arguments):
if '=' in argument:
prefix, default = argument.split('=', 1)
prefix += '='
default, type, itemSeparator = self.guess_type(default)
default, type, itemSeparator = self.guess_type(
default, ignore_filenames=output_streams
)
else:
# possibly a flag with value
prefix = argument[0:2]
default, type, itemSeparator = self.guess_type(
argument[2:]
argument[2:], ignore_filenames=output_streams
)

position += 1
Expand All @@ -335,7 +347,9 @@ def guess_inputs(self, *arguments):
prefix = argument

else:
default, type, itemSeparator = self.guess_type(argument)
default, type, itemSeparator = self.guess_type(
argument, ignore_filenames=output_streams
)
# TODO can be output

# TODO there might be an array
Expand Down

0 comments on commit 6a7315c

Please sign in to comment.