Skip to content

Commit

Permalink
Fix #12: support CWL v1.0 simplified syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Khodak committed Jan 25, 2017
1 parent 755baec commit 60a669b
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 199 deletions.
12 changes: 7 additions & 5 deletions cwl2argparse/cwl_classes.py
Expand Up @@ -27,13 +27,15 @@ class InputParam(Param):
def __init__(self, param):
self.id = param['id']
self.type = param.get('type', None)
if type(self.type) is list and self.type[0] == 'null':
if type(self.type) is str and self.type[-2:] == '[]': # v.1.0 syntax simplification ('<type>[]' == array of <type> )
self.type = "array"
if (type(self.type) is list and self.type[0] == 'null'):
self.optional = True
elif type(self.type) is str and self.type[-1] == '?': # v.1.0 ('<type>?' == ['null', '<type>'])
self.optional = True
self.type = self.type[:-1]
else:
self.optional = False
items_type = param.get('items_type', None)
if items_type:
self.items_type = items_type
self.description = param.get('doc', param.get('description', None))
self.default = param.get('default', None)
input_binding = param.get('inputBinding', None)
Expand Down Expand Up @@ -98,5 +100,5 @@ def __init__(self, filename):
param_dict['id'] = id
param = OutputParam(param_dict)
self.outputs[id] = param
self.description = tool.get('description', '')
self.description = tool.get('doc', tool.get('description', None))
self.cwl_version = tool.get('cwlVersion', '')
29 changes: 29 additions & 0 deletions example/inp.cwl
@@ -0,0 +1,29 @@
cwlVersion: v1.0
class: CommandLineTool
baseCommand: echo
doc: prints a string a to standard output
inputs:
example_flag:
type: boolean
inputBinding:
position: 1
prefix: -f
example_string:
type: string
inputBinding:
position: 3
prefix: --example-string
example_int:
type: int[]
inputBinding:
position: 2
prefix: -i
separate: false
example_file:
type: File?
inputBinding:
prefix: --file=
separate: false
position: 4

outputs: []
18 changes: 18 additions & 0 deletions example/inp.py
@@ -0,0 +1,18 @@
import argparse


def parser():
description="""
prints a string to a standard output
"""
parser = argparse.ArgumentParser(description=description)
example_flag = parser.add_argument("example_flag",
type=bool,)
example_file = parser.add_argument("--file",
type=argparse.FileType(),)
example_string = parser.add_argument("example_string",
type=str,)
example_int = parser.add_argument("example_int",
type=list, nargs="+",)

return parser
157 changes: 0 additions & 157 deletions example/picard-MergeSamFiles.cwl

This file was deleted.

36 changes: 0 additions & 36 deletions example/picard-MergeSamFiles.py

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
@@ -1,7 +1,7 @@
from setuptools import setup

setup(name="cwl2argparse",
version="0.1.6",
version="0.1.7",
description='Generating Python code from CWL tool descriptions with CWL inputs/outputs as argparse arguments',
author='Anton Khodak',
author_email='anton.khodak@ukr.net',
Expand Down

0 comments on commit 60a669b

Please sign in to comment.