Skip to content

Commit

Permalink
Replace uuid strings with pleasant names in dot
Browse files Browse the repository at this point in the history
  • Loading branch information
mrocklin committed Apr 26, 2016
1 parent c0c16c9 commit 86e74ff
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions dask/dot.py
Expand Up @@ -52,6 +52,7 @@ def name(x):


_HASHPAT = re.compile('([0-9a-z]{32})')
_UUIDPAT = re.compile('([0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12})')


def label(x, cache=None):
Expand All @@ -68,21 +69,30 @@ def label(x, cache=None):
>>> x
'x-81dc9bdb52d04dc20036dbd8313ed055-hello'
>>> label(x)
'x-#-hello'
>>> from uuid import uuid1
>>> x = 'x-%s-hello' % uuid1()
>>> x # doctest: +SKIP
'x-4c1a3d7e-0b45-11e6-8334-54ee75105593-hello'
>>> label(x)
'x-#-hello'
"""
s = str(x)
m = re.search(_HASHPAT, s)
if m is not None:
for h in m.groups():
if cache is not None:
n = cache.get(h, len(cache))
label = '#{0}'.format(n)
# cache will be overwritten destructively
cache[h] = n
else:
label = '#'
s = s.replace(h, label)
for pattern in (_HASHPAT, _UUIDPAT):
m = re.search(pattern, s)
if m is not None:
for h in m.groups():
if cache is not None:
n = cache.get(h, len(cache))
label = '#{0}'.format(n)
# cache will be overwritten destructively
cache[h] = n
else:
label = '#'
s = s.replace(h, label)
return s


Expand Down

0 comments on commit 86e74ff

Please sign in to comment.