Ejemplo n.º 1
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))
Ejemplo n.º 2
0
    def __init__(self, pypi=None, pipfile=True, chdir=False, path=None, home_dir=None):
        self.pypi = pypi
        self.original_umask = os.umask(0o007)
        self.original_dir = os.path.abspath(os.curdir)
        os.environ["PIPENV_NOSPIN"] = fs_str("1")
        os.environ["CI"] = fs_str("1")
        warnings.simplefilter("ignore", category=ResourceWarning)
        warnings.filterwarnings("ignore", category=ResourceWarning, message="unclosed.*<ssl.SSLSocket.*>")
        path = os.environ.get("PIPENV_PROJECT_DIR", None)
        if not path:
            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())
        else:
            self._path = None
            self.path = path
        # set file creation perms
        self.pipfile_path = None
        self.chdir = chdir

        if self.pypi:
            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
Ejemplo n.º 3
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
Ejemplo n.º 4
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"]
Ejemplo n.º 5
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"]
Ejemplo n.º 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
Ejemplo n.º 7
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))