Commit 286f4ddb by David Hotham Committed by GitHub

search_for should not raise ValueError to indicate that a package could not be found (#6790)

subclasses of ValueError like UnicodeEncodeError have to be propagated (see #6784)
parent 17e059e3
......@@ -5,7 +5,6 @@ from typing import TYPE_CHECKING
from poetry.mixology.incompatibility_cause import ConflictCause
from poetry.mixology.incompatibility_cause import DependencyCause
from poetry.mixology.incompatibility_cause import NoVersionsCause
from poetry.mixology.incompatibility_cause import PackageNotFoundCause
from poetry.mixology.incompatibility_cause import PlatformCause
from poetry.mixology.incompatibility_cause import PythonCause
from poetry.mixology.incompatibility_cause import RootCause
......@@ -146,11 +145,6 @@ class Incompatibility:
f"no versions of {self._terms[0].dependency.name} match"
f" {self._terms[0].constraint}"
)
elif isinstance(self._cause, PackageNotFoundCause):
assert len(self._terms) == 1
assert self._terms[0].is_positive()
return f"{self._terms[0].dependency.name} doesn't exist"
elif isinstance(self._cause, RootCause):
assert len(self._terms) == 1
assert not self._terms[0].is_positive()
......@@ -420,8 +414,6 @@ class Incompatibility:
buffer.append(f"which requires Python {cause.python_version}")
elif isinstance(latter.cause, NoVersionsCause):
buffer.append("which doesn't match any versions")
elif isinstance(latter.cause, PackageNotFoundCause):
buffer.append("which doesn't exist")
else:
buffer.append("which is forbidden")
......
......@@ -79,17 +79,3 @@ class PlatformCause(IncompatibilityCause):
@property
def platform(self) -> str:
return self._platform
class PackageNotFoundCause(IncompatibilityCause):
"""
The incompatibility represents a package that couldn't be found by its
source.
"""
def __init__(self, error: Exception) -> None:
self._error = error
@property
def error(self) -> Exception:
return self._error
......@@ -3,7 +3,6 @@ from __future__ import annotations
import functools
import time
from contextlib import suppress
from typing import TYPE_CHECKING
from poetry.core.packages.dependency import Dependency
......@@ -12,7 +11,6 @@ from poetry.mixology.failure import SolveFailure
from poetry.mixology.incompatibility import Incompatibility
from poetry.mixology.incompatibility_cause import ConflictCause
from poetry.mixology.incompatibility_cause import NoVersionsCause
from poetry.mixology.incompatibility_cause import PackageNotFoundCause
from poetry.mixology.incompatibility_cause import RootCause
from poetry.mixology.partial_solution import PartialSolution
from poetry.mixology.result import SolverResult
......@@ -395,10 +393,8 @@ class VersionSolver:
if locked:
return is_specific_marker, Preference.LOCKED, 1
try:
num_packages = len(self._dependency_cache.search_for(dependency))
except ValueError:
num_packages = 0
num_packages = len(self._dependency_cache.search_for(dependency))
if num_packages < 2:
preference = Preference.NO_CHOICE
elif use_latest:
......@@ -414,28 +410,8 @@ class VersionSolver:
locked = self._provider.get_locked(dependency)
if locked is None:
try:
packages = self._dependency_cache.search_for(dependency)
except ValueError as e:
self._add_incompatibility(
Incompatibility([Term(dependency, True)], PackageNotFoundCause(e))
)
complete_name: str = dependency.complete_name
return complete_name
package = None
if locked is not None:
package = next(
(
p
for p in packages
if p.package.version == locked.package.version
),
None,
)
if package is None:
with suppress(IndexError):
package = packages[0]
packages = self._dependency_cache.search_for(dependency)
package = next(iter(packages), None)
if package is None:
# If there are no versions that satisfy the constraint,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment