1
1
#! /usr/bin/env python
3
"""Installation script for bzr.
5
'./setup.py install', or
6
'./setup.py --help' for more options
15
# META INFORMATION FOR SETUP
17
META_INFO = {'name': 'bzr',
18
'version': bzrlib.__version__,
19
'author': 'Canonical Ltd',
20
'author_email': 'bazaar@lists.canonical.com',
21
'url': 'http://www.bazaar-vcs.org/',
22
'description': 'Friendly distributed version control system',
23
'license': 'GNU GPL v2',
26
# The list of packages is automatically generated later. Add other things
27
# that are part of BZRLIB here.
30
PKG_DATA = {# install files from selftest suite
31
'package_data': {'bzrlib': ['doc/api/*.txt',
32
'tests/test_patches_data/*',
36
######################################################################
37
# Reinvocation stolen from bzr, we need python2.4 by virtue of bzr_man
38
# including bzrlib.help
41
version_info = sys.version_info
42
except AttributeError:
43
version_info = 1, 5 # 1.5 or older
45
REINVOKE = "__BZR_REINVOKE"
47
KNOWN_PYTHONS = ('python2.4',)
49
if version_info < NEED_VERS:
50
if not os.environ.has_key(REINVOKE):
51
# mutating os.environ doesn't work in old Pythons
52
os.putenv(REINVOKE, "1")
53
for python in KNOWN_PYTHONS:
55
os.execvp(python, [python] + sys.argv)
58
print >>sys.stderr, "bzr: error: cannot find a suitable python interpreter"
59
print >>sys.stderr, " (need %d.%d or later)" % NEED_VERS
61
if getattr(os, "unsetenv", None) is not None:
65
def get_bzrlib_packages():
66
"""Recurse through the bzrlib directory, and extract the package names"""
69
base_path = os.path.dirname(os.path.abspath(bzrlib.__file__))
70
for root, dirs, files in os.walk(base_path):
71
if '__init__.py' in files:
72
assert root.startswith(base_path)
73
# Get just the path below bzrlib
74
package_path = root[len(base_path):]
75
# Remove leading and trailing slashes
76
package_path = package_path.strip('\\/')
78
package_name = 'bzrlib'
80
package_name = ('bzrlib.' +
81
package_path.replace('/', '.').replace('\\', '.'))
82
packages.append(package_name)
83
return sorted(packages)
86
BZRLIB['packages'] = get_bzrlib_packages()
3
# This is an installation script for bzr. Run it with
4
# './setup.py install', or
5
# './setup.py --help' for more options
89
7
from distutils.core import setup
90
from distutils.command.install_scripts import install_scripts
91
from distutils.command.build import build
9
# more sophisticated setup script, based on pychecker setup.py
11
from distutils.command.build_scripts import build_scripts
93
14
###############################
94
15
# Overridden distutils actions
95
16
###############################
97
class my_install_scripts(install_scripts):
98
""" Customized install_scripts distutils action.
18
class my_build_scripts(build_scripts):
19
"""Customized build_scripts distutils action.
99
21
Create bzr.bat for win32.
102
install_scripts.run(self) # standard action
104
25
if sys.platform == "win32":
106
scripts_dir = self.install_dir
107
script_path = self._quoted_path(os.path.join(scripts_dir,
109
python_exe = self._quoted_path(sys.executable)
110
args = self._win_batch_args()
111
batch_str = "@%s %s %s" % (python_exe, script_path, args)
112
batch_path = script_path + ".bat"
113
f = file(batch_path, "w")
116
print "Created:", batch_path
118
print "ERROR: Unable to create %s: %s" % (batch_path, e)
120
def _quoted_path(self, path):
122
return '"' + path + '"'
126
def _win_batch_args(self):
127
from bzrlib.win32utils import winver
128
if winver == 'Windows NT':
131
return '%1 %2 %3 %4 %5 %6 %7 %8 %9'
132
#/class my_install_scripts
135
class bzr_build(build):
136
"""Customized build distutils action.
143
generate_docs.main(argv=["bzr", "man"])
26
bat_path = os.path.join(self.build_dir, "bzr.bat")
27
self.scripts.append(bat_path)
28
self.mkpath(self.build_dir)
29
scripts_dir = self.distribution.get_command_obj("install").\
31
self.execute(func=self._create_bat,
32
args=[bat_path, scripts_dir],
33
msg="Create %s" % bat_path)
34
build_scripts.run(self) # invoke "standard" action
36
def _create_bat(self, bat_path, scripts_dir):
37
""" Creates the batch file for bzr on win32.
40
script_path = os.path.join(scripts_dir, "bzr")
41
bat_str = "@%s %s %%*\n" % (sys.executable, script_path)
42
file(bat_path, "w").write(bat_str)
45
print "ERROR: Unable to create %s: %s" % (bat_path, e)
146
49
########################
148
51
########################
150
command_classes = {'install_scripts': my_install_scripts,
152
from distutils.extension import Extension
155
from Pyrex.Distutils import build_ext
158
# try to build the extension from the prior generated source.
160
print ("The python package 'Pyrex' is not available."
161
" If the .c files are available,")
162
print ("they will be built,"
163
" but modifying the .pyx files will not rebuild them.")
165
from distutils.command.build_ext import build_ext
168
# Override the build_ext if we have Pyrex available
169
command_classes['build_ext'] = build_ext
170
unavailable_files = []
173
def add_pyrex_extension(module_name, **kwargs):
174
"""Add a pyrex module to build.
176
This will use Pyrex to auto-generate the .c file if it is available.
177
Otherwise it will fall back on the .c file. If the .c file is not
178
available, it will warn, and not add anything.
180
You can pass any extra options to Extension through kwargs. One example is
183
:param module_name: The python path to the module. This will be used to
184
determine the .pyx and .c files to use.
186
path = module_name.replace('.', '/')
187
pyrex_name = path + '.pyx'
190
ext_modules.append(Extension(module_name, [pyrex_name]))
192
if not os.path.isfile(c_name):
193
unavailable_files.append(c_name)
195
ext_modules.append(Extension(module_name, [c_name]))
198
add_pyrex_extension('bzrlib._dirstate_helpers_c')
199
add_pyrex_extension('bzrlib._knit_load_data_c')
202
if unavailable_files:
203
print 'C extension(s) not found:'
204
print ' %s' % ('\n '.join(unavailable_files),)
205
print 'The python versions will be used instead.'
209
if 'bdist_wininst' in sys.argv:
212
docs = glob.glob('doc/*.htm') + ['doc/default.css']
213
dev_docs = glob.glob('doc/developers/*.htm')
214
# python's distutils-based win32 installer
215
ARGS = {'scripts': ['bzr', 'tools/win32/bzr-win32-bdist-postinstall.py'],
216
'ext_modules': ext_modules,
218
'data_files': [('Doc/Bazaar', docs),
219
('Doc/Bazaar/developers', dev_docs),
221
# for building pyrex extensions
222
'cmdclass': {'build_ext': build_ext},
225
ARGS.update(META_INFO)
227
ARGS.update(PKG_DATA)
231
elif 'py2exe' in sys.argv:
235
# pick real bzr version
239
for i in bzrlib.version_info[:4]:
244
version_number.append(str(i))
245
version_str = '.'.join(version_number)
247
target = py2exe.build_exe.Target(script = "bzr",
249
icon_resources = [(0,'bzr.ico')],
250
name = META_INFO['name'],
251
version = version_str,
252
description = META_INFO['description'],
253
author = META_INFO['author'],
254
copyright = "(c) Canonical Ltd, 2005-2007",
255
company_name = "Canonical Ltd.",
256
comments = META_INFO['description'],
259
additional_packages = []
260
if sys.version.startswith('2.4'):
261
# adding elementtree package
262
additional_packages.append('elementtree')
263
elif sys.version.startswith('2.5'):
264
additional_packages.append('xml.etree')
267
warnings.warn('Unknown Python version.\n'
268
'Please check setup.py script for compatibility.')
269
# email package from std python library use lazy import,
270
# so we need to explicitly add all package
271
additional_packages.append('email')
273
options_list = {"py2exe": {"packages": BZRLIB['packages'] +
275
"excludes": ["Tkinter", "medusa", "tools"],
276
"dist_dir": "win32_bzr.exe",
279
setup(options=options_list,
281
'tools/win32/bzr_postinstall.py',
283
zipfile='lib/library.zip')
287
ARGS = {'scripts': ['bzr'],
288
'data_files': [('man/man1', ['bzr.1'])],
289
'cmdclass': command_classes,
290
'ext_modules': ext_modules,
293
ARGS.update(META_INFO)
295
ARGS.update(PKG_DATA)
56
author_email='mbp@sourcefrog.net',
57
url='http://www.bazaar-ng.org/',
58
description='Friendly distributed version control system',
66
'bzrlib.util.elementtree',
67
'bzrlib.util.effbot.org',