~ubuntu-branches/ubuntu/maverick/pyrex/maverick

« back to all changes in this revision

Viewing changes to Pyrex/DistutilsOld/build_ext.py

  • Committer: Bazaar Package Importer
  • Author(s): Paul Brossier
  • Date: 2008-01-11 11:50:29 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080111115029-kzpl5gi44c9jozi7
Tags: 0.9.6.4-1
* New upstream release (closes:#406025)
* Move python-all-dev to Build-Depends since python gets called in
  debian/rules:clean
* Delete empty usr/lib from python-pyrex
* Delete blank lines from debian/python-pyrex.doc-base
* Remove empty binary-arch target
* Bump Standards-Version to 3.7.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Subclasses disutils.command.build_ext,
 
2
# replacing it with a Pyrex version that compiles pyx->c
 
3
# before calling the original build_ext command.
 
4
# July 2002, Graham Fawcett
 
5
# Modified by Darrell Gallion <dgallion1@yahoo.com>
 
6
# to allow inclusion of .c files along with .pyx files.
 
7
# Pyrex is (c) Greg Ewing.
 
8
 
 
9
import distutils.command.build_ext
 
10
#import Pyrex.Compiler.Main
 
11
from Pyrex.Compiler.Main import CompilationOptions, default_options, compile
 
12
from Pyrex.Compiler.Errors import PyrexError
 
13
from distutils.dep_util import newer
 
14
import os
 
15
import sys
 
16
 
 
17
def replace_suffix(path, new_suffix):
 
18
    return os.path.splitext(path)[0] + new_suffix
 
19
 
 
20
class build_ext (distutils.command.build_ext.build_ext):
 
21
 
 
22
    description = "compile Pyrex scripts, then build C/C++ extensions (compile/link to build directory)"
 
23
 
 
24
    def finalize_options (self):
 
25
        distutils.command.build_ext.build_ext.finalize_options(self)
 
26
 
 
27
        # The following hack should no longer be needed.
 
28
        if 0:
 
29
            # compiling with mingw32 gets an "initializer not a constant" error
 
30
            # doesn't appear to happen with MSVC!
 
31
            # so if we are compiling with mingw32,
 
32
            # switch to C++ mode, to avoid the problem
 
33
            if self.compiler == 'mingw32':
 
34
                self.swig_cpp = 1
 
35
 
 
36
    def swig_sources (self, sources, extension = None):
 
37
        if not self.extensions:
 
38
            return
 
39
 
 
40
        # collect the names of the source (.pyx) files
 
41
        pyx_sources = []
 
42
        pyx_sources = [source for source in sources if source.endswith('.pyx')]
 
43
        other_sources = [source for source in sources if not source.endswith('.pyx')]
 
44
 
 
45
        #suffix = self.swig_cpp and '.cpp' or '.c'
 
46
        suffix = '.c'
 
47
        for pyx in pyx_sources:
 
48
            # should I raise an exception if it doesn't exist?
 
49
            if os.path.exists(pyx):
 
50
                source = pyx
 
51
                target = replace_suffix(source, suffix)
 
52
                if newer(source, target) or self.force:
 
53
                    self.pyrex_compile(source)
 
54
 
 
55
        return [replace_suffix(src, suffix) for src in pyx_sources] + other_sources
 
56
 
 
57
    def pyrex_compile(self, source):
 
58
        options = CompilationOptions(default_options,
 
59
            include_path = self.include_dirs)
 
60
        result = compile(source, options)
 
61
        if result.num_errors <> 0:
 
62
            sys.exit(1)
 
63