Skip to content

Commit

Permalink
non-package-mode: fix poetry add (#9046)
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering authored Feb 27, 2024
1 parent e8329d4 commit f66f8ab
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
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

0 comments on commit f66f8ab

Please sign in to comment.