Skip to content

Commit

Permalink
fix: poetry add --lock does not perform a full update (python-poetry#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ralbertazzi authored May 14, 2023
1 parent c564e1c commit ede3eca
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 122 deletions.
7 changes: 2 additions & 5 deletions src/poetry/console/commands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])

Expand Down
34 changes: 34 additions & 0 deletions tests/console/commands/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
168 changes: 52 additions & 116 deletions tests/fixtures/up_to_date_lock/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/fixtures/up_to_date_lock/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Poetry Developer <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.8"
docker = "4.3.1"
docker = ">=4.3.1"

[tool.poetry.dev-dependencies]

Expand Down

0 comments on commit ede3eca

Please sign in to comment.