Skip to content

Commit

Permalink
lock: resolve dependencies on no-update
Browse files Browse the repository at this point in the history
This change ensures that we resolve dependencies to correctly propagate
markers when using `lock --no-update`.

Resolves: #3048
  • Loading branch information
abn authored and finswimmer committed Oct 5, 2020
1 parent 349e0dd commit f7a55f4
Show file tree
Hide file tree
Showing 7 changed files with 390 additions and 158 deletions.
14 changes: 13 additions & 1 deletion poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,24 @@ def use_executor(self, use_executor=True): # type: (bool) -> Installer
return self

def _do_refresh(self):
from poetry.puzzle import Solver

# Checking extras
for extra in self._extras:
if extra not in self._package.extras:
raise ValueError("Extra [{}] is not specified.".format(extra))

ops = self._get_operations_from_lock(self._locker.locked_repository(True))
locked_repository = self._locker.locked_repository(True)
solver = Solver(
self._package,
self._pool,
locked_repository,
locked_repository,
self._io, # noqa
)

ops = solver.solve(use_latest=[])

local_repo = Repository()
self._populate_local_repo(local_repo, ops)

Expand Down
57 changes: 57 additions & 0 deletions tests/console/commands/test_lock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import shutil
import sys

import pytest

from poetry.factory import Factory
from poetry.packages import Locker
from poetry.utils._compat import Path


@pytest.fixture
def source_dir(tmp_path): # type: (Path) -> Path
yield Path(tmp_path.as_posix())


@pytest.fixture
def tester(command_tester_factory):
return command_tester_factory("lock")


@pytest.fixture
def poetry_with_old_lockfile(fixture_dir, source_dir):
project_dir = source_dir / "project"
shutil.copytree(str(fixture_dir("old_lock")), str(project_dir))
poetry = Factory().create_poetry(cwd=project_dir)
return poetry


@pytest.mark.skipif(
sys.platform == "win32", reason="does not work on windows under ci environments"
)
def test_lock_no_update(command_tester_factory, poetry_with_old_lockfile, http):
http.disable()

locked_repository = poetry_with_old_lockfile.locker.locked_repository(
with_dev_reqs=True
)
assert (
poetry_with_old_lockfile.locker.lock_data["metadata"].get("lock-version")
== "1.0"
)

tester = command_tester_factory("lock", poetry=poetry_with_old_lockfile)
tester.execute("--no-update")

locker = Locker(
lock=poetry_with_old_lockfile.pyproject.file.path.parent / "poetry.lock",
local_config={},
)
packages = locker.locked_repository(True).packages

assert len(packages) == len(locked_repository.packages)

assert locker.lock_data["metadata"].get("lock-version") == "1.1"

for package in packages:
assert locked_repository.find_packages(package.to_dependency())
153 changes: 153 additions & 0 deletions tests/fixtures/old_lock/poetry.lock

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

15 changes: 15 additions & 0 deletions tests/fixtures/old_lock/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[tool.poetry]
name = "foobar"
version = "0.1.0"
description = ""
authors = ["Poetry Developer <developer@python-poetry.org>"]

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

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Loading

0 comments on commit f7a55f4

Please sign in to comment.