diff --git a/components/polylith/libs/lock_files.py b/components/polylith/libs/lock_files.py index fea2f7a..dabf229 100644 --- a/components/polylith/libs/lock_files.py +++ b/components/polylith/libs/lock_files.py @@ -104,10 +104,19 @@ def get_workspace_enabled_lock_file_data( return data if members else {} +def pick_package_sub_deps(package: dict) -> list: + package_sub_deps = package.get("dependencies", []) + + package_optional_deps_section = package.get("optional-dependencies", {}) + package_optional_deps: List[dict] = sum(package_optional_deps_section.values(), []) + + return package_sub_deps + package_optional_deps + + def pick_packages(data: dict, name: str) -> list: package = next(p for p in data["package"] if p["name"] == name) - package_sub_deps = package.get("dependencies", []) + package_sub_deps = pick_package_sub_deps(package) nested_package_deps = [pick_packages(data, p["name"]) for p in package_sub_deps] flattened = sum(nested_package_deps, []) diff --git a/projects/poetry_polylith_plugin/pyproject.toml b/projects/poetry_polylith_plugin/pyproject.toml index 81da0dc..c4729d7 100644 --- a/projects/poetry_polylith_plugin/pyproject.toml +++ b/projects/poetry_polylith_plugin/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "poetry-polylith-plugin" -version = "1.35.0" +version = "1.36.0" description = "A Poetry plugin that adds tooling support for the Polylith Architecture" authors = ["David Vujic"] homepage = "https://davidvujic.github.io/python-polylith-docs/" diff --git a/projects/polylith_cli/pyproject.toml b/projects/polylith_cli/pyproject.toml index 730d49c..b3afb54 100644 --- a/projects/polylith_cli/pyproject.toml +++ b/projects/polylith_cli/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "polylith-cli" -version = "1.24.0" +version = "1.25.0" description = "Python tooling support for the Polylith Architecture" authors = ['David Vujic'] homepage = "https://davidvujic.github.io/python-polylith-docs/" diff --git a/test/components/polylith/libs/test_parse_lock_file.py b/test/components/polylith/libs/test_parse_lock_file.py index aea8c0e..df3a5a7 100644 --- a/test/components/polylith/libs/test_parse_lock_file.py +++ b/test/components/polylith/libs/test_parse_lock_file.py @@ -128,3 +128,36 @@ def test_parse_contents_of_uv_workspaces_aware_lock_file(setup): assert non_existing == {} assert gcp_libs_from_normalized_name == expected_gcp_libs + + +def test_parse_contents_of_uv_workspaces_aware_lock_file_with_optional_dependencies( + setup, +): + expected_regular = { + "fastapi": "0.106.0", + "anyio": "3.7.1", + "exceptiongroup": "1.2.2", + "idna": "3.7", + "sniffio": "1.3.1", + "pydantic": "2.8.2", + "annotated-types": "0.7.0", + "pydantic-core": "2.20.1", + "typing-extensions": "4.12.2", + "starlette": "0.27.0", + "uvicorn": "0.25.0", + "click": "8.1.7", + "colorama": "0.4.6", + "h11": "0.14.0", + } + + expected_optionals = { + "requests": "2.32.3", + "certifi": "2024.12.14", + "charset-normalizer": "3.4.1", + "urllib3": "2.3.0", + } + expected = {**expected_regular, **expected_optionals} + + my_fastapi_libs = _extract_workspace_member_libs("my-fastapi-project") + + assert my_fastapi_libs == expected diff --git a/test/test_data/uv_workspaces b/test/test_data/uv_workspaces index 4231a80..4ee5f68 100644 --- a/test/test_data/uv_workspaces +++ b/test/test_data/uv_workspaces @@ -32,11 +32,19 @@ dependencies = [ name = "blinker" version = "1.8.2" +[[package]] +name = "certifi" +version = "2024.12.14" + +[[package]] +name = "charset-normalizer" +version = "3.4.1" + [[package]] name = "click" version = "8.1.7" dependencies = [ - { name = "colorama", marker = "platform_system == 'Windows'" }, + { name = "colorama", marker = "sys_platform == 'win32'" }, ] [[package]] @@ -49,7 +57,6 @@ dependencies = [ [[package]] name = "colorama" version = "0.4.6" -source = { registry = "https://pypi.org/simple" } [[package]] name = "confluent-kafka" @@ -65,7 +72,6 @@ dependencies = [ [[package]] name = "deprecation" version = "2.1.0" -source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "packaging" }, ] @@ -103,7 +109,7 @@ dependencies = [ { name = "click" }, { name = "cloudevents" }, { name = "flask" }, - { name = "gunicorn", marker = "platform_system != 'Windows'" }, + { name = "gunicorn", marker = "sys_platform != 'win32'" }, { name = "watchdog" }, ] @@ -186,6 +192,11 @@ dependencies = [ { name = "uvicorn" }, ] +[package.optional-dependencies] +opt = [ + { name = "requests" }, +] + [[package]] name = "my-gcp-function-project" version = "0.1.0" @@ -266,6 +277,16 @@ dependencies = [ { name = "uvicorn" }, ] +[[package]] +name = "requests" +version = "2.32.3" +dependencies = [ + { name = "certifi" }, + { name = "charset-normalizer" }, + { name = "idna" }, + { name = "urllib3" }, +] + [[package]] name = "rich" version = "13.8.0" @@ -324,6 +345,10 @@ dependencies = [ name = "typing-extensions" version = "4.12.2" +[[package]] +name = "urllib3" +version = "2.3.0" + [[package]] name = "uvicorn" version = "0.25.0"