Issue 5254 (#5255)

* Fix for python not defaulting to the virtualenv during a pip install.  Add --ignore-installed flag.
This commit is contained in:
Matt Davis
2022-08-14 23:44:19 -04:00
committed by GitHub
parent c1924dbf44
commit dbea3f5cb7
3 changed files with 11 additions and 12 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
exclude: '^(pipenv/patched/|pipenv/vendor/|tests/)' exclude: '^(pipenv/patched/|pipenv/vendor/|tests/|pipenv/pipenv.1)'
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
+1
View File
@@ -0,0 +1 @@
``pip_install`` method was using a different way of finding the python executable than other ``pipenv`` commands, which caused an issue with skipping package installation if it was already installed in site-packages.
+9 -11
View File
@@ -1,5 +1,3 @@
from __future__ import annotations
import json as simplejson import json as simplejson
import logging import logging
import os import os
@@ -10,6 +8,7 @@ import time
import warnings import warnings
from pathlib import Path from pathlib import Path
from posixpath import expandvars from posixpath import expandvars
from typing import Dict, List, Optional, Union
import dotenv import dotenv
import pipfile import pipfile
@@ -24,6 +23,7 @@ from pipenv.patched.pip._internal.req.constructors import (
install_req_from_parsed_requirement, install_req_from_parsed_requirement,
) )
from pipenv.patched.pip._internal.req.req_file import parse_requirements from pipenv.patched.pip._internal.req.req_file import parse_requirements
from pipenv.project import Project
from pipenv.utils.constants import MYPY_RUNNING from pipenv.utils.constants import MYPY_RUNNING
from pipenv.utils.dependencies import ( from pipenv.utils.dependencies import (
convert_deps_to_pip, convert_deps_to_pip,
@@ -50,12 +50,9 @@ from pipenv.utils.shell import (
) )
from pipenv.utils.spinner import create_spinner from pipenv.utils.spinner import create_spinner
from pipenv.vendor import click from pipenv.vendor import click
from pipenv.vendor.requirementslib.models.requirements import Requirement
if MYPY_RUNNING: if MYPY_RUNNING:
from typing import Dict, List, Optional, Union
from pipenv.project import Project
from pipenv.vendor.requirementslib.models.requirements import Requirement
TSourceDict = Dict[str, Union[str, bool]] TSourceDict = Dict[str, Union[str, bool]]
@@ -1211,7 +1208,7 @@ def do_purge(project, bare=False, downloads=False, allow_global=False):
click.echo(fix_utf8(f"Found {len(to_remove)} installed package(s), purging...")) click.echo(fix_utf8(f"Found {len(to_remove)} installed package(s), purging..."))
command = [ command = [
project_python(project), project_python(project, system=allow_global),
_get_runnable_pip(), _get_runnable_pip(),
"uninstall", "uninstall",
"-y", "-y",
@@ -1529,9 +1526,10 @@ def pip_install(
) )
pip_command = [ pip_command = [
project._which("python", allow_global=allow_global), project_python(project, system=allow_global),
_get_runnable_pip(), _get_runnable_pip(),
"install", "install",
"--ignore-installed",
] ]
pip_args = get_pip_args( pip_args = get_pip_args(
project, project,
@@ -2363,7 +2361,7 @@ def do_uninstall(
if package_name in packages_to_remove: if package_name in packages_to_remove:
with project.environment.activated(): with project.environment.activated():
cmd = [ cmd = [
project_python(project), project_python(project, system=system),
_get_runnable_pip(), _get_runnable_pip(),
"uninstall", "uninstall",
package_name, package_name,
@@ -2669,7 +2667,7 @@ def do_check(
safety_path = os.path.join( safety_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "patched", "safety" os.path.dirname(os.path.abspath(__file__)), "patched", "safety"
) )
_cmd = [project_python(project)] _cmd = [project_python(project, system=system)]
# Run the PEP 508 checker in the virtualenv. # Run the PEP 508 checker in the virtualenv.
cmd = _cmd + [Path(pep508checker_path).as_posix()] cmd = _cmd + [Path(pep508checker_path).as_posix()]
c = run_command(cmd, is_verbose=project.s.is_verbose()) c = run_command(cmd, is_verbose=project.s.is_verbose())
@@ -3017,7 +3015,7 @@ def do_clean(
) )
# Uninstall the package. # Uninstall the package.
cmd = [ cmd = [
project_python(project), project_python(project, system=system),
_get_runnable_pip(), _get_runnable_pip(),
"uninstall", "uninstall",
apparent_bad_package, apparent_bad_package,