Skip to content
This repository was archived by the owner on Jun 9, 2020. It is now read-only.

Commit d322635

Browse files
authored
Merge pull request #22 from illusional/parsing
Primitive parsing of CWL
2 parents ca06118 + 71ff30a commit d322635

12 files changed

+742
-1110
lines changed

Diff for: cwlgen/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from .utils import literal, literal_presenter
1616

17-
from .import_cwl import parse_cwl
17+
from .import_cwl import parse_cwl, parse_cwl_dict
1818

1919
logging.basicConfig(level=logging.INFO)
2020
_LOGGER = logging.getLogger(__name__)
@@ -24,6 +24,7 @@
2424
from .common import *
2525
from .commandlinetool import *
2626
from .workflow import *
27+
from .workflowdeps import *
2728
from .commandlinebinding import CommandLineBinding
2829
from .requirements import *
2930

Diff for: cwlgen/commandlinetool.py

+105-97
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# External libraries
44
import ruamel.yaml
55

6+
from cwlgen.commandlinebinding import CommandLineBinding
67
from .common import CWL_VERSIONS, DEF_VERSION, CWL_SHEBANG, Namespaces, Parameter
78
from .requirements import *
89
from .utils import literal, literal_presenter, Serializable
@@ -15,32 +16,128 @@
1516
# Class(es) ------------------------------
1617

1718

19+
class CommandOutputBinding(Serializable):
20+
'''
21+
Describes how to generate an output parameter based on the files produced.
22+
'''
23+
24+
def __init__(self, glob=None, load_contents=None, output_eval=None):
25+
'''
26+
:param glob: Find corresponding file(s)
27+
:type glob: STRING
28+
:param load_contents: For each file matched, read up to the 1st 64 KiB of text and
29+
place it in the contents field
30+
:type load_contents: BOOLEAN
31+
:param output_eval: Evaluate an expression to generate the output value
32+
:type output_eval: STRING
33+
'''
34+
self.glob = glob
35+
self.loadContents = load_contents
36+
self.outputEval = output_eval
37+
38+
39+
class CommandInputParameter(Parameter):
40+
"""
41+
An input parameter for a :class:`cwlgen.CommandLineTool`.
42+
"""
43+
44+
parse_types = {"inputBinding": [CommandLineBinding]}
45+
46+
def __init__(self, param_id, label=None, secondary_files=None, param_format=None,
47+
streamable=None, doc=None, input_binding=None, default=None, param_type=None):
48+
'''
49+
:param param_id: unique identifier for this parameter
50+
:type param_id: STRING
51+
:param label: short, human-readable label
52+
:type label: STRING
53+
:param secondary_files: If type is a file, describes files that must be
54+
included alongside the primary file(s)
55+
:type secondary_files: STRING
56+
:param param_format: If type is a file, uri to ontology of the format or exact format.
57+
:type param_format: STRING
58+
:param streamable: If type is a file, true indicates that the file is read or written
59+
sequentially without seeking
60+
:type streamable: BOOLEAN
61+
:param doc: documentation
62+
:type doc: STRING
63+
:param input_binding: describes how to handle the input
64+
:type input_binding: :class:`cwlgen.CommandLineBinding` object
65+
:param default: default value
66+
:type default: STRING
67+
:param param_type: type of data assigned to the parameter corresponding to CWLType
68+
:type param_type: STRING
69+
'''
70+
Parameter.__init__(self, param_id=param_id, label=label,
71+
secondary_files=secondary_files, param_format=param_format,
72+
streamable=streamable, doc=doc, param_type=param_type)
73+
self.inputBinding = input_binding
74+
self.default = default
75+
76+
77+
class CommandOutputParameter(Parameter):
78+
'''
79+
An output parameter for a :class:`cwlgen.CommandLineTool`.
80+
'''
81+
82+
parse_types = {"outputBinding": [CommandOutputBinding]}
83+
84+
def __init__(self, param_id, label=None, secondary_files=None, param_format=None,
85+
streamable=None, doc=None, output_binding=None, param_type=None):
86+
'''
87+
:param param_id: unique identifier for this parameter
88+
:type param_id: STRING
89+
:param label: short, human-readable label
90+
:type label: STRING
91+
:param secondary_files: If type is a file, describes files that must be
92+
included alongside the primary file(s)
93+
:type secondary_files: STRING
94+
:param param_format: If type is a file, uri to ontology of the format or exact format
95+
:type param_format: STRING
96+
:param streamable: If type is a file, true indicates that the file is read or written
97+
sequentially without seeking
98+
:type streamable: BOOLEAN
99+
:param doc: documentation
100+
:type doc: STRING
101+
:param output_binding: describes how to handle the output
102+
:type output_binding: :class:`cwlgen.CommandOutputBinding` object
103+
:param param_type: type of data assigned to the parameter corresponding to CWLType
104+
:type param_type: STRING
105+
'''
106+
Parameter.__init__(self, param_id, label, secondary_files, param_format, streamable,
107+
doc, param_type)
108+
self.outputBinding = output_binding
109+
110+
18111
class CommandLineTool(Serializable):
19112
'''
20113
Contain all informations to describe a CWL command line tool.
21114
'''
22115

23116
__CLASS__ = 'CommandLineTool'
24117

118+
parse_types = {'inputs': [[CommandInputParameter]], "outputs": [[CommandOutputParameter]]}
119+
ignore_fields_on_parse = ["namespaces", "class"]
120+
ignore_fields_on_convert = ["namespaces", "class", "metadata", "requirements"]
121+
25122
def __init__(self, tool_id=None, base_command=None, label=None, doc=None,
26123
cwl_version=None, stdin=None, stderr=None, stdout=None, path=None):
27124
'''
28125
:param tool_id: unique identifier for this tool
29-
:type tool_id: STRING
126+
:type tool_id: str
30127
:param base_command: command line for the tool
31-
:type base_command: STRING | list[STRING]
128+
:type base_command: str | list[STRING]
32129
:param label: label of this tool
33-
:type label: STRING
130+
:type label: str
34131
:param doc: documentation for the tool, usually longer than the label
35-
:type doc: STRING
132+
:type doc: str
36133
:param cwl_version: version of the CWL tool
37-
:type cwl_version: STRING
134+
:type cwl_version: str
38135
:param stdin: path to a file whose contents must be piped into stdin
39-
:type stdin: STRING
136+
:type stdin: str
40137
:param stderr: capture stderr into the given file
41-
:type stderr: STRING
138+
:type stderr: str
42139
:param stdout: capture stdout into the given file
43-
:type stdout: STRING
140+
:type stdout: str
44141
45142
inputs (:class:`cwlgen.CommandInputParameter` objects),
46143
outputs (:class:`cwlgen.CommandOutputParameter` objects),
@@ -72,7 +169,6 @@ def __init__(self, tool_id=None, base_command=None, label=None, doc=None,
72169
self._path = path
73170
self.namespaces = Namespaces()
74171
self.metadata = {}
75-
self.ignore_attributes = ["namespaces"]
76172

77173
def get_dict(self):
78174

@@ -113,91 +209,3 @@ def export(self, outfile=None):
113209
out_write.write(CWL_SHEBANG + '\n\n')
114210
out_write.write(rep)
115211
out_write.close()
116-
117-
118-
class CommandInputParameter(Parameter):
119-
'''
120-
An input parameter for a :class:`cwlgen.CommandLineTool`.
121-
'''
122-
123-
def __init__(self, param_id, label=None, secondary_files=None, param_format=None,
124-
streamable=None, doc=None, input_binding=None, default=None, param_type=None):
125-
'''
126-
:param param_id: unique identifier for this parameter
127-
:type param_id: STRING
128-
:param label: short, human-readable label
129-
:type label: STRING
130-
:param secondary_files: If type is a file, describes files that must be
131-
included alongside the primary file(s)
132-
:type secondary_files: STRING
133-
:param param_format: If type is a file, uri to ontology of the format or exact format.
134-
:type param_format: STRING
135-
:param streamable: If type is a file, true indicates that the file is read or written
136-
sequentially without seeking
137-
:type streamable: BOOLEAN
138-
:param doc: documentation
139-
:type doc: STRING
140-
:param input_binding: describes how to handle the input
141-
:type input_binding: :class:`cwlgen.CommandLineBinding` object
142-
:param default: default value
143-
:type default: STRING
144-
:param param_type: type of data assigned to the parameter corresponding to CWLType
145-
:type param_type: STRING
146-
'''
147-
Parameter.__init__(self, param_id=param_id, label=label,
148-
secondary_files=secondary_files, param_format=param_format,
149-
streamable=streamable, doc=doc, param_type=param_type)
150-
self.inputBinding = input_binding
151-
self.default = default
152-
153-
154-
class CommandOutputParameter(Parameter):
155-
'''
156-
An output parameter for a :class:`cwlgen.CommandLineTool`.
157-
'''
158-
159-
def __init__(self, param_id, label=None, secondary_files=None, param_format=None,
160-
streamable=None, doc=None, output_binding=None, param_type=None):
161-
'''
162-
:param param_id: unique identifier for this parameter
163-
:type param_id: STRING
164-
:param label: short, human-readable label
165-
:type label: STRING
166-
:param secondary_files: If type is a file, describes files that must be
167-
included alongside the primary file(s)
168-
:type secondary_files: STRING
169-
:param param_format: If type is a file, uri to ontology of the format or exact format
170-
:type param_format: STRING
171-
:param streamable: If type is a file, true indicates that the file is read or written
172-
sequentially without seeking
173-
:type streamable: BOOLEAN
174-
:param doc: documentation
175-
:type doc: STRING
176-
:param output_binding: describes how to handle the output
177-
:type output_binding: :class:`cwlgen.CommandOutputBinding` object
178-
:param param_type: type of data assigned to the parameter corresponding to CWLType
179-
:type param_type: STRING
180-
'''
181-
Parameter.__init__(self, param_id, label, secondary_files, param_format, streamable,
182-
doc, param_type)
183-
self.outputBinding = output_binding
184-
185-
186-
class CommandOutputBinding(Serializable):
187-
'''
188-
Describes how to generate an output parameter based on the files produced.
189-
'''
190-
191-
def __init__(self, glob=None, load_contents=None, output_eval=None):
192-
'''
193-
:param glob: Find corresponding file(s)
194-
:type glob: STRING
195-
:param load_contents: For each file matched, read up to the 1st 64 KiB of text and
196-
place it in the contents field
197-
:type load_contents: BOOLEAN
198-
:param output_eval: Evaluate an expression to generate the output value
199-
:type output_eval: STRING
200-
'''
201-
self.glob = glob
202-
self.loadContents = load_contents
203-
self.outputEval = output_eval

Diff for: cwlgen/common.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class CwlTypes:
116116

117117
# functions
118118

119-
class Namespaces(object):
119+
class Namespaces(Serializable):
120120
"""
121121
Define different namespace for the description.
122122
"""
@@ -172,6 +172,20 @@ def __init__(self, param_id, label=None, secondary_files=None, param_format=None
172172
self.doc = doc
173173
self.type = parse_type(param_type, requires_type)
174174

175+
@classmethod
176+
def parse_with_id(cls, d, identifier):
177+
d["id"] = identifier
178+
return super(Parameter, cls).parse_dict(d)
179+
180+
# @classmethod
181+
# def parse_dict(cls, d):
182+
# self = super(Parameter, cls).parse_dict(d)
183+
# secs = d.get("secondaryFiles")
184+
# self.secondaryFiles = []
185+
# if secs:
186+
# self.secondaryFiles = secs if isinstance(secs, list) else [secs]
187+
# return self
188+
175189

176190
class CommandInputArraySchema(Serializable):
177191
'''

0 commit comments

Comments
 (0)