##// END OF EJS Templates
Don't forget version at the end of setup.py, write it only if changed....
Thomas Arendsen Hein -
r1977:7eb694a1 default
parent child Browse files
Show More
@@ -1,67 +1,74
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 import util
16 import util
17
17
18 unknown_version = 'unknown'
18 unknown_version = 'unknown'
19 remembered_version = False
19 remembered_version = False
20
20
21 def get_version():
21 def get_version():
22 """Return version information if available."""
22 """Return version information if available."""
23 try:
23 try:
24 from mercurial.__version__ import version
24 from mercurial.__version__ import version
25 except ImportError:
25 except ImportError:
26 version = unknown_version
26 version = unknown_version
27 return version
27 return version
28
28
29 def write_version(version):
29 def write_version(version):
30 """Overwrite version file."""
30 """Overwrite version file."""
31 filename = os.path.join(os.path.dirname(__file__), '__version__.py')
31 if version == get_version():
32 f = open(filename, 'w')
32 return
33 directory = os.path.dirname(__file__)
34 for suffix in ['py', 'pyc', 'pyo']:
35 try:
36 os.unlink(os.path.join(directory, '__version__.%s' % suffix))
37 except OSError:
38 pass
39 f = open(os.path.join(directory, '__version__.py'), 'w')
33 f.write("# This file is auto-generated.\n")
40 f.write("# This file is auto-generated.\n")
34 f.write("version = %r\n" % version)
41 f.write("version = %r\n" % version)
35 f.close()
42 f.close()
36
43
37 def remember_version(version=None):
44 def remember_version(version=None):
38 """Store version information."""
45 """Store version information."""
39 global remembered_version
46 global remembered_version
40 if not version and os.path.isdir(".hg"):
47 if not version and os.path.isdir(".hg"):
41 f = os.popen("hg identify 2> %s" % util.nulldev) # use real hg installation
48 f = os.popen("hg identify 2> %s" % util.nulldev) # use real hg installation
42 ident = f.read()[:-1]
49 ident = f.read()[:-1]
43 if not f.close() and ident:
50 if not f.close() and ident:
44 ids = ident.split(' ', 1)
51 ids = ident.split(' ', 1)
45 version = ids.pop(0)
52 version = ids.pop(0)
46 if version[-1] == '+':
53 if version[-1] == '+':
47 version = version[:-1]
54 version = version[:-1]
48 modified = True
55 modified = True
49 else:
56 else:
50 modified = False
57 modified = False
51 if version.isalnum() and ids:
58 if version.isalnum() and ids:
52 for tag in ids[0].split('/'):
59 for tag in ids[0].split('/'):
53 # is a tag is suitable as a version number?
60 # is a tag is suitable as a version number?
54 if re.match(r'^(\d+\.)+[\w.-]+$', tag):
61 if re.match(r'^(\d+\.)+[\w.-]+$', tag):
55 version = tag
62 version = tag
56 break
63 break
57 if modified:
64 if modified:
58 version += time.strftime('+%Y%m%d')
65 version += time.strftime('+%Y%m%d')
59 if version:
66 if version:
60 remembered_version = True
67 remembered_version = True
61 write_version(version)
68 write_version(version)
62
69
63 def forget_version():
70 def forget_version():
64 """Remove version information."""
71 """Remove version information."""
65 if remembered_version:
72 if remembered_version:
66 write_version(unknown_version)
73 write_version(unknown_version)
67
74
@@ -1,106 +1,103
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 sys
8 import sys
9 if not hasattr(sys, 'version_info') or sys.version_info < (2, 3):
9 if not hasattr(sys, 'version_info') or sys.version_info < (2, 3):
10 raise SystemExit, "Mercurial requires python 2.3 or later."
10 raise SystemExit, "Mercurial requires python 2.3 or later."
11
11
12 import glob
12 import glob
13 from distutils.core import setup, Extension
13 from distutils.core import setup, Extension
14 from distutils.command.install_data import install_data
14 from distutils.command.install_data import install_data
15
15
16 import mercurial.version
16 import mercurial.version
17
17
18 # py2exe needs to be installed to work
18 # py2exe needs to be installed to work
19 try:
19 try:
20 import py2exe
20 import py2exe
21
21
22 # Help py2exe to find win32com.shell
22 # Help py2exe to find win32com.shell
23 try:
23 try:
24 import modulefinder
24 import modulefinder
25 import win32com
25 import win32com
26 for p in win32com.__path__[1:]: # Take the path to win32comext
26 for p in win32com.__path__[1:]: # Take the path to win32comext
27 modulefinder.AddPackagePath("win32com", p)
27 modulefinder.AddPackagePath("win32com", p)
28 pn = "win32com.shell"
28 pn = "win32com.shell"
29 __import__(pn)
29 __import__(pn)
30 m = sys.modules[pn]
30 m = sys.modules[pn]
31 for p in m.__path__[1:]:
31 for p in m.__path__[1:]:
32 modulefinder.AddPackagePath(pn, p)
32 modulefinder.AddPackagePath(pn, p)
33 except ImportError:
33 except ImportError:
34 pass
34 pass
35
35
36 # Due to the use of demandload py2exe is not finding the modules.
36 # Due to the use of demandload py2exe is not finding the modules.
37 # packagescan.getmodules creates a list of modules included in
37 # packagescan.getmodules creates a list of modules included in
38 # the mercurial package plus depdent modules.
38 # the mercurial package plus depdent modules.
39 import mercurial.packagescan
39 import mercurial.packagescan
40 from py2exe.build_exe import py2exe as build_exe
40 from py2exe.build_exe import py2exe as build_exe
41
41
42 class py2exe_for_demandload(build_exe):
42 class py2exe_for_demandload(build_exe):
43 """ overwrites the py2exe command class for getting the build
43 """ overwrites the py2exe command class for getting the build
44 directory and for setting the 'includes' option."""
44 directory and for setting the 'includes' option."""
45 def initialize_options(self):
45 def initialize_options(self):
46 self.build_lib = None
46 self.build_lib = None
47 build_exe.initialize_options(self)
47 build_exe.initialize_options(self)
48 def finalize_options(self):
48 def finalize_options(self):
49 # Get the build directory, ie. where to search for modules.
49 # Get the build directory, ie. where to search for modules.
50 self.set_undefined_options('build',
50 self.set_undefined_options('build',
51 ('build_lib', 'build_lib'))
51 ('build_lib', 'build_lib'))
52 # Sets the 'includes' option with the list of needed modules
52 # Sets the 'includes' option with the list of needed modules
53 if not self.includes:
53 if not self.includes:
54 self.includes = []
54 self.includes = []
55 else:
55 else:
56 self.includes = self.includes.split(',')
56 self.includes = self.includes.split(',')
57 self.includes += mercurial.packagescan.getmodules(self.build_lib,
57 self.includes += mercurial.packagescan.getmodules(self.build_lib,
58 'mercurial')
58 'mercurial')
59 self.includes += mercurial.packagescan.getmodules(self.build_lib,
59 self.includes += mercurial.packagescan.getmodules(self.build_lib,
60 'hgext')
60 'hgext')
61 build_exe.finalize_options(self)
61 build_exe.finalize_options(self)
62 except ImportError:
62 except ImportError:
63 py2exe_for_demandload = None
63 py2exe_for_demandload = None
64
64
65
65
66 # specify version string, otherwise 'hg identify' will be used:
66 # specify version string, otherwise 'hg identify' will be used:
67 version = ''
67 version = ''
68
68
69 class install_package_data(install_data):
69 class install_package_data(install_data):
70 def finalize_options(self):
70 def finalize_options(self):
71 self.set_undefined_options('install',
71 self.set_undefined_options('install',
72 ('install_lib', 'install_dir'))
72 ('install_lib', 'install_dir'))
73 install_data.finalize_options(self)
73 install_data.finalize_options(self)
74
74
75 try:
75 mercurial.version.remember_version(version)
76 mercurial.version.remember_version(version)
76 cmdclass = {'install_data': install_package_data}
77 cmdclass = {'install_data': install_package_data}
77 py2exe_opts = {}
78 py2exe_opts = {}
78 if py2exe_for_demandload is not None:
79 if py2exe_for_demandload is not None:
79 cmdclass['py2exe'] = py2exe_for_demandload
80 cmdclass['py2exe'] = py2exe_for_demandload
80 py2exe_opts['console'] = ['hg']
81 py2exe_opts['console'] = ['hg']
81 setup(name='mercurial',
82 setup(name='mercurial',
82 version=mercurial.version.get_version(),
83 version=mercurial.version.get_version(),
83 author='Matt Mackall',
84 author='Matt Mackall',
84 author_email='mpm@selenic.com',
85 author_email='mpm@selenic.com',
85 url='http://selenic.com/mercurial',
86 url='http://selenic.com/mercurial',
86 description='Scalable distributed SCM',
87 description='Scalable distributed SCM',
87 license='GNU GPL',
88 license='GNU GPL',
88 packages=['mercurial', 'hgext'],
89 packages=['mercurial', 'hgext'],
89 ext_modules=[Extension('mercurial.mpatch', ['mercurial/mpatch.c']),
90 ext_modules=[Extension('mercurial.mpatch', ['mercurial/mpatch.c']),
90 Extension('mercurial.bdiff', ['mercurial/bdiff.c'])],
91 Extension('mercurial.bdiff', ['mercurial/bdiff.c'])],
91 data_files=[('mercurial/templates',
92 data_files=[('mercurial/templates',
92 ['templates/map'] +
93 ['templates/map'] +
93 glob.glob('templates/map-*') +
94 glob.glob('templates/map-*') +
94 glob.glob('templates/*.tmpl')),
95 glob.glob('templates/*.tmpl')),
95 ('mercurial/templates/static',
96 ('mercurial/templates/static',
96 glob.glob('templates/static/*'))],
97 glob.glob('templates/static/*'))],
97 cmdclass=cmdclass,
98 cmdclass=cmdclass,
98 scripts=['hg', 'hgmerge'],
99 scripts=['hg', 'hgmerge'],
99 options=dict(bdist_mpkg=dict(zipdist=True,
100 options=dict(bdist_mpkg=dict(zipdist=True,
100 license='COPYING',
101 license='COPYING',
101 readme='contrib/macosx/Readme.html',
102 readme='contrib/macosx/Readme.html',
102 welcome='contrib/macosx/Welcome.html')),
103 welcome='contrib/macosx/Welcome.html')),
103 **py2exe_opts)
104 **py2exe_opts)
105 finally:
106 mercurial.version.forget_version()
General Comments 0
You need to be logged in to leave comments. Login now