From c1b3ba62d1e1e9ef8e39909d25cb79956acbbd21 Mon Sep 17 00:00:00 2001 From: Marco Macchia Date: Wed, 20 Oct 2021 16:16:37 +0200 Subject: [PATCH 1/6] Executor: Remove duplicate entry with dry-run argument --- src/poetry/installation/executor.py | 7 +- tests/console/commands/plugin/test_remove.py | 122 +++++++++++++++++++ 2 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 tests/console/commands/plugin/test_remove.py diff --git a/src/poetry/installation/executor.py b/src/poetry/installation/executor.py index 3cf3d11d6fd..678cd7b215d 100644 --- a/src/poetry/installation/executor.py +++ b/src/poetry/installation/executor.py @@ -311,8 +311,11 @@ def _do_execute_operation(self, operation: Operation) -> int: return 0 if not self._enabled or self._dry_run: +<<<<<<< HEAD:src/poetry/installation/executor.py self._io.write_line(f" • {operation_message}") +======= +>>>>>>> 73b6da5e (Executor: Remove duplicate entry with dry-run argument):poetry/installation/executor.py return 0 result: int = getattr(self, f"_execute_{method}")(operation) @@ -706,7 +709,9 @@ def _download_archive(self, operation: Install | Update, link: Link) -> Path: return archive def _should_write_operation(self, operation: Operation) -> bool: - return not operation.skipped or self._dry_run or self._verbose + return ( + not operation.skipped or self._dry_run or self._verbose or not self._enabled + ) def _save_url_reference(self, operation: Operation) -> None: """ diff --git a/tests/console/commands/plugin/test_remove.py b/tests/console/commands/plugin/test_remove.py new file mode 100644 index 00000000000..758d35d62b1 --- /dev/null +++ b/tests/console/commands/plugin/test_remove.py @@ -0,0 +1,122 @@ +import pytest +import tomlkit + +from poetry.__version__ import __version__ +from poetry.core.packages.package import Package +from poetry.layouts.layout import POETRY_DEFAULT + + +@pytest.fixture() +def tester(command_tester_factory): + return command_tester_factory("plugin remove") + + +@pytest.fixture() +def pyproject(env): + pyproject = tomlkit.loads(POETRY_DEFAULT) + content = pyproject["tool"]["poetry"] + + content["name"] = "poetry" + content["version"] = __version__ + content["description"] = "" + content["authors"] = ["Sébastien Eustace "] + + dependency_section = content["dependencies"] + dependency_section["python"] = "^3.6" + + env.path.joinpath("pyproject.toml").write_text( + tomlkit.dumps(pyproject), encoding="utf-8" + ) + + +@pytest.fixture(autouse=True) +def install_plugin(env, installed, pyproject): + lock_content = { + "package": [ + { + "name": "poetry-plugin", + "version": "1.2.3", + "category": "main", + "optional": False, + "platform": "*", + "python-versions": "*", + "checksum": [], + }, + ], + "metadata": { + "python-versions": "^3.6", + "platform": "*", + "content-hash": "123456789", + "hashes": {"poetry-plugin": []}, + }, + } + + env.path.joinpath("poetry.lock").write_text( + tomlkit.dumps(lock_content), encoding="utf-8" + ) + + pyproject = tomlkit.loads( + env.path.joinpath("pyproject.toml").read_text(encoding="utf-8") + ) + content = pyproject["tool"]["poetry"] + + dependency_section = content["dependencies"] + dependency_section["poetry-plugin"] = "^1.2.3" + + env.path.joinpath("pyproject.toml").write_text( + tomlkit.dumps(pyproject), encoding="utf-8" + ) + + installed.add_package(Package("poetry-plugin", "1.2.3")) + + +def test_remove_installed_package(app, tester, env): + tester.execute("poetry-plugin") + + expected = """\ +Updating dependencies +Resolving dependencies... + +Writing lock file + +Package operations: 0 installs, 0 updates, 1 removal + + • Removing poetry-plugin (1.2.3) +""" + + assert tester.io.fetch_output() == expected + + remove_command = app.find("remove") + assert remove_command.poetry.file.parent == env.path + assert remove_command.poetry.locker.lock.parent == env.path + assert remove_command.poetry.locker.lock.exists() + assert not remove_command.installer.executor._dry_run + + content = remove_command.poetry.file.read()["tool"]["poetry"] + assert "poetry-plugin" not in content["dependencies"] + + +def test_remove_installed_package_dry_run(app, tester, env): + tester.execute("poetry-plugin --dry-run") + + expected = """\ +Updating dependencies +Resolving dependencies... + +Writing lock file + +Package operations: 0 installs, 0 updates, 1 removal + + • Removing poetry-plugin (1.2.3) +""" + + assert tester.io.fetch_output() == expected + + remove_command = app.find("remove") + assert remove_command.poetry.file.parent == env.path + assert remove_command.poetry.locker.lock.parent == env.path + assert remove_command.poetry.locker.lock.exists() + assert remove_command.installer.executor._dry_run + + content = remove_command.poetry.file.read()["tool"]["poetry"] + assert "poetry-plugin" in content["dependencies"] From 1cbfd09e96c8a083e61c1838e4ce114b3aa1bacb Mon Sep 17 00:00:00 2001 From: mmacchia Date: Sat, 4 Jun 2022 11:44:54 +0200 Subject: [PATCH 2/6] Fixed executor, removed extra code when not self._enabled or self._dry_run --- src/poetry/installation/executor.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/poetry/installation/executor.py b/src/poetry/installation/executor.py index 678cd7b215d..3e6bc40d6f1 100644 --- a/src/poetry/installation/executor.py +++ b/src/poetry/installation/executor.py @@ -311,11 +311,6 @@ def _do_execute_operation(self, operation: Operation) -> int: return 0 if not self._enabled or self._dry_run: -<<<<<<< HEAD:src/poetry/installation/executor.py - self._io.write_line(f" • {operation_message}") - -======= ->>>>>>> 73b6da5e (Executor: Remove duplicate entry with dry-run argument):poetry/installation/executor.py return 0 result: int = getattr(self, f"_execute_{method}")(operation) From f3af27ea249aa51d013fc3818e86a248948cb2dc Mon Sep 17 00:00:00 2001 From: mmacchia Date: Sat, 4 Jun 2022 11:50:12 +0200 Subject: [PATCH 3/6] Removed test_remove --- tests/console/commands/plugin/test_remove.py | 122 ------------------- 1 file changed, 122 deletions(-) delete mode 100644 tests/console/commands/plugin/test_remove.py diff --git a/tests/console/commands/plugin/test_remove.py b/tests/console/commands/plugin/test_remove.py deleted file mode 100644 index 758d35d62b1..00000000000 --- a/tests/console/commands/plugin/test_remove.py +++ /dev/null @@ -1,122 +0,0 @@ -import pytest -import tomlkit - -from poetry.__version__ import __version__ -from poetry.core.packages.package import Package -from poetry.layouts.layout import POETRY_DEFAULT - - -@pytest.fixture() -def tester(command_tester_factory): - return command_tester_factory("plugin remove") - - -@pytest.fixture() -def pyproject(env): - pyproject = tomlkit.loads(POETRY_DEFAULT) - content = pyproject["tool"]["poetry"] - - content["name"] = "poetry" - content["version"] = __version__ - content["description"] = "" - content["authors"] = ["Sébastien Eustace "] - - dependency_section = content["dependencies"] - dependency_section["python"] = "^3.6" - - env.path.joinpath("pyproject.toml").write_text( - tomlkit.dumps(pyproject), encoding="utf-8" - ) - - -@pytest.fixture(autouse=True) -def install_plugin(env, installed, pyproject): - lock_content = { - "package": [ - { - "name": "poetry-plugin", - "version": "1.2.3", - "category": "main", - "optional": False, - "platform": "*", - "python-versions": "*", - "checksum": [], - }, - ], - "metadata": { - "python-versions": "^3.6", - "platform": "*", - "content-hash": "123456789", - "hashes": {"poetry-plugin": []}, - }, - } - - env.path.joinpath("poetry.lock").write_text( - tomlkit.dumps(lock_content), encoding="utf-8" - ) - - pyproject = tomlkit.loads( - env.path.joinpath("pyproject.toml").read_text(encoding="utf-8") - ) - content = pyproject["tool"]["poetry"] - - dependency_section = content["dependencies"] - dependency_section["poetry-plugin"] = "^1.2.3" - - env.path.joinpath("pyproject.toml").write_text( - tomlkit.dumps(pyproject), encoding="utf-8" - ) - - installed.add_package(Package("poetry-plugin", "1.2.3")) - - -def test_remove_installed_package(app, tester, env): - tester.execute("poetry-plugin") - - expected = """\ -Updating dependencies -Resolving dependencies... - -Writing lock file - -Package operations: 0 installs, 0 updates, 1 removal - - • Removing poetry-plugin (1.2.3) -""" - - assert tester.io.fetch_output() == expected - - remove_command = app.find("remove") - assert remove_command.poetry.file.parent == env.path - assert remove_command.poetry.locker.lock.parent == env.path - assert remove_command.poetry.locker.lock.exists() - assert not remove_command.installer.executor._dry_run - - content = remove_command.poetry.file.read()["tool"]["poetry"] - assert "poetry-plugin" not in content["dependencies"] - - -def test_remove_installed_package_dry_run(app, tester, env): - tester.execute("poetry-plugin --dry-run") - - expected = """\ -Updating dependencies -Resolving dependencies... - -Writing lock file - -Package operations: 0 installs, 0 updates, 1 removal - - • Removing poetry-plugin (1.2.3) -""" - - assert tester.io.fetch_output() == expected - - remove_command = app.find("remove") - assert remove_command.poetry.file.parent == env.path - assert remove_command.poetry.locker.lock.parent == env.path - assert remove_command.poetry.locker.lock.exists() - assert remove_command.installer.executor._dry_run - - content = remove_command.poetry.file.read()["tool"]["poetry"] - assert "poetry-plugin" in content["dependencies"] From 40ece6c517ea39b64449ae1297e9d6109816ee82 Mon Sep 17 00:00:00 2001 From: mmacchia Date: Sat, 4 Jun 2022 12:12:18 +0200 Subject: [PATCH 4/6] Revert "Removed test_remove" This reverts commit 5f52980f2a60bbafbdc16b5defc30bcc74638d49. --- tests/console/commands/plugin/test_remove.py | 122 +++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 tests/console/commands/plugin/test_remove.py diff --git a/tests/console/commands/plugin/test_remove.py b/tests/console/commands/plugin/test_remove.py new file mode 100644 index 00000000000..758d35d62b1 --- /dev/null +++ b/tests/console/commands/plugin/test_remove.py @@ -0,0 +1,122 @@ +import pytest +import tomlkit + +from poetry.__version__ import __version__ +from poetry.core.packages.package import Package +from poetry.layouts.layout import POETRY_DEFAULT + + +@pytest.fixture() +def tester(command_tester_factory): + return command_tester_factory("plugin remove") + + +@pytest.fixture() +def pyproject(env): + pyproject = tomlkit.loads(POETRY_DEFAULT) + content = pyproject["tool"]["poetry"] + + content["name"] = "poetry" + content["version"] = __version__ + content["description"] = "" + content["authors"] = ["Sébastien Eustace "] + + dependency_section = content["dependencies"] + dependency_section["python"] = "^3.6" + + env.path.joinpath("pyproject.toml").write_text( + tomlkit.dumps(pyproject), encoding="utf-8" + ) + + +@pytest.fixture(autouse=True) +def install_plugin(env, installed, pyproject): + lock_content = { + "package": [ + { + "name": "poetry-plugin", + "version": "1.2.3", + "category": "main", + "optional": False, + "platform": "*", + "python-versions": "*", + "checksum": [], + }, + ], + "metadata": { + "python-versions": "^3.6", + "platform": "*", + "content-hash": "123456789", + "hashes": {"poetry-plugin": []}, + }, + } + + env.path.joinpath("poetry.lock").write_text( + tomlkit.dumps(lock_content), encoding="utf-8" + ) + + pyproject = tomlkit.loads( + env.path.joinpath("pyproject.toml").read_text(encoding="utf-8") + ) + content = pyproject["tool"]["poetry"] + + dependency_section = content["dependencies"] + dependency_section["poetry-plugin"] = "^1.2.3" + + env.path.joinpath("pyproject.toml").write_text( + tomlkit.dumps(pyproject), encoding="utf-8" + ) + + installed.add_package(Package("poetry-plugin", "1.2.3")) + + +def test_remove_installed_package(app, tester, env): + tester.execute("poetry-plugin") + + expected = """\ +Updating dependencies +Resolving dependencies... + +Writing lock file + +Package operations: 0 installs, 0 updates, 1 removal + + • Removing poetry-plugin (1.2.3) +""" + + assert tester.io.fetch_output() == expected + + remove_command = app.find("remove") + assert remove_command.poetry.file.parent == env.path + assert remove_command.poetry.locker.lock.parent == env.path + assert remove_command.poetry.locker.lock.exists() + assert not remove_command.installer.executor._dry_run + + content = remove_command.poetry.file.read()["tool"]["poetry"] + assert "poetry-plugin" not in content["dependencies"] + + +def test_remove_installed_package_dry_run(app, tester, env): + tester.execute("poetry-plugin --dry-run") + + expected = """\ +Updating dependencies +Resolving dependencies... + +Writing lock file + +Package operations: 0 installs, 0 updates, 1 removal + + • Removing poetry-plugin (1.2.3) +""" + + assert tester.io.fetch_output() == expected + + remove_command = app.find("remove") + assert remove_command.poetry.file.parent == env.path + assert remove_command.poetry.locker.lock.parent == env.path + assert remove_command.poetry.locker.lock.exists() + assert remove_command.installer.executor._dry_run + + content = remove_command.poetry.file.read()["tool"]["poetry"] + assert "poetry-plugin" in content["dependencies"] From 0fbb31d50b963603002c4a052fa71950b4cbf99b Mon Sep 17 00:00:00 2001 From: mmacchia Date: Sat, 4 Jun 2022 12:13:10 +0200 Subject: [PATCH 5/6] Updated test_remove_plugins dry run test case --- tests/console/commands/self/test_remove_plugins.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/console/commands/self/test_remove_plugins.py b/tests/console/commands/self/test_remove_plugins.py index 644e5748510..5821df82356 100644 --- a/tests/console/commands/self/test_remove_plugins.py +++ b/tests/console/commands/self/test_remove_plugins.py @@ -95,7 +95,6 @@ def test_remove_installed_package_dry_run(tester: CommandTester): Package operations: 0 installs, 0 updates, 1 removal, 1 skipped - • Removing poetry-plugin (1.2.3) • Removing poetry-plugin (1.2.3) • Installing poetry ({__version__}): Skipped for the following reason: Already \ installed From 38b405cbf8053bccca73c3d5cde962601ef3ff7f Mon Sep 17 00:00:00 2001 From: mmacchia Date: Sat, 4 Jun 2022 12:40:04 +0200 Subject: [PATCH 6/6] Removed commands plugin folder, align with master --- tests/console/commands/plugin/test_remove.py | 122 ------------------- 1 file changed, 122 deletions(-) delete mode 100644 tests/console/commands/plugin/test_remove.py diff --git a/tests/console/commands/plugin/test_remove.py b/tests/console/commands/plugin/test_remove.py deleted file mode 100644 index 758d35d62b1..00000000000 --- a/tests/console/commands/plugin/test_remove.py +++ /dev/null @@ -1,122 +0,0 @@ -import pytest -import tomlkit - -from poetry.__version__ import __version__ -from poetry.core.packages.package import Package -from poetry.layouts.layout import POETRY_DEFAULT - - -@pytest.fixture() -def tester(command_tester_factory): - return command_tester_factory("plugin remove") - - -@pytest.fixture() -def pyproject(env): - pyproject = tomlkit.loads(POETRY_DEFAULT) - content = pyproject["tool"]["poetry"] - - content["name"] = "poetry" - content["version"] = __version__ - content["description"] = "" - content["authors"] = ["Sébastien Eustace "] - - dependency_section = content["dependencies"] - dependency_section["python"] = "^3.6" - - env.path.joinpath("pyproject.toml").write_text( - tomlkit.dumps(pyproject), encoding="utf-8" - ) - - -@pytest.fixture(autouse=True) -def install_plugin(env, installed, pyproject): - lock_content = { - "package": [ - { - "name": "poetry-plugin", - "version": "1.2.3", - "category": "main", - "optional": False, - "platform": "*", - "python-versions": "*", - "checksum": [], - }, - ], - "metadata": { - "python-versions": "^3.6", - "platform": "*", - "content-hash": "123456789", - "hashes": {"poetry-plugin": []}, - }, - } - - env.path.joinpath("poetry.lock").write_text( - tomlkit.dumps(lock_content), encoding="utf-8" - ) - - pyproject = tomlkit.loads( - env.path.joinpath("pyproject.toml").read_text(encoding="utf-8") - ) - content = pyproject["tool"]["poetry"] - - dependency_section = content["dependencies"] - dependency_section["poetry-plugin"] = "^1.2.3" - - env.path.joinpath("pyproject.toml").write_text( - tomlkit.dumps(pyproject), encoding="utf-8" - ) - - installed.add_package(Package("poetry-plugin", "1.2.3")) - - -def test_remove_installed_package(app, tester, env): - tester.execute("poetry-plugin") - - expected = """\ -Updating dependencies -Resolving dependencies... - -Writing lock file - -Package operations: 0 installs, 0 updates, 1 removal - - • Removing poetry-plugin (1.2.3) -""" - - assert tester.io.fetch_output() == expected - - remove_command = app.find("remove") - assert remove_command.poetry.file.parent == env.path - assert remove_command.poetry.locker.lock.parent == env.path - assert remove_command.poetry.locker.lock.exists() - assert not remove_command.installer.executor._dry_run - - content = remove_command.poetry.file.read()["tool"]["poetry"] - assert "poetry-plugin" not in content["dependencies"] - - -def test_remove_installed_package_dry_run(app, tester, env): - tester.execute("poetry-plugin --dry-run") - - expected = """\ -Updating dependencies -Resolving dependencies... - -Writing lock file - -Package operations: 0 installs, 0 updates, 1 removal - - • Removing poetry-plugin (1.2.3) -""" - - assert tester.io.fetch_output() == expected - - remove_command = app.find("remove") - assert remove_command.poetry.file.parent == env.path - assert remove_command.poetry.locker.lock.parent == env.path - assert remove_command.poetry.locker.lock.exists() - assert remove_command.installer.executor._dry_run - - content = remove_command.poetry.file.read()["tool"]["poetry"] - assert "poetry-plugin" in content["dependencies"]