当前位置: 首页>>代码示例>>Python>>正文


Python Path.rmtree方法代码示例

本文整理汇总了Python中tests.lib.path.Path.rmtree方法的典型用法代码示例。如果您正苦于以下问题:Python Path.rmtree方法的具体用法?Python Path.rmtree怎么用?Python Path.rmtree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tests.lib.path.Path的用法示例。


在下文中一共展示了Path.rmtree方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: virtualenv_template

# 需要导入模块: from tests.lib.path import Path [as 别名]
# 或者: from tests.lib.path.Path import rmtree [as 别名]
def virtualenv_template(tmpdir_factory):
    tmpdir = Path(str(tmpdir_factory.mktemp('virtualenv')))
    # Copy over our source tree so that each virtual environment is self
    # contained
    pip_src = tmpdir.join("pip_src").abspath
    shutil.copytree(
        SRC_DIR,
        pip_src,
        ignore=shutil.ignore_patterns(
            "*.pyc", "__pycache__", "contrib", "docs", "tasks", "*.txt",
            "tests", "pip.egg-info", "build", "dist", ".tox", ".git",
        ),
    )
    # Create the virtual environment
    venv = VirtualEnvironment.create(
        tmpdir.join("venv_orig"),
        pip_source_dir=pip_src,
        relocatable=True,
    )
    if sys.platform == 'win32':
        # Work around setuptools' easy_install.exe
        # not working properly after relocation.
        for exe in os.listdir(venv.bin):
            if exe.startswith('easy_install'):
                (venv.bin / exe).remove()
        with open(venv.bin / 'easy_install.bat', 'w') as fp:
            fp.write('python.exe -m easy_install %*\n')

    # Rename original virtualenv directory to make sure
    # it's not reused by mistake from one of the copies.
    venv_template = tmpdir / "venv_template"
    os.rename(venv.location, venv_template)
    yield venv_template
    tmpdir.rmtree(noerrors=True)
开发者ID:aodag,项目名称:pip,代码行数:36,代码来源:conftest.py

示例2: virtualenv_template

# 需要导入模块: from tests.lib.path import Path [as 别名]
# 或者: from tests.lib.path.Path import rmtree [as 别名]
def virtualenv_template(tmpdir_factory):
    tmpdir = Path(str(tmpdir_factory.mktemp('virtualenv')))
    # Copy over our source tree so that each virtual environment is self
    # contained
    pip_src = tmpdir.join("pip_src").abspath
    shutil.copytree(
        SRC_DIR,
        pip_src,
        ignore=shutil.ignore_patterns(
            "*.pyc", "__pycache__", "contrib", "docs", "tasks", "*.txt",
            "tests", "pip.egg-info", "build", "dist", ".tox", ".git",
        ),
    )
    # Create the virtual environment
    venv = VirtualEnvironment.create(
        tmpdir.join("venv_orig"),
        pip_source_dir=pip_src,
        relocatable=True,
    )
    # Rename original virtualenv directory to make sure
    # it's not reused by mistake from one of the copies.
    venv_template = tmpdir / "venv_template"
    os.rename(venv.location, venv_template)
    yield venv_template
    tmpdir.rmtree(noerrors=True)
开发者ID:oz123,项目名称:pip,代码行数:27,代码来源:conftest.py

示例3: virtualenv_template

# 需要导入模块: from tests.lib.path import Path [as 别名]
# 或者: from tests.lib.path.Path import rmtree [as 别名]
def virtualenv_template(tmpdir_factory, pip_src):
    tmpdir = Path(str(tmpdir_factory.mktemp('virtualenv')))
    # Create the virtual environment
    venv = VirtualEnvironment.create(
        tmpdir.join("venv_orig"),
        pip_source_dir=pip_src,
        relocatable=True,
    )
    # Fix `site.py`.
    site_py = venv.lib / 'site.py'
    with open(site_py) as fp:
        site_contents = fp.read()
    for pattern, replace in (
        (
            # Ensure `virtualenv.system_site_packages = True` (needed
            # for testing `--user`) does not result in adding the real
            # site-packages' directory to `sys.path`.
            (
                '\ndef virtual_addsitepackages(known_paths):\n'
            ),
            (
                '\ndef virtual_addsitepackages(known_paths):\n'
                '    return known_paths\n'
            ),
        ),
        (
            # Fix sites ordering: user site must be added before system site.
            (
                '\n    paths_in_sys = addsitepackages(paths_in_sys)'
                '\n    paths_in_sys = addusersitepackages(paths_in_sys)\n'
            ),
            (
                '\n    paths_in_sys = addusersitepackages(paths_in_sys)'
                '\n    paths_in_sys = addsitepackages(paths_in_sys)\n'
            ),
        ),
    ):
        assert pattern in site_contents
        site_contents = site_contents.replace(pattern, replace)
    with open(site_py, 'w') as fp:
        fp.write(site_contents)
    if sys.platform == 'win32':
        # Work around setuptools' easy_install.exe
        # not working properly after relocation.
        for exe in os.listdir(venv.bin):
            if exe.startswith('easy_install'):
                (venv.bin / exe).remove()
        with open(venv.bin / 'easy_install.bat', 'w') as fp:
            fp.write('python.exe -m easy_install %*\n')

    # Rename original virtualenv directory to make sure
    # it's not reused by mistake from one of the copies.
    venv_template = tmpdir / "venv_template"
    os.rename(venv.location, venv_template)
    yield venv_template
    tmpdir.rmtree(noerrors=True)
开发者ID:vtitor,项目名称:pip,代码行数:58,代码来源:conftest.py

示例4: TestData

# 需要导入模块: from tests.lib.path import Path [as 别名]
# 或者: from tests.lib.path.Path import rmtree [as 别名]
class TestData(object):
    """
    Represents a bundle of pre-created test data.

    This copies a pristine set of test data into a root location that is
    designed to be test specific. The reason for this is when running the tests
    concurrently errors can be generated because the related tooling uses
    the directory as a work space. This leads to two concurrent processes
    trampling over each other. This class gets around that by copying all
    data into a directory and operating on the copied data.
    """

    def __init__(self, root, source=None):
        self.source = source or DATA_DIR
        self.root = Path(root).abspath

    @classmethod
    def copy(cls, root):
        obj = cls(root)
        obj.reset()
        return obj

    def reset(self):
        self.root.rmtree()
        self.source.copytree(self.root)

    @property
    def packages(self):
        return self.root.join("packages")

    @property
    def packages2(self):
        return self.root.join("packages2")

    @property
    def indexes(self):
        return self.root.join("indexes")

    @property
    def reqfiles(self):
        return self.root.join("reqfiles")

    @property
    def find_links(self):
        return path_to_url(self.packages)

    @property
    def find_links2(self):
        return path_to_url(self.packages2)

    def index_url(self, index="simple"):
        return path_to_url(self.root.join("indexes", index))
开发者ID:1stvamp,项目名称:pip,代码行数:54,代码来源:__init__.py


注:本文中的tests.lib.path.Path.rmtree方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。