コード例 #1
0
ファイル: conftest.py プロジェクト: aodag/pip
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)
コード例 #2
0
ファイル: __init__.py プロジェクト: 1stvamp/pip
    def __init__(self, base_path, *args, **kwargs):
        # Make our base_path a test.lib.path.Path object
        base_path = Path(base_path)

        # Store paths related to the virtual environment
        _virtualenv = kwargs.pop("virtualenv")
        venv, lib, include, bin = virtualenv.path_locations(_virtualenv)
        self.venv_path = venv
        self.lib_path = lib
        self.include_path = include
        self.bin_path = bin

        if hasattr(sys, "pypy_version_info"):
            self.site_packages_path = self.venv_path.join("site-packages")
        else:
            self.site_packages_path = self.lib_path.join("site-packages")

        self.user_base_path = self.venv_path.join("user")
        self.user_bin_path = self.user_base_path.join(self.bin_path - self.venv_path)
        self.user_site_path = self.venv_path.join(
            "user",
            site.USER_SITE[len(site.USER_BASE) + 1:],
        )

        # Create a Directory to use as a scratch pad
        self.scratch_path = base_path.join("scratch").mkdir()

        # Set our default working directory
        kwargs.setdefault("cwd", self.scratch_path)

        # Setup our environment
        environ = kwargs.get("environ")
        if environ is None:
            environ = os.environ.copy()

        environ["PIP_LOG_FILE"] = base_path.join("pip-log.txt")
        environ["PATH"] = Path.pathsep.join(
            [self.bin_path] + [environ.get("PATH", [])],
        )
        environ["PYTHONUSERBASE"] = self.user_base_path
        # Writing bytecode can mess up updated file detection
        environ["PYTHONDONTWRITEBYTECODE"] = "1"
        kwargs["environ"] = environ

        # Call the TestFileEnvironment __init__
        super(PipTestEnvironment, self).__init__(base_path, *args, **kwargs)

        # Expand our absolute path directories into relative
        for name in ["base", "venv", "lib", "include", "bin", "site_packages",
                     "user_base", "user_site", "user_bin", "scratch"]:
            real_name = "%s_path" % name
            setattr(self, name, getattr(self, real_name) - self.base_path)

        # Ensure the tmp dir exists, things break horribly if it doesn't
        self.temp_path.mkdir()

        # create easy-install.pth in user_site, so we always have it updated
        #   instead of created
        self.user_site_path.makedirs()
        self.user_site_path.join("easy-install.pth").touch()
コード例 #3
0
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)
コード例 #4
0
ファイル: __init__.py プロジェクト: 1stvamp/pip
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))
コード例 #5
0
ファイル: __init__.py プロジェクト: xiaowzxqaq/pip-cn
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))
コード例 #6
0
def virtualenv_template(request, tmpdir_factory, pip_src, setuptools_install,
                        common_wheels):

    if six.PY3 and request.config.getoption('--use-venv'):
        venv_type = 'venv'
    else:
        venv_type = 'virtualenv'

    # Create the virtual environment
    tmpdir = Path(str(tmpdir_factory.mktemp('virtualenv')))
    venv = VirtualEnvironment(tmpdir.join("venv_orig"), venv_type=venv_type)

    # Install setuptools and pip.
    install_egg_link(venv, 'setuptools', setuptools_install)
    pip_editable = Path(str(tmpdir_factory.mktemp('pip'))) / 'pip'
    pip_src.copytree(pip_editable)
    assert compileall.compile_dir(str(pip_editable), quiet=1)
    subprocess.check_call([venv.bin / 'python', 'setup.py', '-q', 'develop'],
                          cwd=pip_editable)

    # Drop (non-relocatable) launchers.
    for exe in os.listdir(venv.bin):
        if not (exe.startswith('python')
                or exe.startswith('libpy')  # Don't remove libpypy-c.so...
                ):
            (venv.bin / exe).remove()

    # Enable user site packages.
    venv.user_site_packages = True

    # Rename original virtualenv directory to make sure
    # it's not reused by mistake from one of the copies.
    venv_template = tmpdir / "venv_template"
    venv.move(venv_template)
    yield venv
コード例 #7
0
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)
コード例 #8
0
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)
コード例 #9
0
ファイル: conftest.py プロジェクト: mkurnikov/pip
def virtualenv_template(request, tmpdir_factory, pip_src,
                        setuptools_install, common_wheels):

    if six.PY3 and request.config.getoption('--use-venv'):
        venv_type = 'venv'
    else:
        venv_type = 'virtualenv'

    # Create the virtual environment
    tmpdir = Path(str(tmpdir_factory.mktemp('virtualenv')))
    venv = VirtualEnvironment(tmpdir.join("venv_orig"), venv_type=venv_type)

    # Install setuptools and pip.
    install_egg_link(venv, 'setuptools', setuptools_install)
    pip_editable = Path(str(tmpdir_factory.mktemp('pip'))) / 'pip'
    pip_src.copytree(pip_editable)
    assert compileall.compile_dir(str(pip_editable), quiet=1)
    subprocess.check_call([venv.bin / 'python', 'setup.py', '-q', 'develop'],
                          cwd=pip_editable)

    # Drop (non-relocatable) launchers.
    for exe in os.listdir(venv.bin):
        if not (
            exe.startswith('python') or
            exe.startswith('libpy')  # Don't remove libpypy-c.so...
        ):
            (venv.bin / exe).remove()

    # Enable user site packages.
    venv.user_site_packages = True

    # Rename original virtualenv directory to make sure
    # it's not reused by mistake from one of the copies.
    venv_template = tmpdir / "venv_template"
    venv.move(venv_template)
    yield venv
コード例 #10
0
ファイル: __init__.py プロジェクト: twtyjvkg/pip
    def __init__(self, base_path, *args, **kwargs):
        # Make our base_path a test.lib.path.Path object
        base_path = Path(base_path)

        # Store paths related to the virtual environment
        _virtualenv = kwargs.pop("virtualenv")
        path_locations = virtualenv.path_locations(_virtualenv)
        # Make sure we have test.lib.path.Path objects
        venv, lib, include, bin = map(Path, path_locations)
        self.venv_path = venv
        self.lib_path = virtualenv_lib_path(venv, lib)
        self.include_path = include
        self.bin_path = bin

        if hasattr(sys, "pypy_version_info"):
            self.site_packages_path = self.venv_path.join("site-packages")
        else:
            self.site_packages_path = self.lib_path.join("site-packages")

        self.user_base_path = self.venv_path.join("user")
        self.user_site_path = self.venv_path.join(
            "user",
            site.USER_SITE[len(site.USER_BASE) + 1:],
        )
        if sys.platform == 'win32':
            if sys.version_info >= (3, 5):
                scripts_base = self.user_site_path.join('..').normpath
            else:
                scripts_base = self.user_base_path
            self.user_bin_path = scripts_base.join('Scripts')
        else:
            self.user_bin_path = self.user_base_path.join(self.bin_path -
                                                          self.venv_path)

        # Create a Directory to use as a scratch pad
        self.scratch_path = base_path.join("scratch").mkdir()

        # Set our default working directory
        kwargs.setdefault("cwd", self.scratch_path)

        # Setup our environment
        environ = kwargs.get("environ")
        if environ is None:
            environ = os.environ.copy()

        environ["PATH"] = Path.pathsep.join([self.bin_path] +
                                            [environ.get("PATH", [])], )
        environ["PYTHONUSERBASE"] = self.user_base_path
        # Writing bytecode can mess up updated file detection
        environ["PYTHONDONTWRITEBYTECODE"] = "1"
        # Make sure we get UTF-8 on output, even on Windows...
        environ["PYTHONIOENCODING"] = "UTF-8"
        kwargs["environ"] = environ

        # Call the TestFileEnvironment __init__
        super(PipTestEnvironment, self).__init__(base_path, *args, **kwargs)

        # Expand our absolute path directories into relative
        for name in [
                "base", "venv", "lib", "include", "bin", "site_packages",
                "user_base", "user_site", "user_bin", "scratch"
        ]:
            real_name = "%s_path" % name
            setattr(self, name, getattr(self, real_name) - self.base_path)

        # Make sure temp_path is a Path object
        self.temp_path = Path(self.temp_path)
        # Ensure the tmp dir exists, things break horribly if it doesn't
        self.temp_path.mkdir()

        # create easy-install.pth in user_site, so we always have it updated
        #   instead of created
        self.user_site_path.makedirs()
        self.user_site_path.join("easy-install.pth").touch()
コード例 #11
0
ファイル: __init__.py プロジェクト: cjerdonek/pip
    def __init__(self, base_path, *args, **kwargs):
        # Make our base_path a test.lib.path.Path object
        base_path = Path(base_path)

        # Store paths related to the virtual environment
        venv = kwargs.pop("virtualenv")
        self.venv_path = venv.location
        self.lib_path = venv.lib
        self.site_packages_path = venv.site
        self.bin_path = venv.bin

        self.user_base_path = self.venv_path.join("user")
        self.user_site_path = self.venv_path.join(
            "user",
            site.USER_SITE[len(site.USER_BASE) + 1:],
        )
        if sys.platform == 'win32':
            if sys.version_info >= (3, 5):
                scripts_base = self.user_site_path.join('..').normpath
            else:
                scripts_base = self.user_base_path
            self.user_bin_path = scripts_base.join('Scripts')
        else:
            self.user_bin_path = self.user_base_path.join(
                self.bin_path - self.venv_path
            )

        # Create a Directory to use as a scratch pad
        self.scratch_path = base_path.join("scratch").mkdir()

        # Set our default working directory
        kwargs.setdefault("cwd", self.scratch_path)

        # Setup our environment
        environ = kwargs.get("environ")
        if environ is None:
            environ = os.environ.copy()

        environ["PATH"] = Path.pathsep.join(
            [self.bin_path] + [environ.get("PATH", [])],
        )
        environ["PYTHONUSERBASE"] = self.user_base_path
        # Writing bytecode can mess up updated file detection
        environ["PYTHONDONTWRITEBYTECODE"] = "1"
        # Make sure we get UTF-8 on output, even on Windows...
        environ["PYTHONIOENCODING"] = "UTF-8"
        kwargs["environ"] = environ

        # Whether all pip invocations should expect stderr
        # (useful for Python version deprecation)
        self.pip_expect_warning = kwargs.pop('pip_expect_warning', None)

        # Call the TestFileEnvironment __init__
        super(PipTestEnvironment, self).__init__(base_path, *args, **kwargs)

        # Expand our absolute path directories into relative
        for name in ["base", "venv", "bin", "lib", "site_packages",
                     "user_base", "user_site", "user_bin", "scratch"]:
            real_name = "%s_path" % name
            setattr(self, name, getattr(self, real_name) - self.base_path)

        # Make sure temp_path is a Path object
        self.temp_path = Path(self.temp_path)
        # Ensure the tmp dir exists, things break horribly if it doesn't
        self.temp_path.mkdir()

        # create easy-install.pth in user_site, so we always have it updated
        #   instead of created
        self.user_site_path.makedirs()
        self.user_site_path.join("easy-install.pth").touch()
コード例 #12
0
    def __init__(self, base_path, *args, **kwargs):
        # Make our base_path a test.lib.path.Path object
        base_path = Path(base_path)

        # Store paths related to the virtual environment
        _virtualenv = kwargs.pop("virtualenv")
        venv, lib, include, bin = virtualenv.path_locations(_virtualenv)
        # workaround for https://github.com/pypa/virtualenv/issues/306
        if hasattr(sys, "pypy_version_info"):
            lib = os.path.join(venv, 'lib-python', pyversion)
        self.venv_path = venv
        self.lib_path = lib
        self.include_path = include
        self.bin_path = bin

        if hasattr(sys, "pypy_version_info"):
            self.site_packages_path = self.venv_path.join("site-packages")
        else:
            self.site_packages_path = self.lib_path.join("site-packages")

        self.user_base_path = self.venv_path.join("user")
        self.user_bin_path = self.user_base_path.join(self.bin_path -
                                                      self.venv_path)
        self.user_site_path = self.venv_path.join(
            "user",
            site.USER_SITE[len(site.USER_BASE) + 1:],
        )

        # Create a Directory to use as a scratch pad
        self.scratch_path = base_path.join("scratch").mkdir()

        # Set our default working directory
        kwargs.setdefault("cwd", self.scratch_path)

        # Setup our environment
        environ = kwargs.get("environ")
        if environ is None:
            environ = os.environ.copy()

        environ["PATH"] = Path.pathsep.join([self.bin_path] +
                                            [environ.get("PATH", [])], )
        environ["PYTHONUSERBASE"] = self.user_base_path
        # Writing bytecode can mess up updated file detection
        environ["PYTHONDONTWRITEBYTECODE"] = "1"
        kwargs["environ"] = environ

        # Call the TestFileEnvironment __init__
        super(PipTestEnvironment, self).__init__(base_path, *args, **kwargs)

        # Expand our absolute path directories into relative
        for name in [
                "base", "venv", "lib", "include", "bin", "site_packages",
                "user_base", "user_site", "user_bin", "scratch"
        ]:
            real_name = "%s_path" % name
            setattr(self, name, getattr(self, real_name) - self.base_path)

        # Make sure temp_path is a Path object
        self.temp_path = Path(self.temp_path)
        # Ensure the tmp dir exists, things break horribly if it doesn't
        self.temp_path.mkdir()

        # create easy-install.pth in user_site, so we always have it updated
        #   instead of created
        self.user_site_path.makedirs()
        self.user_site_path.join("easy-install.pth").touch()