3
from distutils.core import setup
5
bzr_plugin_name = 'groupcompress'
7
bzr_plugin_version = (1, 6, 0, 'dev', 0)
9
from distutils import log
10
from distutils.errors import CCompilerError, DistutilsPlatformError
11
from distutils.extension import Extension
14
from Pyrex.Distutils import build_ext
17
# try to build the extension from the prior generated source.
19
print ("The python package 'Pyrex' is not available."
20
" If the .c files are available,")
21
print ("they will be built,"
22
" but modifying the .pyx files will not rebuild them.")
24
from distutils.command.build_ext import build_ext
29
class build_ext_if_possible(build_ext):
34
except DistutilsPlatformError, e:
36
log.warn('Extensions cannot be built, '
37
'will use the Python versions instead')
39
def build_extension(self, ext):
41
build_ext.build_extension(self, ext)
42
except CCompilerError:
43
log.warn('Building of "%s" extension failed, '
44
'will use the Python version instead' % (ext.name,))
47
# Override the build_ext if we have Pyrex available
48
unavailable_files = []
51
def add_pyrex_extension(module_name, **kwargs):
52
"""Add a pyrex module to build.
54
This will use Pyrex to auto-generate the .c file if it is available.
55
Otherwise it will fall back on the .c file. If the .c file is not
56
available, it will warn, and not add anything.
58
You can pass any extra options to Extension through kwargs. One example is
61
:param module_name: The python path to the module. This will be used to
62
determine the .pyx and .c files to use.
64
path = module_name.replace('.', '/')
65
pyrex_name = path + '.pyx'
67
# Manually honour package_dir :(
68
module_name = 'bzrlib.plugins.groupcompress.' + module_name
70
ext_modules.append(Extension(module_name, [pyrex_name]))
72
if not os.path.isfile(c_name):
73
unavailable_files.append(c_name)
75
ext_modules.append(Extension(module_name, [c_name]))
77
add_pyrex_extension('_groupcompress_c')
80
if __name__ == '__main__':
81
setup(name="bzr groupcompress",
83
description="bzr group compression.",
84
author="Robert Collins",
85
author_email="bazaar@lists.canonical.com",
86
license = "GNU GPL v2",
87
url="https://launchpad.net/bzr-groupcompress",
88
packages=['bzrlib.plugins.groupcompress',
89
'bzrlib.plugins.groupcompress.tests',
91
package_dir={'bzrlib.plugins.groupcompress': '.'},
92
cmdclass={'build_ext': build_ext_if_possible},
93
ext_modules=ext_modules,