Skip to content

Commit

Permalink
Issue 5254 (#5255)
Browse files Browse the repository at this point in the history
* Fix for python not defaulting to the virtualenv during a pip install.  Add --ignore-installed flag.
  • Loading branch information
matteius authored Aug 15, 2022
1 parent c1924db commit dbea3f5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exclude: '^(pipenv/patched/|pipenv/vendor/|tests/)'
exclude: '^(pipenv/patched/|pipenv/vendor/|tests/|pipenv/pipenv.1)'

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
1 change: 1 addition & 0 deletions news/5254.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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.
20 changes: 9 additions & 11 deletions pipenv/core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import json as simplejson
import logging
import os
Expand All @@ -10,6 +8,7 @@
import warnings
from pathlib import Path
from posixpath import expandvars
from typing import Dict, List, Optional, Union

import dotenv
import pipfile
Expand All @@ -24,6 +23,7 @@
install_req_from_parsed_requirement,
)
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.dependencies import (
convert_deps_to_pip,
Expand All @@ -50,12 +50,9 @@
)
from pipenv.utils.spinner import create_spinner
from pipenv.vendor import click
from pipenv.vendor.requirementslib.models.requirements import Requirement

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]]

Expand Down Expand Up @@ -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..."))

command = [
project_python(project),
project_python(project, system=allow_global),
_get_runnable_pip(),
"uninstall",
"-y",
Expand Down Expand Up @@ -1529,9 +1526,10 @@ def pip_install(
)

pip_command = [
project._which("python", allow_global=allow_global),
project_python(project, system=allow_global),
_get_runnable_pip(),
"install",
"--ignore-installed",
]
pip_args = get_pip_args(
project,
Expand Down Expand Up @@ -2363,7 +2361,7 @@ def do_uninstall(
if package_name in packages_to_remove:
with project.environment.activated():
cmd = [
project_python(project),
project_python(project, system=system),
_get_runnable_pip(),
"uninstall",
package_name,
Expand Down Expand Up @@ -2669,7 +2667,7 @@ def do_check(
safety_path = os.path.join(
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.
cmd = _cmd + [Path(pep508checker_path).as_posix()]
c = run_command(cmd, is_verbose=project.s.is_verbose())
Expand Down Expand Up @@ -3017,7 +3015,7 @@ def do_clean(
)
# Uninstall the package.
cmd = [
project_python(project),
project_python(project, system=system),
_get_runnable_pip(),
"uninstall",
apparent_bad_package,
Expand Down

0 comments on commit dbea3f5

Please sign in to comment.