本文整理汇总了Python中compileall.compile_file方法的典型用法代码示例。如果您正苦于以下问题:Python compileall.compile_file方法的具体用法?Python compileall.compile_file怎么用?Python compileall.compile_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类compileall
的用法示例。
在下文中一共展示了compileall.compile_file方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_compile_files
# 需要导入模块: import compileall [as 别名]
# 或者: from compileall import compile_file [as 别名]
def test_compile_files(self):
# Test compiling a single file, and complete directory
for fn in (self.bc_path, self.bc_path2):
try:
os.unlink(fn)
except:
pass
compileall.compile_file(self.source_path, force=False, quiet=True)
self.assertTrue(os.path.isfile(self.bc_path) \
and not os.path.isfile(self.bc_path2))
os.unlink(self.bc_path)
compileall.compile_dir(self.directory, force=False, quiet=True)
self.assertTrue(os.path.isfile(self.bc_path) \
and os.path.isfile(self.bc_path2))
os.unlink(self.bc_path)
os.unlink(self.bc_path2)
示例2: test_compile_files
# 需要导入模块: import compileall [as 别名]
# 或者: from compileall import compile_file [as 别名]
def test_compile_files(self):
# Test compiling a single file, and complete directory
for fn in (self.bc_path, self.bc_path2):
try:
os.unlink(fn)
except:
pass
compileall.compile_file(self.source_path, force=False, quiet=True)
self.assertTrue(os.path.isfile(self.bc_path) and
not os.path.isfile(self.bc_path2))
os.unlink(self.bc_path)
compileall.compile_dir(self.directory, force=False, quiet=True)
self.assertTrue(os.path.isfile(self.bc_path) and
os.path.isfile(self.bc_path2))
os.unlink(self.bc_path)
os.unlink(self.bc_path2)
示例3: compile_python_sources
# 需要导入模块: import compileall [as 别名]
# 或者: from compileall import compile_file [as 别名]
def compile_python_sources(base_dir, files, exclude=None):
exclude = exclude or []
patterns = dict()
try:
from compileall import compile_file
patterns['*.py'] = (compile_py_func, compile_file)
except:
pass
regex_exclude = [re.compile(r, re.MULTILINE) for r in exclude]
for fnext, funcs in patterns.items():
for fext_file in filter(lambda f: fnmatch.fnmatch(f, fnext), files):
fext_file = os.path.join(base_dir, fext_file)
if os.path.exists(fext_file):
if not any(filter(lambda fp: bool(fp.search(fext_file)), regex_exclude)):
func, subfunc = funcs
funcs[0](fext_file, funcs[1])
print('Compiled {fext_file}.'.format(fext_file=fext_file))
示例4: test_no_pycache_in_non_package
# 需要导入模块: import compileall [as 别名]
# 或者: from compileall import compile_file [as 别名]
def test_no_pycache_in_non_package(self):
# Bug 8563 reported that __pycache__ directories got created by
# compile_file() for non-.py files.
data_dir = os.path.join(self.directory, 'data')
data_file = os.path.join(data_dir, 'file')
os.mkdir(data_dir)
# touch data/file
with open(data_file, 'w'):
pass
compileall.compile_file(data_file)
self.assertFalse(os.path.exists(os.path.join(data_dir, '__pycache__')))
示例5: test_syntax
# 需要导入模块: import compileall [as 别名]
# 或者: from compileall import compile_file [as 别名]
def test_syntax(item):
assert compile_file(item)
示例6: test_abort_patch_context_manager_with_stale_pyc
# 需要导入模块: import compileall [as 别名]
# 或者: from compileall import compile_file [as 别名]
def test_abort_patch_context_manager_with_stale_pyc(testdir):
"""Ensure we don't trigger an error in case the frame where mocker.patch is being
used doesn't have a 'context' (#169)"""
import compileall
py_fn = testdir.makepyfile(
c="""
class C:
x = 1
def check(mocker):
mocker.patch.object(C, "x", 2)
assert C.x == 2
"""
)
testdir.syspathinsert()
testdir.makepyfile(
"""
from c import check
def test_foo(mocker):
check(mocker)
"""
)
result = testdir.runpytest()
result.assert_outcomes(passed=1)
kwargs = {"legacy": True}
assert compileall.compile_file(str(py_fn), **kwargs)
pyc_fn = str(py_fn) + "c"
assert os.path.isfile(pyc_fn)
py_fn.remove()
result = testdir.runpytest()
result.assert_outcomes(passed=1)