+
+def format_version(version):
+ fmt = '{tag}.dev{commitcount}+{gitsha}'
+ parts = version.split('-')
+ assert len(parts) in (3, 4)
+ dirty = len(parts) == 4
+ tag, count, sha = parts[:3]
+ if count == '0' and not dirty:
+ return tag
+ return fmt.format(tag=tag, commitcount=count, gitsha=sha.lstrip('g'))
+
+