From 5c95ec9b9b572f158b2012f6c2b6015683957625 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Tue, 19 May 2020 17:01:11 -0400 Subject: [PATCH 1/4] Load the pip version from the correct prefix - Respect `--system` when it is supplied during install - Fixes #4220 Signed-off-by: Dan Ryan --- news/4220.bugfix.rst | 1 + pipenv/core.py | 9 ++++++--- pipenv/project.py | 35 ++++++++++++++++++++++------------- 3 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 news/4220.bugfix.rst diff --git a/news/4220.bugfix.rst b/news/4220.bugfix.rst new file mode 100644 index 0000000000..4a31e623fe --- /dev/null +++ b/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``. diff --git a/pipenv/core.py b/pipenv/core.py index b28af3491c..b83ac58ce0 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -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"], @@ -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(): @@ -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: diff --git a/pipenv/project.py b/pipenv/project.py index ee2219ef05..40b6b26364 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -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 ( @@ -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): From 8f3ba7ededfc2a3f765420fe03da0e9f65d0610b Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Tue, 19 May 2020 19:50:35 -0400 Subject: [PATCH 2/4] Add missing news entry Signed-off-by: Dan Ryan --- news/3506.feature.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/3506.feature.rst diff --git a/news/3506.feature.rst b/news/3506.feature.rst new file mode 100644 index 0000000000..e13861e52c --- /dev/null +++ b/news/3506.feature.rst @@ -0,0 +1 @@ +``pipenv install`` and ``pipenv sync`` will no longer attempt to install satisfied dependencies during installation. From 2c49876bcfff8877f6258c84c9ba76a0bdc10534 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Tue, 19 May 2020 22:06:25 -0400 Subject: [PATCH 3/4] Detect global setting at environment creation time Signed-off-by: Dan Ryan --- pipenv/core.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pipenv/core.py b/pipenv/core.py index b83ac58ce0..083726299d 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -1338,7 +1338,6 @@ def get_pip_args( 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"], @@ -1354,10 +1353,9 @@ def get_pip_args( ], "src_dir": src_dir, } - environment = project.get_environment(allow_global=allow_global) - if environment.pip_version >= parse_version("19.0"): + if project.environment.pip_version >= parse_version("19.0"): arg_map["no_use_pep517"].append("--no-use-pep517") - if environment.pip_version < parse_version("19.1"): + if project.environment.pip_version < parse_version("19.1"): arg_map["no_use_pep517"].append("--no-build-isolation") arg_set = [] for key in arg_map.keys(): From ed780c4061bcf9680332a29ed966733c6aed2eaa Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Wed, 20 May 2020 01:47:42 -0400 Subject: [PATCH 4/4] Tweak crayons patch with vendored imports - Remove now-unused `allow_global` argument to pip install argument builder - Update vistir version number and code to fix vendoring issue Signed-off-by: Dan Ryan --- pipenv/core.py | 3 +-- pipenv/patched/crayons.py | 4 ++-- pipenv/vendor/vendor.txt | 2 +- pipenv/vendor/vistir/misc.py | 7 +++++-- tasks/vendoring/patches/patched/crayons.patch | 5 +++-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pipenv/core.py b/pipenv/core.py index 083726299d..680e069ad6 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -1335,7 +1335,6 @@ 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 .vendor.packaging.version import parse as parse_version @@ -1496,7 +1495,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, allow_global=allow_global + no_deps=no_deps, require_hashes=not ignore_hashes, ) pip_command.extend(pip_args) if r: diff --git a/pipenv/patched/crayons.py b/pipenv/patched/crayons.py index de735dafe9..d7644a216a 100644 --- a/pipenv/patched/crayons.py +++ b/pipenv/patched/crayons.py @@ -12,8 +12,8 @@ import re import sys -import shellingham -import colorama +from pipenv.vendor import shellingham +from pipenv.vendor import colorama PY3 = sys.version_info[0] >= 3 diff --git a/pipenv/vendor/vendor.txt b/pipenv/vendor/vendor.txt index 98d1e86b41..3e08152026 100644 --- a/pipenv/vendor/vendor.txt +++ b/pipenv/vendor/vendor.txt @@ -38,7 +38,7 @@ six==1.14.0 semver==2.9.0 toml==0.10.1 cached-property==1.5.1 -vistir==0.5.1 +vistir==0.5.2 pip-shims==0.5.2 contextlib2==0.6.0.post1 funcsigs==1.0.2 diff --git a/pipenv/vendor/vistir/misc.py b/pipenv/vendor/vistir/misc.py index 83f30b3578..460e142bb7 100644 --- a/pipenv/vendor/vistir/misc.py +++ b/pipenv/vendor/vistir/misc.py @@ -207,11 +207,14 @@ def __init__( stdout_allowed=False, # type: bool ): # type: (...) -> None + stdout_encoding = None + stderr_encoding = None + preferred_encoding = getpreferredencoding() if subprocess is not None: stdout_encoding = self.get_subprocess_encoding(subprocess, "stdout") stderr_encoding = self.get_subprocess_encoding(subprocess, "stderr") - self.stdout_encoding = stdout_encoding or PREFERRED_ENCODING - self.stderr_encoding = stderr_encoding or PREFERRED_ENCODING + self.stdout_encoding = stdout_encoding or preferred_encoding + self.stderr_encoding = stderr_encoding or preferred_encoding self.stdout_lines = [] self.text_stdout_lines = [] self.stderr_lines = [] diff --git a/tasks/vendoring/patches/patched/crayons.patch b/tasks/vendoring/patches/patched/crayons.patch index d7fa3d40d5..2760ca81c1 100644 --- a/tasks/vendoring/patches/patched/crayons.patch +++ b/tasks/vendoring/patches/patched/crayons.patch @@ -8,8 +8,9 @@ index 455d3e90..de735daf 100644 -PY3 = sys.version_info[0] >= 3 - -+import shellingham - import colorama +-import colorama ++from pipenv.vendor import shellingham ++from pipenv.vendor import colorama +PY3 = sys.version_info[0] >= 3 +