8000 Merge pull request #39 from illusional/fix-hint-binding · phenoflow/python-cwlgen@72674df · GitHub
[go: up one dir, main page]

Skip to content

Commit 72674df

Browse files
authored
Merge pull request common-workflow-lab#39 from illusional/fix-hint-binding
Fix hint binding
2 parents 13eb4f3 + 4bc451b commit 72674df

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

cwlgen/commandlinetool.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ def __init__(
201201
self.cwlVersion = cwl_version
202202
self.id = tool_id
203203
self.label = label
204-
self.requirements = [] # List of Several object inhereting from [Requirement]
205-
self.hints = []
204+
self.requirements = [] # List of objects inheriting from [Requirement]
205+
self.hints = [] # List of objects inheriting from [Requirement]
206206
self.inputs = [] # List of [CommandInputParameter] objects
207207
self.outputs = [] # List of [CommandOutputParameter] objects
208208
self.baseCommand = base_command
@@ -233,26 +233,46 @@ def get_dict(self):
233233
if "$" not in v:
234234
d[self.namespaces.name][k] = v
235235

236+
if "inputs" not in d:
237+
# Tool can have no inputs but still needs to be bound
238+
d["inputs"] = []
239+
236240
if self.requirements:
237241
d["requirements"] = {r.get_class(): r.get_dict() for r in self.requirements}
242+
if self.hints:
243+
d["hints"] = {r.get_class(): r.get_dict() for r in self.hints}
244+
238245
return d
239246

240247
@classmethod
241248
def parse_dict(cls, d):
242-
wf = super(CommandLineTool, cls).parse_dict(d)
249+
clt = super(CommandLineTool, cls).parse_dict(d)
243250

244251
reqs = d.get("requirements")
245252
if reqs:
246253
if isinstance(reqs, list):
247-
wf.requirements = [Requirement.parse_dict(r) for r in reqs]
254+
clt.requirements = [Requirement.parse_dict(r) for r in reqs]
248255
elif isinstance(reqs, dict):
249256
# splat operator here would be so nice {**r, "class": c}
257+
clt.requirements = []
250258
for c, r in reqs.items():
251259
rdict = {'class': c}
252260
rdict.update(r)
253-
wf.requirements.append(Requirement.parse_dict(rdict))
261+
clt.requirements.append(Requirement.parse_dict(rdict))
262+
263+
hnts = d.get("hints")
264+
if hnts:
265+
if isinstance(hnts, list):
266+
clt.hints = [Requirement.parse_dict(r) for r in hnts]
267+
elif isinstance(hnts, dict):
268+
# splat operator here would be so nice {**r, "class": c}
269+
clt.hints = []
270+
for c, r in hnts.items():
271+
rdict = {'class': c}
272+
rdict.update(r)
273+
clt.hints.append(Requirement.parse_dict(rdict))
254274

255-
return wf
275+
return clt
256276

257277
def export_string(self):
258278
ruamel.yaml.add_representer(literal, literal_presenter)

cwlgen/workflow.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def get_dict(self):
7878

7979
if self.requirements:
8080
cwl_workflow['requirements'] = {r.get_class(): r.get_dict() for r in self.requirements}
81+
if self.hints:
82+
cwl_workflow["hints"] = {r.get_class(): r.get_dict() for r in self.hints}
8183

8284
return cwl_workflow
8385

@@ -91,11 +93,24 @@ def parse_dict(cls, d):
9193
wf.requirements = [Requirement.parse_dict(r) for r in reqs]
9294
elif isinstance(reqs, dict):
9395
# splat operator here would be so nice {**r, "class": c}
96+
wf.requirements = []
9497
for c, r in reqs.items():
9598
rdict = {'class': c}
9699
rdict.update(r)
97100
wf.requirements.append(Requirement.parse_dict(rdict))
98101

102+
hnts = d.get("hints")
103+
if hnts:
104+
if isinstance(hnts, list):
105+
wf.hints = [Requirement.parse_dict(r) for r in hnts]
106+
elif isinstance(hnts, dict):
107+
# splat operator here would be so nice {**r, "class": c}
108+
wf.hints = []
109+
for c, r in hnts.items():
110+
rdict = {'class': c}
111+
rdict.update(r)
112+
wf.hints.append(Requirement.parse_dict(rdict))
113+
99114
return wf
100115

101116
def export_string(self):

0 commit comments

Comments
 (0)
0