MCPcopy
hub / github.com/dask/dask / label

Function label

dask/dot.py:64–102  ·  view source on GitHub ↗

>>> label('x') 'x' >>> label(('x', 1)) "('x', 1)" >>> from hashlib import md5 >>> x = 'x-%s-hello' % md5(b'1234').hexdigest() >>> x 'x-81dc9bdb52d04dc20036dbd8313ed055-hello' >>> label(x) 'x-#-hello' >>> from uuid import uuid1 >>> x = 'x-%s-hello

(x, cache=None)

Source from the content-addressed store, hash-verified

62
63
64def label(x, cache=None):
65 """
66
67 >>> label('x')
68 'x'
69
70 >>> label(('x', 1))
71 "('x', 1)"
72
73 >>> from hashlib import md5
74 >>> x = 'x-%s-hello' % md5(b'1234').hexdigest()
75 >>> x
76 'x-81dc9bdb52d04dc20036dbd8313ed055-hello'
77
78 >>> label(x)
79 'x-#-hello'
80
81 >>> from uuid import uuid1
82 >>> x = 'x-%s-hello' % uuid1()
83 >>> x # doctest: +SKIP
84 'x-4c1a3d7e-0b45-11e6-8334-54ee75105593-hello'
85
86 >>> label(x)
87 'x-#-hello'
88 """
89 s = str(x)
90 for pattern in (_HASHPAT, _UUIDPAT):
91 m = re.search(pattern, s)
92 if m is not None:
93 for h in m.groups():
94 if cache is not None:
95 n = cache.get(h, len(cache))
96 label = f"#{n}"
97 # cache will be overwritten destructively
98 cache[h] = n
99 else:
100 label = "#"
101 s = s.replace(h, label)
102 return s
103
104
105def box_label(key, verbose=False):

Callers 3

to_graphvizFunction · 0.90
_to_graphvizMethod · 0.90
test_labelFunction · 0.90

Calls 2

getMethod · 0.45
replaceMethod · 0.45

Tested by 1

test_labelFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…