Commit 2ca2080c by Mathieu Kniewallner Committed by Arun Babu Neelicattu

feat(commands/add): canonicalize package name when looking for existing packages

parent a9fade8a
......@@ -9,6 +9,8 @@ from cleo.helpers import argument
from cleo.helpers import option
from tomlkit.toml_document import TOMLDocument
from poetry.utils.helpers import canonicalize_name
try:
from poetry.core.packages.dependency_group import MAIN_GROUP
......@@ -268,7 +270,7 @@ You can specify a package in the following forms:
for name in packages:
for key in section:
if key.lower() == name.lower():
if canonicalize_name(key) == canonicalize_name(name):
existing_packages.append(name)
return existing_packages
......
......@@ -940,6 +940,30 @@ If you prefer to upgrade it to the latest available version,\
assert expected in tester.io.fetch_output()
def test_add_should_skip_when_adding_canonicalized_existing_package_with_no_constraint(
app: PoetryTestApplication, repo: TestRepository, tester: CommandTester
):
content = app.poetry.file.read()
content["tool"]["poetry"]["dependencies"]["foo-bar"] = "^1.0"
app.poetry.file.write(content)
repo.add_package(get_package("foo-bar", "1.1.2"))
tester.execute("Foo_Bar")
expected = """\
The following packages are already present in the pyproject.toml and will be skipped:
• Foo_Bar
If you want to update it to the latest compatible version,\
you can use `poetry update package`.
If you prefer to upgrade it to the latest available version,\
you can use `poetry add package@latest`.
"""
assert expected in tester.io.fetch_output()
def test_add_should_work_when_adding_existing_package_with_latest_constraint(
app: PoetryTestApplication, repo: TestRepository, tester: CommandTester
):
......
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