Skip to content

Commit

Permalink
Throw a custom exception when no match is found
Browse files Browse the repository at this point in the history
Close #357
  • Loading branch information
frostming committed Mar 30, 2021
1 parent 3dca9ea commit b3a5632
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions news/357.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Throws an error with meaningful message when no candidate is found for one requirement.
2 changes: 1 addition & 1 deletion pdm/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CorruptedCacheError(PdmException):
pass


class PackageIndexError(PdmException):
class CandidateNotFound(PdmException):
pass


Expand Down
10 changes: 8 additions & 2 deletions pdm/models/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from pdm import termui
from pdm._types import CandidateInfo, Package, SearchResult, Source
from pdm.exceptions import CandidateInfoNotFound, CorruptedCacheError
from pdm.exceptions import CandidateInfoNotFound, CandidateNotFound, CorruptedCacheError
from pdm.models.candidates import Candidate
from pdm.models.requirements import (
Requirement,
Expand Down Expand Up @@ -231,10 +231,16 @@ def dependency_generators(self) -> Iterable[Callable[[Candidate], CandidateInfo]
def _find_candidates(self, requirement: Requirement) -> Iterable[Candidate]:
sources = self.get_filtered_sources(requirement)
with self.environment.get_finder(sources, True) as finder, allow_all_wheels():
return [
cans = [
Candidate.from_installation_candidate(c, requirement, self.environment)
for c in finder.find_all_candidates(requirement.project_name)
]
if not cans:
raise CandidateNotFound(
f"Unable to find candidates for {requirement.project_name}. There may "
"exist some issues with the package index or network condition."
)
return cans

def search(self, query: str) -> SearchResult:
pypi_simple = self.sources[0]["url"].rstrip("/")
Expand Down

0 comments on commit b3a5632

Please sign in to comment.