From 2bf16c5081c3fda09c16728544b6eda66ce1ac3c Mon Sep 17 00:00:00 2001 From: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com> Date: Thu, 18 May 2023 10:49:25 -0500 Subject: [PATCH] fix: installation of missing directory dependencies with --skip-directory --- src/poetry/installation/installer.py | 9 +++++++++ src/poetry/puzzle/provider.py | 6 ------ tests/console/commands/test_install.py | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/poetry/installation/installer.py b/src/poetry/installation/installer.py index 53254a4e5c8..a5250750804 100644 --- a/src/poetry/installation/installer.py +++ b/src/poetry/installation/installer.py @@ -1,6 +1,7 @@ from __future__ import annotations from typing import TYPE_CHECKING +from typing import cast from cleo.io.null_io import NullIO from packaging.utils import canonicalize_name @@ -21,6 +22,7 @@ from cleo.io.io import IO from packaging.utils import NormalizedName + from poetry.core.packages.path_dependency import PathDependency from poetry.core.packages.project_package import ProjectPackage from poetry.config.config import Config @@ -336,6 +338,13 @@ def _do_install(self) -> int: # or optional and not requested, are dropped self._filter_operations(ops, lockfile_repo) + # Validate the dependencies + for op in ops: + dep = op.package.to_dependency() + if dep.is_file() or dep.is_directory(): + dep = cast("PathDependency", dep) + dep.validate(raise_error=True) + # Execute operations status = self._execute(ops) diff --git a/src/poetry/puzzle/provider.py b/src/poetry/puzzle/provider.py index 190a0e31d66..3c3b738b832 100644 --- a/src/poetry/puzzle/provider.py +++ b/src/poetry/puzzle/provider.py @@ -43,7 +43,6 @@ from poetry.core.packages.directory_dependency import DirectoryDependency from poetry.core.packages.file_dependency import FileDependency from poetry.core.packages.package import Package - from poetry.core.packages.path_dependency import PathDependency from poetry.core.packages.url_dependency import URLDependency from poetry.core.packages.vcs_dependency import VCSDependency from poetry.core.version.markers import BaseMarker @@ -560,11 +559,6 @@ def complete_package( if locked is not None and locked.package.is_same_package_as(dep): continue self.search_for_direct_origin_dependency(dep) - else: - for dep in _dependencies: - if dep.is_file() or dep.is_directory(): - dep = cast("PathDependency", dep) - dep.validate(raise_error=True) dependencies = self._get_dependencies_with_overrides( _dependencies, dependency_package diff --git a/tests/console/commands/test_install.py b/tests/console/commands/test_install.py index 25fdc1b81c3..bf3c819552a 100644 --- a/tests/console/commands/test_install.py +++ b/tests/console/commands/test_install.py @@ -437,3 +437,23 @@ def test_install_path_dependency_does_not_exist( else: with pytest.raises(ValueError, match="does not exist"): tester.execute(options) + + +@pytest.mark.parametrize("options", ["", "--no-directory"]) +def test_install_missing_directory_dependency_with_no_directory( + command_tester_factory: CommandTesterFactory, + project_factory: ProjectFactory, + fixture_dir: FixtureDirGetter, + options: str, +) -> None: + poetry = _project_factory( + "missing_directory_dependency", project_factory, fixture_dir + ) + assert isinstance(poetry.locker, TestLocker) + poetry.locker.locked(True) + tester = command_tester_factory("install", poetry=poetry) + if options: + tester.execute(options) + else: + with pytest.raises(ValueError, match="does not exist"): + tester.execute(options)