Skip to content

Commit

Permalink
Merge pull request #8590 from pradyunsg/install-conflict-warning-move
Browse files Browse the repository at this point in the history
Change when we warn about dependency conflicts during `pip install`
  • Loading branch information
pradyunsg authored Jul 17, 2020
2 parents 02a1092 + 7ddbcc2 commit 2a07a24
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
31 changes: 22 additions & 9 deletions src/pip/_internal/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from typing import Iterable, List, Optional

from pip._internal.models.format_control import FormatControl
from pip._internal.operations.check import ConflictDetails
from pip._internal.req.req_install import InstallRequirement
from pip._internal.wheel_builder import BinaryAllowedPredicate

Expand Down Expand Up @@ -371,13 +372,14 @@ def run(self, options, args):
requirement_set
)

# Consistency Checking of the package set we're installing.
# Check for conflicts in the package set we're installing.
conflicts = None # type: Optional[ConflictDetails]
should_warn_about_conflicts = (
not options.ignore_dependencies and
options.warn_about_conflicts
)
if should_warn_about_conflicts:
self._warn_about_conflicts(to_install)
conflicts = self._determine_conflicts(to_install)

# Don't warn about script install locations if
# --target has been specified
Expand Down Expand Up @@ -419,6 +421,10 @@ def run(self, options, args):
except Exception:
pass
items.append(item)

if conflicts is not None:
self._warn_about_conflicts(conflicts)

installed_desc = ' '.join(items)
if installed_desc:
write_output(
Expand Down Expand Up @@ -498,16 +504,23 @@ def _handle_target_dir(self, target_dir, target_temp_dir, upgrade):
target_item_dir
)

def _warn_about_conflicts(self, to_install):
# type: (List[InstallRequirement]) -> None
def _determine_conflicts(self, to_install):
# type: (List[InstallRequirement]) -> Optional[ConflictDetails]
try:
package_set, _dep_info = check_install_conflicts(to_install)
return check_install_conflicts(to_install)
except Exception:
logger.error("Error checking for conflicts.", exc_info=True)
return
missing, conflicting = _dep_info
logger.error(
"Error while checking for conflicts. Please file an issue on "
"pip's issue tracker: https://github.com/pypa/pip/issues/new",
exc_info=True
)
return None

def _warn_about_conflicts(self, conflict_details):
# type: (ConflictDetails) -> None
package_set, (missing, conflicting) = conflict_details

# NOTE: There is some duplication here from pip check
# NOTE: There is some duplication here, with commands/check.py
for project_name in missing:
version = package_set[project_name][0]
for dependency in missing[project_name]:
Expand Down
3 changes: 2 additions & 1 deletion src/pip/_internal/operations/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
MissingDict = Dict[str, List[Missing]]
ConflictingDict = Dict[str, List[Conflicting]]
CheckResult = Tuple[MissingDict, ConflictingDict]
ConflictDetails = Tuple[PackageSet, CheckResult]

PackageDetails = namedtuple('PackageDetails', ['version', 'requires'])

Expand Down Expand Up @@ -99,7 +100,7 @@ def check_package_set(package_set, should_ignore=None):


def check_install_conflicts(to_install):
# type: (List[InstallRequirement]) -> Tuple[PackageSet, CheckResult]
# type: (List[InstallRequirement]) -> ConflictDetails
"""For checking if the dependency graph would be consistent after \
installing given requirements
"""
Expand Down

0 comments on commit 2a07a24

Please sign in to comment.