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

[1.8] non-package-mode: fix poetry add #9047

Merged
merged 1 commit into from
Feb 27, 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
4 changes: 3 additions & 1 deletion src/poetry/console/commands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ def handle(self) -> int:
# dictionary.
content: dict[str, Any] = self.poetry.file.read()
poetry_content = content["tool"]["poetry"]
project_name = canonicalize_name(poetry_content["name"])
project_name = (
canonicalize_name(name) if (name := poetry_content.get("name")) else None
)

if group == MAIN_GROUP:
if "dependencies" not in poetry_content:
Expand Down
23 changes: 23 additions & 0 deletions tests/console/commands/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,29 @@ def test_add_no_constraint(
assert content["dependencies"]["cachy"] == "^0.2.0"


def test_add_non_package_mode_no_name(
repo: TestRepository,
project_factory: ProjectFactory,
command_tester_factory: CommandTesterFactory,
) -> None:
repo.add_package(get_package("cachy", "0.2.0"))

poetry = project_factory(
name="foobar", pyproject_content="[tool.poetry]\npackage-mode = false\n"
)
tester = command_tester_factory("add", poetry=poetry)
tester.execute("cachy")

assert isinstance(tester.command, InstallerCommand)
assert tester.command.installer.executor.installations_count == 1

pyproject: dict[str, Any] = poetry.file.read()
content = pyproject["tool"]["poetry"]

assert "cachy" in content["dependencies"]
assert content["dependencies"]["cachy"] == "^0.2.0"


def test_add_replace_by_constraint(
app: PoetryTestApplication, repo: TestRepository, tester: CommandTester
) -> None:
Expand Down
Loading