##// END OF EJS Templates
Make it possible to specify a version number in setup.py....
Thomas Arendsen Hein -
r427:36e644d2 default
parent child Browse files
Show More
@@ -1,65 +1,66 b''
1 # Copyright (C) 2005 by Intevation GmbH
1 # Copyright (C) 2005 by Intevation GmbH
2 # Author(s):
2 # Author(s):
3 # Thomas Arendsen Hein <thomas@intevation.de>
3 # Thomas Arendsen Hein <thomas@intevation.de>
4 #
4 #
5 # This program is free software under the GNU GPL (>=v2)
5 # This program is free software under the GNU GPL (>=v2)
6 # Read the file COPYING coming with the software for details.
6 # Read the file COPYING coming with the software for details.
7
7
8 """
8 """
9 Mercurial version
9 Mercurial version
10 """
10 """
11
11
12 import os
12 import os
13 import os.path
13 import os.path
14 import re
14 import re
15 import time
15 import time
16
16
17 unknown_version = 'unknown'
17 unknown_version = 'unknown'
18 remembered_version = False
18 remembered_version = False
19
19
20 def get_version():
20 def get_version():
21 """Return version information if available."""
21 """Return version information if available."""
22 try:
22 try:
23 from mercurial.__version__ import version
23 from mercurial.__version__ import version
24 except ImportError:
24 except ImportError:
25 version = unknown_version
25 version = unknown_version
26 return version
26 return version
27
27
28 def write_version(version):
28 def write_version(version):
29 """Overwrite version file."""
29 """Overwrite version file."""
30 filename = os.path.join(os.path.dirname(__file__), '__version__.py')
30 filename = os.path.join(os.path.dirname(__file__), '__version__.py')
31 f = open(filename, 'w')
31 f = open(filename, 'w')
32 f.write("# This file is auto-generated.\n")
32 f.write("# This file is auto-generated.\n")
33 f.write("version = %r\n" % version)
33 f.write("version = %r\n" % version)
34 f.close()
34 f.close()
35
35
36 def remember_version():
36 def remember_version(version=None):
37 """Store version information."""
37 """Store version information."""
38 global remembered_version
38 global remembered_version
39 if os.access(".hg", os.F_OK):
39 if not version and os.path.isdir(".hg"):
40 f = os.popen("hg identify 2>/dev/null") # use real hg installation
40 f = os.popen("hg identify 2>/dev/null") # use real hg installation
41 ident = f.read()[:-1]
41 ident = f.read()[:-1]
42 if not f.close() and ident:
42 if not f.close() and ident:
43 ids = ident.split(' ', 1)
43 ids = ident.split(' ', 1)
44 version = ids.pop(0)
44 version = ids.pop(0)
45 if version[-1] == '+':
45 if version[-1] == '+':
46 version = version[:-1]
46 version = version[:-1]
47 modified = True
47 modified = True
48 else:
48 else:
49 modified = False
49 modified = False
50 if version.isalnum() and ids:
50 if version.isalnum() and ids:
51 for tag in ids[0].split('/'):
51 for tag in ids[0].split('/'):
52 # is a tag is suitable as a version number?
52 # is a tag is suitable as a version number?
53 if re.match(r'^(\d+\.)+[\w.-]+$', tag):
53 if re.match(r'^(\d+\.)+[\w.-]+$', tag):
54 version = tag
54 version = tag
55 break
55 break
56 if modified:
56 if modified:
57 version += time.strftime('+%Y%m%d')
57 version += time.strftime('+%Y%m%d')
58 remembered_version = True
58 if version:
59 write_version(version)
59 remembered_version = True
60 write_version(version)
60
61
61 def forget_version():
62 def forget_version():
62 """Remove version information."""
63 """Remove version information."""
63 if remembered_version:
64 if remembered_version:
64 write_version(unknown_version)
65 write_version(unknown_version)
65
66
@@ -1,38 +1,41 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2
2
3 # This is the mercurial setup script.
3 # This is the mercurial setup script.
4 #
4 #
5 # './setup.py install', or
5 # './setup.py install', or
6 # './setup.py --help' for more options
6 # './setup.py --help' for more options
7
7
8 import glob
8 import glob
9 from distutils.core import setup, Extension
9 from distutils.core import setup, Extension
10 from distutils.command.install_data import install_data
10 from distutils.command.install_data import install_data
11
11
12 import mercurial.version
12 import mercurial.version
13
13
14 # specify version string, otherwise 'hg identify' will be used:
15 version = ''
16
14 class install_package_data(install_data):
17 class install_package_data(install_data):
15 def finalize_options(self):
18 def finalize_options(self):
16 self.set_undefined_options('install',
19 self.set_undefined_options('install',
17 ('install_lib', 'install_dir'))
20 ('install_lib', 'install_dir'))
18 install_data.finalize_options(self)
21 install_data.finalize_options(self)
19
22
20 try:
23 try:
21 mercurial.version.remember_version()
24 mercurial.version.remember_version(version)
22 setup(name='mercurial',
25 setup(name='mercurial',
23 version=mercurial.version.get_version(),
26 version=mercurial.version.get_version(),
24 author='Matt Mackall',
27 author='Matt Mackall',
25 author_email='mpm@selenic.com',
28 author_email='mpm@selenic.com',
26 url='http://selenic.com/mercurial',
29 url='http://selenic.com/mercurial',
27 description='scalable distributed SCM',
30 description='scalable distributed SCM',
28 license='GNU GPL',
31 license='GNU GPL',
29 packages=['mercurial'],
32 packages=['mercurial'],
30 ext_modules=[Extension('mercurial.mpatch', ['mercurial/mpatch.c'])],
33 ext_modules=[Extension('mercurial.mpatch', ['mercurial/mpatch.c'])],
31 data_files=[('mercurial/templates',
34 data_files=[('mercurial/templates',
32 ['templates/map'] +
35 ['templates/map'] +
33 glob.glob('templates/map-*') +
36 glob.glob('templates/map-*') +
34 glob.glob('templates/*.tmpl'))],
37 glob.glob('templates/*.tmpl'))],
35 cmdclass = { 'install_data' : install_package_data },
38 cmdclass = { 'install_data' : install_package_data },
36 scripts=['hg', 'hgmerge'])
39 scripts=['hg', 'hgmerge'])
37 finally:
40 finally:
38 mercurial.version.forget_version()
41 mercurial.version.forget_version()
General Comments 0
You need to be logged in to leave comments. Login now