Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always re-solve directory dependencies #6843

Merged
merged 19 commits into from
Oct 30, 2022
8 changes: 7 additions & 1 deletion src/poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,16 @@ def _do_refresh(self) -> int:
self._io,
)

# Always re-solve directory dependencies, otherwise we can't determine
# if anything has changed (and the lock file contains an invalid version).
use_latest = [
p.name for p in locked_repository.packages if p.source_type == "directory"
]

with solver.provider.use_source_root(
source_root=self._env.path.joinpath("src")
):
ops = solver.solve(use_latest=[]).calculate_operations()
ops = solver.solve(use_latest=use_latest).calculate_operations()

lockfile_repo = LockfileRepository()
self._populate_lockfile_repo(lockfile_repo, ops)
Expand Down
38 changes: 38 additions & 0 deletions tests/console/commands/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def _project_factory(
name="foobar",
pyproject_content=pyproject_content,
poetry_lock_content=poetry_lock_content,
source=source,
)


Expand All @@ -67,6 +68,13 @@ def poetry_with_old_lockfile(
return _project_factory("old_lock", project_factory, fixture_dir)


@pytest.fixture
def poetry_with_nested_path_deps_old_lockfile(
project_factory: ProjectFactory, fixture_dir: FixtureDirGetter
) -> Poetry:
return _project_factory("old_lock_path_dependency", project_factory, fixture_dir)


@pytest.fixture
def poetry_with_incompatible_lockfile(
project_factory: ProjectFactory, fixture_dir: FixtureDirGetter
Expand Down Expand Up @@ -166,6 +174,36 @@ def test_lock_no_update(
assert locked_repository.find_packages(package.to_dependency())


def test_lock_no_update_path_dependencies(
command_tester_factory: CommandTesterFactory,
poetry_with_nested_path_deps_old_lockfile: Poetry,
repo: TestRepository,
):
"""
The lock file contains a variant of the directory dependency "quix" that does
not depend on "sampleproject". Although the version of "quix" has not been changed,
it should be re-solved because there is always only one valid version
of a directory dependency at any time.
"""
repo.add_package(get_package("sampleproject", "1.3.1"))

locker = Locker(
lock=poetry_with_nested_path_deps_old_lockfile.pyproject.file.path.parent
/ "poetry.lock",
local_config=poetry_with_nested_path_deps_old_lockfile.locker._local_config,
)
poetry_with_nested_path_deps_old_lockfile.set_locker(locker)

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

packages = locker.locked_repository().packages

assert {p.name for p in packages} == {"quix", "sampleproject"}


@pytest.mark.parametrize("is_no_update", [False, True])
def test_lock_with_incompatible_lockfile(
command_tester_factory: CommandTesterFactory,
Expand Down
20 changes: 20 additions & 0 deletions tests/fixtures/old_lock_path_dependency/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_path_dependency/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 <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.8"
quix = { path = "./quix", develop = true}

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
11 changes: 11 additions & 0 deletions tests/fixtures/old_lock_path_dependency/quix/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[tool.poetry]
name = "quix"
version = "1.2.3"
description = "Some description."
authors = ["Poetry Maintainer <[email protected]>"]
license = "MIT"

# Requirements
[tool.poetry.dependencies]
python = "~2.7 || ^3.4"
sampleproject = ">=1.3.1"