1
1
#! /usr/bin/env python
3
# This is an installation script for bzr. Run it with
4
# './setup.py install', or
5
# './setup.py --help' for more options
3
"""Installation script for bzr.
5
'./setup.py install', or
6
'./setup.py --help' for more options
12
if sys.version_info < (2, 4):
13
sys.stderr.write("[ERROR] Not a supported Python version. Need 2.4+\n")
19
# META INFORMATION FOR SETUP
21
META_INFO = {'name': 'bzr',
22
'version': bzrlib.__version__,
23
'author': 'Canonical Ltd',
24
'author_email': 'bazaar@lists.canonical.com',
25
'url': 'http://www.bazaar-vcs.org/',
26
'description': 'Friendly distributed version control system',
27
'license': 'GNU GPL v2',
30
# The list of packages is automatically generated later. Add other things
31
# that are part of BZRLIB here.
34
PKG_DATA = {# install files from selftest suite
35
'package_data': {'bzrlib': ['doc/api/*.txt',
36
'tests/test_patches_data/*',
37
'help_topics/en/*.txt',
42
def get_bzrlib_packages():
43
"""Recurse through the bzrlib directory, and extract the package names"""
46
base_path = os.path.dirname(os.path.abspath(bzrlib.__file__))
47
for root, dirs, files in os.walk(base_path):
48
if '__init__.py' in files:
49
assert root.startswith(base_path)
50
# Get just the path below bzrlib
51
package_path = root[len(base_path):]
52
# Remove leading and trailing slashes
53
package_path = package_path.strip('\\/')
55
package_name = 'bzrlib'
57
package_name = ('bzrlib.' +
58
package_path.replace('/', '.').replace('\\', '.'))
59
packages.append(package_name)
60
return sorted(packages)
63
BZRLIB['packages'] = get_bzrlib_packages()
7
66
from distutils.core import setup
12
author_email='mbp@sourcefrog.net',
13
url='http://www.bazaar-ng.org/',
14
description='Friendly distributed version control system',
67
from distutils.command.install_scripts import install_scripts
68
from distutils.command.build import build
70
###############################
71
# Overridden distutils actions
72
###############################
74
class my_install_scripts(install_scripts):
75
""" Customized install_scripts distutils action.
76
Create bzr.bat for win32.
79
install_scripts.run(self) # standard action
81
if sys.platform == "win32":
83
scripts_dir = os.path.join(sys.prefix, 'Scripts')
84
script_path = self._quoted_path(os.path.join(scripts_dir,
86
python_exe = self._quoted_path(sys.executable)
87
args = self._win_batch_args()
88
batch_str = "@%s %s %s" % (python_exe, script_path, args)
89
batch_path = os.path.join(self.install_dir, "bzr.bat")
90
f = file(batch_path, "w")
93
print "Created:", batch_path
95
print "ERROR: Unable to create %s: %s" % (batch_path, e)
97
def _quoted_path(self, path):
99
return '"' + path + '"'
103
def _win_batch_args(self):
104
from bzrlib.win32utils import winver
105
if winver == 'Windows NT':
108
return '%1 %2 %3 %4 %5 %6 %7 %8 %9'
109
#/class my_install_scripts
112
class bzr_build(build):
113
"""Customized build distutils action.
120
generate_docs.main(argv=["bzr", "man"])
123
########################
125
########################
127
command_classes = {'install_scripts': my_install_scripts,
129
from distutils import log
130
from distutils.errors import CCompilerError, DistutilsPlatformError
131
from distutils.extension import Extension
134
from Pyrex.Distutils import build_ext
137
# try to build the extension from the prior generated source.
139
print ("The python package 'Pyrex' is not available."
140
" If the .c files are available,")
141
print ("they will be built,"
142
" but modifying the .pyx files will not rebuild them.")
144
from distutils.command.build_ext import build_ext
149
class build_ext_if_possible(build_ext):
154
except DistutilsPlatformError, e:
156
log.warn('Extensions cannot be built, '
157
'will use the Python versions instead')
159
def build_extension(self, ext):
161
build_ext.build_extension(self, ext)
162
except CCompilerError:
163
log.warn('Building of "%s" extension failed, '
164
'will use the Python version instead' % (ext.name,))
167
# Override the build_ext if we have Pyrex available
168
command_classes['build_ext'] = build_ext_if_possible
169
unavailable_files = []
172
def add_pyrex_extension(module_name, **kwargs):
173
"""Add a pyrex module to build.
175
This will use Pyrex to auto-generate the .c file if it is available.
176
Otherwise it will fall back on the .c file. If the .c file is not
177
available, it will warn, and not add anything.
179
You can pass any extra options to Extension through kwargs. One example is
182
:param module_name: The python path to the module. This will be used to
183
determine the .pyx and .c files to use.
185
path = module_name.replace('.', '/')
186
pyrex_name = path + '.pyx'
189
ext_modules.append(Extension(module_name, [pyrex_name]))
191
if not os.path.isfile(c_name):
192
unavailable_files.append(c_name)
194
ext_modules.append(Extension(module_name, [c_name]))
197
add_pyrex_extension('bzrlib._dirstate_helpers_c')
198
add_pyrex_extension('bzrlib._knit_load_data_c')
199
ext_modules.append(Extension('bzrlib._patiencediff_c', ['bzrlib/_patiencediff_c.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
for root, dirs, files in os.walk('doc'):
215
if (os.path.splitext(f)[1] in ('.html','.css','.png','.pdf')
216
or f == 'quick-start-summary.svg'):
217
r.append(os.path.join(root, f))
221
target = os.path.join('Doc\\Bazaar', relative)
223
target = 'Doc\\Bazaar'
224
docs.append((target, r))
227
# python's distutils-based win32 installer
228
ARGS = {'scripts': ['bzr', 'tools/win32/bzr-win32-bdist-postinstall.py'],
229
'ext_modules': ext_modules,
231
'data_files': find_docs(),
232
# for building pyrex extensions
233
'cmdclass': {'build_ext': build_ext_if_possible},
236
ARGS.update(META_INFO)
238
ARGS.update(PKG_DATA)
242
elif 'py2exe' in sys.argv:
247
# pick real bzr version
251
for i in bzrlib.version_info[:4]:
256
version_number.append(str(i))
257
version_str = '.'.join(version_number)
259
target = py2exe.build_exe.Target(script = "bzr",
261
icon_resources = [(0,'bzr.ico')],
262
name = META_INFO['name'],
263
version = version_str,
264
description = META_INFO['description'],
265
author = META_INFO['author'],
266
copyright = "(c) Canonical Ltd, 2005-2007",
267
company_name = "Canonical Ltd.",
268
comments = META_INFO['description'],
271
packages = BZRLIB['packages']
272
packages.remove('bzrlib')
273
packages = [i for i in packages if not i.startswith('bzrlib.plugins')]
275
for i in glob.glob('bzrlib\\*.py'):
276
module = i[:-3].replace('\\', '.')
277
if module.endswith('__init__'):
278
module = module[:-len('__init__')]
279
includes.append(module)
281
additional_packages = set()
282
if sys.version.startswith('2.4'):
283
# adding elementtree package
284
additional_packages.add('elementtree')
285
elif sys.version.startswith('2.5'):
286
additional_packages.add('xml.etree')
289
warnings.warn('Unknown Python version.\n'
290
'Please check setup.py script for compatibility.')
291
# email package from std python library use lazy import,
292
# so we need to explicitly add all package
293
additional_packages.add('email')
295
# text files for help topis
296
text_topics = glob.glob('bzrlib/help_topics/en/*.txt')
297
topics_files = [('lib/help_topics/en', text_topics)]
301
for root, dirs, files in os.walk('bzrlib/plugins'):
304
if not i.endswith('.py'):
306
if i == '__init__.py' and root == 'bzrlib/plugins':
308
x.append(os.path.join(root, i))
310
target_dir = root[len('bzrlib/'):] # install to 'plugins/...'
311
plugins_files.append((target_dir, x))
312
# find modules for built-in plugins
313
import tools.package_mf
314
mf = tools.package_mf.CustomModuleFinder()
315
mf.run_package('bzrlib/plugins')
316
packs, mods = mf.get_result()
317
additional_packages.update(packs)
319
options_list = {"py2exe": {"packages": packages + list(additional_packages),
320
"includes": includes + mods,
321
"excludes": ["Tkinter", "medusa", "tools"],
322
"dist_dir": "win32_bzr.exe",
325
setup(options=options_list,
327
'tools/win32/bzr_postinstall.py',
329
zipfile='lib/library.zip',
330
data_files=topics_files + plugins_files,
334
# ad-hoc for easy_install
336
if not 'bdist_egg' in sys.argv:
337
# generate and install bzr.1 only with plain install, not easy_install one
338
DATA_FILES = [('man/man1', ['bzr.1'])]
341
ARGS = {'scripts': ['bzr'],
342
'data_files': DATA_FILES,
343
'cmdclass': command_classes,
344
'ext_modules': ext_modules,
347
ARGS.update(META_INFO)
349
ARGS.update(PKG_DATA)