Skip to content

Commit

Permalink
fix: Normalize uv workspace member names before lookup (#270)
Browse files Browse the repository at this point in the history
* fix(uv workspaces): normalize the member name (i.e. project name)

* bump CLI to 1.19.1

* bump Poetry plugin to 1.30.2
  • Loading branch information
DavidVujic authored Sep 29, 2024
1 parent 481b7af commit 4d9e092
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
11 changes: 10 additions & 1 deletion components/polylith/libs/lock_files.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from functools import reduce
from pathlib import Path
from typing import List

Expand Down Expand Up @@ -93,6 +94,14 @@ def pick_packages(data: dict, name: str) -> list:
return [package] + flattened if flattened else [package]


def normalized(name: str) -> str:
chars = {"_", "."}

normalized = reduce(lambda acc, char: str.replace(acc, char, "-"), chars, name)

return str.lower(normalized)


def extract_workspace_member_libs(
root: Path,
project_data: dict,
Expand All @@ -109,7 +118,7 @@ def extract_workspace_member_libs(

data = load_toml(path)
members = data.get("manifest", {}).get("members", [])
member_name = project_data["name"]
member_name = normalized(project_data["name"])

if member_name not in members:
return {}
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.30.1"
version = "1.30.2"
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.19.0"
version = "1.19.1"
description = "Python tooling support for the Polylith Architecture"
authors = ['David Vujic']
homepage = "https://davidvujic.github.io/python-polylith-docs/"
Expand Down
6 changes: 6 additions & 0 deletions test/components/polylith/libs/test_parse_lock_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ def test_parse_contents_of_uv_workspaces_aware_lock_file(setup):
aws_lambda_libs = _extract_workspace_member_libs("my-aws-lambda-project")
non_existing = _extract_workspace_member_libs("this-workspace-member-doesnt-exist")

gcp_libs_from_normalized_name = _extract_workspace_member_libs(
"my_gcp_Function-project"
)

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

0 comments on commit 4d9e092

Please sign in to comment.