Commit 623bfffb by Wagner Macedo Committed by GitHub

Only write lock file when installation is success (#7498)

(affects `poetry add` and `poetry update`)
parent 161b19cb
...@@ -291,12 +291,10 @@ class Installer: ...@@ -291,12 +291,10 @@ class Installer:
lockfile_repo = LockfileRepository() lockfile_repo = LockfileRepository()
self._populate_lockfile_repo(lockfile_repo, ops) self._populate_lockfile_repo(lockfile_repo, ops)
if self._update: if self._lock and self._update:
# If we are only in lock mode, no need to go any further
self._write_lock_file(lockfile_repo) self._write_lock_file(lockfile_repo)
return 0
if self._lock:
# If we are only in lock mode, no need to go any further
return 0
if self._groups is not None: if self._groups is not None:
root = self._package.with_dependency_groups(list(self._groups), only=True) root = self._package.with_dependency_groups(list(self._groups), only=True)
...@@ -362,7 +360,13 @@ class Installer: ...@@ -362,7 +360,13 @@ class Installer:
self._filter_operations(ops, lockfile_repo) self._filter_operations(ops, lockfile_repo)
# Execute operations # Execute operations
return self._execute(ops) status = self._execute(ops)
if status == 0 and self._update:
# Only write lock file when installation is success
self._write_lock_file(lockfile_repo)
return status
def _write_lock_file(self, repo: LockfileRepository, force: bool = False) -> None: def _write_lock_file(self, repo: LockfileRepository, force: bool = False) -> None:
if self._write_lock and (force or self._update): if self._write_lock and (force or self._update):
......
...@@ -224,6 +224,18 @@ class Locker: ...@@ -224,6 +224,18 @@ class Locker:
return repository return repository
def set_lock_data(self, root: Package, packages: list[Package]) -> bool: def set_lock_data(self, root: Package, packages: list[Package]) -> bool:
"""Store lock data and eventually persist to the lock file"""
lock = self._compute_lock_data(root, packages)
if self._should_write(lock):
self._write_lock_data(lock)
return True
return False
def _compute_lock_data(
self, root: Package, packages: list[Package]
) -> TOMLDocument:
package_specs = self._lock_packages(packages) package_specs = self._lock_packages(packages)
# Retrieving hashes # Retrieving hashes
for package in package_specs: for package in package_specs:
...@@ -254,6 +266,10 @@ class Locker: ...@@ -254,6 +266,10 @@ class Locker:
"content-hash": self._content_hash, "content-hash": self._content_hash,
} }
return lock
def _should_write(self, lock: TOMLDocument) -> bool:
# if lock file exists: compare with existing lock data
do_write = True do_write = True
if self.is_locked(): if self.is_locked():
try: try:
...@@ -263,8 +279,6 @@ class Locker: ...@@ -263,8 +279,6 @@ class Locker:
pass pass
else: else:
do_write = lock != lock_data do_write = lock != lock_data
if do_write:
self._write_lock_data(lock)
return do_write return do_write
def _write_lock_data(self, data: TOMLDocument) -> None: def _write_lock_data(self, data: TOMLDocument) -> None:
......
...@@ -49,11 +49,11 @@ Using version ^0.1.0 for poetry-plugin ...@@ -49,11 +49,11 @@ Using version ^0.1.0 for poetry-plugin
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
• Installing poetry-plugin (0.1.0) • Installing poetry-plugin (0.1.0)
Writing lock file
""" """
assert_plugin_add_result(tester, expected, "^0.1.0") assert_plugin_add_result(tester, expected, "^0.1.0")
...@@ -71,11 +71,11 @@ def test_add_with_constraint( ...@@ -71,11 +71,11 @@ def test_add_with_constraint(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
• Installing poetry-plugin (0.2.0) • Installing poetry-plugin (0.2.0)
Writing lock file
""" """
assert_plugin_add_result(tester, expected, "^0.2.0") assert_plugin_add_result(tester, expected, "^0.2.0")
...@@ -93,12 +93,12 @@ def test_add_with_git_constraint( ...@@ -93,12 +93,12 @@ def test_add_with_git_constraint(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (2.0.5) • Installing pendulum (2.0.5)
• Installing poetry-plugin (0.1.2 9cf87a2) • Installing poetry-plugin (0.1.2 9cf87a2)
Writing lock file
""" """
assert_plugin_add_result( assert_plugin_add_result(
...@@ -119,13 +119,13 @@ def test_add_with_git_constraint_with_extras( ...@@ -119,13 +119,13 @@ def test_add_with_git_constraint_with_extras(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 3 installs, 0 updates, 0 removals Package operations: 3 installs, 0 updates, 0 removals
• Installing pendulum (2.0.5) • Installing pendulum (2.0.5)
• Installing tomlkit (0.7.0) • Installing tomlkit (0.7.0)
• Installing poetry-plugin (0.1.2 9cf87a2) • Installing poetry-plugin (0.1.2 9cf87a2)
Writing lock file
""" """
assert_plugin_add_result( assert_plugin_add_result(
...@@ -162,12 +162,12 @@ def test_add_with_git_constraint_with_subdirectory( ...@@ -162,12 +162,12 @@ def test_add_with_git_constraint_with_subdirectory(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (2.0.5) • Installing pendulum (2.0.5)
• Installing poetry-plugin (0.1.2 9cf87a2) • Installing poetry-plugin (0.1.2 9cf87a2)
Writing lock file
""" """
constraint = { constraint = {
...@@ -262,11 +262,11 @@ Using version ^2.3.4 for poetry-plugin ...@@ -262,11 +262,11 @@ Using version ^2.3.4 for poetry-plugin
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 0 installs, 1 update, 0 removals Package operations: 0 installs, 1 update, 0 removals
• Updating poetry-plugin (1.2.3 -> 2.3.4) • Updating poetry-plugin (1.2.3 -> 2.3.4)
Writing lock file
""" """
assert_plugin_add_result(tester, expected, "^2.3.4") assert_plugin_add_result(tester, expected, "^2.3.4")
...@@ -298,12 +298,12 @@ Using version ^1.2.3 for poetry-plugin ...@@ -298,12 +298,12 @@ Using version ^1.2.3 for poetry-plugin
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 1 update, 0 removals Package operations: 1 install, 1 update, 0 removals
• Updating tomlkit (0.7.1 -> 0.7.2) • Updating tomlkit (0.7.1 -> 0.7.2)
• Installing poetry-plugin (1.2.3) • Installing poetry-plugin (1.2.3)
Writing lock file
""" """
assert_plugin_add_result(tester, expected, "^1.2.3") assert_plugin_add_result(tester, expected, "^1.2.3")
...@@ -73,11 +73,11 @@ def test_remove_installed_package(tester: CommandTester): ...@@ -73,11 +73,11 @@ def test_remove_installed_package(tester: CommandTester):
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 0 installs, 0 updates, 1 removal Package operations: 0 installs, 0 updates, 1 removal
• Removing poetry-plugin (1.2.3) • Removing poetry-plugin (1.2.3)
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
......
...@@ -71,12 +71,12 @@ Using version ^{new_version} for poetry ...@@ -71,12 +71,12 @@ Using version ^{new_version} for poetry
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 0 installs, 2 updates, 0 removals Package operations: 0 installs, 2 updates, 0 removals
• Updating cleo (0.8.2 -> 1.0.0) • Updating cleo (0.8.2 -> 1.0.0)
• Updating poetry ({__version__} -> {new_version}) • Updating poetry ({__version__} -> {new_version})
Writing lock file
""" """
assert tester.io.fetch_output() == expected_output assert tester.io.fetch_output() == expected_output
...@@ -16,6 +16,8 @@ from tests.helpers import get_package ...@@ -16,6 +16,8 @@ from tests.helpers import get_package
if TYPE_CHECKING: if TYPE_CHECKING:
from typing import Any
from cleo.testers.command_tester import CommandTester from cleo.testers.command_tester import CommandTester
from pytest_mock import MockerFixture from pytest_mock import MockerFixture
...@@ -70,11 +72,11 @@ Using version ^0.2.0 for cachy ...@@ -70,11 +72,11 @@ Using version ^0.2.0 for cachy
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.2.0) • Installing cachy (0.2.0)
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -100,11 +102,11 @@ Using version ^0.2.0 for cachy ...@@ -100,11 +102,11 @@ Using version ^0.2.0 for cachy
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.2.0) • Installing cachy (0.2.0)
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
assert tester.command.installer.executor.installations_count == 1 assert tester.command.installer.executor.installations_count == 1
...@@ -119,11 +121,11 @@ Package operations: 1 install, 0 updates, 0 removals ...@@ -119,11 +121,11 @@ Package operations: 1 install, 0 updates, 0 removals
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.1.0) • Installing cachy (0.1.0)
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -167,11 +169,11 @@ def test_add_equal_constraint( ...@@ -167,11 +169,11 @@ def test_add_equal_constraint(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.1.0) • Installing cachy (0.1.0)
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -191,11 +193,11 @@ def test_add_greater_constraint( ...@@ -191,11 +193,11 @@ def test_add_greater_constraint(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.2.0) • Installing cachy (0.2.0)
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -225,12 +227,12 @@ def test_add_constraint_with_extras( ...@@ -225,12 +227,12 @@ def test_add_constraint_with_extras(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
• Installing msgpack-python (0.5.3) • Installing msgpack-python (0.5.3)
• Installing cachy (0.1.0) • Installing cachy (0.1.0)
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -255,12 +257,12 @@ def test_add_constraint_dependencies( ...@@ -255,12 +257,12 @@ def test_add_constraint_dependencies(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
• Installing msgpack-python (0.5.3) • Installing msgpack-python (0.5.3)
• Installing cachy (0.2.0) • Installing cachy (0.2.0)
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -285,12 +287,12 @@ def test_add_git_constraint( ...@@ -285,12 +287,12 @@ def test_add_git_constraint(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4) • Installing pendulum (1.4.4)
• Installing demo (0.1.2 9cf87a2) • Installing demo (0.1.2 9cf87a2)
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -321,12 +323,12 @@ def test_add_git_constraint_with_poetry( ...@@ -321,12 +323,12 @@ def test_add_git_constraint_with_poetry(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4) • Installing pendulum (1.4.4)
• Installing demo (0.1.2 9cf87a2) • Installing demo (0.1.2 9cf87a2)
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -354,14 +356,14 @@ def test_add_git_constraint_with_extras( ...@@ -354,14 +356,14 @@ def test_add_git_constraint_with_extras(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 4 installs, 0 updates, 0 removals Package operations: 4 installs, 0 updates, 0 removals
• Installing cleo (0.6.5) • Installing cleo (0.6.5)
• Installing pendulum (1.4.4) • Installing pendulum (1.4.4)
• Installing tomlkit (0.5.5) • Installing tomlkit (0.5.5)
• Installing demo (0.1.2 9cf87a2) • Installing demo (0.1.2 9cf87a2)
Writing lock file
""" """
assert tester.io.fetch_output().strip() == expected.strip() assert tester.io.fetch_output().strip() == expected.strip()
...@@ -400,11 +402,11 @@ def test_add_git_constraint_with_subdirectory( ...@@ -400,11 +402,11 @@ def test_add_git_constraint_with_subdirectory(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
• Installing two (2.0.0 9cf87a2) • Installing two (2.0.0 9cf87a2)
Writing lock file
""" """
assert tester.io.fetch_output().strip() == expected.strip() assert tester.io.fetch_output().strip() == expected.strip()
assert tester.command.installer.executor.installations_count == 1 assert tester.command.installer.executor.installations_count == 1
...@@ -444,12 +446,12 @@ def test_add_git_ssh_constraint( ...@@ -444,12 +446,12 @@ def test_add_git_ssh_constraint(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4) • Installing pendulum (1.4.4)
• Installing demo (0.1.2 9cf87a2) • Installing demo (0.1.2 9cf87a2)
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -491,12 +493,12 @@ def test_add_directory_constraint( ...@@ -491,12 +493,12 @@ def test_add_directory_constraint(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4) • Installing pendulum (1.4.4)
• Installing demo (0.1.2 {app.poetry.file.parent.joinpath(path).resolve().as_posix()}) • Installing demo (0.1.2 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -532,12 +534,12 @@ def test_add_directory_with_poetry( ...@@ -532,12 +534,12 @@ def test_add_directory_with_poetry(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4) • Installing pendulum (1.4.4)
• Installing demo (0.1.2 {app.poetry.file.parent.joinpath(path).resolve().as_posix()}) • Installing demo (0.1.2 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -564,12 +566,12 @@ def test_add_file_constraint_wheel( ...@@ -564,12 +566,12 @@ def test_add_file_constraint_wheel(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4) • Installing pendulum (1.4.4)
• Installing demo (0.1.0 {app.poetry.file.parent.joinpath(path).resolve().as_posix()}) • Installing demo (0.1.0 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -600,12 +602,12 @@ def test_add_file_constraint_sdist( ...@@ -600,12 +602,12 @@ def test_add_file_constraint_sdist(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4) • Installing pendulum (1.4.4)
• Installing demo (0.1.0 {app.poetry.file.parent.joinpath(path).resolve().as_posix()}) • Installing demo (0.1.0 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -640,12 +642,12 @@ def test_add_constraint_with_extras_option( ...@@ -640,12 +642,12 @@ def test_add_constraint_with_extras_option(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
• Installing msgpack-python (0.5.3) • Installing msgpack-python (0.5.3)
• Installing cachy (0.2.0) • Installing cachy (0.2.0)
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -680,13 +682,13 @@ def test_add_url_constraint_wheel( ...@@ -680,13 +682,13 @@ def test_add_url_constraint_wheel(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4) • Installing pendulum (1.4.4)
• Installing demo\ • Installing demo\
(0.1.0 https://python-poetry.org/distributions/demo-0.1.0-py2.py3-none-any.whl) (0.1.0 https://python-poetry.org/distributions/demo-0.1.0-py2.py3-none-any.whl)
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -722,8 +724,6 @@ def test_add_url_constraint_wheel_with_extras( ...@@ -722,8 +724,6 @@ def test_add_url_constraint_wheel_with_extras(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 4 installs, 0 updates, 0 removals Package operations: 4 installs, 0 updates, 0 removals
• Installing cleo (0.6.5) • Installing cleo (0.6.5)
...@@ -731,6 +731,8 @@ Package operations: 4 installs, 0 updates, 0 removals ...@@ -731,6 +731,8 @@ Package operations: 4 installs, 0 updates, 0 removals
• Installing tomlkit (0.5.5) • Installing tomlkit (0.5.5)
• Installing demo\ • Installing demo\
(0.1.0 https://python-poetry.org/distributions/demo-0.1.0-py2.py3-none-any.whl) (0.1.0 https://python-poetry.org/distributions/demo-0.1.0-py2.py3-none-any.whl)
Writing lock file
""" """
# Order might be different, split into lines and compare the overall output. # Order might be different, split into lines and compare the overall output.
expected = set(expected.splitlines()) expected = set(expected.splitlines())
...@@ -764,11 +766,11 @@ def test_add_constraint_with_python( ...@@ -764,11 +766,11 @@ def test_add_constraint_with_python(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.2.0) • Installing cachy (0.2.0)
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -802,11 +804,11 @@ def test_add_constraint_with_platform( ...@@ -802,11 +804,11 @@ def test_add_constraint_with_platform(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.2.0) • Installing cachy (0.2.0)
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -853,11 +855,11 @@ def test_add_constraint_with_source( ...@@ -853,11 +855,11 @@ def test_add_constraint_with_source(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.2.0) • Installing cachy (0.2.0)
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -915,11 +917,11 @@ Using version ^0.2.0 for cachy ...@@ -915,11 +917,11 @@ Using version ^0.2.0 for cachy
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.2.0) • Installing cachy (0.2.0)
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -962,11 +964,11 @@ Using version ^0.2.0 for cachy ...@@ -962,11 +964,11 @@ Using version ^0.2.0 for cachy
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.2.0) • Installing cachy (0.2.0)
Writing lock file
""" """
assert tester.io.fetch_error() == warning assert tester.io.fetch_error() == warning
...@@ -993,11 +995,11 @@ Using version ^3.13 for pyyaml ...@@ -993,11 +995,11 @@ Using version ^3.13 for pyyaml
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
• Installing pyyaml (3.13) • Installing pyyaml (3.13)
Writing lock file
""" """
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
...@@ -1112,11 +1114,11 @@ Using version ^1.1.2 for foo ...@@ -1112,11 +1114,11 @@ Using version ^1.1.2 for foo
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
• Installing foo (1.1.2) • Installing foo (1.1.2)
Writing lock file
""" """
assert expected in tester.io.fetch_output() assert expected in tester.io.fetch_output()
...@@ -1141,11 +1143,11 @@ Using version ^1.2.3b1 for foo ...@@ -1141,11 +1143,11 @@ Using version ^1.2.3b1 for foo
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
• Installing foo (1.2.3b1) • Installing foo (1.2.3b1)
Writing lock file
""" """
assert expected in tester.io.fetch_output() assert expected in tester.io.fetch_output()
...@@ -1164,11 +1166,11 @@ Using version ^1.2.3 for foo ...@@ -1164,11 +1166,11 @@ Using version ^1.2.3 for foo
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
• Installing foo (1.2.3) • Installing foo (1.2.3)
Writing lock file
""" """
assert expected in tester.io.fetch_output() assert expected in tester.io.fetch_output()
...@@ -1212,11 +1214,11 @@ Using version ^0.2.0 for cachy ...@@ -1212,11 +1214,11 @@ Using version ^0.2.0 for cachy
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
- Installing cachy (0.2.0) - Installing cachy (0.2.0)
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1245,11 +1247,11 @@ def test_add_equal_constraint_old_installer( ...@@ -1245,11 +1247,11 @@ def test_add_equal_constraint_old_installer(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
- Installing cachy (0.1.0) - Installing cachy (0.1.0)
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1273,11 +1275,11 @@ def test_add_greater_constraint_old_installer( ...@@ -1273,11 +1275,11 @@ def test_add_greater_constraint_old_installer(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
- Installing cachy (0.2.0) - Installing cachy (0.2.0)
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1309,12 +1311,12 @@ def test_add_constraint_with_extras_old_installer( ...@@ -1309,12 +1311,12 @@ def test_add_constraint_with_extras_old_installer(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
- Installing msgpack-python (0.5.3) - Installing msgpack-python (0.5.3)
- Installing cachy (0.1.0) - Installing cachy (0.1.0)
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1343,12 +1345,12 @@ def test_add_constraint_dependencies_old_installer( ...@@ -1343,12 +1345,12 @@ def test_add_constraint_dependencies_old_installer(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
- Installing msgpack-python (0.5.3) - Installing msgpack-python (0.5.3)
- Installing cachy (0.2.0) - Installing cachy (0.2.0)
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1372,12 +1374,12 @@ def test_add_git_constraint_old_installer( ...@@ -1372,12 +1374,12 @@ def test_add_git_constraint_old_installer(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4) - Installing pendulum (1.4.4)
- Installing demo (0.1.2 9cf87a2) - Installing demo (0.1.2 9cf87a2)
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1407,12 +1409,12 @@ def test_add_git_constraint_with_poetry_old_installer( ...@@ -1407,12 +1409,12 @@ def test_add_git_constraint_with_poetry_old_installer(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4) - Installing pendulum (1.4.4)
- Installing demo (0.1.2 9cf87a2) - Installing demo (0.1.2 9cf87a2)
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1439,14 +1441,14 @@ def test_add_git_constraint_with_extras_old_installer( ...@@ -1439,14 +1441,14 @@ def test_add_git_constraint_with_extras_old_installer(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 4 installs, 0 updates, 0 removals Package operations: 4 installs, 0 updates, 0 removals
- Installing cleo (0.6.5) - Installing cleo (0.6.5)
- Installing pendulum (1.4.4) - Installing pendulum (1.4.4)
- Installing tomlkit (0.5.5) - Installing tomlkit (0.5.5)
- Installing demo (0.1.2 9cf87a2) - Installing demo (0.1.2 9cf87a2)
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1478,12 +1480,12 @@ def test_add_git_ssh_constraint_old_installer( ...@@ -1478,12 +1480,12 @@ def test_add_git_ssh_constraint_old_installer(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4) - Installing pendulum (1.4.4)
- Installing demo (0.1.2 9cf87a2) - Installing demo (0.1.2 9cf87a2)
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1520,12 +1522,12 @@ def test_add_directory_constraint_old_installer( ...@@ -1520,12 +1522,12 @@ def test_add_directory_constraint_old_installer(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4) - Installing pendulum (1.4.4)
- Installing demo (0.1.2 {app.poetry.file.parent.joinpath(path).resolve().as_posix()}) - Installing demo (0.1.2 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1558,12 +1560,12 @@ def test_add_directory_with_poetry_old_installer( ...@@ -1558,12 +1560,12 @@ def test_add_directory_with_poetry_old_installer(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4) - Installing pendulum (1.4.4)
- Installing demo (0.1.2 {app.poetry.file.parent.joinpath(path).resolve().as_posix()}) - Installing demo (0.1.2 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1591,12 +1593,12 @@ def test_add_file_constraint_wheel_old_installer( ...@@ -1591,12 +1593,12 @@ def test_add_file_constraint_wheel_old_installer(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4) - Installing pendulum (1.4.4)
- Installing demo (0.1.0 {app.poetry.file.parent.joinpath(path).resolve().as_posix()}) - Installing demo (0.1.0 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1629,12 +1631,12 @@ def test_add_file_constraint_sdist_old_installer( ...@@ -1629,12 +1631,12 @@ def test_add_file_constraint_sdist_old_installer(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4) - Installing pendulum (1.4.4)
- Installing demo (0.1.0 {app.poetry.file.parent.joinpath(path).resolve().as_posix()}) - Installing demo (0.1.0 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1671,12 +1673,12 @@ def test_add_constraint_with_extras_option_old_installer( ...@@ -1671,12 +1673,12 @@ def test_add_constraint_with_extras_option_old_installer(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
- Installing msgpack-python (0.5.3) - Installing msgpack-python (0.5.3)
- Installing cachy (0.2.0) - Installing cachy (0.2.0)
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1713,13 +1715,13 @@ def test_add_url_constraint_wheel_old_installer( ...@@ -1713,13 +1715,13 @@ def test_add_url_constraint_wheel_old_installer(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4) - Installing pendulum (1.4.4)
- Installing demo\ - Installing demo\
(0.1.0 https://python-poetry.org/distributions/demo-0.1.0-py2.py3-none-any.whl) (0.1.0 https://python-poetry.org/distributions/demo-0.1.0-py2.py3-none-any.whl)
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1756,8 +1758,6 @@ def test_add_url_constraint_wheel_with_extras_old_installer( ...@@ -1756,8 +1758,6 @@ def test_add_url_constraint_wheel_with_extras_old_installer(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 4 installs, 0 updates, 0 removals Package operations: 4 installs, 0 updates, 0 removals
- Installing cleo (0.6.5) - Installing cleo (0.6.5)
...@@ -1765,6 +1765,8 @@ Package operations: 4 installs, 0 updates, 0 removals ...@@ -1765,6 +1765,8 @@ Package operations: 4 installs, 0 updates, 0 removals
- Installing tomlkit (0.5.5) - Installing tomlkit (0.5.5)
- Installing demo\ - Installing demo\
(0.1.0 https://python-poetry.org/distributions/demo-0.1.0-py2.py3-none-any.whl) (0.1.0 https://python-poetry.org/distributions/demo-0.1.0-py2.py3-none-any.whl)
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1800,11 +1802,11 @@ def test_add_constraint_with_python_old_installer( ...@@ -1800,11 +1802,11 @@ def test_add_constraint_with_python_old_installer(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
- Installing cachy (0.2.0) - Installing cachy (0.2.0)
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1840,11 +1842,11 @@ def test_add_constraint_with_platform_old_installer( ...@@ -1840,11 +1842,11 @@ def test_add_constraint_with_platform_old_installer(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
- Installing cachy (0.2.0) - Installing cachy (0.2.0)
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1893,11 +1895,11 @@ def test_add_constraint_with_source_old_installer( ...@@ -1893,11 +1895,11 @@ def test_add_constraint_with_source_old_installer(
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
- Installing cachy (0.2.0) - Installing cachy (0.2.0)
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1959,11 +1961,11 @@ Using version ^0.2.0 for cachy ...@@ -1959,11 +1961,11 @@ Using version ^0.2.0 for cachy
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
- Installing cachy (0.2.0) - Installing cachy (0.2.0)
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -1993,11 +1995,11 @@ Using version ^3.13 for pyyaml ...@@ -1993,11 +1995,11 @@ Using version ^3.13 for pyyaml
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
- Installing pyyaml (3.13) - Installing pyyaml (3.13)
Writing lock file
""" """
assert old_tester.io.fetch_output() == expected assert old_tester.io.fetch_output() == expected
...@@ -2058,11 +2060,11 @@ Using version ^1.1.2 for foo ...@@ -2058,11 +2060,11 @@ Using version ^1.1.2 for foo
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
- Installing foo (1.1.2) - Installing foo (1.1.2)
Writing lock file
""" """
assert expected in old_tester.io.fetch_output() assert expected in old_tester.io.fetch_output()
...@@ -2090,11 +2092,11 @@ Using version ^1.2.3b1 for foo ...@@ -2090,11 +2092,11 @@ Using version ^1.2.3b1 for foo
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
- Installing foo (1.2.3b1) - Installing foo (1.2.3b1)
Writing lock file
""" """
assert expected in old_tester.io.fetch_output() assert expected in old_tester.io.fetch_output()
...@@ -2116,11 +2118,11 @@ Using version ^1.2.3 for foo ...@@ -2116,11 +2118,11 @@ Using version ^1.2.3 for foo
Updating dependencies Updating dependencies
Resolving dependencies... Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals Package operations: 1 install, 0 updates, 0 removals
- Installing foo (1.2.3) - Installing foo (1.2.3)
Writing lock file
""" """
assert expected in old_tester.io.fetch_output() assert expected in old_tester.io.fetch_output()
...@@ -2157,7 +2159,8 @@ def test_add_keyboard_interrupt_restore_content( ...@@ -2157,7 +2159,8 @@ def test_add_keyboard_interrupt_restore_content(
tester = command_tester_factory("add", poetry=poetry_with_up_to_date_lockfile) tester = command_tester_factory("add", poetry=poetry_with_up_to_date_lockfile)
mocker.patch( mocker.patch(
"poetry.installation.installer.Installer.run", side_effect=KeyboardInterrupt() "poetry.installation.installer.Installer._execute",
side_effect=KeyboardInterrupt(),
) )
original_pyproject_content = poetry_with_up_to_date_lockfile.file.read() original_pyproject_content = poetry_with_up_to_date_lockfile.file.read()
original_lockfile_content = poetry_with_up_to_date_lockfile._locker.lock_data original_lockfile_content = poetry_with_up_to_date_lockfile._locker.lock_data
...@@ -2200,3 +2203,39 @@ def test_add_with_dry_run_keep_files_intact( ...@@ -2200,3 +2203,39 @@ def test_add_with_dry_run_keep_files_intact(
assert ( assert (
poetry_with_up_to_date_lockfile._locker.lock_data == original_lockfile_content poetry_with_up_to_date_lockfile._locker.lock_data == original_lockfile_content
) )
def test_add_should_not_change_lock_file_when_dependency_installation_fail(
poetry_with_up_to_date_lockfile: Poetry,
repo: TestRepository,
command_tester_factory: CommandTesterFactory,
mocker: MockerFixture,
):
tester = command_tester_factory("add", poetry=poetry_with_up_to_date_lockfile)
repo.add_package(get_package("docker", "4.3.1"))
repo.add_package(get_package("cachy", "0.2.0"))
original_pyproject_content = poetry_with_up_to_date_lockfile.file.read()
original_lockfile_content = poetry_with_up_to_date_lockfile.locker.lock_data
def error(_: Any) -> int:
tester.io.write("\n BuildError\n\n")
return 1
mocker.patch("poetry.installation.installer.Installer._execute", side_effect=error)
tester.execute("cachy")
expected = """\
Using version ^0.2.0 for cachy
Updating dependencies
Resolving dependencies...
BuildError
"""
assert poetry_with_up_to_date_lockfile.file.read() == original_pyproject_content
assert poetry_with_up_to_date_lockfile.locker.lock_data == original_lockfile_content
assert tester.io.fetch_output() == expected
...@@ -105,6 +105,7 @@ class Locker(BaseLocker): ...@@ -105,6 +105,7 @@ class Locker(BaseLocker):
self._lock = lock_path / "poetry.lock" self._lock = lock_path / "poetry.lock"
self._written_data = None self._written_data = None
self._locked = False self._locked = False
self._lock_data = None
self._content_hash = self._get_content_hash() self._content_hash = self._get_content_hash()
@property @property
...@@ -2415,6 +2416,29 @@ def test_installer_can_handle_old_lock_files( ...@@ -2415,6 +2416,29 @@ def test_installer_can_handle_old_lock_files(
assert installer.executor.installations_count == 8 assert installer.executor.installations_count == 8
def test_installer_does_not_write_lock_file_when_installation_fails(
installer: Installer,
locker: Locker,
repo: Repository,
package: ProjectPackage,
mocker: MockerFixture,
):
repo.add_package(get_package("A", "1.0"))
package.add_dependency(Factory.create_dependency("A", "~1.0"))
locker.locked(False)
mocker.patch("poetry.installation.installer.Installer._execute", return_value=1)
result = installer.run()
assert result == 1 # error
assert locker._lock_data is None
assert installer.executor.installations_count == 0
assert installer.executor.updates_count == 0
assert installer.executor.removals_count == 0
@pytest.mark.parametrize("quiet", [True, False]) @pytest.mark.parametrize("quiet", [True, False])
def test_run_with_dependencies_quiet( def test_run_with_dependencies_quiet(
installer: Installer, installer: Installer,
......
...@@ -62,6 +62,7 @@ class Locker(BaseLocker): ...@@ -62,6 +62,7 @@ class Locker(BaseLocker):
self._lock = lock_path / "poetry.lock" self._lock = lock_path / "poetry.lock"
self._written_data = None self._written_data = None
self._locked = False self._locked = False
self._lock_data = None
self._content_hash = self._get_content_hash() self._content_hash = self._get_content_hash()
@property @property
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment