comparison setup.py @ 509:ac9c9e1a8022

setup: write out version info
author Augie Fackler <durin42@gmail.com>
date Tue, 15 Dec 2009 09:12:00 -0600
parents 1ad05cffb20f
children 3c2f3444ffba
comparison
equal deleted inserted replaced
508:e5dedda7bee0 509:ac9c9e1a8022
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 import os 3 import os
4 import subprocess
4 import sys 5 import sys
6 import time
5 if not hasattr(sys, 'version_info') or sys.version_info < (2, 4, 0, 'final'): 7 if not hasattr(sys, 'version_info') or sys.version_info < (2, 4, 0, 'final'):
6 raise SystemExit("Mercurial requires python 2.4 or later.") 8 raise SystemExit("Mercurial requires python 2.4 or later.")
7 9
8 try: 10 try:
9 from distutils.command.build_py import build_py_2to3 as build_py 11 from distutils.command.build_py import build_py_2to3 as build_py
12 try: 14 try:
13 from setuptools import setup 15 from setuptools import setup
14 except ImportError: 16 except ImportError:
15 from distutils.core import setup 17 from distutils.core import setup
16 18
19 def runcmd(cmd, env):
20 p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
21 stderr=subprocess.PIPE, env=env)
22 out, err = p.communicate()
23 # If root is executing setup.py, but the repository is owned by
24 # another user (as in "sudo python setup.py install") we will get
25 # trust warnings since the .hg/hgrc file is untrusted. That is
26 # fine, we don't want to load it anyway.
27 err = [e for e in err.splitlines()
28 if not e.startswith('Not trusting file')]
29 if err:
30 return ''
31 return out
32
33
34 version = ''
35
36 if os.path.isdir('.hg'):
37 # Execute hg out of this directory with a custom environment which
38 # includes the pure Python modules in mercurial/pure. We also take
39 # care to not use any hgrc files and do no localization.
40 env = {'HGRCPATH': '',
41 'LANGUAGE': 'C'}
42 for copyenv in ('LD_LIBRARY_PATH', 'PYTHONPATH', 'PATH'):
43 if copyenv in os.environ:
44 env[copyenv] = os.environ[copyenv]
45 if 'SystemRoot' in os.environ:
46 # Copy SystemRoot into the custom environment for Python 2.6
47 # under Windows. Otherwise, the subprocess will fail with
48 # error 0xc0150004. See: http://bugs.python.org/issue3440
49 env['SystemRoot'] = os.environ['SystemRoot']
50 cmd = ['hg', 'id', '-i', '-t']
51 print runcmd(cmd, env)
52 l = runcmd(cmd, env).split()
53 print l
54 while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags
55 l.pop()
56 if len(l) > 1: # tag found
57 version = l[-1]
58 if l[0].endswith('+'): # propagate the dirty status to the tag
59 version += '+'
60 elif len(l) == 1: # no tag found
61 cmd = ['hg', 'parents', '--template',
62 '{latesttag}+{latesttagdistance}-']
63 version = runcmd(cmd, env) + l[0]
64 if not version:
65 version = runcmd(['hg', 'parents', '--template' '{node|short}\n'],
66 env)
67 print 'xxx', version
68 if version:
69 version = version.split()[0]
70 if version.endswith('+'):
71 version += time.strftime('%Y%m%d')
72 elif os.path.exists('.hg_archival.txt'):
73 kw = dict([t.strip() for t in l.split(':', 1)]
74 for l in open('.hg_archival.txt'))
75 if 'tag' in kw:
76 version = kw['tag']
77 elif 'latesttag' in kw:
78 version = '%(latesttag)s+%(latesttagdistance)s-%(node).12s' % kw
79 else:
80 version = kw.get('node', '')[:12]
81
82 if version:
83 f = open("hgsubversion/__version__.py", "w")
84 f.write('# this file is autogenerated by setup.py\n')
85 f.write('version = "%s"\n' % version)
86 f.close()
87
88 try:
89 from hgsubversion import __version__
90 version = __version__.version
91 except ImportError:
92 version = 'unknown'
93
17 setup( 94 setup(
18 name = 'hgsubversion', 95 name = 'hgsubversion',
19 version = '0.0.1', 96 version = version,
20 url = 'http://bitbucket.org/durin42/hgsubversion', 97 url = 'http://bitbucket.org/durin42/hgsubversion',
21 license = 'GNU GPL', 98 license = 'GNU GPL',
22 author = 'Augie Fackler, others', 99 author = 'Augie Fackler, others',
23 author_email = 'hgsubversion@googlegroups.com', 100 author_email = 'hgsubversion@googlegroups.com',
24 description = ('hgsubversion is a Mercurial extension for working with ' 101 description = ('hgsubversion is a Mercurial extension for working with '