當前位置: 首頁>>代碼示例>>Python>>正文


Python compileall.compile_file方法代碼示例

本文整理匯總了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) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:test_compileall.py

示例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) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:18,代碼來源:test_compileall.py

示例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)) 
開發者ID:vstconsulting,項目名稱:polemarch,代碼行數:21,代碼來源:setup.py

示例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__'))) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:13,代碼來源:test_compileall.py

示例5: test_syntax

# 需要導入模塊: import compileall [as 別名]
# 或者: from compileall import compile_file [as 別名]
def test_syntax(item):
    assert compile_file(item) 
開發者ID:atc-project,項目名稱:atomic-threat-coverage,代碼行數:4,代碼來源:test_syntax.py

示例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) 
開發者ID:pytest-dev,項目名稱:pytest-mock,代碼行數:38,代碼來源:test_pytest_mock.py


注:本文中的compileall.compile_file方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。