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


Python pkg_resources.__getstate__方法代碼示例

本文整理匯總了Python中pkg_resources.__getstate__方法的典型用法代碼示例。如果您正苦於以下問題:Python pkg_resources.__getstate__方法的具體用法?Python pkg_resources.__getstate__怎麽用?Python pkg_resources.__getstate__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pkg_resources的用法示例。


在下文中一共展示了pkg_resources.__getstate__方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: save_pkg_resources_state

# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import __getstate__ [as 別名]
def save_pkg_resources_state():
    saved = pkg_resources.__getstate__()
    try:
        yield saved
    finally:
        pkg_resources.__setstate__(saved) 
開發者ID:jpush,項目名稱:jbox,代碼行數:8,代碼來源:sandbox.py

示例2: test_setup_requires_overrides_version_conflict

# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import __getstate__ [as 別名]
def test_setup_requires_overrides_version_conflict(self):
        """
        Regression test for issue #323.

        Ensures that a distribution's setup_requires requirements can still be
        installed and used locally even if a conflicting version of that
        requirement is already on the path.
        """

        pr_state = pkg_resources.__getstate__()
        fake_dist = PRDistribution('does-not-matter', project_name='foobar',
                                   version='0.0')
        working_set.add(fake_dist)

        try:
            with tempdir_context() as temp_dir:
                test_pkg = create_setup_requires_package(temp_dir)
                test_setup_py = os.path.join(test_pkg, 'setup.py')
                with quiet_context() as (stdout, stderr):
                    with reset_setup_stop_context():
                        try:
                            # Don't even need to install the package, just
                            # running the setup.py at all is sufficient
                            run_setup(test_setup_py, ['--name'])
                        except VersionConflict:
                            self.fail('Installing setup.py requirements '
                                'caused a VersionConflict')

                lines = stdout.readlines()
                self.assertTrue(len(lines) > 0)
                self.assertTrue(lines[-1].strip(), 'test_pkg')
        finally:
            pkg_resources.__setstate__(pr_state) 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:35,代碼來源:test_easy_install.py

示例3: save_pkg_resources_state

# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import __getstate__ [as 別名]
def save_pkg_resources_state():
    pr_state = pkg_resources.__getstate__()
    # also save sys.path
    sys_path = sys.path[:]
    try:
        yield pr_state, sys_path
    finally:
        sys.path[:] = sys_path
        pkg_resources.__setstate__(pr_state) 
開發者ID:pypa,項目名稱:setuptools,代碼行數:11,代碼來源:contexts.py

示例4: run_setup

# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import __getstate__ [as 別名]
def run_setup(setup_script, args):
    """Run a distutils setup script, sandboxed in its directory"""
    old_dir = os.getcwd()
    save_argv = sys.argv[:]
    save_path = sys.path[:]
    setup_dir = os.path.abspath(os.path.dirname(setup_script))
    temp_dir = os.path.join(setup_dir,'temp')
    if not os.path.isdir(temp_dir): os.makedirs(temp_dir)
    save_tmp = tempfile.tempdir
    save_modules = sys.modules.copy()
    pr_state = pkg_resources.__getstate__()
    try:
        tempfile.tempdir = temp_dir
        os.chdir(setup_dir)
        try:
            sys.argv[:] = [setup_script]+list(args)
            sys.path.insert(0, setup_dir)
            # reset to include setup dir, w/clean callback list
            working_set.__init__()
            working_set.callbacks.append(lambda dist:dist.activate())
            DirectorySandbox(setup_dir).run(
                lambda: execfile(
                    "setup.py",
                    {'__file__':setup_script, '__name__':'__main__'}
                )
            )
        except SystemExit:
            v = sys.exc_info()[1]
            if v.args and v.args[0]:
                raise
            # Normal exit, just return
    finally:
        pkg_resources.__setstate__(pr_state)
        sys.modules.update(save_modules)
        # remove any modules imported within the sandbox
        del_modules = [
            mod_name for mod_name in sys.modules
            if mod_name not in save_modules
            # exclude any encodings modules. See #285
            and not mod_name.startswith('encodings.')
        ]
        list(map(sys.modules.__delitem__, del_modules))
        os.chdir(old_dir)
        sys.path[:] = save_path
        sys.argv[:] = save_argv
        tempfile.tempdir = save_tmp 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:48,代碼來源:sandbox.py

示例5: run_setup

# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import __getstate__ [as 別名]
def run_setup(setup_script, args):
    """Run a distutils setup script, sandboxed in its directory"""
    old_dir = os.getcwd()
    save_argv = sys.argv[:]
    save_path = sys.path[:]
    setup_dir = os.path.abspath(os.path.dirname(setup_script))
    temp_dir = os.path.join(setup_dir,'temp')
    if not os.path.isdir(temp_dir): os.makedirs(temp_dir)
    save_tmp = tempfile.tempdir
    save_modules = sys.modules.copy()
    pr_state = pkg_resources.__getstate__()
    try:
        tempfile.tempdir = temp_dir
        os.chdir(setup_dir)
        try:
            sys.argv[:] = [setup_script]+list(args)
            sys.path.insert(0, setup_dir)
            # reset to include setup dir, w/clean callback list
            working_set.__init__()
            working_set.callbacks.append(lambda dist:dist.activate())
            def runner():
                ns = dict(__file__=setup_script, __name__='__main__')
                _execfile(setup_script, ns)
            DirectorySandbox(setup_dir).run(runner)
        except SystemExit:
            v = sys.exc_info()[1]
            if v.args and v.args[0]:
                raise
            # Normal exit, just return
    finally:
        pkg_resources.__setstate__(pr_state)
        sys.modules.update(save_modules)
        # remove any modules imported within the sandbox
        del_modules = [
            mod_name for mod_name in sys.modules
            if mod_name not in save_modules
            # exclude any encodings modules. See #285
            and not mod_name.startswith('encodings.')
        ]
        list(map(sys.modules.__delitem__, del_modules))
        os.chdir(old_dir)
        sys.path[:] = save_path
        sys.argv[:] = save_argv
        tempfile.tempdir = save_tmp 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:46,代碼來源:sandbox.py


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