~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-08-17 22:43:26 UTC
  • mfrom: (4617.1.2 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090817224326-uhljmr5me5x3xyda
(robertc) Multiple 2a-as-default fixes. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
import os
3
 
from distutils.core import setup
4
 
 
5
 
bzr_plugin_name = 'groupcompress'
6
 
 
7
 
bzr_plugin_version = (1, 6, 0, 'dev', 0)
8
 
 
9
 
from distutils import log
10
 
from distutils.errors import CCompilerError, DistutilsPlatformError
11
 
from distutils.extension import Extension
12
 
ext_modules = []
13
 
try:
14
 
    from Pyrex.Distutils import build_ext
15
 
except ImportError:
16
 
    have_pyrex = False
17
 
    # try to build the extension from the prior generated source.
18
 
    print
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.")
23
 
    print
24
 
    from distutils.command.build_ext import build_ext
25
 
else:
26
 
    have_pyrex = True
27
 
 
28
 
 
29
 
class build_ext_if_possible(build_ext):
30
 
 
31
 
    def run(self):
32
 
        try:
33
 
            build_ext.run(self)
34
 
        except DistutilsPlatformError, e:
35
 
            log.warn(str(e))
36
 
            log.warn('Extensions cannot be built, '
37
 
                     'will use the Python versions instead')
38
 
 
39
 
    def build_extension(self, ext):
40
 
        try:
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,))
45
 
 
46
 
 
47
 
# Override the build_ext if we have Pyrex available
48
 
unavailable_files = []
49
 
 
50
 
 
51
 
def add_pyrex_extension(module_name, **kwargs):
52
 
    """Add a pyrex module to build.
53
 
 
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.
57
 
 
58
 
    You can pass any extra options to Extension through kwargs. One example is
59
 
    'libraries = []'.
60
 
 
61
 
    :param module_name: The python path to the module. This will be used to
62
 
        determine the .pyx and .c files to use.
63
 
    """
64
 
    path = module_name.replace('.', '/')
65
 
    pyrex_name = path + '.pyx'
66
 
    c_name = path + '.c'
67
 
    # Manually honour package_dir :(
68
 
    module_name = 'bzrlib.plugins.groupcompress.' + module_name
69
 
    if have_pyrex:
70
 
        ext_modules.append(Extension(module_name, [pyrex_name]))
71
 
    else:
72
 
        if not os.path.isfile(c_name):
73
 
            unavailable_files.append(c_name)
74
 
        else:
75
 
            ext_modules.append(Extension(module_name, [c_name]))
76
 
 
77
 
add_pyrex_extension('_groupcompress_c')
78
 
 
79
 
 
80
 
if __name__ == '__main__':
81
 
    setup(name="bzr groupcompress",
82
 
          version="1.6.0dev0",
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',
90
 
                    ],
91
 
          package_dir={'bzrlib.plugins.groupcompress': '.'},
92
 
          cmdclass={'build_ext': build_ext_if_possible},
93
 
          ext_modules=ext_modules,
94
 
          )