comparison env/lib/python3.9/site-packages/gxformat2/_labels.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
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: str):
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: str):
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_")