-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
233 additions
and
50 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .python_requirement_solution_provider import PythonRequirementSolutionProvider |
30 changes: 30 additions & 0 deletions
30
poetry/mixology/solutions/providers/python_requirement_solution_provider.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import re | ||
|
||
from typing import List | ||
|
||
from crashtest.contracts.has_solutions_for_exception import HasSolutionsForException | ||
from crashtest.contracts.solution import Solution | ||
|
||
|
||
class PythonRequirementSolutionProvider(HasSolutionsForException): | ||
def can_solve(self, exception): # type: (Exception) -> bool | ||
from poetry.puzzle.exceptions import SolverProblemError | ||
|
||
if not isinstance(exception, SolverProblemError): | ||
return False | ||
|
||
m = re.match( | ||
"^The current project's Python requirement (.+) is not compatible " | ||
"with some of the required packages Python requirement", | ||
str(exception), | ||
) | ||
|
||
if not m: | ||
return False | ||
|
||
return True | ||
|
||
def get_solutions(self, exception): # type: (Exception) -> List[Solution] | ||
from ..solutions.python_requirement_solution import PythonRequirementSolution | ||
|
||
return [PythonRequirementSolution(exception)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .python_requirement_solution import PythonRequirementSolution |
52 changes: 52 additions & 0 deletions
52
poetry/mixology/solutions/solutions/python_requirement_solution.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from crashtest.contracts.solution import Solution | ||
|
||
|
||
class PythonRequirementSolution(Solution): | ||
def __init__(self, exception): | ||
from poetry.mixology.incompatibility_cause import PythonCause | ||
from poetry.core.semver import parse_constraint | ||
|
||
self._title = "Check your dependencies Python requirement." | ||
|
||
failure = exception.error | ||
version_solutions = [] | ||
for incompatibility in failure._incompatibility.external_incompatibilities: | ||
if isinstance(incompatibility.cause, PythonCause): | ||
root_constraint = parse_constraint( | ||
incompatibility.cause.root_python_version | ||
) | ||
constraint = parse_constraint(incompatibility.cause.python_version) | ||
|
||
version_solutions.append( | ||
"For <fg=default;options=bold>{}</>, a possible solution would be " | ||
'to set the `<fg=default;options=bold>python</>` property to <fg=yellow>"{}"</>'.format( | ||
incompatibility.terms[0].dependency.name, | ||
root_constraint.intersect(constraint), | ||
) | ||
) | ||
|
||
description = ( | ||
"The Python requirement can be specified via the `<fg=default;options=bold>python</>` " | ||
"or `<fg=default;options=bold>markers</>` properties" | ||
) | ||
if version_solutions: | ||
description += "\n\n" + "\n".join(version_solutions) | ||
|
||
description += "\n" | ||
|
||
self._description = description | ||
|
||
@property | ||
def solution_title(self) -> str: | ||
return self._title | ||
|
||
@property | ||
def solution_description(self): | ||
return self._description | ||
|
||
@property | ||
def documentation_links(self): | ||
return [ | ||
"https://python-poetry.org/docs/dependency-specification/#python-restricted-dependencies", | ||
"https://python-poetry.org/docs/dependency-specification/#using-environment-markers", | ||
] |
Oops, something went wrong.