29
29
class build_ext_if_possible(build_ext):
31
user_options = build_ext.user_options + [
32
('allow-python-fallback', None,
33
"When an extension cannot be built, allow falling"
34
" back to the pure-python implementation.")
37
def initialize_options(self):
38
build_ext.initialize_options(self)
39
self.allow_python_fallback = False
33
43
build_ext.run(self)
34
44
except DistutilsPlatformError, e:
45
if not self.allow_python_fallback:
46
log.warn('\n Cannot build extensions.\n'
47
' Use "build_ext --allow-python-fallback" to use'
48
' slower python implementations instead.\n')
36
log.warn('Extensions cannot be built, '
37
'will use the Python versions instead')
51
log.warn('\n Extensions cannot be built.\n'
52
' Using the slower Python implementations instead.\n')
39
54
def build_extension(self, ext):
41
56
build_ext.build_extension(self, ext)
42
57
except CCompilerError:
43
log.warn('Building of "%s" extension failed, '
44
'will use the Python version instead' % (ext.name,))
58
if not self.allow_python_fallback:
59
log.warn('\n Cannot build extension (%s).\n'
60
' Use "build_ext --allow-python-fallback" to use'
61
' slower python implementations instead.\n'
64
log.warn('\n Building of "%s" extension failed.\n'
65
' Using the slower Python implementation instead.'
47
69
# Override the build_ext if we have Pyrex available
48
70
unavailable_files = []
51
def add_pyrex_extension(module_name, **kwargs):
73
def add_pyrex_extension(module_name, extra_source=[]):
52
74
"""Add a pyrex module to build.
54
76
This will use Pyrex to auto-generate the .c file if it is available.
67
89
# Manually honour package_dir :(
68
90
module_name = 'bzrlib.plugins.groupcompress.' + module_name
70
ext_modules.append(Extension(module_name, [pyrex_name]))
93
elif not os.path.isfile(c_name):
94
unavailable_files.append(c_name)
72
if not os.path.isfile(c_name):
73
unavailable_files.append(c_name)
75
ext_modules.append(Extension(module_name, [c_name]))
98
source.extend(extra_source)
99
ext_modules.append(Extension(module_name, source,
100
extra_compile_args = ['-O3']))
77
add_pyrex_extension('_groupcompress_c')
102
add_pyrex_extension('_groupcompress_pyx',
103
extra_source=['diff-delta.c'])
80
106
if __name__ == '__main__':