theano/gof/cmodule.py
def _try_compile_tmp(cls, src_code, tmp_prefix='', flags=(),
                         try_run=False, output=False, compiler=None,
                         comp_args=True):
        """
        Try to compile (and run) a test program.

        This is useful in various occasions, to check if libraries
        or compilers are behaving as expected.

        If try_run is True, the src_code is assumed to be executable,
        and will be run.

        If try_run is False, returns the compilation status.
        If try_run is True, returns a (compile_status, run_status) pair.
        If output is there, we append the stdout and stderr to the output.

        Compile arguments from the Compiler's compile_args() method are added
        if comp_args=True.
        """
        if not compiler:
            return False
        flags = list(flags)
        # Get compile arguments from compiler method if required
        if comp_args:
            args = cls.compile_args()
        else:
            args = []
        compilation_ok = True
        run_ok = False
        out, err = None, None
        try:
            fd, path = tempfile.mkstemp(suffix='.c', prefix=tmp_prefix)
            exe_path = path[:-2]
            if os.name == 'nt':
                path = "\"" + path + "\""
                exe_path = "\"" + exe_path + "\""
            try:
                # Python3 compatibility: try to cast Py3 strings as Py2 strings
                try:
                    src_code = b(src_code)
                except Exception:
                    pass
                os.write(fd, src_code)
                os.close(fd)
                fd = None
                out, err, p_ret = output_subprocess_Popen(
                    [compiler] + args + [path, '-o', exe_path] + flags)
                if p_ret != 0:
                    compilation_ok = False
                elif try_run:
                    out, err, p_ret = output_subprocess_Popen([exe_path])
                    run_ok = (p_ret == 0)
            finally:
                try:
                    if fd is not None:
                        os.close(fd)
                finally:
                    if os.path.exists(path):
                        os.remove(path)
                    if os.path.exists(exe_path):
                        os.remove(exe_path)
                    if os.path.exists(exe_path + ".exe"):
                        os.remove(exe_path + ".exe")
        except OSError as e:
            if err is None:
                err = str(e)
            else:
                err = str(err) + "\n" + str(e)
            compilation_ok = False

        if not try_run and not output:
            return compilation_ok
        elif not try_run and output:
            return (compilation_ok, out, err)
        elif not output:
            return (compilation_ok, run_ok)
        else:
            return (compilation_ok, run_ok, out, err)

        Try to compile (and run) a test program.

        This is useful in various occasions, to check if libraries
        or compilers are behaving as expected.

        If try_run is True, the src_code is assumed to be executable,
        and will be run.

        If try_run is False, returns the compilation status.
        If try_run is True, returns a (compile_status, run_status) pair.
        If output is there, we append the stdout and stderr to the output.

        Compile arguments from the Compiler's compile_args() method are added
        if comp_args=True.
        
Try to compile (and run) a test program.
This is useful in various occasions, to check if libraries
or compilers are behaving as expected.

If try_run is True, the src_code is assumed to be executable,
and will be run.

If try_run is False, returns the compilation status.

Compile arguments from the Compiler's compile_args() method are added
if comp_args=True.
Try to compile ( and run ) a test program . This is useful in various occasions to check if libraries or compilers are behaving as expected . If try_run is True the src_code is assumed to be executable and will be run . If try_run is False returns the compilation status . Compile arguments from the Compiler ' s compile_args () method are added if comp_args = True .
def _try_compile_tmp(cls, src_code, tmp_prefix='', flags=(),
                         try_run=False, output=False, compiler=None,
                         comp_args=True):
        if not compiler:
            return False
        flags = list(flags)
        if comp_args:
            args = cls.compile_args()
        else:
            args = []
        compilation_ok = True
        run_ok = False
        out, err = None, None
        try:
            fd, path = tempfile.mkstemp(suffix='.c', prefix=tmp_prefix)
            exe_path = path[:-2]
            if os.name == 'nt':
                path = "\"" + path + "\""
                exe_path = "\"" + exe_path + "\""
            try:
                try:
                    src_code = b(src_code)
                except Exception:
                    pass
                os.write(fd, src_code)
                os.close(fd)
                fd = None
                out, err, p_ret = output_subprocess_Popen(
                    [compiler] + args + [path, '-o', exe_path] + flags)
                if p_ret != 0:
                    compilation_ok = False
                elif try_run:
                    out, err, p_ret = output_subprocess_Popen([exe_path])
                    run_ok = (p_ret == 0)
            finally:
                try:
                    if fd is not None:
                        os.close(fd)
                finally:
                    if os.path.exists(path):
                        os.remove(path)
                    if os.path.exists(exe_path):
                        os.remove(exe_path)
                    if os.path.exists(exe_path + ".exe"):
                        os.remove(exe_path + ".exe")
        except OSError as e:
            if err is None:
                err = str(e)
            else:
                err = str(err) + "\n" + str(e)
            compilation_ok = False
        if not try_run and not output:
            return compilation_ok
        elif not try_run and output:
            return (compilation_ok, out, err)
        elif not output:
            return (compilation_ok, run_ok)
        else:
            return (compilation_ok, run_ok, out, err)
def _try_compile_tmp ( cls , src_code , tmp_prefix = '' , flags = ( ) , try_run = False , output = False , compiler = None , comp_args = True ) : if not compiler : return False flags = list ( flags ) if comp_args : args = cls . compile_args ( ) else : args = [ ] compilation_ok = True run_ok = False out , err = None , None try : fd , path = tempfile . mkstemp ( suffix = '.c' , prefix = tmp_prefix ) exe_path = path [ : - 2 ] if os . name == 'nt' : path = "\"" + path + "\"" exe_path = "\"" + exe_path + "\"" try : try : src_code = b ( src_code ) except Exception : pass os . write ( fd , src_code ) os . close ( fd ) fd = None out , err , p_ret = output_subprocess_Popen ( [ compiler ] + args + [ path , '-o' , exe_path ] + flags ) if p_ret != 0 : compilation_ok = False elif try_run : out , err , p_ret = output_subprocess_Popen ( [ exe_path ] ) run_ok = ( p_ret == 0 ) finally : try : if fd is not None : os . close ( fd ) finally : if os . path . exists ( path ) : os . remove ( path ) if os . path . exists ( exe_path ) : os . remove ( exe_path ) if os . path . exists ( exe_path + ".exe" ) : os . remove ( exe_path + ".exe" ) except OSError as e : if err is None : err = str ( e ) else : err = str ( err ) + "\n" + str ( e ) compilation_ok = False if not try_run and not output : return compilation_ok elif not try_run and output : return ( compilation_ok , out , err ) elif not output : return ( compilation_ok , run_ok ) else : return ( compilation_ok , run_ok , out , err )
Try to compile (and run) a test program.
Try to compile ( and run ) a test program .
"""
        Try to compile (and run) a test program.

        This is useful in various occasions, to check if libraries
        or compilers are behaving as expected.

        If try_run is True, the src_code is assumed to be executable,
        and will be run.

        If try_run is False, returns the compilation status.
        If try_run is True, returns a (compile_status, run_status) pair.
        If output is there, we append the stdout and stderr to the output.

        Compile arguments from the Compiler's compile_args() method are added
        if comp_args=True.
        """ # Get compile arguments from compiler method if required # Python3 compatibility: try to cast Py3 strings as Py2 strings
cls
src_code
tmp_prefix
flags
try_run
output
compiler
comp_args