1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
#! /usr/bin/env python
"""Installation script for bzr.
Run it with
'./setup.py install', or
'./setup.py --help' for more options
"""
import os
import sys
import bzrlib
##
# META INFORMATION FOR SETUP
META_INFO = {'name': 'bzr',
'version': bzrlib.__version__,
'author': 'Canonical Ltd',
'author_email': 'bazaar@lists.canonical.com',
'url': 'http://www.bazaar-vcs.org/',
'description': 'Friendly distributed version control system',
'license': 'GNU GPL v2',
}
# The list of packages is automatically generated later. Add other things
# that are part of BZRLIB here.
BZRLIB = {}
PKG_DATA = {# install files from selftest suite
'package_data': {'bzrlib': ['doc/api/*.txt',
'tests/test_patches_data/*',
]},
}
######################################################################
# Reinvocation stolen from bzr, we need python2.4 by virtue of bzr_man
# including bzrlib.help
try:
version_info = sys.version_info
except AttributeError:
version_info = 1, 5 # 1.5 or older
REINVOKE = "__BZR_REINVOKE"
NEED_VERS = (2, 4)
KNOWN_PYTHONS = ('python2.4',)
if version_info < NEED_VERS:
if not os.environ.has_key(REINVOKE):
# mutating os.environ doesn't work in old Pythons
os.putenv(REINVOKE, "1")
for python in KNOWN_PYTHONS:
try:
os.execvp(python, [python] + sys.argv)
except OSError:
pass
print >>sys.stderr, "bzr: error: cannot find a suitable python interpreter"
print >>sys.stderr, " (need %d.%d or later)" % NEED_VERS
sys.exit(1)
if getattr(os, "unsetenv", None) is not None:
os.unsetenv(REINVOKE)
def get_bzrlib_packages():
"""Recurse through the bzrlib directory, and extract the package names"""
packages = []
base_path = os.path.dirname(os.path.abspath(bzrlib.__file__))
for root, dirs, files in os.walk(base_path):
if '__init__.py' in files:
assert root.startswith(base_path)
# Get just the path below bzrlib
package_path = root[len(base_path):]
# Remove leading and trailing slashes
package_path = package_path.strip('\\/')
if not package_path:
package_name = 'bzrlib'
else:
package_name = ('bzrlib.' +
package_path.replace('/', '.').replace('\\', '.'))
packages.append(package_name)
return sorted(packages)
BZRLIB['packages'] = get_bzrlib_packages()
from distutils.core import setup
from distutils.command.install_scripts import install_scripts
from distutils.command.build import build
###############################
# Overridden distutils actions
###############################
class my_install_scripts(install_scripts):
""" Customized install_scripts distutils action.
Create bzr.bat for win32.
"""
def run(self):
install_scripts.run(self) # standard action
if sys.platform == "win32":
try:
scripts_dir = os.path.join(sys.prefix, 'Scripts')
script_path = self._quoted_path(os.path.join(scripts_dir,
"bzr"))
python_exe = self._quoted_path(sys.executable)
args = self._win_batch_args()
batch_str = "@%s %s %s" % (python_exe, script_path, args)
batch_path = os.path.join(self.install_dir, "bzr.bat")
f = file(batch_path, "w")
f.write(batch_str)
f.close()
print "Created:", batch_path
except Exception, e:
print "ERROR: Unable to create %s: %s" % (batch_path, e)
def _quoted_path(self, path):
if ' ' in path:
return '"' + path + '"'
else:
return path
def _win_batch_args(self):
from bzrlib.win32utils import winver
if winver == 'Windows NT':
return '%*'
else:
return '%1 %2 %3 %4 %5 %6 %7 %8 %9'
#/class my_install_scripts
class bzr_build(build):
"""Customized build distutils action.
Generate bzr.1.
"""
def run(self):
build.run(self)
import generate_docs
generate_docs.main(argv=["bzr", "man"])
########################
## Setup
########################
command_classes = {'install_scripts': my_install_scripts,
'build': bzr_build}
from distutils import log
from distutils.errors import CCompilerError, DistutilsPlatformError
from distutils.extension import Extension
ext_modules = []
try:
from Pyrex.Distutils import build_ext
except ImportError:
have_pyrex = False
# try to build the extension from the prior generated source.
print
print ("The python package 'Pyrex' is not available."
" If the .c files are available,")
print ("they will be built,"
" but modifying the .pyx files will not rebuild them.")
print
from distutils.command.build_ext import build_ext
else:
have_pyrex = True
class build_ext_if_possible(build_ext):
def run(self):
try:
build_ext.run(self)
except DistutilsPlatformError, e:
if sys.platform == 'win32':
log.warn(str(e))
log.warn("Extensions cannot be compiled, "
"will use pure Python modules instead")
def build_extension(self, ext):
try:
build_ext.build_extension(self, ext)
except CCompilerError:
log.warn("building of '%s' extension failed, will "
"use the Python version instead" % (ext.name,))
# Override the build_ext if we have Pyrex available
command_classes['build_ext'] = build_ext_if_possible
unavailable_files = []
def add_pyrex_extension(module_name, **kwargs):
"""Add a pyrex module to build.
This will use Pyrex to auto-generate the .c file if it is available.
Otherwise it will fall back on the .c file. If the .c file is not
available, it will warn, and not add anything.
You can pass any extra options to Extension through kwargs. One example is
'libraries = []'.
:param module_name: The python path to the module. This will be used to
determine the .pyx and .c files to use.
"""
path = module_name.replace('.', '/')
pyrex_name = path + '.pyx'
c_name = path + '.c'
if have_pyrex:
ext_modules.append(Extension(module_name, [pyrex_name]))
else:
if not os.path.isfile(c_name):
unavailable_files.append(c_name)
else:
ext_modules.append(Extension(module_name, [c_name]))
add_pyrex_extension('bzrlib._dirstate_helpers_c')
add_pyrex_extension('bzrlib._knit_load_data_c')
ext_modules.append(Extension('bzrlib._patiencediff_c', ['bzrlib/_patiencediff_c.c']))
if unavailable_files:
print 'C extension(s) not found:'
print ' %s' % ('\n '.join(unavailable_files),)
print 'The python versions will be used instead.'
print
if 'bdist_wininst' in sys.argv:
def find_docs():
docs = []
for root, dirs, files in os.walk('doc'):
r = []
for f in files:
if os.path.splitext(f)[1] in ('.html', '.css'):
r.append(os.path.join(root, f))
if r:
relative = root[4:]
if relative:
target = os.path.join('Doc\\Bazaar', relative)
else:
target = 'Doc\\Bazaar'
docs.append((target, r))
return docs
# python's distutils-based win32 installer
ARGS = {'scripts': ['bzr', 'tools/win32/bzr-win32-bdist-postinstall.py'],
'ext_modules': ext_modules,
# help pages
'data_files': find_docs(),
# for building pyrex extensions
'cmdclass': {'build_ext': build_ext_if_possible},
}
ARGS.update(META_INFO)
ARGS.update(BZRLIB)
ARGS.update(PKG_DATA)
setup(**ARGS)
elif 'py2exe' in sys.argv:
# py2exe setup
import py2exe
# pick real bzr version
import bzrlib
version_number = []
for i in bzrlib.version_info[:4]:
try:
i = int(i)
except ValueError:
i = 0
version_number.append(str(i))
version_str = '.'.join(version_number)
target = py2exe.build_exe.Target(script = "bzr",
dest_base = "bzr",
icon_resources = [(0,'bzr.ico')],
name = META_INFO['name'],
version = version_str,
description = META_INFO['description'],
author = META_INFO['author'],
copyright = "(c) Canonical Ltd, 2005-2007",
company_name = "Canonical Ltd.",
comments = META_INFO['description'],
)
additional_packages = []
if sys.version.startswith('2.4'):
# adding elementtree package
additional_packages.append('elementtree')
elif sys.version.startswith('2.5'):
additional_packages.append('xml.etree')
else:
import warnings
warnings.warn('Unknown Python version.\n'
'Please check setup.py script for compatibility.')
# email package from std python library use lazy import,
# so we need to explicitly add all package
additional_packages.append('email')
options_list = {"py2exe": {"packages": BZRLIB['packages'] +
additional_packages,
"excludes": ["Tkinter", "medusa", "tools"],
"dist_dir": "win32_bzr.exe",
},
}
setup(options=options_list,
console=[target,
'tools/win32/bzr_postinstall.py',
],
zipfile='lib/library.zip')
else:
# ad-hoc for easy_install
DATA_FILES = []
if not 'bdist_egg' in sys.argv:
# generate and install bzr.1 only with plain install, not easy_install one
DATA_FILES = [('man/man1', ['bzr.1'])]
# std setup
ARGS = {'scripts': ['bzr'],
'data_files': DATA_FILES,
'cmdclass': command_classes,
'ext_modules': ext_modules,
}
ARGS.update(META_INFO)
ARGS.update(BZRLIB)
ARGS.update(PKG_DATA)
setup(**ARGS)
|