Skip to content

Commit

Permalink
feat(uv workspaces): add support for optional dependencies (#320)
Browse files Browse the repository at this point in the history
* test: add optional-dependencies in uv workspaces example/test lock file

* feat(uv workspaces): add support for identifying optional dependencies

* bump Poetry plugin to 1.36.0

* bump CLI to 1.25.0
  • Loading branch information
DavidVujic authored Jan 30, 2025
1 parent d9ea5cc commit 6897a13
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 7 deletions.
11 changes: 10 additions & 1 deletion components/polylith/libs/lock_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, [])
Expand Down
2 changes: 1 addition & 1 deletion projects/poetry_polylith_plugin/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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/"
Expand Down
2 changes: 1 addition & 1 deletion projects/polylith_cli/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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/"
Expand Down
33 changes: 33 additions & 0 deletions test/components/polylith/libs/test_parse_lock_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 29 additions & 4 deletions test/test_data/uv_workspaces
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand All @@ -49,7 +57,6 @@ dependencies = [
[[package]]
name = "colorama"
version = "0.4.6"
source = { registry = "https://pypi.org/simple" }

[[package]]
name = "confluent-kafka"
Expand All @@ -65,7 +72,6 @@ dependencies = [
[[package]]
name = "deprecation"
version = "2.1.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "packaging" },
]
Expand Down Expand Up @@ -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" },
]

Expand Down Expand Up @@ -186,6 +192,11 @@ dependencies = [
{ name = "uvicorn" },
]

[package.optional-dependencies]
opt = [
{ name = "requests" },
]

[[package]]
name = "my-gcp-function-project"
version = "0.1.0"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 6897a13

Please sign in to comment.