From 185aa94506dcc8a6b2288d96cb4201beb6f76838 Mon Sep 17 00:00:00 2001 From: ralbertazzi Date: Sun, 14 May 2023 12:05:02 +0200 Subject: [PATCH] fix: poetry add --lock does not perform a full update --- src/poetry/console/commands/add.py | 7 +- tests/console/commands/test_add.py | 34 ++++ tests/fixtures/up_to_date_lock/poetry.lock | 168 ++++++------------ tests/fixtures/up_to_date_lock/pyproject.toml | 2 +- 4 files changed, 89 insertions(+), 122 deletions(-) diff --git a/src/poetry/console/commands/add.py b/src/poetry/console/commands/add.py index 3815a2e1292..9fda60fbc7e 100644 --- a/src/poetry/console/commands/add.py +++ b/src/poetry/console/commands/add.py @@ -254,9 +254,7 @@ def handle(self) -> int: ) # Refresh the locker - self.poetry.set_locker( - self.poetry.locker.__class__(self.poetry.locker.lock, poetry_content) - ) + self.poetry.locker.set_local_config(poetry_content) self.installer.set_locker(self.poetry.locker) # Cosmetic new line @@ -266,8 +264,7 @@ def handle(self) -> int: self.installer.dry_run(self.option("dry-run")) self.installer.verbose(self.io.is_verbose()) self.installer.update(True) - if self.option("lock"): - self.installer.lock() + self.installer.execute_operations(not self.option("lock")) self.installer.whitelist([r["name"] for r in requirements]) diff --git a/tests/console/commands/test_add.py b/tests/console/commands/test_add.py index 25d3eb49fed..33d7848b482 100644 --- a/tests/console/commands/test_add.py +++ b/tests/console/commands/test_add.py @@ -15,6 +15,7 @@ from poetry.console.commands.installer_command import InstallerCommand from poetry.puzzle.exceptions import SolverProblemError from poetry.repositories.legacy_repository import LegacyRepository +from tests.helpers import TestLocker from tests.helpers import get_dependency from tests.helpers import get_package @@ -1506,3 +1507,36 @@ def test_add_extras_only_accepts_one_package( str(e.value) == "You can only specify one package when using the --extras option" ) + + +@pytest.mark.parametrize("command", ["foo", "foo --lock"]) +@pytest.mark.parametrize( + ("locked", "expected_docker"), [(True, "4.3.1"), (False, "4.3.2")] +) +def test_add_does_not_update_locked_dependencies( + repo: TestRepository, + poetry_with_up_to_date_lockfile: Poetry, + tester: CommandTester, + command_tester_factory: CommandTesterFactory, + command: str, + locked: bool, + expected_docker: str, +) -> None: + assert isinstance(poetry_with_up_to_date_lockfile.locker, TestLocker) + poetry_with_up_to_date_lockfile.locker.locked(locked) + tester = command_tester_factory("add", poetry=poetry_with_up_to_date_lockfile) + docker_locked = get_package("docker", "4.3.1") + docker_new = get_package("docker", "4.3.2") + docker_dep = get_dependency("docker", ">=4.0.0") + foo = get_package("foo", "0.1.0") + foo.add_dependency(docker_dep) + for package in docker_locked, docker_new, foo: + repo.add_package(package) + + tester.execute(command) + + lock_data = poetry_with_up_to_date_lockfile.locker.lock_data + docker_locked_after_command = next( + p for p in lock_data["package"] if p["name"] == "docker" + ) + assert docker_locked_after_command["version"] == expected_docker diff --git a/tests/fixtures/up_to_date_lock/poetry.lock b/tests/fixtures/up_to_date_lock/poetry.lock index 8b2ca8737e0..4155300cea5 100644 --- a/tests/fixtures/up_to_date_lock/poetry.lock +++ b/tests/fixtures/up_to_date_lock/poetry.lock @@ -1,17 +1,15 @@ +# This file is automatically @generated by Poetry 1.5.0.dev0 and should not be changed by hand. + [[package]] name = "certifi" version = "2020.12.5" description = "Python package for providing Mozilla's CA Bundle." optional = false python-versions = "*" - -[[package.files]] -file = "certifi-2020.12.5-py2.py3-none-any.whl" -hash = "sha256:719a74fb9e33b9bd44cc7f3a8d94bc35e4049deebe19ba7d8e108280cfd59830" - -[[package.files]] -file = "certifi-2020.12.5.tar.gz" -hash = "sha256:1a4995114262bffbc2413b159f2a1a480c969de6e6eb13ee966d470af86af59c" +files = [ + {file = "certifi-2020.12.5-py2.py3-none-any.whl", hash = "sha256:719a74fb9e33b9bd44cc7f3a8d94bc35e4049deebe19ba7d8e108280cfd59830"}, + {file = "certifi-2020.12.5.tar.gz", hash = "sha256:1a4995114262bffbc2413b159f2a1a480c969de6e6eb13ee966d470af86af59c"}, +] [[package]] name = "chardet" @@ -19,14 +17,10 @@ version = "4.0.0" description = "Universal encoding detector for Python 2 and 3" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" - -[[package.files]] -file = "chardet-4.0.0-py2.py3-none-any.whl" -hash = "sha256:f864054d66fd9118f2e67044ac8981a54775ec5b67aed0441892edb553d21da5" - -[[package.files]] -file = "chardet-4.0.0.tar.gz" -hash = "sha256:0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa" +files = [ + {file = "chardet-4.0.0-py2.py3-none-any.whl", hash = "sha256:f864054d66fd9118f2e67044ac8981a54775ec5b67aed0441892edb553d21da5"}, + {file = "chardet-4.0.0.tar.gz", hash = "sha256:0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa"}, +] [[package]] name = "docker" @@ -34,14 +28,10 @@ version = "4.3.1" description = "A Python library for the Docker Engine API." optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" - -[[package.files]] -file = "docker-4.3.1-py2.py3-none-any.whl" -hash = "sha256:13966471e8bc23b36bfb3a6fb4ab75043a5ef1dac86516274777576bed3b9828" - -[[package.files]] -file = "docker-4.3.1.tar.gz" -hash = "sha256:bad94b8dd001a8a4af19ce4becc17f41b09f228173ffe6a4e0355389eef142f2" +files = [ + {file = "docker-4.3.1-py2.py3-none-any.whl", hash = "sha256:13966471e8bc23b36bfb3a6fb4ab75043a5ef1dac86516274777576bed3b9828"}, + {file = "docker-4.3.1.tar.gz", hash = "sha256:bad94b8dd001a8a4af19ce4becc17f41b09f228173ffe6a4e0355389eef142f2"}, +] [package.dependencies] pywin32 = {version = "227", markers = "sys_platform == \"win32\""} @@ -51,7 +41,7 @@ websocket-client = ">=0.32.0" [package.extras] ssh = ["paramiko (>=2.4.2)"] -tls = ["pyOpenSSL (>=17.5.0)", "cryptography (>=1.3.4)", "idna (>=2.0.0)"] +tls = ["cryptography (>=1.3.4)", "idna (>=2.0.0)", "pyOpenSSL (>=17.5.0)"] [[package]] name = "idna" @@ -59,14 +49,10 @@ version = "2.10" description = "Internationalized Domain Names in Applications (IDNA)" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" - -[[package.files]] -file = "idna-2.10-py2.py3-none-any.whl" -hash = "sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0" - -[[package.files]] -file = "idna-2.10.tar.gz" -hash = "sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6" +files = [ + {file = "idna-2.10-py2.py3-none-any.whl", hash = "sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0"}, + {file = "idna-2.10.tar.gz", hash = "sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6"}, +] [[package]] name = "pywin32" @@ -74,54 +60,20 @@ version = "227" description = "Python for Window Extensions" optional = false python-versions = "*" - -[[package.files]] -file = "pywin32-227-cp27-cp27m-win32.whl" -hash = "sha256:371fcc39416d736401f0274dd64c2302728c9e034808e37381b5e1b22be4a6b0" - -[[package.files]] -file = "pywin32-227-cp27-cp27m-win_amd64.whl" -hash = "sha256:4cdad3e84191194ea6d0dd1b1b9bdda574ff563177d2adf2b4efec2a244fa116" - -[[package.files]] -file = "pywin32-227-cp35-cp35m-win32.whl" -hash = "sha256:f4c5be1a293bae0076d93c88f37ee8da68136744588bc5e2be2f299a34ceb7aa" - -[[package.files]] -file = "pywin32-227-cp35-cp35m-win_amd64.whl" -hash = "sha256:a929a4af626e530383a579431b70e512e736e9588106715215bf685a3ea508d4" - -[[package.files]] -file = "pywin32-227-cp36-cp36m-win32.whl" -hash = "sha256:300a2db938e98c3e7e2093e4491439e62287d0d493fe07cce110db070b54c0be" - -[[package.files]] -file = "pywin32-227-cp36-cp36m-win_amd64.whl" -hash = "sha256:9b31e009564fb95db160f154e2aa195ed66bcc4c058ed72850d047141b36f3a2" - -[[package.files]] -file = "pywin32-227-cp37-cp37m-win32.whl" -hash = "sha256:47a3c7551376a865dd8d095a98deba954a98f326c6fe3c72d8726ca6e6b15507" - -[[package.files]] -file = "pywin32-227-cp37-cp37m-win_amd64.whl" -hash = "sha256:31f88a89139cb2adc40f8f0e65ee56a8c585f629974f9e07622ba80199057511" - -[[package.files]] -file = "pywin32-227-cp38-cp38-win32.whl" -hash = "sha256:7f18199fbf29ca99dff10e1f09451582ae9e372a892ff03a28528a24d55875bc" - -[[package.files]] -file = "pywin32-227-cp38-cp38-win_amd64.whl" -hash = "sha256:7c1ae32c489dc012930787f06244426f8356e129184a02c25aef163917ce158e" - -[[package.files]] -file = "pywin32-227-cp39-cp39-win32.whl" -hash = "sha256:c054c52ba46e7eb6b7d7dfae4dbd987a1bb48ee86debe3f245a2884ece46e295" - -[[package.files]] -file = "pywin32-227-cp39-cp39-win_amd64.whl" -hash = "sha256:f27cec5e7f588c3d1051651830ecc00294f90728d19c3bf6916e6dba93ea357c" +files = [ + {file = "pywin32-227-cp27-cp27m-win32.whl", hash = "sha256:371fcc39416d736401f0274dd64c2302728c9e034808e37381b5e1b22be4a6b0"}, + {file = "pywin32-227-cp27-cp27m-win_amd64.whl", hash = "sha256:4cdad3e84191194ea6d0dd1b1b9bdda574ff563177d2adf2b4efec2a244fa116"}, + {file = "pywin32-227-cp35-cp35m-win32.whl", hash = "sha256:f4c5be1a293bae0076d93c88f37ee8da68136744588bc5e2be2f299a34ceb7aa"}, + {file = "pywin32-227-cp35-cp35m-win_amd64.whl", hash = "sha256:a929a4af626e530383a579431b70e512e736e9588106715215bf685a3ea508d4"}, + {file = "pywin32-227-cp36-cp36m-win32.whl", hash = "sha256:300a2db938e98c3e7e2093e4491439e62287d0d493fe07cce110db070b54c0be"}, + {file = "pywin32-227-cp36-cp36m-win_amd64.whl", hash = "sha256:9b31e009564fb95db160f154e2aa195ed66bcc4c058ed72850d047141b36f3a2"}, + {file = "pywin32-227-cp37-cp37m-win32.whl", hash = "sha256:47a3c7551376a865dd8d095a98deba954a98f326c6fe3c72d8726ca6e6b15507"}, + {file = "pywin32-227-cp37-cp37m-win_amd64.whl", hash = "sha256:31f88a89139cb2adc40f8f0e65ee56a8c585f629974f9e07622ba80199057511"}, + {file = "pywin32-227-cp38-cp38-win32.whl", hash = "sha256:7f18199fbf29ca99dff10e1f09451582ae9e372a892ff03a28528a24d55875bc"}, + {file = "pywin32-227-cp38-cp38-win_amd64.whl", hash = "sha256:7c1ae32c489dc012930787f06244426f8356e129184a02c25aef163917ce158e"}, + {file = "pywin32-227-cp39-cp39-win32.whl", hash = "sha256:c054c52ba46e7eb6b7d7dfae4dbd987a1bb48ee86debe3f245a2884ece46e295"}, + {file = "pywin32-227-cp39-cp39-win_amd64.whl", hash = "sha256:f27cec5e7f588c3d1051651830ecc00294f90728d19c3bf6916e6dba93ea357c"}, +] [[package]] name = "requests" @@ -129,14 +81,10 @@ version = "2.25.1" description = "Python HTTP for Humans." optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" - -[[package.files]] -file = "requests-2.25.1-py2.py3-none-any.whl" -hash = "sha256:c210084e36a42ae6b9219e00e48287def368a26d03a048ddad7bfee44f75871e" - -[[package.files]] -file = "requests-2.25.1.tar.gz" -hash = "sha256:27973dd4a904a4f13b263a19c866c13b92a39ed1c964655f025f3f8d3d75b804" +files = [ + {file = "requests-2.25.1-py2.py3-none-any.whl", hash = "sha256:c210084e36a42ae6b9219e00e48287def368a26d03a048ddad7bfee44f75871e"}, + {file = "requests-2.25.1.tar.gz", hash = "sha256:27973dd4a904a4f13b263a19c866c13b92a39ed1c964655f025f3f8d3d75b804"}, +] [package.dependencies] certifi = ">=2017.4.17" @@ -145,7 +93,7 @@ idna = ">=2.5,<3" urllib3 = ">=1.21.1,<1.27" [package.extras] -security = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)"] +security = ["cryptography (>=1.3.4)", "pyOpenSSL (>=0.14)"] socks = ["PySocks (>=1.5.6,!=1.5.7)", "win-inet-pton"] [[package]] @@ -154,14 +102,10 @@ version = "1.15.0" description = "Python 2 and 3 compatibility utilities" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" - -[[package.files]] -file = "six-1.15.0-py2.py3-none-any.whl" -hash = "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced" - -[[package.files]] -file = "six-1.15.0.tar.gz" -hash = "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259" +files = [ + {file = "six-1.15.0-py2.py3-none-any.whl", hash = "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced"}, + {file = "six-1.15.0.tar.gz", hash = "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259"}, +] [[package]] name = "urllib3" @@ -169,18 +113,14 @@ version = "1.26.3" description = "HTTP library with thread-safe connection pooling, file post, and more." optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4" - -[[package.files]] -file = "urllib3-1.26.3-py2.py3-none-any.whl" -hash = "sha256:1b465e494e3e0d8939b50680403e3aedaa2bc434b7d5af64dfd3c958d7f5ae80" - -[[package.files]] -file = "urllib3-1.26.3.tar.gz" -hash = "sha256:de3eedaad74a2683334e282005cd8d7f22f4d55fa690a2a1020a416cb0a47e73" +files = [ + {file = "urllib3-1.26.3-py2.py3-none-any.whl", hash = "sha256:1b465e494e3e0d8939b50680403e3aedaa2bc434b7d5af64dfd3c958d7f5ae80"}, + {file = "urllib3-1.26.3.tar.gz", hash = "sha256:de3eedaad74a2683334e282005cd8d7f22f4d55fa690a2a1020a416cb0a47e73"}, +] [package.extras] brotli = ["brotlipy (>=0.6.0)"] -secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "ipaddress"] +secure = ["certifi", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "ipaddress", "pyOpenSSL (>=0.14)"] socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] [[package]] @@ -189,14 +129,10 @@ version = "0.58.0" description = "WebSocket client for Python with low level API options" optional = false python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" - -[[package.files]] -file = "websocket_client-0.58.0-py2.py3-none-any.whl" -hash = "sha256:44b5df8f08c74c3d82d28100fdc81f4536809ce98a17f0757557813275fbb663" - -[[package.files]] -file = "websocket_client-0.58.0.tar.gz" -hash = "sha256:63509b41d158ae5b7f67eb4ad20fecbb4eee99434e73e140354dc3ff8e09716f" +files = [ + {file = "websocket_client-0.58.0-py2.py3-none-any.whl", hash = "sha256:44b5df8f08c74c3d82d28100fdc81f4536809ce98a17f0757557813275fbb663"}, + {file = "websocket_client-0.58.0.tar.gz", hash = "sha256:63509b41d158ae5b7f67eb4ad20fecbb4eee99434e73e140354dc3ff8e09716f"}, +] [package.dependencies] six = "*" @@ -204,4 +140,4 @@ six = "*" [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "0cd068218f235c162f7b74bc8faf4ce3387b82daee1c1bb7a97af034f27ee116" +content-hash = "67c4543fd4f299cfeeaf82c5846ce720aa576e49811fbf9ccd0463ac8d5b52e4" diff --git a/tests/fixtures/up_to_date_lock/pyproject.toml b/tests/fixtures/up_to_date_lock/pyproject.toml index 555147605ea..dd388ab9d00 100644 --- a/tests/fixtures/up_to_date_lock/pyproject.toml +++ b/tests/fixtures/up_to_date_lock/pyproject.toml @@ -6,7 +6,7 @@ authors = ["Poetry Developer "] [tool.poetry.dependencies] python = "^3.8" -docker = "4.3.1" +docker = ">=4.3.1" [tool.poetry.dev-dependencies]