comparison toolfactory/galaxyxml/tool/parameters/__init__.py @ 36:ce2b1f8ea68d draft

passes flake8 tests finally :)
author fubar
date Mon, 10 Aug 2020 23:24:41 -0400
parents 5d38cb3d9be8
children a30536c100bf
comparison
equal deleted inserted replaced
35:5d38cb3d9be8 36:ce2b1f8ea68d
3 from lxml import etree 3 from lxml import etree
4 from galaxyxml import Util 4 from galaxyxml import Util
5 5
6 6
7 class XMLParam(object): 7 class XMLParam(object):
8 name = 'node' 8 name = "node"
9 9
10 def __init__(self, *args, **kwargs): 10 def __init__(self, *args, **kwargs):
11 # http://stackoverflow.com/a/12118700 11 # http://stackoverflow.com/a/12118700
12 self.children = [] 12 self.children = []
13 kwargs = {k: v for k, v in list(kwargs.items()) if v is not None} 13 kwargs = {k: v for k, v in list(kwargs.items()) if v is not None}
20 # If one of ours, they aren't etree nodes, they're custom objects 20 # If one of ours, they aren't etree nodes, they're custom objects
21 if issubclass(type(sub_node), XMLParam): 21 if issubclass(type(sub_node), XMLParam):
22 self.node.append(sub_node.node) 22 self.node.append(sub_node.node)
23 self.children.append(sub_node) 23 self.children.append(sub_node)
24 else: 24 else:
25 raise Exception("Child was unacceptable to parent (%s is not appropriate for %s)" % ( 25 raise Exception(
26 type(self), type(sub_node))) 26 "Child was unacceptable to parent (%s is not appropriate for %s)"
27 % (type(self), type(sub_node))
28 )
27 else: 29 else:
28 raise Exception("Child was unacceptable to parent (%s is not appropriate for %s)" % ( 30 raise Exception(
29 type(self), type(sub_node))) 31 "Child was unacceptable to parent (%s is not appropriate for %s)"
32 % (type(self), type(sub_node))
33 )
30 34
31 def validate(self): 35 def validate(self):
32 # Very few need validation, but some nodes we may want to have 36 # Very few need validation, but some nodes we may want to have
33 # validation routines on. Should only be called when DONE. 37 # validation routines on. Should only be called when DONE.
34 for child in self.children: 38 for child in self.children:
40 def cli(self): 44 def cli(self):
41 lines = [] 45 lines = []
42 for child in self.children: 46 for child in self.children:
43 lines.append(child.command_line()) 47 lines.append(child.command_line())
44 # lines += child.command_line() 48 # lines += child.command_line()
45 return '\n'.join(lines) 49 return "\n".join(lines)
46 50
47 def command_line(self): 51 def command_line(self):
48 return None 52 return None
49 53
50 54
51 class RequestParamTranslation(XMLParam): 55 class RequestParamTranslation(XMLParam):
52 name = 'request_param_translation' 56 name = "request_param_translation"
53 57
54 def __init__(self, **kwargs): 58 def __init__(self, **kwargs):
55 self.node = etree.Element(self.name) 59 self.node = etree.Element(self.name)
56 60
57 def acceptable_child(self, child): 61 def acceptable_child(self, child):
58 return isinstance(child, RequestParamTranslation) 62 return isinstance(child, RequestParamTranslation)
59 63
60 64
61 class RequestParam(XMLParam): 65 class RequestParam(XMLParam):
62 name = 'request_param' 66 name = "request_param"
63 67
64 def __init__(self, galaxy_name, remote_name, missing, **kwargs): 68 def __init__(self, galaxy_name, remote_name, missing, **kwargs):
65 # TODO: bulk copy locals into self.attr? 69 # TODO: bulk copy locals into self.attr?
66 self.galaxy_name = galaxy_name 70 self.galaxy_name = galaxy_name
67 # http://stackoverflow.com/a/1408860 71 # http://stackoverflow.com/a/1408860
71 def acceptable_child(self, child): 75 def acceptable_child(self, child):
72 return isinstance(child, AppendParam) and self.galaxy_name == "URL" 76 return isinstance(child, AppendParam) and self.galaxy_name == "URL"
73 77
74 78
75 class AppendParam(XMLParam): 79 class AppendParam(XMLParam):
76 name = 'append_param' 80 name = "append_param"
77 81
78 def __init__(self, separator="&", first_separator="?", join="=", **kwargs): 82 def __init__(self, separator="&", first_separator="?", join="=", **kwargs):
79 params = Util.clean_kwargs(locals().copy()) 83 params = Util.clean_kwargs(locals().copy())
80 super(AppendParam, self).__init__(**params) 84 super(AppendParam, self).__init__(**params)
81 85
82 def acceptable_child(self, child): 86 def acceptable_child(self, child):
83 return isinstance(child, AppendParamValue) 87 return isinstance(child, AppendParamValue)
84 88
85 89
86 class AppendParamValue(XMLParam): 90 class AppendParamValue(XMLParam):
87 name = 'value' 91 name = "value"
88 92
89 def __init__(self, name="_export", missing="1", **kwargs): 93 def __init__(self, name="_export", missing="1", **kwargs):
90 params = Util.clean_kwargs(locals().copy()) 94 params = Util.clean_kwargs(locals().copy())
91 super(AppendParamValue, self).__init__(**params) 95 super(AppendParamValue, self).__init__(**params)
92 96
93 def acceptable_child(self, child): 97 def acceptable_child(self, child):
94 return False 98 return False
95 99
96 100
97 class EdamOperations(XMLParam): 101 class EdamOperations(XMLParam):
98 name = 'edam_operations' 102 name = "edam_operations"
99 103
100 def acceptable_child(self, child): 104 def acceptable_child(self, child):
101 return issubclass(type(child), EdamOperation) 105 return issubclass(type(child), EdamOperation)
102 106
103 def has_operation(self, edam_operation): 107 def has_operation(self, edam_operation):
111 return True 115 return True
112 return False 116 return False
113 117
114 118
115 class EdamOperation(XMLParam): 119 class EdamOperation(XMLParam):
116 name = 'edam_operation' 120 name = "edam_operation"
117 121
118 def __init__(self, value): 122 def __init__(self, value):
119 super(EdamOperation, self).__init__() 123 super(EdamOperation, self).__init__()
120 self.node.text = str(value) 124 self.node.text = str(value)
121 125
122 126
123 class EdamTopics(XMLParam): 127 class EdamTopics(XMLParam):
124 name = 'edam_topics' 128 name = "edam_topics"
125 129
126 def acceptable_child(self, child): 130 def acceptable_child(self, child):
127 return issubclass(type(child), EdamTopic) 131 return issubclass(type(child), EdamTopic)
128 132
129 def has_topic(self, edam_topic): 133 def has_topic(self, edam_topic):
137 return True 141 return True
138 return False 142 return False
139 143
140 144
141 class EdamTopic(XMLParam): 145 class EdamTopic(XMLParam):
142 name = 'edam_topic' 146 name = "edam_topic"
143 147
144 def __init__(self, value): 148 def __init__(self, value):
145 super(EdamTopic, self).__init__() 149 super(EdamTopic, self).__init__()
146 self.node.text = str(value) 150 self.node.text = str(value)
147 151
148 152
149 class Requirements(XMLParam): 153 class Requirements(XMLParam):
150 name = 'requirements' 154 name = "requirements"
151 # This bodes to be an issue -__- 155 # This bodes to be an issue -__-
152 156
153 def acceptable_child(self, child): 157 def acceptable_child(self, child):
154 return issubclass(type(child), Requirement) or issubclass(type(child), Container) 158 return issubclass(type(child), Requirement) or issubclass(
159 type(child), Container
160 )
155 161
156 162
157 class Requirement(XMLParam): 163 class Requirement(XMLParam):
158 name = 'requirement' 164 name = "requirement"
159 165
160 def __init__(self, type, value, version=None, **kwargs): 166 def __init__(self, type, value, version=None, **kwargs):
161 params = Util.clean_kwargs(locals().copy()) 167 params = Util.clean_kwargs(locals().copy())
162 passed_kwargs = {} 168 passed_kwargs = {}
163 passed_kwargs['version'] = params['version'] 169 passed_kwargs["version"] = params["version"]
164 passed_kwargs['type'] = params['type'] 170 passed_kwargs["type"] = params["type"]
165 super(Requirement, self).__init__(**passed_kwargs) 171 super(Requirement, self).__init__(**passed_kwargs)
166 self.node.text = str(value) 172 self.node.text = str(value)
167 173
168 174
169 class Container(XMLParam): 175 class Container(XMLParam):
170 name = 'container' 176 name = "container"
171 177
172 def __init__(self, type, value, **kwargs): 178 def __init__(self, type, value, **kwargs):
173 params = Util.clean_kwargs(locals().copy()) 179 params = Util.clean_kwargs(locals().copy())
174 passed_kwargs = {} 180 passed_kwargs = {}
175 passed_kwargs['type'] = params['type'] 181 passed_kwargs["type"] = params["type"]
176 super(Container, self).__init__(**passed_kwargs) 182 super(Container, self).__init__(**passed_kwargs)
177 self.node.text = str(value) 183 self.node.text = str(value)
178 184
179 185
180 class Configfiles(XMLParam): 186 class Configfiles(XMLParam):
181 name = 'configfiles' 187 name = "configfiles"
182 188
183 def acceptable_child(self, child): 189 def acceptable_child(self, child):
184 return issubclass(type(child), Configfile) or issubclass(type(child), ConfigfileDefaultInputs) 190 return issubclass(type(child), Configfile) or issubclass(
191 type(child), ConfigfileDefaultInputs
192 )
185 193
186 194
187 class Configfile(XMLParam): 195 class Configfile(XMLParam):
188 name = 'configfile' 196 name = "configfile"
189 197
190 def __init__(self, name, text, **kwargs): 198 def __init__(self, name, text, **kwargs):
191 params = Util.clean_kwargs(locals().copy()) 199 params = Util.clean_kwargs(locals().copy())
192 passed_kwargs = {} 200 passed_kwargs = {}
193 passed_kwargs['name'] = params['name'] 201 passed_kwargs["name"] = params["name"]
194 super(Configfile, self).__init__(**passed_kwargs) 202 super(Configfile, self).__init__(**passed_kwargs)
195 self.node.text = etree.CDATA(str(text)) 203 self.node.text = etree.CDATA(str(text))
196 204
197 205
198 class ConfigfileDefaultInputs(XMLParam): 206 class ConfigfileDefaultInputs(XMLParam):
199 name = 'inputs' 207 name = "inputs"
200 208
201 def __init__(self, name, **kwargs): 209 def __init__(self, name, **kwargs):
202 params = Util.clean_kwargs(locals().copy()) 210 params = Util.clean_kwargs(locals().copy())
203 passed_kwargs = {} 211 passed_kwargs = {}
204 passed_kwargs['name'] = params['name'] 212 passed_kwargs["name"] = params["name"]
205 super(ConfigfileDefaultInputs, self).__init__(**passed_kwargs) 213 super(ConfigfileDefaultInputs, self).__init__(**passed_kwargs)
206 214
207 215
208 class Inputs(XMLParam): 216 class Inputs(XMLParam):
209 name = 'inputs' 217 name = "inputs"
210 # This bodes to be an issue -__- 218 # This bodes to be an issue -__-
211 219
212 def __init__(self, action=None, check_value=None, method=None, 220 def __init__(
213 target=None, nginx_upload=None, **kwargs): 221 self,
222 action=None,
223 check_value=None,
224 method=None,
225 target=None,
226 nginx_upload=None,
227 **kwargs,
228 ):
214 params = Util.clean_kwargs(locals().copy()) 229 params = Util.clean_kwargs(locals().copy())
215 super(Inputs, self).__init__(**params) 230 super(Inputs, self).__init__(**params)
216 231
217 def acceptable_child(self, child): 232 def acceptable_child(self, child):
218 return issubclass(type(child), InputParameter) 233 return issubclass(type(child), InputParameter)
219 234
220 235
221 class InputParameter(XMLParam): 236 class InputParameter(XMLParam):
222
223 def __init__(self, name, **kwargs): 237 def __init__(self, name, **kwargs):
224 # TODO: look at 238 # TODO: look at
225 self.mako_identifier = name 239 self.mako_identifier = name
226 # We use kwargs instead of the usual locals(), so manually copy the 240 # We use kwargs instead of the usual locals(), so manually copy the
227 # name to kwargs 241 # name to kwargs
228 if name is not None: 242 if name is not None:
229 kwargs['name'] = name 243 kwargs["name"] = name
230 244
231 # Handle positional parameters 245 # Handle positional parameters
232 if 'positional' in kwargs and kwargs['positional']: 246 if "positional" in kwargs and kwargs["positional"]:
233 self.positional = True 247 self.positional = True
234 else: 248 else:
235 self.positional = False 249 self.positional = False
236 250
237 if 'num_dashes' in kwargs: 251 if "num_dashes" in kwargs:
238 self.num_dashes = kwargs['num_dashes'] 252 self.num_dashes = kwargs["num_dashes"]
239 del kwargs['num_dashes'] 253 del kwargs["num_dashes"]
240 else: 254 else:
241 self.num_dashes = 0 255 self.num_dashes = 0
242 256
243 self.space_between_arg = " " 257 self.space_between_arg = " "
244 258
245 # Not sure about this :( 259 # Not sure about this :(
246 # https://wiki.galaxyproject.org/Tools/BestPractices#Parameter_help 260 # https://wiki.galaxyproject.org/Tools/BestPractices#Parameter_help
247 if 'label' in kwargs: 261 if "label" in kwargs:
248 # TODO: replace with positional attribute 262 # TODO: replace with positional attribute
249 if len(self.flag()) > 0: 263 if len(self.flag()) > 0:
250 if kwargs['label'] is None: 264 if kwargs["label"] is None:
251 kwargs[ 265 kwargs[
252 'label'] = 'Author did not provide help for this parameter... ' 266 "label"
267 ] = "Author did not provide help for this parameter... "
253 if not self.positional: 268 if not self.positional:
254 kwargs['argument'] = self.flag() 269 kwargs["argument"] = self.flag()
255 270
256 super(InputParameter, self).__init__(**kwargs) 271 super(InputParameter, self).__init__(**kwargs)
257 272
258 def command_line(self): 273 def command_line(self):
259 before = self.command_line_before() 274 before = self.command_line_before()
260 cli = self.command_line_actual() 275 cli = self.command_line_actual()
261 after = self.command_line_after() 276 after = self.command_line_after()
262 277
263 complete = [x for x in (before, cli, after) if x is not None] 278 complete = [x for x in (before, cli, after) if x is not None]
264 return '\n'.join(complete) 279 return "\n".join(complete)
265 280
266 def command_line_before(self): 281 def command_line_before(self):
267 try: 282 try:
268 return self.command_line_before_override 283 return self.command_line_before_override
269 except Exception: 284 except Exception:
280 return self.command_line_override 295 return self.command_line_override
281 except Exception: 296 except Exception:
282 if self.positional: 297 if self.positional:
283 return self.mako_name() 298 return self.mako_name()
284 else: 299 else:
285 return "%s%s%s" % (self.flag(), self.space_between_arg, self.mako_name()) 300 return "%s%s%s" % (
301 self.flag(),
302 self.space_between_arg,
303 self.mako_name(),
304 )
286 305
287 def mako_name(self): 306 def mako_name(self):
288 # TODO: enhance logic to check up parents for things like 307 # TODO: enhance logic to check up parents for things like
289 # repeat>condotion>param 308 # repeat>condotion>param
290 return '$' + self.mako_identifier 309 return "$" + self.mako_identifier
291 310
292 def flag(self): 311 def flag(self):
293 flag = '-' * self.num_dashes 312 flag = "-" * self.num_dashes
294 return flag + self.mako_identifier 313 return flag + self.mako_identifier
295 314
296 315
297 class Section(InputParameter): 316 class Section(InputParameter):
298 name = 'section' 317 name = "section"
299 318
300 def __init__(self, name, title, expanded=None, help=None, **kwargs): 319 def __init__(self, name, title, expanded=None, help=None, **kwargs):
301 params = Util.clean_kwargs(locals().copy()) 320 params = Util.clean_kwargs(locals().copy())
302 super(Section, self).__init__(**params) 321 super(Section, self).__init__(**params)
303 322
304 def acceptable_child(self, child): 323 def acceptable_child(self, child):
305 return issubclass(type(child), InputParameter) 324 return issubclass(type(child), InputParameter)
306 325
307 326
308 class Repeat(InputParameter): 327 class Repeat(InputParameter):
309 name = 'repeat' 328 name = "repeat"
310 329
311 def __init__(self, name, title, min=None, max=None, default=None, 330 def __init__(self, name, title, min=None, max=None, default=None, **kwargs):
312 **kwargs):
313 params = Util.clean_kwargs(locals().copy()) 331 params = Util.clean_kwargs(locals().copy())
314 # Allow overriding 332 # Allow overriding
315 self.command_line_before_override = '#for $i in $%s:' % name 333 self.command_line_before_override = "#for $i in $%s:" % name
316 self.command_line_after_override = '#end for' 334 self.command_line_after_override = "#end for"
317 # self.command_line_override 335 # self.command_line_override
318 super(Repeat, self).__init__(**params) 336 super(Repeat, self).__init__(**params)
319 337
320 def acceptable_child(self, child): 338 def acceptable_child(self, child):
321 return issubclass(type(child), InputParameter) 339 return issubclass(type(child), InputParameter)
322 340
323 def command_line_actual(self): 341 def command_line_actual(self):
324 if hasattr(self, 'command_line_override'): 342 if hasattr(self, "command_line_override"):
325 return self.command_line_override 343 return self.command_line_override
326 else: 344 else:
327 return "%s" % self.mako_name() 345 return "%s" % self.mako_name()
328 346
329 347
330 class Conditional(InputParameter): 348 class Conditional(InputParameter):
331 name = 'conditional' 349 name = "conditional"
332 350
333 def __init__(self, name, **kwargs): 351 def __init__(self, name, **kwargs):
334 params = Util.clean_kwargs(locals().copy()) 352 params = Util.clean_kwargs(locals().copy())
335 super(Conditional, self).__init__(**params) 353 super(Conditional, self).__init__(**params)
336 354
337 def acceptable_child(self, child): 355 def acceptable_child(self, child):
338 return issubclass(type(child), InputParameter) \ 356 return issubclass(type(child), InputParameter) and not isinstance(
339 and not isinstance(child, Conditional) 357 child, Conditional
358 )
340 359
341 def validate(self): 360 def validate(self):
342 # Find a way to check if one of the kids is a WHEN 361 # Find a way to check if one of the kids is a WHEN
343 pass 362 pass
344 363
345 364
346 class When(InputParameter): 365 class When(InputParameter):
347 name = 'when' 366 name = "when"
348 367
349 def __init__(self, value): 368 def __init__(self, value):
350 params = Util.clean_kwargs(locals().copy()) 369 params = Util.clean_kwargs(locals().copy())
351 super(When, self).__init__(None, **params) 370 super(When, self).__init__(None, **params)
352 371
353 def acceptable_child(self, child): 372 def acceptable_child(self, child):
354 return issubclass(type(child), InputParameter) 373 return issubclass(type(child), InputParameter)
355 374
356 375
357 class Param(InputParameter): 376 class Param(InputParameter):
358 name = 'param' 377 name = "param"
359 378
360 # This...isn't really valid as-is, and shouldn't be used. 379 # This...isn't really valid as-is, and shouldn't be used.
361 def __init__(self, name, optional=None, label=None, help=None, **kwargs): 380 def __init__(self, name, optional=None, label=None, help=None, **kwargs):
362 params = Util.clean_kwargs(locals().copy()) 381 params = Util.clean_kwargs(locals().copy())
363 params['type'] = self.type 382 params["type"] = self.type
364 super(Param, self).__init__(**params) 383 super(Param, self).__init__(**params)
365 384
366 if type(self) == Param: 385 if type(self) == Param:
367 raise Exception( 386 raise Exception(
368 "Param class is not an actual parameter type, use a subclass of Param") 387 "Param class is not an actual parameter type, use a subclass of Param"
369 388 )
370 def acceptable_child(self, child): 389
371 return issubclass(type(child, InputParameter) or isinstance(child), ValidatorParam) 390 def acceptable_child(self, child):
391 return issubclass(
392 type(child, InputParameter) or isinstance(child), ValidatorParam
393 )
372 394
373 395
374 class TextParam(Param): 396 class TextParam(Param):
375 type = 'text' 397 type = "text"
376 398
377 def __init__(self, name, optional=None, label=None, help=None, 399 def __init__(
378 value=None, **kwargs): 400 self, name, optional=None, label=None, help=None, value=None, **kwargs
401 ):
379 params = Util.clean_kwargs(locals().copy()) 402 params = Util.clean_kwargs(locals().copy())
380 super(TextParam, self).__init__(**params) 403 super(TextParam, self).__init__(**params)
381 404
382 def command_line_actual(self): 405 def command_line_actual(self):
383 try: 406 try:
388 else: 411 else:
389 return f"{self.flag}{self.space_between_arg}'{self.mako_name()}'" 412 return f"{self.flag}{self.space_between_arg}'{self.mako_name()}'"
390 413
391 414
392 class _NumericParam(Param): 415 class _NumericParam(Param):
393 416 def __init__(
394 def __init__(self, name, value, optional=None, label=None, help=None, 417 self,
395 min=None, max=None, **kwargs): 418 name,
419 value,
420 optional=None,
421 label=None,
422 help=None,
423 min=None,
424 max=None,
425 **kwargs,
426 ):
396 params = Util.clean_kwargs(locals().copy()) 427 params = Util.clean_kwargs(locals().copy())
397 super(_NumericParam, self).__init__(**params) 428 super(_NumericParam, self).__init__(**params)
398 429
399 430
400 class IntegerParam(_NumericParam): 431 class IntegerParam(_NumericParam):
401 type = 'integer' 432 type = "integer"
402 433
403 434
404 class FloatParam(_NumericParam): 435 class FloatParam(_NumericParam):
405 type = 'float' 436 type = "float"
406 437
407 438
408 class BooleanParam(Param): 439 class BooleanParam(Param):
409 type = 'boolean' 440 type = "boolean"
410 441
411 def __init__(self, name, optional=None, label=None, help=None, 442 def __init__(
412 checked=False, truevalue=None, falsevalue=None, **kwargs): 443 self,
444 name,
445 optional=None,
446 label=None,
447 help=None,
448 checked=False,
449 truevalue=None,
450 falsevalue=None,
451 **kwargs,
452 ):
413 params = Util.clean_kwargs(locals().copy()) 453 params = Util.clean_kwargs(locals().copy())
414 454
415 super(BooleanParam, self).__init__(**params) 455 super(BooleanParam, self).__init__(**params)
416 if truevalue is None: 456 if truevalue is None:
417 # If truevalue and falsevalue are None, then we use "auto", the IUC 457 # If truevalue and falsevalue are None, then we use "auto", the IUC
420 # truevalue is set to the parameter's value, and falsevalue is not. 460 # truevalue is set to the parameter's value, and falsevalue is not.
421 # 461 #
422 # Unfortunately, mako_identifier is set as a result of the super 462 # Unfortunately, mako_identifier is set as a result of the super
423 # call, which we shouldn't call TWICE, so we'll just hack around this :( 463 # call, which we shouldn't call TWICE, so we'll just hack around this :(
424 # params['truevalue'] = '%s%s' % (self.) 464 # params['truevalue'] = '%s%s' % (self.)
425 self.node.attrib['truevalue'] = self.flag() 465 self.node.attrib["truevalue"] = self.flag()
426 466
427 if falsevalue is None: 467 if falsevalue is None:
428 self.node.attrib['falsevalue'] = "" 468 self.node.attrib["falsevalue"] = ""
429 469
430 def command_line_actual(self): 470 def command_line_actual(self):
431 if hasattr(self, 'command_line_override'): 471 if hasattr(self, "command_line_override"):
432 return self.command_line_override 472 return self.command_line_override
433 else: 473 else:
434 return "%s" % self.mako_name() 474 return "%s" % self.mako_name()
435 475
436 476
437 class DataParam(Param): 477 class DataParam(Param):
438 type = 'data' 478 type = "data"
439 479
440 def __init__(self, name, optional=None, label=None, help=None, format=None, 480 def __init__(
441 multiple=None, **kwargs): 481 self,
482 name,
483 optional=None,
484 label=None,
485 help=None,
486 format=None,
487 multiple=None,
488 **kwargs,
489 ):
442 params = Util.clean_kwargs(locals().copy()) 490 params = Util.clean_kwargs(locals().copy())
443 super(DataParam, self).__init__(**params) 491 super(DataParam, self).__init__(**params)
444 492
445 493
446 class SelectParam(Param): 494 class SelectParam(Param):
447 type = 'select' 495 type = "select"
448 496
449 def __init__(self, name, optional=None, label=None, help=None, 497 def __init__(
450 data_ref=None, display=None, multiple=None, options=None, 498 self,
451 default=None, **kwargs): 499 name,
452 params = Util.clean_kwargs(locals().copy()) 500 optional=None,
453 del params['options'] 501 label=None,
454 del params['default'] 502 help=None,
503 data_ref=None,
504 display=None,
505 multiple=None,
506 options=None,
507 default=None,
508 **kwargs,
509 ):
510 params = Util.clean_kwargs(locals().copy())
511 del params["options"]
512 del params["default"]
455 513
456 super(SelectParam, self).__init__(**params) 514 super(SelectParam, self).__init__(**params)
457 515
458 if options is not None and default is not None: 516 if options is not None and default is not None:
459 if default not in options: 517 if default not in options:
460 raise Exception("Specified a default that isn't in options") 518 raise Exception("Specified a default that isn't in options")
461 519
462 if options: 520 if options:
463 for k, v in list(sorted(options.items())): 521 for k, v in list(sorted(options.items())):
464 selected = (k == default) 522 selected = k == default
465 self.append(SelectOption(k, v, selected=selected)) 523 self.append(SelectOption(k, v, selected=selected))
466 524
467 def acceptable_child(self, child): 525 def acceptable_child(self, child):
468 return issubclass(type(child), SelectOption) \ 526 return issubclass(type(child), SelectOption) or issubclass(type(child), Options)
469 or issubclass(type(child), Options)
470 527
471 528
472 class SelectOption(InputParameter): 529 class SelectOption(InputParameter):
473 name = 'option' 530 name = "option"
474 531
475 def __init__(self, value, text, selected=False, **kwargs): 532 def __init__(self, value, text, selected=False, **kwargs):
476 params = Util.clean_kwargs(locals().copy()) 533 params = Util.clean_kwargs(locals().copy())
477 534
478 passed_kwargs = {} 535 passed_kwargs = {}
479 if selected: 536 if selected:
480 passed_kwargs['selected'] = "true" 537 passed_kwargs["selected"] = "true"
481 passed_kwargs['value'] = params['value'] 538 passed_kwargs["value"] = params["value"]
482 539
483 super(SelectOption, self).__init__(None, **passed_kwargs) 540 super(SelectOption, self).__init__(None, **passed_kwargs)
484 self.node.text = str(text) 541 self.node.text = str(text)
485 542
486 543
487 class Options(InputParameter): 544 class Options(InputParameter):
488 name = 'options' 545 name = "options"
489 546
490 def __init__(self, from_dataset=None, from_file=None, from_data_table=None, 547 def __init__(
491 from_parameter=None, **kwargs): 548 self,
549 from_dataset=None,
550 from_file=None,
551 from_data_table=None,
552 from_parameter=None,
553 **kwargs,
554 ):
492 params = Util.clean_kwargs(locals().copy()) 555 params = Util.clean_kwargs(locals().copy())
493 super(Options, self).__init__(None, **params) 556 super(Options, self).__init__(None, **params)
494 557
495 def acceptable_child(self, child): 558 def acceptable_child(self, child):
496 return issubclass(type(child), Column) or issubclass(type(child), Filter) 559 return issubclass(type(child), Column) or issubclass(type(child), Filter)
497 560
498 561
499 class Column(InputParameter): 562 class Column(InputParameter):
500 name = 'column' 563 name = "column"
501 564
502 def __init__(self, name, index, **kwargs): 565 def __init__(self, name, index, **kwargs):
503 params = Util.clean_kwargs(locals().copy()) 566 params = Util.clean_kwargs(locals().copy())
504 super(Column, self).__init__(**params) 567 super(Column, self).__init__(**params)
505 568
506 569
507 class Filter(InputParameter): 570 class Filter(InputParameter):
508 name = 'filter' 571 name = "filter"
509 572
510 def __init__(self, type, column=None, name=None, ref=None, key=None, 573 def __init__(
511 multiple=None, separator=None, keep=None, value=None, 574 self,
512 ref_attribute=None, index=None, **kwargs): 575 type,
576 column=None,
577 name=None,
578 ref=None,
579 key=None,
580 multiple=None,
581 separator=None,
582 keep=None,
583 value=None,
584 ref_attribute=None,
585 index=None,
586 **kwargs,
587 ):
513 params = Util.clean_kwargs(locals().copy()) 588 params = Util.clean_kwargs(locals().copy())
514 super(Filter, self).__init__(**params) 589 super(Filter, self).__init__(**params)
515 590
516 591
517 class ValidatorParam(InputParameter): 592 class ValidatorParam(InputParameter):
518 name = 'validator' 593 name = "validator"
519 594
520 def __init__(self, type, message=None, filename=None, metadata_name=None, 595 def __init__(
521 metadata_column=None, line_startswith=None, min=None, 596 self,
522 max=None, **kwargs): 597 type,
598 message=None,
599 filename=None,
600 metadata_name=None,
601 metadata_column=None,
602 line_startswith=None,
603 min=None,
604 max=None,
605 **kwargs,
606 ):
523 params = Util.clean_kwargs(locals().copy()) 607 params = Util.clean_kwargs(locals().copy())
524 super(ValidatorParam, self).__init__(**params) 608 super(ValidatorParam, self).__init__(**params)
525 609
526 610
527 class Outputs(XMLParam): 611 class Outputs(XMLParam):
528 name = 'outputs' 612 name = "outputs"
529 613
530 def acceptable_child(self, child): 614 def acceptable_child(self, child):
531 return isinstance(child, OutputData) or isinstance(child, OutputCollection) 615 return isinstance(child, OutputData) or isinstance(child, OutputCollection)
532 616
533 617
534 class OutputData(XMLParam): 618 class OutputData(XMLParam):
535 """Copypasta of InputParameter, needs work 619 """Copypasta of InputParameter, needs work
536 """ 620 """
537 name = 'data' 621
538 622 name = "data"
539 def __init__(self, name, format, format_source=None, metadata_source=None, 623
540 label=None, from_work_dir=None, hidden=False, **kwargs): 624 def __init__(
625 self,
626 name,
627 format,
628 format_source=None,
629 metadata_source=None,
630 label=None,
631 from_work_dir=None,
632 hidden=False,
633 **kwargs,
634 ):
541 # TODO: validate format_source&metadata_source against something in the 635 # TODO: validate format_source&metadata_source against something in the
542 # XMLParam children tree. 636 # XMLParam children tree.
543 self.mako_identifier = name 637 self.mako_identifier = name
544 if 'num_dashes' in kwargs: 638 if "num_dashes" in kwargs:
545 self.num_dashes = kwargs['num_dashes'] 639 self.num_dashes = kwargs["num_dashes"]
546 del kwargs['num_dashes'] 640 del kwargs["num_dashes"]
547 else: 641 else:
548 self.num_dashes = 0 642 self.num_dashes = 0
549 self.space_between_arg = " " 643 self.space_between_arg = " "
550 params = Util.clean_kwargs(locals().copy()) 644 params = Util.clean_kwargs(locals().copy())
551 645
552 super(OutputData, self).__init__(**params) 646 super(OutputData, self).__init__(**params)
553 647
554 def command_line(self): 648 def command_line(self):
555 if hasattr(self, 'command_line_override'): 649 if hasattr(self, "command_line_override"):
556 return self.command_line_override 650 return self.command_line_override
557 else: 651 else:
558 return "%s%s%s" % (self.flag(), self.space_between_arg, self.mako_name()) 652 return "%s%s%s" % (self.flag(), self.space_between_arg, self.mako_name())
559 653
560 def mako_name(self): 654 def mako_name(self):
561 return '$' + self.mako_identifier 655 return "$" + self.mako_identifier
562 656
563 def flag(self): 657 def flag(self):
564 flag = '-' * self.num_dashes 658 flag = "-" * self.num_dashes
565 return flag + self.mako_identifier 659 return flag + self.mako_identifier
566 660
567 def acceptable_child(self, child): 661 def acceptable_child(self, child):
568 return isinstance(child, OutputFilter) or \ 662 return (
569 isinstance(child, ChangeFormat) or \ 663 isinstance(child, OutputFilter)
570 isinstance(child, DiscoverDatasets) 664 or isinstance(child, ChangeFormat)
665 or isinstance(child, DiscoverDatasets)
666 )
571 667
572 668
573 class OutputFilter(XMLParam): 669 class OutputFilter(XMLParam):
574 name = 'filter' 670 name = "filter"
575 671
576 def __init__(self, text, **kwargs): 672 def __init__(self, text, **kwargs):
577 params = Util.clean_kwargs(locals().copy()) 673 params = Util.clean_kwargs(locals().copy())
578 del params['text'] 674 del params["text"]
579 super(OutputFilter, self).__init__(**params) 675 super(OutputFilter, self).__init__(**params)
580 self.node.text = text 676 self.node.text = text
581 677
582 def acceptable_child(self, child): 678 def acceptable_child(self, child):
583 return False 679 return False
584 680
585 681
586 class ChangeFormat(XMLParam): 682 class ChangeFormat(XMLParam):
587 name = 'change_format' 683 name = "change_format"
588 684
589 def __init__(self, **kwargs): 685 def __init__(self, **kwargs):
590 params = Util.clean_kwargs(locals().copy()) 686 params = Util.clean_kwargs(locals().copy())
591 super(ChangeFormat, self).__init__(**params) 687 super(ChangeFormat, self).__init__(**params)
592 688
593 def acceptable_child(self, child): 689 def acceptable_child(self, child):
594 return isinstance(child, ChangeFormatWhen) 690 return isinstance(child, ChangeFormatWhen)
595 691
596 692
597 class ChangeFormatWhen(XMLParam): 693 class ChangeFormatWhen(XMLParam):
598 name = 'when' 694 name = "when"
599 695
600 def __init__(self, input, format, value, **kwargs): 696 def __init__(self, input, format, value, **kwargs):
601 params = Util.clean_kwargs(locals().copy()) 697 params = Util.clean_kwargs(locals().copy())
602 super(ChangeFormatWhen, self).__init__(**params) 698 super(ChangeFormatWhen, self).__init__(**params)
603 699
604 def acceptable_child(self, child): 700 def acceptable_child(self, child):
605 return False 701 return False
606 702
607 703
608 class OutputCollection(XMLParam): 704 class OutputCollection(XMLParam):
609 name = 'collection' 705 name = "collection"
610 706
611 def __init__(self, name, type=None, label=None, format_source=None, 707 def __init__(
612 type_source=None, structured_like=None, inherit_format=None, **kwargs): 708 self,
709 name,
710 type=None,
711 label=None,
712 format_source=None,
713 type_source=None,
714 structured_like=None,
715 inherit_format=None,
716 **kwargs,
717 ):
613 params = Util.clean_kwargs(locals().copy()) 718 params = Util.clean_kwargs(locals().copy())
614 super(OutputCollection, self).__init__(**params) 719 super(OutputCollection, self).__init__(**params)
615 720
616 def acceptable_child(self, child): 721 def acceptable_child(self, child):
617 return isinstance(child, OutputData) or isinstance(child, OutputFilter) \ 722 return (
723 isinstance(child, OutputData)
724 or isinstance(child, OutputFilter)
618 or isinstance(child, DiscoverDatasets) 725 or isinstance(child, DiscoverDatasets)
726 )
619 727
620 728
621 class DiscoverDatasets(XMLParam): 729 class DiscoverDatasets(XMLParam):
622 name = 'discover_datasets' 730 name = "discover_datasets"
623 731
624 def __init__(self, pattern, directory=None, format=None, ext=None, 732 def __init__(
625 visible=None, **kwargs): 733 self, pattern, directory=None, format=None, ext=None, visible=None, **kwargs
734 ):
626 params = Util.clean_kwargs(locals().copy()) 735 params = Util.clean_kwargs(locals().copy())
627 super(DiscoverDatasets, self).__init__(**params) 736 super(DiscoverDatasets, self).__init__(**params)
628 737
629 738
630 class Tests(XMLParam): 739 class Tests(XMLParam):
631 name = 'tests' 740 name = "tests"
632 741
633 def acceptable_child(self, child): 742 def acceptable_child(self, child):
634 return issubclass(type(child), Test) 743 return issubclass(type(child), Test)
635 744
636 745
637 class Test(XMLParam): 746 class Test(XMLParam):
638 name = 'test' 747 name = "test"
639 748
640 def acceptable_child(self, child): 749 def acceptable_child(self, child):
641 return isinstance(child, TestParam) or isinstance(child, TestOutput) 750 return isinstance(child, TestParam) or isinstance(child, TestOutput)
642 751
643 752
644 class TestParam(XMLParam): 753 class TestParam(XMLParam):
645 name = 'param' 754 name = "param"
646 755
647 def __init__(self, name, value=None, ftype=None, dbkey=None, **kwargs): 756 def __init__(self, name, value=None, ftype=None, dbkey=None, **kwargs):
648 params = Util.clean_kwargs(locals().copy()) 757 params = Util.clean_kwargs(locals().copy())
649 super(TestParam, self).__init__(**params) 758 super(TestParam, self).__init__(**params)
650 759
651 760
652 class TestOutput(XMLParam): 761 class TestOutput(XMLParam):
653 name = 'output' 762 name = "output"
654 763
655 def __init__(self, name=None, file=None, ftype=None, sort=None, value=None, 764 def __init__(
656 md5=None, checksum=None, compare=None, lines_diff=None, 765 self,
657 delta=None, **kwargs): 766 name=None,
767 file=None,
768 ftype=None,
769 sort=None,
770 value=None,
771 md5=None,
772 checksum=None,
773 compare=None,
774 lines_diff=None,
775 delta=None,
776 **kwargs,
777 ):
658 params = Util.clean_kwargs(locals().copy()) 778 params = Util.clean_kwargs(locals().copy())
659 super(TestOutput, self).__init__(**params) 779 super(TestOutput, self).__init__(**params)
660 780
661 781
662 class Citations(XMLParam): 782 class Citations(XMLParam):
663 name = 'citations' 783 name = "citations"
664 784
665 def acceptable_child(self, child): 785 def acceptable_child(self, child):
666 return issubclass(type(child), Citation) 786 return issubclass(type(child), Citation)
667 787
668 def has_citation(self, type, value): 788 def has_citation(self, type, value):
671 791
672 :type type: STRING 792 :type type: STRING
673 :type value: STRING 793 :type value: STRING
674 """ 794 """
675 for citation in self.children: 795 for citation in self.children:
676 if citation.node.attrib['type'] == type and citation.node.text == value: 796 if citation.node.attrib["type"] == type and citation.node.text == value:
677 return True 797 return True
678 return False 798 return False
679 799
680 800
681 class Citation(XMLParam): 801 class Citation(XMLParam):
682 name = 'citation' 802 name = "citation"
683 803
684 def __init__(self, type, value): 804 def __init__(self, type, value):
685 passed_kwargs = {} 805 passed_kwargs = {}
686 passed_kwargs['type'] = type 806 passed_kwargs["type"] = type
687 super(Citation, self).__init__(**passed_kwargs) 807 super(Citation, self).__init__(**passed_kwargs)
688 self.node.text = str(value) 808 self.node.text = str(value)