Commit b1f5f22c by David Fortini Committed by GitHub

Give a clear error message when adding package with the same name as your local package (#3841)

* give error message when package to be installed is the same as the package name

* handle AssertionError in check_solver_result

* added unit test to check a clear error message when package is a dependence of itself

* fixed message of unit test

* update explanation as in master branch

* added unit test typing hints
parent a17f1ba3
......@@ -59,7 +59,8 @@ class Incompatibility:
# incompatibility irrelevant, since we already know that mutually
# exclusive version ranges are incompatible. We should never derive
# an irrelevant incompatibility.
assert by_ref[ref] is not None
err_msg = f"Package '{ref}' is listed as a dependency of itself."
assert by_ref[ref] is not None, err_msg
else:
by_ref[ref] = term
......
......@@ -48,7 +48,6 @@ def check_solver_result(
locked = {k: DependencyPackage(l.to_dependency(), l) for k, l in locked.items()}
solver = VersionSolver(root, provider, locked=locked, use_latest=use_latest)
try:
solution = solver.solve()
except SolveFailure as e:
......@@ -61,6 +60,11 @@ def check_solver_result(
return
raise
except AssertionError as e:
if error:
assert str(e) == error
return
raise
packages = {}
for package in solution.packages:
......
......@@ -110,3 +110,13 @@ Thus, b is forbidden.
So, because myapp depends on b (*), version solving failed."""
check_solver_result(root, provider, error=error, tries=2)
def test_package_with_the_same_name_gives_clear_error_message(
root: "ProjectPackage", provider: "Provider", repo: "Repository"
):
pkg_name = "a"
root.add_dependency(Factory.create_dependency(pkg_name, "*"))
add_to_repo(repo, pkg_name, "1.0.0", deps={pkg_name: "1.0.0"})
error = f"Package '{pkg_name}' is listed as a dependency of itself."
check_solver_result(root, provider, error=error)
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