From f13f4f474f7c2defb1ac7615d8b5ef32afb345d0 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sat, 9 Nov 2013 21:45:30 +0100 Subject: [PATCH] bump version to 0.2.0b0, add Version code, read version number from package init for use in setup.py and sphinx docs --- docs/conf.py | 5 ++-- nsupdate/__init__.py | 65 ++++++++++++++++++++++++++++++++++++++++++++ setup.py | 4 ++- 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 46dab4f..659cfe1 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -48,10 +48,11 @@ copyright = u'2013, The nsupdate.info Team' # |version| and |release|, also used in various other places throughout the # built documents. # +from nsupdate import version as nsupdate_version # The short X.Y version. -version = '0.0.1' +version = '%d.%d' % nsupdate_version[:2] # The full version, including alpha/beta/rc tags. -release = '0.0.1a0' +release = str(nsupdate_version) # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/nsupdate/__init__.py b/nsupdate/__init__.py index e69de29..d2f7072 100644 --- a/nsupdate/__init__.py +++ b/nsupdate/__init__.py @@ -0,0 +1,65 @@ +""" +nsupdate - dynamic DNS service +""" + +import re + + +class Version(tuple): + """ + Version objects store versions like 1.2.3a4 in a structured + way and support version comparisons and direct version component access. + 1: major version (digits only) + 2: minor version (digits only) + 3: (maintenance) release version (digits only) + a4: optional additional version specification (str) + + See PEP386 for more details. + TODO: use 3rd party code for PEP386 version numbers later. + + You can create a Version instance either by giving the components, like: + Version(1,2,3,'a4') + or by giving the composite version string, like: + Version(version="1.2.3a4"). + + Version subclasses tuple, so comparisons to tuples should work. + Also, we inherit all the comparison logic from tuple base class. + """ + VERSION_RE = re.compile( + r""" + (?P\d+) + \. + (?P\d+) + \. + (?P\d+) + (?P[abc]\d+)?""", + re.VERBOSE) + + @classmethod + def parse_version(cls, version): + match = cls.VERSION_RE.match(version) + if match is None: + raise ValueError("Unexpected version string format: {0!r}".format(version)) + v = match.groupdict() + return int(v['major']), int(v['minor']), int(v['release']), str(v['additional'] or 'd0') + + def __new__(cls, major=0, minor=0, release=0, additional='d0', version=None): + # HACK: Use "d0" for release, as "d0" > "c99". + if version: + major, minor, release, additional = cls.parse_version(version) + return tuple.__new__(cls, (major, minor, release, additional)) + + # properties for easy access of version components + major = property(lambda self: self[0]) + minor = property(lambda self: self[1]) + release = property(lambda self: self[2]) + additional = property(lambda self: self[3] if self[3] != 'd0' else '') + + def __str__(self): + version_str = "{0}.{1}.{2}".format(self.major, self.minor, self.release) + if self.additional != 'd0': + version_str += self.additional + return version_str + + +version = Version(0, 2, 0, 'b0') diff --git a/setup.py b/setup.py index dae5e88..91709ec 100644 --- a/setup.py +++ b/setup.py @@ -4,12 +4,14 @@ setup for nsupdate package from setuptools import setup, find_packages +from nsupdate import version + with open('README.rst') as f: readme_content = f.read() setup( name='nsupdate', - version='0.0.1a0', + version=str(version), url='http://github.com/nsupdate-info/nsupdate.info/', license='BSD', author='The nsupdate.info Team (see AUTHORS)',