Skip to content

Commit

Permalink
Recursive third party dependencies (#322)
Browse files Browse the repository at this point in the history
* fix(poly check): handle third-party dependencies with recursive dependencies (sub deps with dependencies to the library)

* bump CLI to 1.25.1

* bump Polylith plugin to 1.36.1

* fix(poly check): do a soft-get when looking up package or project version
  • Loading branch information
DavidVujic authored Feb 4, 2025
1 parent 6897a13 commit 4b1429a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
16 changes: 9 additions & 7 deletions components/polylith/libs/lock_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def pick_lock_file(path: Path) -> dict:


def extract_libs_from_packages(packages: List[dict]) -> dict:
return {p["name"]: p["version"] for p in packages}
return {p["name"]: p.get("version", "") for p in packages}


def extract_libs_from_toml(path: Path) -> dict:
Expand Down Expand Up @@ -113,13 +113,15 @@ def pick_package_sub_deps(package: dict) -> list:
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)
def pick_packages(data: dict, name: str, picked: list) -> list:
if any(True for c in picked if c["name"] == name):
return []

package_sub_deps = pick_package_sub_deps(package)
nested_package_deps = [pick_packages(data, p["name"]) for p in package_sub_deps]
package = next(p for p in data["package"] if p["name"] == name)
sub_deps = pick_package_sub_deps(package)
nested_deps = [pick_packages(data, p["name"], picked + [package]) for p in sub_deps]

flattened = sum(nested_package_deps, [])
flattened = sum(nested_deps, [])

return [package] + flattened if flattened else [package]

Expand All @@ -140,7 +142,7 @@ def extract_workspace_member_libs(data: dict, project_data: dict) -> dict:
return {}

try:
packages = pick_packages(data, member_name)
packages = pick_packages(data, member_name, [])
extracted = extract_libs_from_packages(packages)
except KeyError as e:
raise ValueError(f"Failed parsing lock-file data: {repr(e)}") from e
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.36.0"
version = "1.36.1"
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.25.0"
version = "1.25.1"
description = "Python tooling support for the Polylith Architecture"
authors = ['David Vujic']
homepage = "https://davidvujic.github.io/python-polylith-docs/"
Expand Down
17 changes: 17 additions & 0 deletions test/components/polylith/libs/test_parse_lock_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ def test_parse_contents_of_uv_workspaces_aware_lock_file(setup):
}

expected_consumer_libs = {"confluent-kafka": "2.3.0"}
expected_cli_libs_with_recursive_deps = {
"rich": "13.8.0",
"tomlkit": "0.13.2",
"typer": "0.12.5",
"markdown-it-py": "3.0.0",
"pygments": "2.18.0",
"mdurl": "0.1.2",
"mdit-py-plugins": "0.4.2",
"click": "8.1.7",
"colorama": "0.4.6",
"shellingham": "1.5.4",
"typing-extensions": "4.12.2",
}

gcp_libs = _extract_workspace_member_libs("my-gcp-function-project")
consumer_libs = _extract_workspace_member_libs("consumer-project")
Expand All @@ -122,13 +135,17 @@ def test_parse_contents_of_uv_workspaces_aware_lock_file(setup):
"my_gcp_Function-project"
)

cli_libs = _extract_workspace_member_libs("polylith-cli")

assert gcp_libs == expected_gcp_libs
assert consumer_libs == expected_consumer_libs
assert aws_lambda_libs == {}
assert non_existing == {}

assert gcp_libs_from_normalized_name == expected_gcp_libs

assert cli_libs == expected_cli_libs_with_recursive_deps


def test_parse_contents_of_uv_workspaces_aware_lock_file_with_optional_dependencies(
setup,
Expand Down
13 changes: 13 additions & 0 deletions test/test_data/uv_workspaces
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"my-fastapi-project",
"my-gcp-function-project",
"python-polylith-example-with-uv",
"polylith-cli",
]

[[package]]
Expand Down Expand Up @@ -162,6 +163,18 @@ dependencies = [
{ name = "mdurl" },
]

[package.optional-dependencies]
plugins = [
{ name = "mdit-py-plugins" },
]

[[package]]
name = "mdit-py-plugins"
version = "0.4.2"
dependencies = [
{ name = "markdown-it-py" },
]

[[package]]
name = "markupsafe"
version = "2.1.5"
Expand Down

0 comments on commit 4b1429a

Please sign in to comment.