Skip to content

Commit

Permalink
fix: Inconsistent behavior between pdm remove and pdm update (#2886)
Browse files Browse the repository at this point in the history
* fix: Inconsistent behavior between `pdm remove` and `pdm update`
Fixes #2885

Signed-off-by: Frost Ming <[email protected]>

* fix: add test

Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming committed May 16, 2024
1 parent e504768 commit 98928b8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions news/2885.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Raise an error if the package given by `pdm update` does not exist in the select dependency group but in other groups.
8 changes: 8 additions & 0 deletions src/pdm/cli/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ def do_update(
f"[req]{name}[/] does not exist in [primary]{group}[/] "
f"{'dev-' if selection.dev else ''}dependencies nor is a transitive dependency."
)
look_in_other_group = next(
(g for g, deps in all_dependencies.items() if normalized_name in deps and g != group), None
)
if look_in_other_group is not None:
raise ProjectError(
f"[req]{name}[/] does not exist in [primary]{group}[/], but exists in [primary]{look_in_other_group}[/]."
" Please specify the correct group with `-G/--group`."
)
tracked_names.add(normalized_name)
else:
matched_req.prerelease = prerelease
Expand Down
12 changes: 10 additions & 2 deletions tests/cli/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,21 @@ def test_update_transitive(project, repository, pdm):


@pytest.mark.usefixtures("working_set")
def test_update_transitive_nonexistant_dependencies(project, repository, pdm):
def test_update_transitive_nonexistant_dependencies(project, pdm):
pdm(["add", "requests", "--no-sync"], obj=project, strict=True)
result = pdm(["update", "numpy"])
result = pdm(["update", "numpy"], obj=project)
assert "ProjectError" in result.stderr
assert "numpy does not exist in" in result.stderr


@pytest.mark.usefixtures("working_set")
def test_update_package_wrong_group(project, pdm):
pdm(["add", "-d", "requests"], obj=project, strict=True)
result = pdm(["update", "requests"], obj=project)
assert "ProjectError" in result.stderr
assert "requests does not exist in default, but exists in dev" in result.stderr


@pytest.mark.usefixtures("working_set")
def test_update_transitive_non_transitive_dependencies(project, repository, pdm):
pdm(["add", "requests", "pytz", "--no-sync"], obj=project, strict=True)
Expand Down

0 comments on commit 98928b8

Please sign in to comment.