Mercurial > hg
comparison setup.py @ 7632:9626819b2e3d
refactor version code
- simplify version detection code
- move detection code into setup.py
- move version reading function into util.py
- drop version.py code
This makes hg more closely follow its own recommendation of how to deal with
versioning your builds: use hg id in your build script.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sat, 10 Jan 2009 18:02:38 -0600 |
parents | dc211ad8d681 |
children | f7256cd9beff |
comparison
equal
deleted
inserted
replaced
7631:0b2ee57dfdb1 | 7632:9626819b2e3d |
---|---|
24 import zlib | 24 import zlib |
25 except: | 25 except: |
26 raise SystemExit( | 26 raise SystemExit( |
27 "Couldn't import standard zlib (incomplete Python install).") | 27 "Couldn't import standard zlib (incomplete Python install).") |
28 | 28 |
29 import os | 29 import os, time |
30 import shutil | 30 import shutil |
31 import tempfile | 31 import tempfile |
32 from distutils.core import setup, Extension | 32 from distutils.core import setup, Extension |
33 from distutils.command.install_data import install_data | 33 from distutils.command.install_data import install_data |
34 from distutils.ccompiler import new_compiler | 34 from distutils.ccompiler import new_compiler |
35 | |
36 import mercurial.version | |
37 | 35 |
38 extra = {} | 36 extra = {} |
39 scripts = ['hg'] | 37 scripts = ['hg'] |
40 if os.name == 'nt': | 38 if os.name == 'nt': |
41 scripts.append('contrib/win32/hg.bat') | 39 scripts.append('contrib/win32/hg.bat') |
93 extra['console'] = ['hg'] | 91 extra['console'] = ['hg'] |
94 | 92 |
95 except ImportError: | 93 except ImportError: |
96 pass | 94 pass |
97 | 95 |
98 # specify version string, otherwise 'hg identify' will be used: | 96 try: |
99 version = '' | 97 l = os.popen('hg id -it').read().split() |
98 while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags | |
99 l.pop() | |
100 version = l[-1] or 'unknown' # latest tag or revision number | |
101 if version.endswith('+'): | |
102 version += time.strftime('%Y%m%d') | |
103 | |
104 except OSError: | |
105 version = "unknown" | |
106 | |
107 f = file("mercurial/__version__.py", "w") | |
108 f.write('# this file is autogenerated by setup.py\n') | |
109 f.write('version = "%s"\n' % version) | |
110 f.close() | |
100 | 111 |
101 class install_package_data(install_data): | 112 class install_package_data(install_data): |
102 def finalize_options(self): | 113 def finalize_options(self): |
103 self.set_undefined_options('install', | 114 self.set_undefined_options('install', |
104 ('install_lib', 'install_dir')) | 115 ('install_lib', 'install_dir')) |
105 install_data.finalize_options(self) | 116 install_data.finalize_options(self) |
106 | 117 |
107 mercurial.version.remember_version(version) | |
108 cmdclass = {'install_data': install_package_data} | 118 cmdclass = {'install_data': install_package_data} |
109 | 119 |
110 ext_modules=[ | 120 ext_modules=[ |
111 Extension('mercurial.base85', ['mercurial/base85.c']), | 121 Extension('mercurial.base85', ['mercurial/base85.c']), |
112 Extension('mercurial.bdiff', ['mercurial/bdiff.c']), | 122 Extension('mercurial.bdiff', ['mercurial/bdiff.c']), |
138 packages.extend(['hgext.inotify', 'hgext.inotify.linux']) | 148 packages.extend(['hgext.inotify', 'hgext.inotify.linux']) |
139 except ImportError: | 149 except ImportError: |
140 pass | 150 pass |
141 | 151 |
142 setup(name='mercurial', | 152 setup(name='mercurial', |
143 version=mercurial.version.get_version(), | 153 version=version, |
144 author='Matt Mackall', | 154 author='Matt Mackall', |
145 author_email='mpm@selenic.com', | 155 author_email='mpm@selenic.com', |
146 url='http://selenic.com/mercurial', | 156 url='http://selenic.com/mercurial', |
147 description='Scalable distributed SCM', | 157 description='Scalable distributed SCM', |
148 license='GNU GPL', | 158 license='GNU GPL', |