2020-10-20 03:30:15 +02:00
|
|
|
from collections import defaultdict
|
|
|
|
from logging import getLogger
|
|
|
|
|
|
|
|
from pip._vendor.resolvelib.reporters import BaseReporter
|
|
|
|
|
2020-10-20 03:37:14 +02:00
|
|
|
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
|
|
|
|
|
|
|
if MYPY_CHECK_RUNNING:
|
|
|
|
from typing import DefaultDict
|
|
|
|
|
|
|
|
from .base import Candidate
|
|
|
|
|
|
|
|
|
2020-10-20 03:30:15 +02:00
|
|
|
logger = getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class PipReporter(BaseReporter):
|
|
|
|
|
|
|
|
def __init__(self):
|
2020-10-20 03:37:14 +02:00
|
|
|
# type: () -> None
|
|
|
|
self.backtracks_by_package = defaultdict(int) # type: DefaultDict[str, int]
|
2020-10-20 03:30:15 +02:00
|
|
|
|
|
|
|
self._messages_at_backtrack = {
|
2020-10-26 12:07:10 +01:00
|
|
|
1: (
|
|
|
|
"pip is looking at multiple versions of this package to determine "
|
|
|
|
"which version is compatible with other requirements. "
|
|
|
|
"This could take a while."
|
|
|
|
),
|
2020-10-20 03:30:15 +02:00
|
|
|
8: (
|
|
|
|
"pip is looking at multiple versions of this package to determine "
|
|
|
|
"which version is compatible with other requirements. "
|
|
|
|
"This could take a while."
|
|
|
|
),
|
|
|
|
13: (
|
|
|
|
"This is taking longer than usual. You might need to provide the "
|
|
|
|
"dependency resolver with stricter constraints to reduce runtime."
|
|
|
|
"If you want to abort this run, you can press Ctrl + C to do so."
|
2020-10-26 20:52:13 +01:00
|
|
|
"To improve how pip performs, tell us that this happened here: "
|
|
|
|
"https://pip.pypa.io/surveys/backtracking"
|
2020-10-20 03:30:15 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
def backtracking(self, candidate):
|
2020-10-20 03:37:14 +02:00
|
|
|
# type: (Candidate) -> None
|
2020-10-20 03:30:15 +02:00
|
|
|
self.backtracks_by_package[candidate.name] += 1
|
|
|
|
|
|
|
|
count = self.backtracks_by_package[candidate.name]
|
|
|
|
if count not in self._messages_at_backtrack:
|
|
|
|
return
|
|
|
|
|
|
|
|
message = self._messages_at_backtrack[count]
|
2020-10-26 12:11:59 +01:00
|
|
|
logger.info("INFO: %s", message)
|