# HG changeset patch # User Ludovic Chabant # Date 1391752832 28800 # Node ID 964fd28e9b396755127ed4030eb796d1b84cfc90 # Parent 07528bfadd35f22277283dbe85b228d245458d7f Added automatic versioning. diff -r 07528bfadd35 -r 964fd28e9b39 .hgignore --- 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 diff -r 07528bfadd35 -r 964fd28e9b39 setup.py --- 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', diff -r 07528bfadd35 -r 964fd28e9b39 wikked/__init__.py --- a/wikked/__init__.py Thu Feb 06 21:40:33 2014 -0800 +++ b/wikked/__init__.py Thu Feb 06 22:00:32 2014 -0800 @@ -1,2 +1,1 @@ -VERSION = '0.1.0'