python_requirement_solution.py (poetry-1.1.15) | : | python_requirement_solution.py (poetry-1.2.0) | ||
---|---|---|---|---|
from __future__ import annotations | ||||
from typing import TYPE_CHECKING | ||||
from crashtest.contracts.solution import Solution | from crashtest.contracts.solution import Solution | |||
class PythonRequirementSolution(Solution): | if TYPE_CHECKING: | |||
def __init__(self, exception): | from poetry.mixology.failure import SolveFailure | |||
from poetry.core.semver import parse_constraint | from poetry.puzzle.exceptions import SolverProblemError | |||
class PythonRequirementSolution(Solution): # type: ignore[misc] | ||||
def __init__(self, exception: SolverProblemError) -> None: | ||||
from poetry.core.semver.helpers import parse_constraint | ||||
from poetry.mixology.incompatibility_cause import PythonCause | from poetry.mixology.incompatibility_cause import PythonCause | |||
self._title = "Check your dependencies Python requirement." | self._title = "Check your dependencies Python requirement." | |||
failure = exception.error | failure: SolveFailure = exception.error | |||
version_solutions = [] | version_solutions = [] | |||
for incompatibility in failure._incompatibility.external_incompatibiliti es: | for incompatibility in failure._incompatibility.external_incompatibiliti es: | |||
if isinstance(incompatibility.cause, PythonCause): | if isinstance(incompatibility.cause, PythonCause): | |||
root_constraint = parse_constraint( | root_constraint = parse_constraint( | |||
incompatibility.cause.root_python_version | incompatibility.cause.root_python_version | |||
) | ) | |||
constraint = parse_constraint(incompatibility.cause.python_versi on) | constraint = parse_constraint(incompatibility.cause.python_versi on) | |||
version_solutions.append( | version_solutions.append( | |||
"For <fg=default;options=bold>{}</>, a possible solution wou | "For <fg=default;options=bold>" | |||
ld be " | f"{incompatibility.terms[0].dependency.name}</>," | |||
'to set the `<fg=default;options=bold>python</>` property to | " a possible solution would be to set the" | |||
<fg=yellow>"{}"</>'.format( | " `<fg=default;options=bold>python</>` property to" | |||
incompatibility.terms[0].dependency.name, | f' <fg=yellow>"{root_constraint.intersect(constraint)}"</>' | |||
root_constraint.intersect(constraint), | ||||
) | ||||
) | ) | |||
description = ( | description = ( | |||
"The Python requirement can be specified via the `<fg=default;option | "The Python requirement can be specified via the" | |||
s=bold>python</>` " | " `<fg=default;options=bold>python</>` or" | |||
"or `<fg=default;options=bold>markers</>` properties" | " `<fg=default;options=bold>markers</>` properties" | |||
) | ) | |||
if version_solutions: | if version_solutions: | |||
description += "\n\n" + "\n".join(version_solutions) | description += "\n\n" + "\n".join(version_solutions) | |||
description += "\n" | description += "\n" | |||
self._description = description | self._description = description | |||
@property | @property | |||
def solution_title(self) -> str: | def solution_title(self) -> str: | |||
return self._title | return self._title | |||
@property | @property | |||
def solution_description(self): | def solution_description(self) -> str: | |||
return self._description | return self._description | |||
@property | @property | |||
def documentation_links(self): | def documentation_links(self) -> list[str]: | |||
return [ | return [ | |||
"https://python-poetry.org/docs/dependency-specification/#python-res | "https://python-poetry.org/docs/dependency-specification/#python-res | |||
tricted-dependencies", | tricted-dependencies", # noqa: E501 | |||
"https://python-poetry.org/docs/dependency-specification/#using-envi | "https://python-poetry.org/docs/dependency-specification/#using-envi | |||
ronment-markers", | ronment-markers", # noqa: E501 | |||
] | ] | |||
End of changes. 8 change blocks. | ||||
20 lines changed or deleted | 27 lines changed or added |