diff --git a/poetry.lock b/poetry.lock index 54a1753..f579742 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1031,13 +1031,13 @@ files = [ [[package]] name = "pytest" -version = "8.3.3" +version = "8.3.4" description = "pytest: simple powerful testing with Python" optional = false python-versions = ">=3.8" files = [ - {file = "pytest-8.3.3-py3-none-any.whl", hash = "sha256:a6853c7375b2663155079443d2e45de913a911a11d669df02a50814944db57b2"}, - {file = "pytest-8.3.3.tar.gz", hash = "sha256:70b98107bd648308a7952b06e6ca9a50bc660be218d53c257cc1fc94fda10181"}, + {file = "pytest-8.3.4-py3-none-any.whl", hash = "sha256:50e16d954148559c9a74109af1eaf0c945ba2d8f30f0a3d3335edde19788b6f6"}, + {file = "pytest-8.3.4.tar.gz", hash = "sha256:965370d062bce11e73868e0335abac31b4d3de0e82f4007408d242b4f8610761"}, ] [package.dependencies] diff --git a/poetry_monoranger_plugin/path_rewriter.py b/poetry_monoranger_plugin/path_rewriter.py index d41b4a7..70cc51e 100644 --- a/poetry_monoranger_plugin/path_rewriter.py +++ b/poetry_monoranger_plugin/path_rewriter.py @@ -97,4 +97,10 @@ def _pin_dependency(self, poetry: Poetry, dependency: DirectoryDependency): else: raise ValueError(f"Invalid version rewrite rule: {self.plugin_conf.version_rewrite_rule}") - return Dependency(name, pinned_version, groups=dependency.groups) + return Dependency( + name, + pinned_version, + groups=dependency.groups, + optional=dependency.is_optional(), + extras=dependency.extras, + ) diff --git a/tests/conftest.py b/tests/conftest.py index 777b0ce..a378594 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,7 +3,7 @@ import pytest from poetry.core.packages.dependency import Dependency -from poetry.core.packages.dependency_group import DependencyGroup +from poetry.core.packages.dependency_group import MAIN_GROUP, DependencyGroup from poetry.core.packages.directory_dependency import DirectoryDependency from poetry.poetry import Poetry @@ -15,9 +15,17 @@ def mock_event_gen(): def _factory(command_cls: type[Command], disable_cache: bool): from cleo.events.console_command_event import ConsoleCommandEvent - main_grp = DependencyGroup("main") - main_grp.add_dependency(DirectoryDependency("packageB", Path("../packageB"), develop=True)) + main_grp = DependencyGroup(MAIN_GROUP) main_grp.add_dependency(Dependency("numpy", "==1.5.0")) + main_grp.add_dependency( + DirectoryDependency( + "packageB", + Path("../packageB"), + develop=True, + optional=True, + extras=["fast"], + ) + ) mock_command = Mock(spec=command_cls) mock_command.poetry = Mock(spec=Poetry) diff --git a/tests/test_path_rewriter.py b/tests/test_path_rewriter.py index 61e31f9..6d0afff 100644 --- a/tests/test_path_rewriter.py +++ b/tests/test_path_rewriter.py @@ -35,6 +35,8 @@ def test_executes_path_rewriting_for_build_command(mock_event_gen, disable_cache new_dependencies = sorted(new_dependencies.dependencies, key=lambda x: x.name) for i, dep in enumerate(new_dependencies): assert dep.name == original_dependencies[i].name + assert dep.is_optional() == original_dependencies[i].is_optional() + assert dep.extras == original_dependencies[i].extras if isinstance(original_dependencies[i], DirectoryDependency): assert dep.pretty_constraint == "0.1.0" else: