Skip to content

Commit

Permalink
Load the pip version from the correct prefix
Browse files Browse the repository at this point in the history
- Respect `--system` when it is supplied during install
- Fixes #4220

Signed-off-by: Dan Ryan <dan.ryan@canonical.com>
  • Loading branch information
techalchemy committed May 19, 2020
1 parent 23a2e7c commit 5c95ec9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
1 change: 1 addition & 0 deletions news/4220.bugfix.rst
@@ -0,0 +1 @@
Fixed a bug which caused pipenv to search non-existent virtual environments for ``pip`` when installing using ``--system``.
9 changes: 6 additions & 3 deletions pipenv/core.py
Expand Up @@ -1335,8 +1335,10 @@ def get_pip_args(
no_deps=False, # type: bool,
selective_upgrade=False, # type: bool
src_dir=None, # type: Optional[str]
allow_global=False, # type: bool
):
# type: (...) -> List[str]
from .environment import Environment
from .vendor.packaging.version import parse as parse_version
arg_map = {
"pre": ["--pre"],
Expand All @@ -1352,9 +1354,10 @@ def get_pip_args(
],
"src_dir": src_dir,
}
if project.environment.pip_version >= parse_version("19.0"):
environment = project.get_environment(allow_global=allow_global)
if environment.pip_version >= parse_version("19.0"):
arg_map["no_use_pep517"].append("--no-use-pep517")
if project.environment.pip_version < parse_version("19.1"):
if environment.pip_version < parse_version("19.1"):
arg_map["no_use_pep517"].append("--no-build-isolation")
arg_set = []
for key in arg_map.keys():
Expand Down Expand Up @@ -1495,7 +1498,7 @@ def pip_install(
pip_args = get_pip_args(
pre=pre, verbose=environments.is_verbose(), upgrade=True,
selective_upgrade=selective_upgrade, no_use_pep517=not use_pep517,
no_deps=no_deps, require_hashes=not ignore_hashes
no_deps=no_deps, require_hashes=not ignore_hashes, allow_global=allow_global
)
pip_command.extend(pip_args)
if r:
Expand Down
35 changes: 22 additions & 13 deletions pipenv/project.py
Expand Up @@ -25,7 +25,7 @@
from .environments import (
PIPENV_DEFAULT_PYTHON_VERSION, PIPENV_IGNORE_VIRTUALENVS, PIPENV_MAX_DEPTH,
PIPENV_PIPFILE, PIPENV_PYTHON, PIPENV_TEST_INDEX, PIPENV_VENV_IN_PROJECT,
is_in_virtualenv, is_type_checking
PIPENV_USE_SYSTEM, is_in_virtualenv, is_type_checking
)
from .vendor.requirementslib.models.utils import get_default_pyproject_backend
from .utils import (
Expand Down Expand Up @@ -328,21 +328,30 @@ def pipfile_package_names(self):
"combined": dev_keys | default_keys
}

def get_environment(self, allow_global=False):
# type: (bool) -> Environment
if allow_global:
prefix = sys.prefix
else:
prefix = self.virtualenv_location
is_venv = is_in_virtualenv()
sources = self.sources if self.sources else [DEFAULT_SOURCE]
environment = Environment(
prefix=prefix, is_venv=is_venv, sources=sources, pipfile=self.parsed_pipfile,
project=self
)
pipenv_dist = get_pipenv_dist(pkg="pipenv")
if pipenv_dist:
environment.extend_dists(pipenv_dist)
else:
environment.add_dist("pipenv")
return environment

@property
def environment(self):
if not self._environment:
prefix = self.virtualenv_location
is_venv = is_in_virtualenv()
sources = self.sources if self.sources else [DEFAULT_SOURCE]
self._environment = Environment(
prefix=prefix, is_venv=is_venv, sources=sources, pipfile=self.parsed_pipfile,
project=self
)
pipenv_dist = get_pipenv_dist(pkg="pipenv")
if pipenv_dist:
self._environment.extend_dists(pipenv_dist)
else:
self._environment.add_dist("pipenv")
allow_global = os.environ.get("PIPENV_USE_SYSTEM", PIPENV_USE_SYSTEM)
self._environment = self.get_environment(allow_global=allow_global)
return self._environment

def get_outdated_packages(self):
Expand Down

0 comments on commit 5c95ec9

Please sign in to comment.