Permalink
Browse files

added next() method, to minimally increment the version number

  • Loading branch information...
1 parent 18a70ab commit bf6970785f7c03461e26503eec6b8ea4cd728fcb @timbertson committed Aug 7, 2011
Showing with 63 additions and 0 deletions.
  1. +57 −0 version.py
  2. +6 −0 version.xml
View
@@ -59,6 +59,57 @@ def __init__(self, number, desc=None):
self.number = number
self.desc = desc
+ def next(self):
+ """
+ Increment the version number *minimally*, according to the zero-install
+ version numbers spec (http://0install.net/interface-spec.html#versions):
+
+ >>> Version('1.0').next()
+ Version('1.0-post')
+
+ >>> Version('1.0-pre').next()
+ Version('1.0-pre1')
+ >>> Version('1.0-pre1').next()
+ Version('1.0-pre2')
+
+ >>> Version('1.0-post1-pre').next()
+ Version('1.0-post1-pre1')
+ >>> Version('1.0-post1-pre1').next()
+ Version('1.0-post1-pre2')
+
+ >>> Version('1.0-rc').next()
+ Version('1.0-rc1')
+ >>> Version('1.0-rc1').next()
+ Version('1.0-rc2')
+
+ >>> Version('1.0-post').next()
+ Version('1.0-post1')
+ >>> Version('1.0-post1').next()
+ Version('1.0-post2')
+ >>> Version('1.0-post07').next()
+ Version('1.0-post8')
+ >>> Version('1.0-post9').next()
+ Version('1.0-post10')
+
+ # arbitrary suffixes are supported, if present:
+ >>> Version('1.0-foo').next()
+ Version('1.0-foo1')
+ """
+
+ parts = self.number.rsplit('-', 1)
+ if len(parts) == 1:
+ return Version("%s-post" % (self.number,))
+ pre, suffix = parts
+ end_num = re.compile(r"\d+$")
+ end_num_match = re.search(end_num, suffix)
+ if not end_num_match:
+ next_num = 1
+ else:
+ next_num = int(end_num_match.group(), 10) + 1
+ suffix = suffix[:end_num_match.start()]
+ suffix = "%s%s" % (suffix, next_num)
+ return Version('-'.join((pre, suffix)))
+
def increment(self, levels=1):
"""
Increment the version component at `levels` least-significant
@@ -128,6 +179,7 @@ def main(opts, input=None):
... if new: print ":: new %s" % (new,)
... return [Version('0.1.2', 'fake')]
>>> version.version_types = version_types
+ >>> version.prompt = lambda *a: True
>>> class Object(object):
... def __init__(self, **k):
... [setattr(self, k, v) for k, v in k.items()]
@@ -187,6 +239,9 @@ def get_version(input, current_versions):
>>> get_version(None, [Version('0.1')])
Version('0.1')
+ >>> get_version('.', [Version('0.1')])
+ Version('0.1-post')
+
"""
if input is None:
return current_versions[0]
@@ -198,6 +253,8 @@ def get_version(input, current_versions):
return Version(v)
elif input == '=':
return current_versions[0]
+ elif input == '.':
+ return current_versions[0].next()
else:
return Version(input)
View
@@ -68,6 +68,12 @@ To increment the second-most minor version number
</div>
</rich-description>
<group main="version.py">
+ <command name="test">
+ <runner interface="http://gfxmonk.net/dist/0install/nose.xml">
+ <arg>--with-doctest</arg>
+ <arg>--exe</arg>
+ </runner>
+ </command>
<environment insert="" mode="prepend" name="PYTHONPATH"/>
<implementation id="sha1new=bea229b667512d5b01b6b7f35919ca88ee95af50" released="2010-07-31" version="0.2">
<manifest-digest sha256="193941f6f9f61c35ea94156cfd1c8e52e25577ce3e23f89db0eead9120154a65"/>

0 comments on commit bf69707

Please sign in to comment.