Mercurial > wikked
changeset 195:964fd28e9b39
Added automatic versioning.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 06 Feb 2014 22:00:32 -0800 |
parents | 07528bfadd35 |
children | cbf7db1ff0d5 |
files | .hgignore setup.py wikked/__init__.py |
diffstat | 3 files changed, 51 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Thu Feb 06 21:40:33 2014 -0800 +++ b/.hgignore Thu Feb 06 22:00:32 2014 -0800 @@ -2,6 +2,7 @@ venv node_modules wikked/static +wikked/__version__.py dist build *.pyc
--- a/setup.py Thu Feb 06 21:40:33 2014 -0800 +++ b/setup.py Thu Feb 06 22:00:32 2014 -0800 @@ -1,7 +1,8 @@ import os import os.path +import time +import subprocess from setuptools import setup, find_packages -from wikked import VERSION def read(fname): @@ -9,14 +10,58 @@ return fp.read() -#TODO: get the build version from the source control revision. -BUILD_VERSION = 4 -FULL_VERSION = '%s.%s' % (VERSION, BUILD_VERSION) +def runcmd(cmd): + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, err = p.communicate() + return out, err + + +# Figure out the version. +# (this is loosely based on what Mercurial does) +try: + if os.path.isdir('.hg'): + cmd = ['hg', 'log', '-r', '.', '--template', '{tags}\n'] + tags, err = runcmd(cmd) + versions = [t for t in tags.split() if t[0].isdigit()] + + cmd = ['hg', 'id', '-i'] + hgid, err = runcmd(cmd) + hgid = hgid.strip() + + if versions: + # Use tag found at the current revision. Add dirty flag if any. + version = versions[-1] + if hgid.endswith('+'): + version += '+' + else: + # Use latest tag. + cmd = ['hg', 'parents', '--template', '{latesttag}+{latesttagdistance}-'] + version, err = runcmd(cmd) + version += hgid + if version.endswith('+'): + version += time.strftime('%Y%m%d') +except OSError: + # Mercurial isn't installed, or not in the PATH. + version = None + +if version: + f = open("wikked/__version__.py", "w") + f.write('# this file is autogenerated by setup.py\n') + f.write('version = "%s"\n' % version) + f.close() + + +try: + from wikked import __version__ + version = __version__.version +except ImportError: + version = 'unknown' setup( name='Wikked', - version=FULL_VERSION, + version=version, description=("A wiki engine entirely managed with text files " "stored in a revision control system."), author='Ludovic Chabant',