comparison env/lib/python3.7/site-packages/gxformat2/_labels.py @ 0:26e78fe6e8c4 draft

"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author shellac
date Sat, 02 May 2020 07:14:21 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:26e78fe6e8c4
1 """Utilities for handling unlabelled objects when translating workflow formats."""
2
3
4 class Labels(object):
5 """Track labels assigned and generate anonymous ones."""
6
7 def __init__(self):
8 """Initialize labels that have been encountered or generated."""
9 self.seen_labels = set()
10 self.anonymous_labels = 0
11
12 def ensure_new_output_label(self, label):
13 """Ensure supplied label has value or generate an anonymous one."""
14 if label is None:
15 self.anonymous_labels += 1
16 label = "_anonymous_output_%d" % self.anonymous_labels
17 assert label not in self.seen_labels
18 self.seen_labels.add(label)
19 return label
20
21 @staticmethod
22 def is_anonymous_output_label(label):
23 """Predicate determining if supplied label was generated for anonymous output."""
24 # label likely can't be null according to the schema definition - but we've got a test
25 # in Galaxy that doesn't define a label in order to great a .ga file without output
26 # labels (which is completely normal).
27 return not label or label.startswith("_anonymous_output_")