Skip to content

Commit 12ee359

Browse files
Marco Macchiammacchia
Marco Macchia
authored andcommitted
Executor: Remove duplicate entry with dry-run argument
1 parent 53e50d9 commit 12ee359

File tree

2 files changed

+128
-1
lines changed

2 files changed

+128
-1
lines changed

src/poetry/installation/executor.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,11 @@ def _do_execute_operation(self, operation: Operation) -> int:
311311
return 0
312312

313313
if not self._enabled or self._dry_run:
314+
<<<<<<< HEAD:src/poetry/installation/executor.py
314315
self._io.write_line(f" <fg=blue;options=bold>•</> {operation_message}")
315316

317+
=======
318+
>>>>>>> 73b6da5e (Executor: Remove duplicate entry with dry-run argument):poetry/installation/executor.py
316319
return 0
317320

318321
result: int = getattr(self, f"_execute_{method}")(operation)
@@ -713,7 +716,9 @@ def _download_archive(self, operation: Install | Update, link: Link) -> Path:
713716
return archive
714717

715718
def _should_write_operation(self, operation: Operation) -> bool:
716-
return not operation.skipped or self._dry_run or self._verbose
719+
return (
720+
not operation.skipped or self._dry_run or self._verbose or not self._enabled
721+
)
717722

718723
def _save_url_reference(self, operation: Operation) -> None:
719724
"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import pytest
2+
import tomlkit
3+
4+
from poetry.__version__ import __version__
5+
from poetry.core.packages.package import Package
6+
from poetry.layouts.layout import POETRY_DEFAULT
7+
8+
9+
@pytest.fixture()
10+
def tester(command_tester_factory):
11+
return command_tester_factory("plugin remove")
12+
13+
14+
@pytest.fixture()
15+
def pyproject(env):
16+
pyproject = tomlkit.loads(POETRY_DEFAULT)
17+
content = pyproject["tool"]["poetry"]
18+
19+
content["name"] = "poetry"
20+
content["version"] = __version__
21+
content["description"] = ""
22+
content["authors"] = ["Sébastien Eustace <[email protected]>"]
23+
24+
dependency_section = content["dependencies"]
25+
dependency_section["python"] = "^3.6"
26+
27+
env.path.joinpath("pyproject.toml").write_text(
28+
tomlkit.dumps(pyproject), encoding="utf-8"
29+
)
30+
31+
32+
@pytest.fixture(autouse=True)
33+
def install_plugin(env, installed, pyproject):
34+
lock_content = {
35+
"package": [
36+
{
37+
"name": "poetry-plugin",
38+
"version": "1.2.3",
39+
"category": "main",
40+
"optional": False,
41+
"platform": "*",
42+
"python-versions": "*",
43+
"checksum": [],
44+
},
45+
],
46+
"metadata": {
47+
"python-versions": "^3.6",
48+
"platform": "*",
49+
"content-hash": "123456789",
50+
"hashes": {"poetry-plugin": []},
51+
},
52+
}
53+
54+
env.path.joinpath("poetry.lock").write_text(
55+
tomlkit.dumps(lock_content), encoding="utf-8"
56+
)
57+
58+
pyproject = tomlkit.loads(
59+
env.path.joinpath("pyproject.toml").read_text(encoding="utf-8")
60+
)
61+
content = pyproject["tool"]["poetry"]
62+
63+
dependency_section = content["dependencies"]
64+
dependency_section["poetry-plugin"] = "^1.2.3"
65+
66+
env.path.joinpath("pyproject.toml").write_text(
67+
tomlkit.dumps(pyproject), encoding="utf-8"
68+
)
69+
70+
installed.add_package(Package("poetry-plugin", "1.2.3"))
71+
72+
73+
def test_remove_installed_package(app, tester, env):
74+
tester.execute("poetry-plugin")
75+
76+
expected = """\
77+
Updating dependencies
78+
Resolving dependencies...
79+
80+
Writing lock file
81+
82+
Package operations: 0 installs, 0 updates, 1 removal
83+
84+
• Removing poetry-plugin (1.2.3)
85+
"""
86+
87+
assert tester.io.fetch_output() == expected
88+
89+
remove_command = app.find("remove")
90+
assert remove_command.poetry.file.parent == env.path
91+
assert remove_command.poetry.locker.lock.parent == env.path
92+
assert remove_command.poetry.locker.lock.exists()
93+
assert not remove_command.installer.executor._dry_run
94+
95+
content = remove_command.poetry.file.read()["tool"]["poetry"]
96+
assert "poetry-plugin" not in content["dependencies"]
97+
98+
99+
def test_remove_installed_package_dry_run(app, tester, env):
100+
tester.execute("poetry-plugin --dry-run")
101+
102+
expected = """\
103+
Updating dependencies
104+
Resolving dependencies...
105+
106+
Writing lock file
107+
108+
Package operations: 0 installs, 0 updates, 1 removal
109+
110+
• Removing poetry-plugin (1.2.3)
111+
"""
112+
113+
assert tester.io.fetch_output() == expected
114+
115+
remove_command = app.find("remove")
116+
assert remove_command.poetry.file.parent == env.path
117+
assert remove_command.poetry.locker.lock.parent == env.path
118+
assert remove_command.poetry.locker.lock.exists()
119+
assert remove_command.installer.executor._dry_run
120+
121+
content = remove_command.poetry.file.read()["tool"]["poetry"]
122+
assert "poetry-plugin" in content["dependencies"]

0 commit comments

Comments
 (0)