def test_local_vcs_urls_work(PipenvInstance, pypi):
    with PipenvInstance(pypi=pypi, chdir=True) as p:
        six_path = Path(p.path).joinpath("six").absolute()
        c = delegator.run(
            "git clone " "https://github.com/benjaminp/six.git {0}".format(six_path)
        )
        assert c.return_code == 0

        c = p.pipenv("install git+{0}#egg=six".format(six_path.as_uri()))
        assert c.return_code == 0
def test_file_urls_work(PipenvInstance, pip_src_dir):
    with PipenvInstance(chdir=True) as p:
        whl = Path(__file__).parent.parent.joinpath(
            "pypi", "six", "six-1.11.0-py2.py3-none-any.whl"
        )
        try:
            whl = whl.resolve()
        except OSError:
            whl = whl.absolute()
        wheel_url = whl.as_uri()
        c = p.pipenv('install "{0}"'.format(wheel_url))
        assert c.return_code == 0
        assert "six" in p.pipfile["packages"]
        assert "file" in p.pipfile["packages"]["six"]
def test_install_venv_project_directory(PipenvInstance, pypi):
    """Test the project functionality during virtualenv creation.
    """
    with PipenvInstance(pypi=pypi, chdir=True) as p:
        with temp_environ(), TemporaryDirectory(
            prefix="pipenv-", suffix="temp_workon_home"
        ) as workon_home:
            os.environ["WORKON_HOME"] = workon_home.name
            if "PIPENV_VENV_IN_PROJECT" in os.environ:
                del os.environ["PIPENV_VENV_IN_PROJECT"]

            c = p.pipenv("install six")
            assert c.return_code == 0

            venv_loc = None
            for line in c.err.splitlines():
                if line.startswith("Virtualenv location:"):
                    venv_loc = Path(line.split(":", 1)[-1].strip())
            assert venv_loc is not None
            assert venv_loc.joinpath(".project").exists()
def test_get_vcs_refs(PipenvInstance, pip_src_dir):
    with PipenvInstance(chdir=True) as p:
        c = p.pipenv(
            "install -e git+https://github.com/benjaminp/[email protected]#egg=six"
        )
        assert c.return_code == 0
        assert "six" in p.pipfile["packages"]
        assert "six" in p.lockfile["default"]
        assert (
            p.lockfile["default"]["six"]["ref"]
            == "5efb522b0647f7467248273ec1b893d06b984a59"
        )
        pipfile = Path(p.pipfile_path)
        new_content = pipfile.read_bytes().replace(b"1.9.0", b"1.11.0")
        pipfile.write_bytes(new_content)
        c = p.pipenv("lock")
        assert c.return_code == 0
        assert (
            p.lockfile["default"]["six"]["ref"]
            == "15e31431af97e5e64b80af0a3f598d382bcdd49a"
        )
        assert "six" in p.pipfile["packages"]
        assert "six" in p.lockfile["default"]
Exemple #5
0
def local_tempdir(request):
    old_temp = os.environ.get("TEMP", "")
    new_temp = Path(os.getcwd()).absolute() / "temp"
    new_temp.mkdir(parents=True, exist_ok=True)
    os.environ["TEMP"] = new_temp.as_posix()

    def finalize():
        os.environ['TEMP'] = fs_str(old_temp)
        _rmtree_func(new_temp.as_posix())

    request.addfinalizer(finalize)
    with TemporaryDirectory(dir=new_temp.as_posix()) as temp_dir:
        yield Path(temp_dir.name)
Exemple #6
0
    def __init__(self, pypi=None, pipfile=True, chdir=False):
        self.pypi = pypi
        self.original_umask = os.umask(0o007)
        self.original_dir = os.path.abspath(os.curdir)
        self._path = TemporaryDirectory(suffix='-project', prefix='pipenv-')
        path = Path(self._path.name)
        try:
            self.path = str(path.resolve())
        except OSError:
            self.path = str(path.absolute())
        # set file creation perms
        self.pipfile_path = None
        self.chdir = chdir

        if self.pypi:
            os.environ['PIPENV_TEST_INDEX'] = '{0}/simple'.format(self.pypi.url)

        if pipfile:
            p_path = os.sep.join([self.path, 'Pipfile'])
            with open(p_path, 'a'):
                os.utime(p_path, None)

            self.chdir = False or chdir
            self.pipfile_path = p_path
def test_file_urls_work(PipenvInstance, pip_src_dir):
    with PipenvInstance(chdir=True) as p:
        whl = (
            Path(__file__).parent.parent
            .joinpath('pypi', 'six', 'six-1.11.0-py2.py3-none-any.whl')
        )
        try:
            whl = whl.resolve()
        except OSError:
            whl = whl.absolute()
        wheel_url = whl.as_uri()
        c = p.pipenv('install "{0}"'.format(wheel_url))
        assert c.return_code == 0
        assert 'six' in p.pipfile['packages']
        assert 'file' in p.pipfile['packages']['six']
Exemple #8
0
    def __init__(self, pypi=None, pipfile=True, chdir=False):
        self.pypi = pypi
        self.original_umask = os.umask(0o007)
        self.original_dir = os.path.abspath(os.curdir)
        self._path = TemporaryDirectory(suffix='-project', prefix='pipenv-')
        path = Path(self._path.name)
        try:
            self.path = str(path.resolve())
        except OSError:
            self.path = str(path.absolute())
        # set file creation perms
        self.pipfile_path = None
        self.chdir = chdir

        if self.pypi:
            os.environ['PIPENV_TEST_INDEX'] = '{0}/simple'.format(self.pypi.url)

        if pipfile:
            p_path = os.sep.join([self.path, 'Pipfile'])
            with open(p_path, 'a'):
                os.utime(p_path, None)

            self.chdir = False or chdir
            self.pipfile_path = p_path
Exemple #9
0
def test_venv_file_exists(PipenvInstance, pypi):
    """Tests virtualenv creation & package installation when a .venv file exists
    at the project root.
    """
    with PipenvInstance(pypi=pypi, chdir=True) as p:
        file_path = os.path.join(p.path, '.venv')
        with open(file_path, 'w') as f:
            f.write('')

        with temp_environ(), TemporaryDirectory(
                prefix='pipenv-', suffix='temp_workon_home') as workon_home:
            os.environ['WORKON_HOME'] = workon_home.name
            if 'PIPENV_VENV_IN_PROJECT' in os.environ:
                del os.environ['PIPENV_VENV_IN_PROJECT']

            c = p.pipenv('install requests')
            assert c.return_code == 0

            venv_loc = None
            for line in c.err.splitlines():
                if line.startswith('Virtualenv location:'):
                    venv_loc = Path(line.split(':', 1)[-1].strip())
            assert venv_loc is not None
            assert venv_loc.joinpath('.project').exists()
Exemple #10
0
 def create(self):
     python = Path(sys.executable).absolute().as_posix()
     cmd = [python, "-m", "virtualenv", self.path.absolute().as_posix()]
     c = run(
         cmd,
         verbose=False,
         return_object=True,
         write_to_stdout=False,
         combine_stderr=False,
         block=True,
         nospin=True,
     )
     # cmd = "{0} -m virtualenv {1}".format(python, self.path.as_posix())
     # c = delegator.run(cmd, block=True)
     assert c.returncode == 0
Exemple #11
0
def test_install_venv_project_directory(PipenvInstance, pypi):
    """Test pew's project functionality during virtualenv creation.

    Since .venv virtualenvs are not created with pew, we need to swap to a
    workon_home based virtualenv for this test.
    """
    with PipenvInstance(pypi=pypi, chdir=True) as p:
        with temp_environ(), TemporaryDirectory(
                prefix='pipenv-', suffix='temp_workon_home') as workon_home:
            os.environ['WORKON_HOME'] = workon_home.name
            if 'PIPENV_VENV_IN_PROJECT' in os.environ:
                del os.environ['PIPENV_VENV_IN_PROJECT']
            c = p.pipenv('install six')
            assert c.return_code == 0
            project = Project()
            assert Path(
                project.virtualenv_location).joinpath('.project').exists()
Exemple #12
0
def test_system_and_deploy_work(PipenvInstance):
    with PipenvInstance(chdir=True) as p:
        c = p.pipenv("install tablib")
        assert c.return_code == 0
        c = p.pipenv("--rm")
        assert c.return_code == 0
        c = delegator.run("virtualenv .venv")
        assert c.return_code == 0
        c = p.pipenv("install --system --deploy")
        assert c.return_code == 0
        c = p.pipenv("--rm")
        assert c.return_code == 0
        Path(p.pipfile_path).write_text(u"""
[packages]
tablib = "*"
        """.strip())
        c = p.pipenv("install --system")
        assert c.return_code == 0
def test_system_and_deploy_work(PipenvInstance):
    with PipenvInstance(chdir=True) as p:
        c = p.pipenv("install tablib")
        assert c.returncode == 0
        c = p.pipenv("--rm")
        assert c.returncode == 0
        c = subprocess_run(["virtualenv", ".venv"])
        assert c.returncode == 0
        c = p.pipenv("install --system --deploy")
        assert c.returncode == 0
        c = p.pipenv("--rm")
        assert c.returncode == 0
        Path(p.pipfile_path).write_text("""
[packages]
tablib = "*"
        """.strip())
        c = p.pipenv("install --system")
        assert c.returncode == 0
Exemple #14
0
def test_system_and_deploy_work(PipenvInstance, pypi):
    with PipenvInstance(chdir=True, pypi=pypi) as p:
        c = p.pipenv('install six requests')
        assert c.return_code == 0
        c = p.pipenv('--rm')
        assert c.return_code == 0
        c = delegator.run('virtualenv .venv')
        assert c.return_code == 0
        c = p.pipenv('install --system --deploy')
        assert c.return_code == 0
        c = p.pipenv('--rm')
        assert c.return_code == 0
        Path(p.pipfile_path).write_text(u"""
[packages]
requests
        """.strip())
        c = p.pipenv('install --system')
        assert c.return_code == 0
Exemple #15
0
 def __init__(self, name="venv", base_dir=None):
     if base_dir is None:
         base_dir = Path(_create_tracked_dir())
     self.base_dir = base_dir
     self.name = name
     self.path = (base_dir / name).resolve()
Exemple #16
0
    def __init__(self,
                 pypi=None,
                 pipfile=True,
                 chdir=True,
                 path=None,
                 capfd=None,
                 venv_root=None,
                 ignore_virtualenvs=True,
                 venv_in_project=True,
                 name=None):
        self.index_url = os.getenv("PIPENV_TEST_INDEX")
        self.pypi = None
        self.env = {}
        self.capfd = capfd
        if pypi:
            self.pypi = pypi.url
        elif self.index_url is not None:
            self.pypi, _, _ = self.index_url.rpartition(
                "/") if self.index_url else ""
        self.index = os.getenv("PIPENV_PYPI_INDEX")
        self.env["PYTHONWARNINGS"] = "ignore:DEPRECATION"
        if ignore_virtualenvs:
            self.env["PIPENV_IGNORE_VIRTUALENVS"] = fs_str("1")
        if venv_root:
            self.env["VIRTUAL_ENV"] = venv_root
        if venv_in_project:
            self.env["PIPENV_VENV_IN_PROJECT"] = fs_str("1")
        else:
            self.env.pop("PIPENV_VENV_IN_PROJECT", None)

        self.original_dir = Path(__file__).parent.parent.parent
        path = path if path else os.environ.get("PIPENV_PROJECT_DIR", None)
        if name is not None:
            path = Path(os.environ["HOME"]) / "projects" / name
            path.mkdir(exist_ok=True)
        if not path:
            path = TemporaryDirectory(suffix='-project', prefix='pipenv-')
        if isinstance(path, TemporaryDirectory):
            self._path = path
            path = Path(self._path.name)
            try:
                self.path = str(path.resolve())
            except OSError:
                self.path = str(path.absolute())
        elif isinstance(path, Path):
            self._path = path
            try:
                self.path = str(path.resolve())
            except OSError:
                self.path = str(path.absolute())
        else:
            self._path = path
            self.path = path
        # set file creation perms
        self.pipfile_path = None
        self.chdir = chdir

        if self.pypi and "PIPENV_PYPI_URL" not in os.environ:
            self.env['PIPENV_PYPI_URL'] = fs_str(f'{self.pypi}')
            # os.environ['PIPENV_PYPI_URL'] = fs_str('{0}'.format(self.pypi.url))
            # os.environ['PIPENV_TEST_INDEX'] = fs_str('{0}/simple'.format(self.pypi.url))

        if pipfile:
            p_path = os.sep.join([self.path, 'Pipfile'])
            with open(p_path, 'a'):
                os.utime(p_path, None)

            self.chdir = False or chdir
            self.pipfile_path = p_path
            self._pipfile = _Pipfile(Path(p_path))
Exemple #17
0
 def get_fixture_path(cls, path):
     return Path(
         __file__).absolute().parent.parent / "test_artifacts" / path
Exemple #18
0
 def create_tmpdir():
     return Path(_create_tracked_dir())
Exemple #19
0
def vistir_tmpdir():
    temp_path = _create_tracked_dir()
    yield Path(temp_path)
Exemple #20
0
def pathlib_tmpdir(request, tmpdir):
    yield Path(str(tmpdir))
    try:
        tmpdir.remove(ignore_errors=True)
    except Exception:
        pass
Exemple #21
0
    def __init__(self,
                 pypi=None,
                 pipfile=True,
                 chdir=False,
                 path=None,
                 home_dir=None,
                 venv_root=None,
                 ignore_virtualenvs=True,
                 venv_in_project=True,
                 name=None):
        self.pypi = pypi
        if ignore_virtualenvs:
            os.environ["PIPENV_IGNORE_VIRTUALENVS"] = fs_str("1")
        if venv_root:
            os.environ["VIRTUAL_ENV"] = venv_root
        if venv_in_project:
            os.environ["PIPENV_VENV_IN_PROJECT"] = fs_str("1")
        else:
            os.environ.pop("PIPENV_VENV_IN_PROJECT", None)

        self.original_dir = os.path.abspath(os.curdir)
        path = path if path else os.environ.get("PIPENV_PROJECT_DIR", None)
        if name is not None:
            path = Path(os.environ["HOME"]) / "projects" / name
            path.mkdir(exist_ok=True)
        if not path:
            path = TemporaryDirectory(suffix='-project', prefix='pipenv-')
        if isinstance(path, TemporaryDirectory):
            self._path = path
            path = Path(self._path.name)
            try:
                self.path = str(path.resolve())
            except OSError:
                self.path = str(path.absolute())
        elif isinstance(path, Path):
            self._path = path
            try:
                self.path = str(path.resolve())
            except OSError:
                self.path = str(path.absolute())
        else:
            self._path = path
            self.path = path
        # set file creation perms
        self.pipfile_path = None
        self.chdir = chdir

        if self.pypi:
            os.environ['PIPENV_PYPI_URL'] = fs_str('{0}'.format(self.pypi.url))
            os.environ['PIPENV_TEST_INDEX'] = fs_str('{0}/simple'.format(
                self.pypi.url))

        if pipfile:
            p_path = os.sep.join([self.path, 'Pipfile'])
            with open(p_path, 'a'):
                os.utime(p_path, None)

            self.chdir = False or chdir
            self.pipfile_path = p_path
            self._pipfile = _Pipfile(Path(p_path))
Exemple #22
0
 def create(self):
     python = Path(sys.executable).as_posix()
     cmd = "{0} -m virtualenv {1}".format(python, self.path.as_posix())
     c = delegator.run(cmd, block=True)
     assert c.return_code == 0