Skip to content

Commit 1812780

Browse files
authored
fix(poly check, poly libs): normalize library name and dist name during top namespaces lookup (#249)
* fix(poly check, poly libs): lookup third-party library top namespaces by normalizing the library and dist names (i.e. replace hyphens and dot with underscore) * bump Poetry plugin to 1.27.2 * bump CLI to 1.14.2
1 parent 982fd69 commit 1812780

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

components/polylith/alias/core.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@ def parse(aliases: List[str]) -> Dict[str, List[str]]:
1515
return reduce(_to_key_with_values, aliases, {})
1616

1717

18+
def _normalized_name(name: str) -> str:
19+
chars = {"-", "."}
20+
21+
normalized = reduce(lambda acc, char: str.replace(acc, char, "_"), chars, name)
22+
23+
return str.lower(normalized)
24+
25+
1826
def pick(aliases: Dict[str, List[str]], keys: Set) -> Set:
19-
normalized_keys = {str.lower(k) for k in keys}
27+
normalized_keys = {_normalized_name(k) for k in keys}
2028

21-
matrix = [v for k, v in aliases.items() if str.lower(k) in normalized_keys]
29+
matrix = [v for k, v in aliases.items() if _normalized_name(k) in normalized_keys]
2230

2331
flattened: List = sum(matrix, [])
2432

projects/poetry_polylith_plugin/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "poetry-polylith-plugin"
3-
version = "1.27.1"
3+
version = "1.27.2"
44
description = "A Poetry plugin that adds tooling support for the Polylith Architecture"
55
authors = ["David Vujic"]
66
homepage = "https://davidvujic.github.io/python-polylith-docs/"

projects/polylith_cli/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "polylith-cli"
3-
version = "1.14.1"
3+
version = "1.14.2"
44
description = "Python tooling support for the Polylith Architecture"
55
authors = ['David Vujic']
66
homepage = "https://davidvujic.github.io/python-polylith-docs/"

test/components/polylith/alias/test_alias.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ def test_pick_aliases_by_case_insensitive_keys():
5959
assert res == {"cv2", "jinja2", "jwt", "_yaml", "yaml"}
6060

6161

62+
def test_pick_aliases_by_keys_using_normalized_names():
63+
aliases = {
64+
"name_with_underscore": ["with_underscore"],
65+
"name-with-hyphen": ["with_hyphen"],
66+
"name.something": ["with_dot"],
67+
}
68+
69+
keys = {"name-with-underscore", "name-with-hyphen", "name-something"}
70+
71+
res = alias.pick(aliases, keys)
72+
73+
assert res == {"with_underscore", "with_hyphen", "with_dot"}
74+
75+
6276
def test_pick_empty_alias_by_keys():
6377
aliases = {}
6478

0 commit comments

Comments
 (0)