Skip to content

Commit

Permalink
add extra data types
Browse files Browse the repository at this point in the history
  • Loading branch information
giannisdoukas committed Jun 20, 2020
1 parent 39207ff commit df64c68
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
14 changes: 12 additions & 2 deletions ipython2cwl/cwltool.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import astor
import yaml

from .iotypes import CWLFilePathInput, CWLBooleanInput
from .iotypes import CWLFilePathInput, CWLBooleanInput, CWLIntInput, CWLStringInput
from .requirements_manager import RequirementsManager

with open(os.sep.join([os.path.abspath(os.path.dirname(__file__)), 'template.dockerfile'])) as f:
Expand Down Expand Up @@ -41,7 +41,17 @@ def visit_AnnAssign(self, node):
'boolean',
'click.BOOL',
input_flag,
)
),
CWLIntInput.__name__: (
'int',
'click.INT',
input_flag,
),
CWLStringInput.__name__: (
'string',
'click.STRING',
input_flag,
),
}
"""Mapping types. First tuple required, second optional"""
try:
Expand Down
8 changes: 8 additions & 0 deletions ipython2cwl/iotypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ class CWLFilePathInput(typing.TextIO):

class CWLBooleanInput:
pass


class CWLStringInput:
pass


class CWLIntInput:
pass
20 changes: 19 additions & 1 deletion tests/test_cwltool.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@


class TestCWLTool(TestCase):
maxDiff = None

def test_AnnotatedIPython2CWLToolConverter_cwl_command_line_tool(self):
annotated_python_script = os.linesep.join([
"import csv",
"input_filename: CWLFilePathInput = 'data.csv'",
"flag: CWLBooleanInput = true",
"num: CWLIntInput = 1",
"msg: CWLStringInput = 'hello world'",
"with open(input_filename) as f:",
"\tcsv_reader = csv.reader(f)",
"\tdata = [line for line in reader]",
"print(msg)",
"print(num)",
"print(flag)",
])

cwl_tool = AnnotatedIPython2CWLToolConverter(annotated_python_script).cwl_command_line_tool()
Expand All @@ -39,7 +45,19 @@ def test_AnnotatedIPython2CWLToolConverter_cwl_command_line_tool(self):
'inputBinding': {
'prefix': '--flag'
}
}
},
'num': {
'type': 'int',
'inputBinding': {
'prefix': '--num'
}
},
'msg': {
'type': 'string',
'inputBinding': {
'prefix': '--msg'
}
},
},
'outputs': [],
},
Expand Down

0 comments on commit df64c68

Please sign in to comment.