Skip to content

Commit 87d8641

Browse files
committed
self install: in this context the project is not a package so we should set package-mode to false
1 parent 0a3d4b6 commit 87d8641

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/poetry/console/commands/self/self_command.py

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def generate_system_pyproject(self) -> None:
7373
package.python_versions = ".".join(str(v) for v in self.env.version_info[:3])
7474

7575
content = Factory.create_pyproject_from_package(package=package)
76+
content["tool"]["poetry"]["package-mode"] = False # type: ignore[index]
7677

7778
for key in preserved:
7879
content["tool"]["poetry"][key] = preserved[key] # type: ignore[index]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
4+
5+
import pytest
6+
7+
from poetry.console.commands.self.install import SelfInstallCommand
8+
9+
10+
if TYPE_CHECKING:
11+
from cleo.testers.command_tester import CommandTester
12+
13+
from tests.types import CommandTesterFactory
14+
15+
16+
@pytest.fixture
17+
def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
18+
return command_tester_factory("self install")
19+
20+
21+
@pytest.mark.parametrize(
22+
"pyproject_content",
23+
(
24+
None,
25+
"""\
26+
[tool.poetry]
27+
name = "poetry-instance"
28+
version = "1.2"
29+
description = ""
30+
authors = []
31+
license = ""
32+
# no package-mode -> defaults to true
33+
34+
[tool.poetry.dependencies]
35+
python = "3.9"
36+
poetry = "1.2"
37+
""",
38+
),
39+
)
40+
def test_self_install(
41+
tester: CommandTester,
42+
pyproject_content: str | None,
43+
) -> None:
44+
command = tester.command
45+
assert isinstance(command, SelfInstallCommand)
46+
pyproject_path = command.system_pyproject
47+
if pyproject_content:
48+
pyproject_path.write_text(pyproject_content)
49+
else:
50+
assert not pyproject_path.exists()
51+
52+
tester.execute()
53+
54+
expected_output = """\
55+
Updating dependencies
56+
Resolving dependencies...
57+
58+
Writing lock file
59+
"""
60+
61+
assert tester.io.fetch_output() == expected_output
62+
assert tester.io.fetch_error() == ""

0 commit comments

Comments
 (0)