Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat add candidate output #421

Merged
merged 2 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/421.misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add log output about found candidates and their origin.
3 changes: 2 additions & 1 deletion pdm/models/candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ def get_metadata(
return self.metadata

def __repr__(self) -> str:
return f"<Candidate {self.name} {self.version}>"
source = getattr(self.link, "comes_from", "unknown")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the value if the candidate is from a file link(including VCS, remote file and local file)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I haven't tried and don't know. At least it doesn't break if comes_from is not set.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure it displays a meaningful value not confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the cases you mentioned, pdm doesn't seem to go through the repository search. At least I wasn't able to get the candidate list output.

return f"<Candidate {self.name} {self.version} from {source}>"

@classmethod
def from_installation_candidate(
Expand Down
32 changes: 32 additions & 0 deletions pdm/models/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ def find_candidates(
reverse=True,
)

if not sorted_cans:
termui.logger.debug("\tCould not find any matching candidates.")

if not sorted_cans and allow_prereleases is None:
# No non-pre-releases is found, force pre-releases now
sorted_cans = sorted(
Expand All @@ -124,6 +127,35 @@ def find_candidates(
key=lambda c: c.version,
reverse=True,
)

if not sorted_cans:
termui.logger.debug(
"\tCould not find any matching candidates even when considering "
"pre-releases.",
)

def print_candidates(
title: str, candidates: List[Candidate], max_lines: int = 10
) -> None:
termui.logger.debug("\t" + title)
logged_lines = set()
for can in candidates:
new_line = f"\t {can}"
if new_line not in logged_lines:
logged_lines.add(new_line)
if len(logged_lines) > max_lines:
termui.logger.debug(
f"\t ... [{len(candidates)-max_lines} more candidate(s)]"
)
break
else:
termui.logger.debug(new_line)

if sorted_cans:
print_candidates("Found matching candidates:", sorted_cans)
elif cans:
print_candidates("Found but non-matching candidates:", cans)

return sorted_cans

def _get_dependencies_from_cache(self, candidate: Candidate) -> CandidateInfo:
Expand Down