Skip to content

Commit

Permalink
Add solutions for common errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater committed May 8, 2020
1 parent 7049bd5 commit d2f8cda
Show file tree
Hide file tree
Showing 14 changed files with 246 additions and 50 deletions.
87 changes: 43 additions & 44 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions poetry/console/config/application_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from poetry.console.commands.env_command import EnvCommand
from poetry.console.logging.io_formatter import IOFormatter
from poetry.console.logging.io_handler import IOHandler
from poetry.utils._compat import PY36


class ApplicationConfig(BaseApplicationConfig):
Expand All @@ -46,6 +47,15 @@ def configure(self):
self.add_event_listener(PRE_HANDLE, self.register_command_loggers)
self.add_event_listener(PRE_HANDLE, self.set_env)

if PY36:
from poetry.solution_providers import (
PythonRequirementIncompatibilitySolutionProvider,
)

self._solution_provider_repository.register_solution_providers(
[PythonRequirementIncompatibilitySolutionProvider]
)

def register_command_loggers(
self, event, event_name, _
): # type: (PreHandleEvent, str, Any) -> None
Expand Down
9 changes: 8 additions & 1 deletion poetry/mixology/failure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from typing import List
from typing import Tuple

from poetry.core.semver import parse_constraint

from .incompatibility import Incompatibility
from .incompatibility_cause import ConflictCause
from .incompatibility_cause import PythonCause
Expand Down Expand Up @@ -44,10 +46,15 @@ def write(self):
)
required_python_version_notification = True

root_constraint = parse_constraint(
incompatibility.cause.root_python_version
)
constraint = parse_constraint(incompatibility.cause.python_version)
buffer.append(
" - {} requires Python {}".format(
" - {} requires Python {}, so it will not be satisfied for Python {}".format(
incompatibility.terms[0].dependency.name,
incompatibility.cause.python_version,
root_constraint.difference(constraint),
)
)

Expand Down
3 changes: 1 addition & 2 deletions poetry/mixology/version_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from poetry.core.packages import ProjectPackage
from poetry.core.semver import Version
from poetry.core.semver import VersionRange
from poetry.puzzle.provider import Provider

from .failure import SolveFailure
from .incompatibility import Incompatibility
Expand Down Expand Up @@ -40,7 +39,7 @@ class VersionSolver:
def __init__(
self,
root, # type: ProjectPackage
provider, # type: Provider
provider,
locked=None, # type: Dict[str, Package]
use_latest=None, # type: List[str]
):
Expand Down
3 changes: 3 additions & 0 deletions poetry/solution_providers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .python_requirement_incompatibility_solution_provider import (
PythonRequirementIncompatibilitySolutionProvider,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import re

from typing import List

from crashtest.contracts.has_solutions_for_exception import HasSolutionsForException
from crashtest.contracts.solution import Solution


class PythonRequirementIncompatibilitySolutionProvider(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 poetry.solutions.python_requirement_compatibility_solution import (
PythonRequirementCompatibilitySolution,
)

return [PythonRequirementCompatibilitySolution(exception)]
Empty file added poetry/solutions/__init__.py
Empty file.
Loading

0 comments on commit d2f8cda

Please sign in to comment.