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

fix: drop version from search result #3328

Merged
merged 2 commits into from
Dec 3, 2024
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/3328.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Drop version from the search result, following the change of warehouse.
11 changes: 3 additions & 8 deletions src/pdm/cli/commands/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,19 @@
for hit in hits:
name = hit.name
summary = hit.summary or ""
latest = hit.version or ""
if terminal_width is not None:
target_width = terminal_width - name_column_width - 5
if target_width > 10:
# wrap and indent summary to fit terminal
summary = ("\n" + " " * (name_column_width + 2)).join(textwrap.wrap(summary, target_width))
current_width = len(name) + len(latest) + 4
current_width = len(name) + 1
spaces = " " * (name_column_width - current_width)
line = f"[req]{name}[/] ([warning]{latest}[/]){spaces} - {summary}"
line = f"[req]{name}[/]{spaces} - {summary}"
try:
ui.echo(line)
if normalize_name(name) in working_set:
dist = working_set[normalize_name(name)]
if dist.version == latest:
ui.echo(f" INSTALLED: {dist.version} (latest)")
else:
ui.echo(f" INSTALLED: {dist.version}")
ui.echo(f" LATEST: {latest}")
ui.echo(f" INSTALLED: {dist.version}")

Check warning on line 43 in src/pdm/cli/commands/search.py

View check run for this annotation

Codecov / codecov/patch

src/pdm/cli/commands/search.py#L43

Added line #L43 was not covered by tests
except UnicodeEncodeError:
pass

Expand Down
2 changes: 1 addition & 1 deletion src/pdm/models/repositories/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def search(self, query: str) -> SearchResults:
f"to {self.DEFAULT_INDEX_URL!r} now.\n"
"This may take longer depending on your network condition.",
)
resp = session.get(f"{self.DEFAULT_INDEX_URL}/search", params={"q": query})
resp = session.get(f"{self.DEFAULT_INDEX_URL}/search/", params={"q": query}, follow_redirects=True)
parser = SearchResultParser()
resp.raise_for_status()
parser.feed(resp.text)
Expand Down
2 changes: 1 addition & 1 deletion src/pdm/models/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ def handle_endtag(self, tag: str) -> None:
return
self._nest_anchors -= 1
if self._nest_anchors == 0:
if self._current.name and self._current.version:
if self._current.name:
self.results.append(self._current.as_frozen())
self._current = None
3 changes: 1 addition & 2 deletions tests/cli/test_others.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ def test_import_requirement_no_overwrite(project, pdm, tmp_path):
@pytest.mark.network
def test_search_package(pdm, tmp_path):
with cd(tmp_path):
result = pdm(["search", "requests"])
assert result.exit_code == 0
result = pdm(["search", "requests"], strict=True)
assert len(result.output.splitlines()) > 0
assert not tmp_path.joinpath("__pypackages__").exists()
assert not tmp_path.joinpath(".pdm-python").exists()
Expand Down
Loading