Mercurial > wikked
comparison setup.py @ 195:964fd28e9b39
Added automatic versioning.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 06 Feb 2014 22:00:32 -0800 |
parents | f1003615a261 |
children | 719bcebefd68 |
comparison
equal
deleted
inserted
replaced
194:07528bfadd35 | 195:964fd28e9b39 |
---|---|
1 import os | 1 import os |
2 import os.path | 2 import os.path |
3 import time | |
4 import subprocess | |
3 from setuptools import setup, find_packages | 5 from setuptools import setup, find_packages |
4 from wikked import VERSION | |
5 | 6 |
6 | 7 |
7 def read(fname): | 8 def read(fname): |
8 with open(os.path.join(os.path.dirname(__file__), fname)) as fp: | 9 with open(os.path.join(os.path.dirname(__file__), fname)) as fp: |
9 return fp.read() | 10 return fp.read() |
10 | 11 |
11 | 12 |
12 #TODO: get the build version from the source control revision. | 13 def runcmd(cmd): |
13 BUILD_VERSION = 4 | 14 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, |
14 FULL_VERSION = '%s.%s' % (VERSION, BUILD_VERSION) | 15 stderr=subprocess.PIPE) |
16 out, err = p.communicate() | |
17 return out, err | |
18 | |
19 | |
20 # Figure out the version. | |
21 # (this is loosely based on what Mercurial does) | |
22 try: | |
23 if os.path.isdir('.hg'): | |
24 cmd = ['hg', 'log', '-r', '.', '--template', '{tags}\n'] | |
25 tags, err = runcmd(cmd) | |
26 versions = [t for t in tags.split() if t[0].isdigit()] | |
27 | |
28 cmd = ['hg', 'id', '-i'] | |
29 hgid, err = runcmd(cmd) | |
30 hgid = hgid.strip() | |
31 | |
32 if versions: | |
33 # Use tag found at the current revision. Add dirty flag if any. | |
34 version = versions[-1] | |
35 if hgid.endswith('+'): | |
36 version += '+' | |
37 else: | |
38 # Use latest tag. | |
39 cmd = ['hg', 'parents', '--template', '{latesttag}+{latesttagdistance}-'] | |
40 version, err = runcmd(cmd) | |
41 version += hgid | |
42 if version.endswith('+'): | |
43 version += time.strftime('%Y%m%d') | |
44 except OSError: | |
45 # Mercurial isn't installed, or not in the PATH. | |
46 version = None | |
47 | |
48 if version: | |
49 f = open("wikked/__version__.py", "w") | |
50 f.write('# this file is autogenerated by setup.py\n') | |
51 f.write('version = "%s"\n' % version) | |
52 f.close() | |
53 | |
54 | |
55 try: | |
56 from wikked import __version__ | |
57 version = __version__.version | |
58 except ImportError: | |
59 version = 'unknown' | |
15 | 60 |
16 | 61 |
17 setup( | 62 setup( |
18 name='Wikked', | 63 name='Wikked', |
19 version=FULL_VERSION, | 64 version=version, |
20 description=("A wiki engine entirely managed with text files " | 65 description=("A wiki engine entirely managed with text files " |
21 "stored in a revision control system."), | 66 "stored in a revision control system."), |
22 author='Ludovic Chabant', | 67 author='Ludovic Chabant', |
23 author_email='ludovic@chabant.com', | 68 author_email='ludovic@chabant.com', |
24 url="https://github.com/ludovicchabant/Wikked", | 69 url="https://github.com/ludovicchabant/Wikked", |