Added automatic versioning.
3 files changed, 51 insertions(+), 6 deletions(-)

M .hgignore
M setup.py
M wikked/__init__.py
M .hgignore +1 -0
@@ 2,6 2,7 @@ syntax:glob
 venv
 node_modules
 wikked/static
+wikked/__version__.py
 dist
 build
 *.pyc

          
M setup.py +50 -5
@@ 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 @@ def read(fname):
         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',

          
M wikked/__init__.py +0 -1
@@ 1,2 1,1 @@ 
-VERSION = '0.1.0'