python类temppath()的实例源码

util.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def build_code(source_code, options=[], skip=[], only=[], suffix=None,
               module_name=None):
    """
    Compile and import Fortran code using f2py.

    """
    if suffix is None:
        suffix = '.f'
    with temppath(suffix=suffix) as path:
        with open(path, 'w') as f:
            f.write(source_code)
        return build_module([path], options=options, skip=skip, only=only,
                            module_name=module_name)

#
# Check if compilers are available at all...
#
test_mrecords.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_fromtextfile(self):
        # Tests reading from a text file.
        fcontent = (
"""#
'One (S)','Two (I)','Three (F)','Four (M)','Five (-)','Six (C)'
'strings',1,1.0,'mixed column',,1
'with embedded "double quotes"',2,2.0,1.0,,1
'strings',3,3.0E5,3,,1
'strings',4,-1e-10,,,1
""")
        with temppath() as path:
            with open(path, 'w') as f:
                f.write(fcontent)
            mrectxt = fromtextfile(path, delimitor=',', varnames='ABCDEFG')
        self.assertTrue(isinstance(mrectxt, MaskedRecords))
        assert_equal(mrectxt.F, [1, 1, 1, 1])
        assert_equal(mrectxt.E._mask, [1, 1, 1, 1])
        assert_equal(mrectxt.C, [1, 2, 3.e+5, -1e-10])
util.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def build_code(source_code, options=[], skip=[], only=[], suffix=None,
               module_name=None):
    """
    Compile and import Fortran code using f2py.

    """
    if suffix is None:
        suffix = '.f'
    with temppath(suffix=suffix) as path:
        with open(path, 'w') as f:
            f.write(source_code)
        return build_module([path], options=options, skip=skip, only=only,
                            module_name=module_name)

#
# Check if compilers are available at all...
#
test_mrecords.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_fromtextfile(self):
        # Tests reading from a text file.
        fcontent = (
"""#
'One (S)','Two (I)','Three (F)','Four (M)','Five (-)','Six (C)'
'strings',1,1.0,'mixed column',,1
'with embedded "double quotes"',2,2.0,1.0,,1
'strings',3,3.0E5,3,,1
'strings',4,-1e-10,,,1
""")
        with temppath() as path:
            with open(path, 'w') as f:
                f.write(fcontent)
            mrectxt = fromtextfile(path, delimitor=',', varnames='ABCDEFG')
        self.assertTrue(isinstance(mrectxt, MaskedRecords))
        assert_equal(mrectxt.F, [1, 1, 1, 1])
        assert_equal(mrectxt.E._mask, [1, 1, 1, 1])
        assert_equal(mrectxt.C, [1, 2, 3.e+5, -1e-10])
util.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def build_code(source_code, options=[], skip=[], only=[], suffix=None,
               module_name=None):
    """
    Compile and import Fortran code using f2py.

    """
    if suffix is None:
        suffix = '.f'
    with temppath(suffix=suffix) as path:
        with open(path, 'w') as f:
            f.write(source_code)
        return build_module([path], options=options, skip=skip, only=only,
                            module_name=module_name)

#
# Check if compilers are available at all...
#
test_mrecords.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_fromtextfile(self):
        # Tests reading from a text file.
        fcontent = (
"""#
'One (S)','Two (I)','Three (F)','Four (M)','Five (-)','Six (C)'
'strings',1,1.0,'mixed column',,1
'with embedded "double quotes"',2,2.0,1.0,,1
'strings',3,3.0E5,3,,1
'strings',4,-1e-10,,,1
""")
        with temppath() as path:
            with open(path, 'w') as f:
                f.write(fcontent)
            mrectxt = fromtextfile(path, delimitor=',', varnames='ABCDEFG')
        self.assertTrue(isinstance(mrectxt, MaskedRecords))
        assert_equal(mrectxt.F, [1, 1, 1, 1])
        assert_equal(mrectxt.E._mask, [1, 1, 1, 1])
        assert_equal(mrectxt.C, [1, 2, 3.e+5, -1e-10])
util.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def build_code(source_code, options=[], skip=[], only=[], suffix=None,
               module_name=None):
    """
    Compile and import Fortran code using f2py.

    """
    if suffix is None:
        suffix = '.f'
    with temppath(suffix=suffix) as path:
        with open(path, 'w') as f:
            f.write(source_code)
        return build_module([path], options=options, skip=skip, only=only,
                            module_name=module_name)

#
# Check if compilers are available at all...
#
test_mrecords.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_fromtextfile(self):
        # Tests reading from a text file.
        fcontent = (
"""#
'One (S)','Two (I)','Three (F)','Four (M)','Five (-)','Six (C)'
'strings',1,1.0,'mixed column',,1
'with embedded "double quotes"',2,2.0,1.0,,1
'strings',3,3.0E5,3,,1
'strings',4,-1e-10,,,1
""")
        with temppath() as path:
            with open(path, 'w') as f:
                f.write(fcontent)
            mrectxt = fromtextfile(path, delimitor=',', varnames='ABCDEFG')
        self.assertTrue(isinstance(mrectxt, MaskedRecords))
        assert_equal(mrectxt.F, [1, 1, 1, 1])
        assert_equal(mrectxt.E._mask, [1, 1, 1, 1])
        assert_equal(mrectxt.C, [1, 2, 3.e+5, -1e-10])
util.py 文件源码 项目:Alfred 作者: jkachhadia 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def build_code(source_code, options=[], skip=[], only=[], suffix=None,
               module_name=None):
    """
    Compile and import Fortran code using f2py.

    """
    if suffix is None:
        suffix = '.f'
    with temppath(suffix=suffix) as path:
        with open(path, 'w') as f:
            f.write(source_code)
        return build_module([path], options=options, skip=skip, only=only,
                            module_name=module_name)

#
# Check if compilers are available at all...
#
test_mrecords.py 文件源码 项目:Alfred 作者: jkachhadia 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_fromtextfile(self):
        # Tests reading from a text file.
        fcontent = (
"""#
'One (S)','Two (I)','Three (F)','Four (M)','Five (-)','Six (C)'
'strings',1,1.0,'mixed column',,1
'with embedded "double quotes"',2,2.0,1.0,,1
'strings',3,3.0E5,3,,1
'strings',4,-1e-10,,,1
""")
        with temppath() as path:
            with open(path, 'w') as f:
                f.write(fcontent)
            mrectxt = fromtextfile(path, delimitor=',', varnames='ABCDEFG')
        self.assertTrue(isinstance(mrectxt, MaskedRecords))
        assert_equal(mrectxt.F, [1, 1, 1, 1])
        assert_equal(mrectxt.E._mask, [1, 1, 1, 1])
        assert_equal(mrectxt.C, [1, 2, 3.e+5, -1e-10])
test_npy_pkg_config.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_simple(self):
        with temppath('foo.ini') as path:
            with open(path,  'w') as f:
                f.write(simple)
            pkg = os.path.splitext(path)[0]
            out = read_config(pkg)

        self.assertTrue(out.cflags() == simple_d['cflags'])
        self.assertTrue(out.libs() == simple_d['libflags'])
        self.assertTrue(out.name == simple_d['name'])
        self.assertTrue(out.version == simple_d['version'])
test_npy_pkg_config.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def test_simple_variable(self):
        with temppath('foo.ini') as path:
            with open(path,  'w') as f:
                f.write(simple_variable)
            pkg = os.path.splitext(path)[0]
            out = read_config(pkg)

        self.assertTrue(out.cflags() == simple_variable_d['cflags'])
        self.assertTrue(out.libs() == simple_variable_d['libflags'])
        self.assertTrue(out.name == simple_variable_d['name'])
        self.assertTrue(out.version == simple_variable_d['version'])
        out.vars['prefix'] = '/Users/david'
        self.assertTrue(out.cflags() == '-I/Users/david/include')
test_npy_pkg_config.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_simple(self):
        with temppath('foo.ini') as path:
            with open(path,  'w') as f:
                f.write(simple)
            pkg = os.path.splitext(path)[0]
            out = read_config(pkg)

        self.assertTrue(out.cflags() == simple_d['cflags'])
        self.assertTrue(out.libs() == simple_d['libflags'])
        self.assertTrue(out.name == simple_d['name'])
        self.assertTrue(out.version == simple_d['version'])
test_npy_pkg_config.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_simple_variable(self):
        with temppath('foo.ini') as path:
            with open(path,  'w') as f:
                f.write(simple_variable)
            pkg = os.path.splitext(path)[0]
            out = read_config(pkg)

        self.assertTrue(out.cflags() == simple_variable_d['cflags'])
        self.assertTrue(out.libs() == simple_variable_d['libflags'])
        self.assertTrue(out.name == simple_variable_d['name'])
        self.assertTrue(out.version == simple_variable_d['version'])
        out.vars['prefix'] = '/Users/david'
        self.assertTrue(out.cflags() == '-I/Users/david/include')
test_npy_pkg_config.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_simple(self):
        with temppath('foo.ini') as path:
            with open(path,  'w') as f:
                f.write(simple)
            pkg = os.path.splitext(path)[0]
            out = read_config(pkg)

        self.assertTrue(out.cflags() == simple_d['cflags'])
        self.assertTrue(out.libs() == simple_d['libflags'])
        self.assertTrue(out.name == simple_d['name'])
        self.assertTrue(out.version == simple_d['version'])
test_npy_pkg_config.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def test_simple_variable(self):
        with temppath('foo.ini') as path:
            with open(path,  'w') as f:
                f.write(simple_variable)
            pkg = os.path.splitext(path)[0]
            out = read_config(pkg)

        self.assertTrue(out.cflags() == simple_variable_d['cflags'])
        self.assertTrue(out.libs() == simple_variable_d['libflags'])
        self.assertTrue(out.name == simple_variable_d['name'])
        self.assertTrue(out.version == simple_variable_d['version'])
        out.vars['prefix'] = '/Users/david'
        self.assertTrue(out.cflags() == '-I/Users/david/include')
test_npy_pkg_config.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_simple(self):
        with temppath('foo.ini') as path:
            with open(path,  'w') as f:
                f.write(simple)
            pkg = os.path.splitext(path)[0]
            out = read_config(pkg)

        self.assertTrue(out.cflags() == simple_d['cflags'])
        self.assertTrue(out.libs() == simple_d['libflags'])
        self.assertTrue(out.name == simple_d['name'])
        self.assertTrue(out.version == simple_d['version'])
test_npy_pkg_config.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_simple_variable(self):
        with temppath('foo.ini') as path:
            with open(path,  'w') as f:
                f.write(simple_variable)
            pkg = os.path.splitext(path)[0]
            out = read_config(pkg)

        self.assertTrue(out.cflags() == simple_variable_d['cflags'])
        self.assertTrue(out.libs() == simple_variable_d['libflags'])
        self.assertTrue(out.name == simple_variable_d['name'])
        self.assertTrue(out.version == simple_variable_d['version'])
        out.vars['prefix'] = '/Users/david'
        self.assertTrue(out.cflags() == '-I/Users/david/include')
test_npy_pkg_config.py 文件源码 项目:Alfred 作者: jkachhadia 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_simple(self):
        with temppath('foo.ini') as path:
            with open(path,  'w') as f:
                f.write(simple)
            pkg = os.path.splitext(path)[0]
            out = read_config(pkg)

        self.assertTrue(out.cflags() == simple_d['cflags'])
        self.assertTrue(out.libs() == simple_d['libflags'])
        self.assertTrue(out.name == simple_d['name'])
        self.assertTrue(out.version == simple_d['version'])
test_npy_pkg_config.py 文件源码 项目:Alfred 作者: jkachhadia 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_simple_variable(self):
        with temppath('foo.ini') as path:
            with open(path,  'w') as f:
                f.write(simple_variable)
            pkg = os.path.splitext(path)[0]
            out = read_config(pkg)

        self.assertTrue(out.cflags() == simple_variable_d['cflags'])
        self.assertTrue(out.libs() == simple_variable_d['libflags'])
        self.assertTrue(out.name == simple_variable_d['name'])
        self.assertTrue(out.version == simple_variable_d['version'])
        out.vars['prefix'] = '/Users/david'
        self.assertTrue(out.cflags() == '-I/Users/david/include')
util.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _get_compiler_status():
    global _compiler_status
    if _compiler_status is not None:
        return _compiler_status

    _compiler_status = (False, False, False)

    # XXX: this is really ugly. But I don't know how to invoke Distutils
    #      in a safer way...
    code = """
import os
import sys
sys.path = %(syspath)s

def configuration(parent_name='',top_path=None):
    global config
    from numpy.distutils.misc_util import Configuration
    config = Configuration('', parent_name, top_path)
    return config

from numpy.distutils.core import setup
setup(configuration=configuration)

config_cmd = config.get_config_cmd()
have_c = config_cmd.try_compile('void foo() {}')
print('COMPILERS:%%d,%%d,%%d' %% (have_c,
                                  config.have_f77c(),
                                  config.have_f90c()))
sys.exit(99)
"""
    code = code % dict(syspath=repr(sys.path))

    with temppath(suffix='.py') as script:
        with open(script, 'w') as f:
            f.write(code)

        cmd = [sys.executable, script, 'config']
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
        out, err = p.communicate()

    m = re.search(asbytes(r'COMPILERS:(\d+),(\d+),(\d+)'), out)
    if m:
        _compiler_status = (bool(int(m.group(1))), bool(int(m.group(2))),
                            bool(int(m.group(3))))
    # Finished
    return _compiler_status
util.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def _get_compiler_status():
    global _compiler_status
    if _compiler_status is not None:
        return _compiler_status

    _compiler_status = (False, False, False)

    # XXX: this is really ugly. But I don't know how to invoke Distutils
    #      in a safer way...
    code = """
import os
import sys
sys.path = %(syspath)s

def configuration(parent_name='',top_path=None):
    global config
    from numpy.distutils.misc_util import Configuration
    config = Configuration('', parent_name, top_path)
    return config

from numpy.distutils.core import setup
setup(configuration=configuration)

config_cmd = config.get_config_cmd()
have_c = config_cmd.try_compile('void foo() {}')
print('COMPILERS:%%d,%%d,%%d' %% (have_c,
                                  config.have_f77c(),
                                  config.have_f90c()))
sys.exit(99)
"""
    code = code % dict(syspath=repr(sys.path))

    with temppath(suffix='.py') as script:
        with open(script, 'w') as f:
            f.write(code)

        cmd = [sys.executable, script, 'config']
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
        out, err = p.communicate()

    m = re.search(asbytes(r'COMPILERS:(\d+),(\d+),(\d+)'), out)
    if m:
        _compiler_status = (bool(int(m.group(1))), bool(int(m.group(2))),
                            bool(int(m.group(3))))
    # Finished
    return _compiler_status
util.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _get_compiler_status():
    global _compiler_status
    if _compiler_status is not None:
        return _compiler_status

    _compiler_status = (False, False, False)

    # XXX: this is really ugly. But I don't know how to invoke Distutils
    #      in a safer way...
    code = """
import os
import sys
sys.path = %(syspath)s

def configuration(parent_name='',top_path=None):
    global config
    from numpy.distutils.misc_util import Configuration
    config = Configuration('', parent_name, top_path)
    return config

from numpy.distutils.core import setup
setup(configuration=configuration)

config_cmd = config.get_config_cmd()
have_c = config_cmd.try_compile('void foo() {}')
print('COMPILERS:%%d,%%d,%%d' %% (have_c,
                                  config.have_f77c(),
                                  config.have_f90c()))
sys.exit(99)
"""
    code = code % dict(syspath=repr(sys.path))

    with temppath(suffix='.py') as script:
        with open(script, 'w') as f:
            f.write(code)

        cmd = [sys.executable, script, 'config']
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
        out, err = p.communicate()

    m = re.search(asbytes(r'COMPILERS:(\d+),(\d+),(\d+)'), out)
    if m:
        _compiler_status = (bool(int(m.group(1))), bool(int(m.group(2))),
                            bool(int(m.group(3))))
    # Finished
    return _compiler_status
util.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _get_compiler_status():
    global _compiler_status
    if _compiler_status is not None:
        return _compiler_status

    _compiler_status = (False, False, False)

    # XXX: this is really ugly. But I don't know how to invoke Distutils
    #      in a safer way...
    code = """
import os
import sys
sys.path = %(syspath)s

def configuration(parent_name='',top_path=None):
    global config
    from numpy.distutils.misc_util import Configuration
    config = Configuration('', parent_name, top_path)
    return config

from numpy.distutils.core import setup
setup(configuration=configuration)

config_cmd = config.get_config_cmd()
have_c = config_cmd.try_compile('void foo() {}')
print('COMPILERS:%%d,%%d,%%d' %% (have_c,
                                  config.have_f77c(),
                                  config.have_f90c()))
sys.exit(99)
"""
    code = code % dict(syspath=repr(sys.path))

    with temppath(suffix='.py') as script:
        with open(script, 'w') as f:
            f.write(code)

        cmd = [sys.executable, script, 'config']
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
        out, err = p.communicate()

    m = re.search(asbytes(r'COMPILERS:(\d+),(\d+),(\d+)'), out)
    if m:
        _compiler_status = (bool(int(m.group(1))), bool(int(m.group(2))),
                            bool(int(m.group(3))))
    # Finished
    return _compiler_status
util.py 文件源码 项目:Alfred 作者: jkachhadia 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def _get_compiler_status():
    global _compiler_status
    if _compiler_status is not None:
        return _compiler_status

    _compiler_status = (False, False, False)

    # XXX: this is really ugly. But I don't know how to invoke Distutils
    #      in a safer way...
    code = """
import os
import sys
sys.path = %(syspath)s

def configuration(parent_name='',top_path=None):
    global config
    from numpy.distutils.misc_util import Configuration
    config = Configuration('', parent_name, top_path)
    return config

from numpy.distutils.core import setup
setup(configuration=configuration)

config_cmd = config.get_config_cmd()
have_c = config_cmd.try_compile('void foo() {}')
print('COMPILERS:%%d,%%d,%%d' %% (have_c,
                                  config.have_f77c(),
                                  config.have_f90c()))
sys.exit(99)
"""
    code = code % dict(syspath=repr(sys.path))

    with temppath(suffix='.py') as script:
        with open(script, 'w') as f:
            f.write(code)

        cmd = [sys.executable, script, 'config']
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
        out, err = p.communicate()

    m = re.search(asbytes(r'COMPILERS:(\d+),(\d+),(\d+)'), out)
    if m:
        _compiler_status = (bool(int(m.group(1))), bool(int(m.group(2))),
                            bool(int(m.group(3))))
    # Finished
    return _compiler_status


问题


面经


文章

微信
公众号

扫码关注公众号