Skip to content

Commit

Permalink
fix(poly check, poly libs): normalize library name and dist name duri…
Browse files Browse the repository at this point in the history
…ng 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
  • Loading branch information
DavidVujic committed Aug 11, 2024
1 parent 982fd69 commit 1812780
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
12 changes: 10 additions & 2 deletions components/polylith/alias/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ def parse(aliases: List[str]) -> Dict[str, List[str]]:
return reduce(_to_key_with_values, aliases, {})


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

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

return str.lower(normalized)


def pick(aliases: Dict[str, List[str]], keys: Set) -> Set:
normalized_keys = {str.lower(k) for k in keys}
normalized_keys = {_normalized_name(k) for k in keys}

matrix = [v for k, v in aliases.items() if str.lower(k) in normalized_keys]
matrix = [v for k, v in aliases.items() if _normalized_name(k) in normalized_keys]

flattened: List = sum(matrix, [])

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.27.1"
version = "1.27.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.14.1"
version = "1.14.2"
description = "Python tooling support for the Polylith Architecture"
authors = ['David Vujic']
homepage = "https://davidvujic.github.io/python-polylith-docs/"
Expand Down
14 changes: 14 additions & 0 deletions test/components/polylith/alias/test_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ def test_pick_aliases_by_case_insensitive_keys():
assert res == {"cv2", "jinja2", "jwt", "_yaml", "yaml"}


def test_pick_aliases_by_keys_using_normalized_names():
aliases = {
"name_with_underscore": ["with_underscore"],
"name-with-hyphen": ["with_hyphen"],
"name.something": ["with_dot"],
}

keys = {"name-with-underscore", "name-with-hyphen", "name-something"}

res = alias.pick(aliases, keys)

assert res == {"with_underscore", "with_hyphen", "with_dot"}


def test_pick_empty_alias_by_keys():
aliases = {}

Expand Down

0 comments on commit 1812780

Please sign in to comment.