comparison setup.py @ 80:009e7858a93b

setup: add version number lookup
author Matt Mackall <mpm@selenic.com>
date Thu, 10 Nov 2011 16:42:12 -0600
parents 358fd5c84270
children 1b47146a4a2c
comparison
equal deleted inserted replaced
79:ca5f8f43e585 80:009e7858a93b
1 import os 1 import os, time
2 from distutils.core import setup 2 from distutils.core import setup
3
4 # query Mercurial for version number
5 version = 'unknown'
6 if os.path.isdir('.hg'):
7 cmd = "hg id -i -t"
8 l = os.popen(cmd).read().split()
9 while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags
10 l.pop()
11 if len(l) > 1: # tag found
12 version = l[-1]
13 if l[0].endswith('+'): # propagate the dirty status to the tag
14 version += '+'
15 elif len(l) == 1: # no tag found
16 cmd = 'hg parents --template "{latesttag}+{latesttagdistance}-"'
17 version = os.popen(cmd).read() + l[0]
18 if version.endswith('+'):
19 version += time.strftime('%Y%m%d')
20 elif os.path.exists('.hg_archival.txt'):
21 kw = dict([[t.strip() for t in l.split(':', 1)]
22 for l in open('.hg_archival.txt')])
23 if 'tag' in kw:
24 version = kw['tag']
25 elif 'latesttag' in kw:
26 version = '%(latesttag)s+%(latesttagdistance)s-%(node).12s' % kw
27 else:
28 version = kw.get('node', '')[:12]
3 29
4 setup( 30 setup(
5 name='python-hglib', 31 name='python-hglib',
6 version='0.1', 32 version=version,
7 author='Idan Kamara', 33 author='Idan Kamara',
8 author_email='idankk86@gmail.com', 34 author_email='idankk86@gmail.com',
9 url='http://selenic.com/repo/python-hglib', 35 url='http://selenic.com/repo/python-hglib',
10 description='Mercurial Python library', 36 description='Mercurial Python library',
11 long_description=open(os.path.join(os.path.dirname(__file__), 'README')).read(), 37 long_description=open(os.path.join(os.path.dirname(__file__), 'README')).read(),