当前位置: 首页>>代码示例>>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;未经允许,请勿转载。