Repository: python-poetry/poetry

Issue:
poetry lock --no-update does not reflect directory packages changes
- [x] I am on the [latest](https://github.com/python-poetry/poetry/releases/latest) Poetry version.
- [x] I have searched the [issues](https://github.com/python-poetry/poetry/issues) of this repo and believe that this is not a duplicate.
- [x] If an exception occurs when executing a command, I executed it again in debug mode (`-vvv` option).
- **OS version and name**: MacOS 10.15.7 
- **Poetry version**: 1.1.5

## Issue
When using packages with the directory source type, I would expect that running `poetry lock --no-update` inside the package would update the `poetry.lock` file with changes for all directory packages being used. 

The issue can be reproduced with:
```
poetry new lib
poetry new project

# project depends on lib (directory package)
cd project && poetry add ../lib

# lib is updated with a new dependency
cd ../lib && poetry add arrow

# we try to update the project with --no-update (we do not want to run poetry update that will update too much)
cd ../project
poetry lock --no-update

# the lock file is not updated correctly
grep arrow poetry.lock  # lock file is not updated
```

To my knowledge the only workaround are:
1) `poetry update` (which naturally updates more than we want here – i.e. unrelated dependencies)
2) `poetry update <dir_package1> <dir_package2>...` (cumbersome if you have a lot of directory packages – especially painful in a big mono repository)

I believe the suggested behavior makes sense for both editable and non-editable directory packages.


Discussion:
I had a look at fixing this. It might be an option to change the `_solve` function to something like this:

```diff

diff --git a/poetry/puzzle/solver.py b/poetry/puzzle/solver.py
index 7465df1b..fe3f26fd 100644
--- a/poetry/puzzle/solver.py
+++ b/poetry/puzzle/solver.py
@@ -245,9 +245,14 @@ class Solver:
         if self._provider._overrides:
             self._overrides.append(self._provider._overrides)
 
+        if use_latest is None:
+            use_latest = []
+
         locked = {}
         for package in self._locked.packages:
             locked[package.name] = DependencyPackage(package.to_dependency(), package)
+            if package.source_type == "directory":
+                # NOTE: we could be less strict here and only append these in case the use didn't
+                # specify any `use_latest` packages. That means that `poetry update arrow` will not
+                # pull in directory package changes.
+                use_latest.append(package.name)
 
         try:
             result = resolve_version(
```

Let me know if there are better solutions to this. I would like to create a PR to fix this issue. :)

I see that the code snippet doesn't cover `poetry lock --check`. I'm wondering if the locker needs to change instead of the solver. I will investigate further.

Resolving patch:
diff --git a/src/poetry/installation/installer.py b/src/poetry/installation/installer.py
--- 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)


Test patch:
diff --git a/tests/console/commands/test_lock.py b/tests/console/commands/test_lock.py
--- 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
--- /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
--- /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 <developer@python-poetry.org>"]
+
+[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
--- /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 <tests@python-poetry.org>"]
+license = "MIT"
+
+# Requirements
+[tool.poetry.dependencies]
+python = "~2.7 || ^3.4"
+sampleproject = ">=1.3.1"