def skip_if_no_cython(self):

        if sys.hexversion > 0x03000000:
            self.skip("no cython for python 3.0")
        
        if not hasattr(config.compilers, 'cython') or len(config.compilers.cython) == 0:
            self.skip("cython not configured")
            
        process, output, error = compile_tools.open_subprocess([config.compilers.cython, '-V'])
        if process.returncode:
            self.skip("cython not available")
        
        error = error.strip()[0:7].decode('utf-8')
        if not error.startswith('Cython'):
            self.skip("cython not available")
    def skip_if_no_cython(self):

        if sys.hexversion > 0x03000000:
            self.skip("no cython for python 3.0")
        
        if not hasattr(config.compilers, 'cython') or len(config.compilers.cython) == 0:
            self.skip("cython not configured")
            
        process, output, error = compile_tools.open_subprocess([config.compilers.cython, '-V'])
        if process.returncode:
            self.skip("cython not available")
        
        error = error.strip()[0:7].decode('utf-8')
        if not error.startswith('Cython'):
            self.skip("cython not available")
    def build_worker(self):
        
        path = os.path.abspath(self.get_path_to_results())
        codefile = os.path.join(path,"code.o")
        interfacefile = os.path.join(path,"interface.o")
        headerfile = os.path.join(path,"worker_code.h")
        self.sofile = os.path.join(path,"interface.so")
        self.interfacec_o_file = os.path.join(path,"interfacec.o")
        self.exefile = os.path.join(path,"c_worker")
        
        compile_tools.fortran_compile(codefile, test_fortran_implementation.codestring,
                                      extra_args=["-fPIC"])
        
        
        uc = create_c.GenerateACHeaderStringFromASpecificationClass()
        uc.specification_class = test_fortran_implementation.ForTestingInterface
        uc.needs_mpi = False
        header =  uc.result
        
        
        with open(headerfile, "w") as f:
            f.write(header)
        
        
        root, ext = os.path.splitext(interfacefile)
        sourcename = root + '.pyx'
        cname = root + '.c'
        
        uc = create_cython.GenerateACythonSourcecodeStringFromASpecificationClass()
        uc.specification_class = test_fortran_implementation.ForTestingInterface
        uc.function_name_prefix = "ci_"
        uc.needs_mpi = True
        code =  uc.result
        
        with open(sourcename, "w") as f:
            f.write(code)


        uc = create_cython.GenerateACythonStartScriptStringFromASpecificationClass()
        uc.specification_class = test_fortran_implementation.ForTestingInterface
        uc.needs_mpi = True
        script =  uc.result
        
        with open(self.exefile, "w") as f:
            f.write(script)

        os.chmod(self.exefile, 0777)

        import mpi4py
        process, stdout, stderr = compile_tools.open_subprocess([config.compilers.cython, 
        '-I',
        mpi4py.get_include(),
         sourcename, '-o', cname])

        if process.returncode == 0:
            compile_tools.wait_for_file(cname)
        
        if process.returncode != 0 or not os.path.exists(cname):
            print "Could not cythonize {0}, error = {1}".format(sourcename, stderr)
            raise Exception("Could not cythonize {0}, error = {1}".format(sourcename, stderr))
        
        with open(cname, "r") as f:
            string = f.read()


        
        
        uc = create_cython.GenerateAFortranInterfaceSourcecodeStringFromASpecificationClass()
        uc.specification_class = test_fortran_implementation.ForTestingInterface
        uc.function_name_prefix = "ci_"
        uc.needs_mpi = False
        code =  uc.result

        compile_tools.fortran_compile(self.interfacec_o_file, code,
                                      extra_args=["-fPIC"])

        compile_tools.c_pythondev_compile(interfacefile, string)
        compile_tools.fortran_pythondev_buildso(self.sofile,  [interfacefile, codefile, self.interfacec_o_file] )
    def build_worker(self):
        
        path = os.path.abspath(self.get_path_to_results())
        codefile = os.path.join(path,"code.o")
        interfacefile = os.path.join(path,"interface.o")
        headerfile = os.path.join(path,"worker_code.h")
        self.sofile = os.path.join(path,"interface.so")
        self.interfacec_o_file = os.path.join(path,"interfacec.o")
        self.exefile = os.path.join(path,"c_worker")
        
        compile_tools.fortran_compile(codefile, test_fortran_implementation.codestring,
                                      extra_args=["-fPIC"])
        
        
        uc = create_c.GenerateACHeaderStringFromASpecificationClass()
        uc.specification_class = test_fortran_implementation.ForTestingInterface
        uc.needs_mpi = False
        header =  uc.result
        
        
        with open(headerfile, "w") as f:
            f.write(header)
        
        
        root, ext = os.path.splitext(interfacefile)
        sourcename = root + '.pyx'
        cname = root + '.c'
        
        uc = create_cython.GenerateACythonSourcecodeStringFromASpecificationClass()
        uc.specification_class = test_fortran_implementation.ForTestingInterface
        uc.function_name_prefix = "ci_"
        uc.needs_mpi = True
        code =  uc.result
        
        with open(sourcename, "w") as f:
            f.write(code)


        uc = create_cython.GenerateACythonStartScriptStringFromASpecificationClass()
        uc.specification_class = test_fortran_implementation.ForTestingInterface
        uc.needs_mpi = True
        script =  uc.result
        
        with open(self.exefile, "w") as f:
            f.write(script)

        os.chmod(self.exefile, 0777)

        import mpi4py
        process, stdout, stderr = compile_tools.open_subprocess([config.compilers.cython, 
        '-I',
        mpi4py.get_include(),
         sourcename, '-o', cname])

        if process.returncode == 0:
            compile_tools.wait_for_file(cname)
        
        if process.returncode != 0 or not os.path.exists(cname):
            print "Could not cythonize {0}, error = {1}".format(sourcename, stderr)
            raise Exception("Could not cythonize {0}, error = {1}".format(sourcename, stderr))
        
        with open(cname, "r") as f:
            string = f.read()


        
        
        uc = create_cython.GenerateAFortranInterfaceSourcecodeStringFromASpecificationClass()
        uc.specification_class = test_fortran_implementation.ForTestingInterface
        uc.function_name_prefix = "ci_"
        uc.needs_mpi = False
        code =  uc.result

        compile_tools.fortran_compile(self.interfacec_o_file, code,
                                      extra_args=["-fPIC"])

        compile_tools.c_pythondev_compile(interfacefile, string)
        compile_tools.fortran_pythondev_buildso(self.sofile,  [interfacefile, codefile, self.interfacec_o_file] )