Пример #1
0
    def OnCompile(self, event):
        from Pyrex.Compiler import Main, Errors

        model = self.getModel()
        try:
            result = Main.compile(model.localFilename(), c_only=1)
        except Errors.PyrexError, err:
            wx.LogError(str(err))
            msg = 'Error'
Пример #2
0
    def OnCompile(self, event):
        from Pyrex.Compiler import Main, Errors

        model = self.getModel()
        try:
            result = Main.compile(model.localFilename(), c_only=1)
        except Errors.PyrexError, err:
            wx.LogError(str(err))
            msg = 'Error'
Пример #3
0
def compile_and_link(pyx_file):
    try:
        result = Main.compile(pyx_file, c_compile=1, c_link=1)
    except CCompilerError:
        fail("C compilation failed.")
    except:
        fail_with_exception("Pyrex compiler failed.")
    if result.num_errors <> 0:
        fail("%d Pyrex errors reported" % result.num_errors)
    return result
Пример #4
0
def compile_and_link(pyx_file):
	try:
		result = Main.compile(pyx_file, c_compile = 1, c_link = 1)
	except CCompilerError:
		fail("C compilation failed.")
	except:
		fail_with_exception("Pyrex compiler failed.")
	if result.num_errors <> 0:
		fail("%d Pyrex errors reported" % result.num_errors)
	return result
Пример #5
0
 def pyrex_sources(self, sources, extension):
     have_pyrex = False
     try:
         import Pyrex
         have_pyrex = True
     except ImportError:
         pass
     new_sources = []
     ext_name = extension.name.split('.')[-1]
     for source in sources:
         (base, ext) = os.path.splitext(source)
         if ext == '.pyx':
             if self.inplace or not have_pyrex:
                 target_dir = os.path.dirname(base)
             else:
                 target_dir = appendpath(self.build_src,
                                         os.path.dirname(base))
             target_file = os.path.join(target_dir, ext_name + '.c')
             depends = [source] + extension.depends
             if (self.force or newer_group(depends, target_file, 'newer')):
                 if have_pyrex:
                     log.info("pyrexc:> %s" % (target_file))
                     self.mkpath(target_dir)
                     from Pyrex.Compiler import Main
                     options = Main.CompilationOptions(
                         defaults=Main.default_options,
                         output_file=target_file)
                     pyrex_result = Main.compile(source, options=options)
                     if pyrex_result.num_errors != 0:
                         raise DistutilsError,"%d errors while compiling %r with Pyrex" \
                               % (pyrex_result.num_errors, source)
                 elif os.path.isfile(target_file):
                     log.warn("Pyrex required for compiling %r but not available,"\
                              " using old target %r"\
                              % (source, target_file))
                 else:
                     raise DistutilsError, "Pyrex required for compiling %r but not available" % (
                         source)
             new_sources.append(target_file)
         else:
             new_sources.append(source)
     return new_sources
Пример #6
0
 def pyrex_sources(self, sources, extension):
     have_pyrex = False
     try:
         import Pyrex
         have_pyrex = True
     except ImportError:
         pass
     new_sources = []
     ext_name = extension.name.split('.')[-1]
     for source in sources:
         (base, ext) = os.path.splitext(source)
         if ext == '.pyx':
             if self.inplace or not have_pyrex:
                 target_dir = os.path.dirname(base)
             else:
                 target_dir = appendpath(self.build_src, os.path.dirname(base))
             target_file = os.path.join(target_dir, ext_name + '.c')
             depends = [source] + extension.depends
             if (self.force or newer_group(depends, target_file, 'newer')):
                 if have_pyrex:
                     log.info("pyrexc:> %s" % (target_file))
                     self.mkpath(target_dir)
                     from Pyrex.Compiler import Main
                     options = Main.CompilationOptions(
                         defaults=Main.default_options,
                         output_file=target_file)
                     pyrex_result = Main.compile(source, options=options)
                     if pyrex_result.num_errors != 0:
                         raise DistutilsError,"%d errors while compiling %r with Pyrex" \
                               % (pyrex_result.num_errors, source)
                 elif os.path.isfile(target_file):
                     log.warn("Pyrex required for compiling %r but not available,"\
                              " using old target %r"\
                              % (source, target_file))
                 else:
                     raise DistutilsError,"Pyrex required for compiling %r but not available" % (source)
             new_sources.append(target_file)
         else:
             new_sources.append(source)
     return new_sources
Пример #7
0
Python/JavaScript bridge module, making use of Mozilla's spidermonkey
JavaScript implementation.  Allows implementation of JavaScript classes,
objects and functions in Python, and evaluation and calling of JavaScript
scripts and functions respectively.  Borrows heavily from Claes Jacobssen's
Javascript Perl module, in turn based on Mozilla's 'PerlConnect' Perl binding.
""",

import os
import sys
import ez_setup
ez_setup.use_setuptools()
from setuptools import setup, Extension

try:
    import Pyrex.Compiler.Main as Compiler
    res = Compiler.compile(["spidermonkey/spidermonkey.pyx"], timestamps=True)
except ImportError:
    print >>sys.stderr, "Pyrex not found. Skipping source re-generation."

def get_platform_config():
    """Retrieve platform specific locatiosn for headers and libraries."""
    platforms = {
        "darwin": {
            "include_dirs": ["/usr/include", "/usr/local/include", "/opt/local/include/js"],
            "library_dirs": ["/usr/lib", "/usr/local/lib", "/opt/local/lib"],
            "libraries": ["js"]
        },
        "freebsd": {
            "include_dirs": ["/usr/include", "/usr/local/include", "/usr/local/include/js"],
            "library_dirs": ["/usr/lib", "/usr/local/lib"],
            "libraries": ["js"]
Пример #8
0
def run_compile_test(item, link=0):
    """Run a single compile-only or compile-and-link test.
	   If linking, the linked extension module is kept for use by later tests.
	"""
    try:
        mark_item(item, "failed")
        dir = path.dirname(item)
        name = path.basename(item)
        global mangled_module_name
        module_name, _ = os.path.splitext(name)
        mangled_module_name = "%d%s_" % (len(module_name), module_name)
        produces_include_files = name.startswith("i_") or name.startswith(
            "ia_")
        produces_api_file = name.startswith("a_") or name.startswith("ia_")
        is_error_test = (name[:2] == "e_" or name[:3] == "se_")
        options = Main.CompilationOptions(Main.default_options)
        if is_error_test:
            options.use_listing_file = 1
            options.errors_to_stderr = 0
        try:
            result = Main.compile(item, options)
        except CCompilerError:
            fail("C compilation error.")
        except:
            fail_with_exception("Exception raised in Pyrex compiler.")
        #print "result =", result.__dict__ ###
        if is_error_test:
            if result.num_errors == 0:
                fail("No errors produced, expected some")
            if result.listing_file is None:
                fail("No listing file produced")
            compare_with_reference(result.listing_file,
                                   show_diffs=0,
                                   line_munger=munge_error_line)
            remove_file(replace_suffix(item, ".c"))
            remove_file(replace_suffix(item, ".cpp"))
        else:
            if result.num_errors <> 0:
                #display_files(replace_suffix(item, ".lis"))
                fail("%s errors reported, expected none" % result.num_errors)
            if result.c_file is None:
                fail("No C file produced")
            compare_with_reference(result.c_file,
                                   show_diffs=1,
                                   line_munger=munge_c_line)
            if produces_include_files:
                if result.h_file is None:
                    fail("No header file produced")
                compare_with_reference(result.h_file,
                                       show_diffs=1,
                                       line_munger=munge_c_line)
                if result.i_file is None:
                    pass
                    # .pxi files no longer produced by default
                    #fail("No include file produced")
                else:
                    compare_with_reference(result.i_file,
                                           show_diffs=1,
                                           line_munger=None)
            if produces_api_file:
                if result.api_file is None:
                    fail("No api header file produced")
                compare_with_reference(result.api_file,
                                       show_diffs=1,
                                       line_munger=munge_c_line)
            try:
                result.object_file = c_compile(result.c_file)
            except CCompilerError:
                fail("C compilation error.")
            except:
                fail_with_exception("C compiler failed.")
            try:
                cplus_object_file = c_compile(result.c_file,
                                              cplus=1,
                                              obj_suffix=".cplus.o")
            except CCompilerError:
                fail("C++ compilation error.")
            except:
                fail_with_exception("C++ compiler failed.")
            if link:
                try:
                    c_link(result.object_file)
                except CCompilerError:
                    fail("C linking error.")
            remove_file(result.listing_file)
            remove_file(result.object_file)
            remove_file(cplus_object_file)
        mark_item(item, "passed")
        return "passed"
    except FailureError:
        return "failed"
Пример #9
0
def run_compile_test(item, link = 0):
	"""Run a single compile-only or compile-and-link test.
	   If linking, the linked extension module is kept for use by later tests.
	"""
	try:
		mark_item(item, "failed")
		dir = path.dirname(item)
		name = path.basename(item)
		global mangled_module_name
		module_name, _ = os.path.splitext(name)
		mangled_module_name = "%d%s_" % (len(module_name), module_name)
		produces_include_files = name.startswith("i_") or name.startswith("ia_")
		produces_api_file = name.startswith("a_") or name.startswith("ia_")
		is_error_test = (
			name[:2] == "e_" or
			name[:3] == "se_")
		options = Main.CompilationOptions(Main.default_options)
		if is_error_test:
			options.use_listing_file = 1
			options.errors_to_stderr = 0
		try:
			result = Main.compile(item, options)
		except CCompilerError:
			fail("C compilation error.")
		except:
			fail_with_exception("Exception raised in Pyrex compiler.")
		#print "result =", result.__dict__ ###
		if is_error_test:
			if result.num_errors == 0:
				fail("No errors produced, expected some")
			if result.listing_file is None:
				fail("No listing file produced")
			compare_with_reference(result.listing_file, show_diffs = 0,
				line_munger = munge_error_line)
			remove_file(replace_suffix(item, ".c"))
			remove_file(replace_suffix(item, ".cpp"))
		else:
			if result.num_errors <> 0:
				#display_files(replace_suffix(item, ".lis"))
				fail("%s errors reported, expected none" %
					result.num_errors)
			if result.c_file is None:
				fail("No C file produced")
			compare_with_reference(result.c_file, show_diffs = 1,
				line_munger = munge_c_line)
			if produces_include_files:
				if result.h_file is None:
					fail("No header file produced")
				compare_with_reference(result.h_file, show_diffs = 1,
					line_munger = munge_c_line)
				if result.i_file is None:
					pass
					# .pxi files no longer produced by default
					#fail("No include file produced")
				else:
					compare_with_reference(result.i_file, show_diffs = 1,
						line_munger = None)
			if produces_api_file:
				if result.api_file is None:
					fail("No api header file produced")
				compare_with_reference(result.api_file, show_diffs = 1,
					line_munger = munge_c_line)
			try:
				result.object_file = c_compile(result.c_file)
			except CCompilerError:
				fail("C compilation error.")
			except:
				fail_with_exception("C compiler failed.")
			try:
				cplus_object_file = c_compile(result.c_file, cplus = 1, obj_suffix = ".cplus.o")
			except CCompilerError:
				fail("C++ compilation error.")
			except:
				fail_with_exception("C++ compiler failed.")
			if link:
				try:
					c_link(result.object_file)
				except CCompilerError:
					fail("C linking error.")
			remove_file(result.listing_file)
			remove_file(result.object_file)
			remove_file(cplus_object_file)
		mark_item(item, "passed")
		return "passed"
	except FailureError:
		return "failed"