148
150
########################
150
152
command_classes = {'install_scripts': my_install_scripts,
154
from distutils import log
155
from distutils.errors import CCompilerError, DistutilsPlatformError
156
from distutils.extension import Extension
154
159
from Pyrex.Distutils import build_ext
155
160
except ImportError:
156
162
# try to build the extension from the prior generated source.
157
print ("Pyrex not available, while bzr will build, "
158
"you cannot modify the C extensions.")
164
print ("The python package 'Pyrex' is not available."
165
" If the .c files are available,")
166
print ("they will be built,"
167
" but modifying the .pyx files will not rebuild them.")
159
169
from distutils.command.build_ext import build_ext
160
from distutils.extension import Extension
162
# Extension("bzrlib.modulename", ["bzrlib/foo.c"], libraries = []))
164
from distutils.extension import Extension
166
# Extension("bzrlib.modulename", ["bzrlib/foo.pyx"], libraries = []))
167
command_classes['build_ext'] = build_ext
174
class build_ext_if_possible(build_ext):
179
except DistutilsPlatformError, e:
181
log.warn('Extensions cannot be built, '
182
'will use the Python versions instead')
184
def build_extension(self, ext):
186
build_ext.build_extension(self, ext)
187
except CCompilerError:
188
log.warn('Building of "%s" extension failed, '
189
'will use the Python version instead' % (ext.name,))
192
# Override the build_ext if we have Pyrex available
193
command_classes['build_ext'] = build_ext_if_possible
194
unavailable_files = []
197
def add_pyrex_extension(module_name, **kwargs):
198
"""Add a pyrex module to build.
200
This will use Pyrex to auto-generate the .c file if it is available.
201
Otherwise it will fall back on the .c file. If the .c file is not
202
available, it will warn, and not add anything.
204
You can pass any extra options to Extension through kwargs. One example is
207
:param module_name: The python path to the module. This will be used to
208
determine the .pyx and .c files to use.
210
path = module_name.replace('.', '/')
211
pyrex_name = path + '.pyx'
214
ext_modules.append(Extension(module_name, [pyrex_name]))
216
if not os.path.isfile(c_name):
217
unavailable_files.append(c_name)
219
ext_modules.append(Extension(module_name, [c_name]))
222
add_pyrex_extension('bzrlib._dirstate_helpers_c')
223
add_pyrex_extension('bzrlib._knit_load_data_c')
224
ext_modules.append(Extension('bzrlib._patiencediff_c', ['bzrlib/_patiencediff_c.c']))
227
if unavailable_files:
228
print 'C extension(s) not found:'
229
print ' %s' % ('\n '.join(unavailable_files),)
230
print 'The python versions will be used instead.'
169
234
if 'bdist_wininst' in sys.argv:
172
docs = glob.glob('doc/*.htm') + ['doc/default.css']
173
dev_docs = glob.glob('doc/developers/*.htm')
237
for root, dirs, files in os.walk('doc'):
240
if os.path.splitext(f)[1] in ('.html','.css','.png','.pdf'):
241
r.append(os.path.join(root, f))
245
target = os.path.join('Doc\\Bazaar', relative)
247
target = 'Doc\\Bazaar'
248
docs.append((target, r))
174
251
# python's distutils-based win32 installer
175
252
ARGS = {'scripts': ['bzr', 'tools/win32/bzr-win32-bdist-postinstall.py'],
253
'ext_modules': ext_modules,
177
'data_files': [('Doc/Bazaar', docs),
178
('Doc/Bazaar/developers', dev_docs),
255
'data_files': find_docs(),
256
# for building pyrex extensions
257
'cmdclass': {'build_ext': build_ext_if_possible},
182
260
ARGS.update(META_INFO)
235
320
'tools/win32/bzr_postinstall.py',
237
zipfile='lib/library.zip')
322
zipfile='lib/library.zip',
323
data_files=[('lib/help_topics/en', text_topics)],
327
# ad-hoc for easy_install
329
if not 'bdist_egg' in sys.argv:
330
# generate and install bzr.1 only with plain install, not easy_install one
331
DATA_FILES = [('man/man1', ['bzr.1'])]
241
334
ARGS = {'scripts': ['bzr'],
242
'data_files': [('man/man1', ['bzr.1'])],
335
'data_files': DATA_FILES,
243
336
'cmdclass': command_classes,
244
337
'ext_modules': ext_modules,
247
340
ARGS.update(META_INFO)
248
341
ARGS.update(BZRLIB)
249
342
ARGS.update(PKG_DATA)