Skip to content

Commit

Permalink
minor code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
NishchayKarle committed Feb 19, 2024
1 parent c664177 commit 300e6aa
Showing 1 changed file with 18 additions and 32 deletions.
50 changes: 18 additions & 32 deletions cwl/cwl_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from schema import Or, Regex, Schema, SchemaError


# pylint: disable=too-many-instance-attributes
class InputArgument:
"""Class to represent input arguments for a command line tool"""

Expand All @@ -39,7 +38,6 @@ class InputArgument:
LONG = "long"
STRING = "string"

# pylint: disable=too-many-arguments
def __init__(
self,
arg_id: str,
Expand Down Expand Up @@ -89,7 +87,7 @@ def to_string_template(self) -> str:

input_arg_str = ""
if self.array:
itm_sep = self.item_separator if self.item_separator else " "
itm_sep = self.item_separator or " "
input_arg_str += f"<{self.arg_id}_1{itm_sep}...{itm_sep}{self.arg_id}_n>"

else:
Expand Down Expand Up @@ -122,15 +120,13 @@ def to_string(self, value: Any = None) -> str:

if self.prefix:
res_string = (
f"{self.prefix} " + res_string if self.separate else f"{self.prefix}{res_string}"
f"{self.prefix} {res_string}" if self.separate else f"{self.prefix}{res_string}"
)

return res_string

def __boolean_to_string(self, value: Any) -> str:
if value:
return str(self.prefix)
return ""
return str(self.prefix) if value else ""

def __process_value(self, value: Any, str_quote="") -> str:
if self.array:
Expand All @@ -143,7 +139,7 @@ def __process_value(self, value: Any, str_quote="") -> str:
)

def __process_array_value(self, value: Any, str_quote="") -> str:
itm_sep = self.item_separator if self.item_separator else " "
itm_sep = self.item_separator or " "
str_value_list = [
(
f"{str_quote}{str(v)}{str_quote}"
Expand All @@ -156,16 +152,9 @@ def __process_array_value(self, value: Any, str_quote="") -> str:
return itm_sep.join(str_value_list)

def __lt__(self, other) -> bool:
if self.position is None and other.position is None:
return True

if self.position is None:
return False

if other.position is None:
return True

return self.position < other.position
return other.position is None
return True if other.position is None else self.position < other.position


OutputArgument = namedtuple("Output", ["arg_id", "arg_type", "array"])
Expand Down Expand Up @@ -241,7 +230,6 @@ def __call__(self, **kwargs: Any):
the input and output arguments in the CWL file.
"""

# pylint: disable=unused-argument
@bash_app
def __parsl_bash_app__(
command: str,
Expand Down Expand Up @@ -529,24 +517,22 @@ def __get_parsl_bash_app_args(self, **kwargs) -> Dict[str, Any]:
"""

def handle_input_output_files(file):
if file.arg_type == "File" and file.arg_id in kwargs:
if file.array:
for f in kwargs[file.arg_id]:
if not isinstance(f, (File, DataFuture)):
raise TypeError(
f"{file.arg_id}: Expected list[{File}] type, got {type(f)}"
)
if file.arg_type != "File" or file.arg_id not in kwargs:
return []

return kwargs[file.arg_id]
if file.array:
for f in kwargs[file.arg_id]:
if not isinstance(f, (File, DataFuture)):
raise TypeError(f"{file.arg_id}: Expected list[{File}] type, got {type(f)}")

if not isinstance(kwargs[file.arg_id], (File, DataFuture)):
raise TypeError(
f"{file.arg_id}: Expected {File} type, got {type(kwargs[file.arg_id])}"
)
return kwargs[file.arg_id]

return [kwargs[file.arg_id]]
if not isinstance(kwargs[file.arg_id], (File, DataFuture)):
raise TypeError(
f"{file.arg_id}: Expected {File} type, got {type(kwargs[file.arg_id])}"
)

return []
return [kwargs[file.arg_id]]

# Check if all the output arguments are provided
stdout = None
Expand Down

0 comments on commit 300e6aa

Please sign in to comment.