diff --git a/src/poetry/installation/installer.py b/src/poetry/installation/installer.py index 83082020d21..e3cdcb9e0ed 100644 --- a/src/poetry/installation/installer.py +++ b/src/poetry/installation/installer.py @@ -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) diff --git a/tests/console/commands/test_lock.py b/tests/console/commands/test_lock.py index 69de642e117..a8ef7c2aac9 100644 --- a/tests/console/commands/test_lock.py +++ b/tests/console/commands/test_lock.py @@ -43,6 +43,7 @@ def _project_factory( name="foobar", pyproject_content=pyproject_content, poetry_lock_content=poetry_lock_content, + source=source, ) @@ -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 @@ -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, diff --git a/tests/fixtures/old_lock_path_dependency/poetry.lock b/tests/fixtures/old_lock_path_dependency/poetry.lock new file mode 100644 index 00000000000..45c6e792d7f --- /dev/null +++ b/tests/fixtures/old_lock_path_dependency/poetry.lock @@ -0,0 +1,20 @@ +# This file is automatically @generated by Poetry and should not be changed by hand. + +[[package]] +name = "quix" +version = "1.2.3" +description = "Some description." +category = "main" +optional = false +python-versions = "~2.7 || ^3.4" +files = [] +develop = true + +[package.source] +type = "directory" +url = "quix" + +[metadata] +lock-version = "2.0" +python-versions = "^3.8" +content-hash = "d2e1cf4390093213432fb8b58f90774a5247bfe860dedc2b023b27accc14cfad" diff --git a/tests/fixtures/old_lock_path_dependency/pyproject.toml b/tests/fixtures/old_lock_path_dependency/pyproject.toml new file mode 100644 index 00000000000..00547cfee26 --- /dev/null +++ b/tests/fixtures/old_lock_path_dependency/pyproject.toml @@ -0,0 +1,15 @@ +[tool.poetry] +name = "foobar" +version = "0.1.0" +description = "" +authors = ["Poetry Developer "] + +[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" diff --git a/tests/fixtures/old_lock_path_dependency/quix/pyproject.toml b/tests/fixtures/old_lock_path_dependency/quix/pyproject.toml new file mode 100644 index 00000000000..1bec75cf124 --- /dev/null +++ b/tests/fixtures/old_lock_path_dependency/quix/pyproject.toml @@ -0,0 +1,11 @@ +[tool.poetry] +name = "quix" +version = "1.2.3" +description = "Some description." +authors = ["Poetry Maintainer "] +license = "MIT" + +# Requirements +[tool.poetry.dependencies] +python = "~2.7 || ^3.4" +sampleproject = ">=1.3.1"