Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions components/polylith/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,21 @@ def run(root: Path, ns: str, project_data: dict, options: dict) -> bool:
deps = project_data["deps"]
alias = options["alias"]

from_lock_file = libs.is_from_lock_file(deps)

collected_imports = check.report.collect_all_imports(root, ns, project_data)
collected_libs = distributions.known_aliases_and_sub_dependencies(
deps, alias, options
deps,
alias,
options,
from_lock_file,
)

details = check.report.create_report(
project_data,
collected_imports,
collected_libs,
is_strict,
is_strict or from_lock_file,
)

res = all([not details["brick_diff"], not details["libs_diff"]])
Expand Down
8 changes: 5 additions & 3 deletions components/polylith/commands/libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import List, Set

from polylith import distributions
from polylith.libs import report
from polylith.libs import is_from_lock_file, report


def missing_libs(project_data: dict, imports: dict, options: dict) -> bool:
Expand All @@ -15,15 +15,17 @@ def missing_libs(project_data: dict, imports: dict, options: dict) -> bool:

brick_imports = imports[name]

from_lock_file = is_from_lock_file(deps)

libs = distributions.known_aliases_and_sub_dependencies(
deps, library_alias, options
deps, library_alias, options, from_lock_file
)

return report.print_missing_installed_libs(
brick_imports,
libs,
name,
is_strict,
is_strict or from_lock_file,
)


Expand Down
5 changes: 2 additions & 3 deletions components/polylith/distributions/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,22 @@ def extract_library_names(deps: dict) -> Set[str]:


def known_aliases_and_sub_dependencies(
deps: dict, library_alias: list, options: dict
deps: dict, library_alias: list, options: dict, from_lock_file: bool,
) -> Set[str]:
"""Collect known aliases (packages) for third-party libraries.

When the library origin is not from a lock-file:
collect sub-dependencies and distribution top-namespace for each library, and append to the result.
"""

lock_file = any(str.endswith(deps["source"], s) for s in {".lock", ".txt"})
third_party_libs = extract_library_names(deps)

fn = options.get("dists_fn", get_distributions)
dists = fn()

dist_packages = distributions_packages(dists)
custom_aliases = alias.parse(library_alias)
sub_deps = distributions_sub_packages(dists) if not lock_file else {}
sub_deps = distributions_sub_packages(dists) if not from_lock_file else {}

a = alias.pick(dist_packages, third_party_libs)
b = alias.pick(custom_aliases, third_party_libs)
Expand Down
3 changes: 2 additions & 1 deletion components/polylith/libs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from polylith.libs import report
from polylith.libs.grouping import extract_third_party_imports, get_third_party_imports
from polylith.libs.lock_files import extract_libs, pick_lock_file
from polylith.libs.lock_files import extract_libs, is_from_lock_file, pick_lock_file

__all__ = [
"report",
"extract_third_party_imports",
"get_third_party_imports",
"extract_libs",
"is_from_lock_file",
"pick_lock_file",
]
4 changes: 4 additions & 0 deletions components/polylith/libs/lock_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ def extract_libs(project_data: dict, filename: str, filetype: str) -> dict:
return extract_lib_names_from_txt(path)
except (IndexError, KeyError, ValueError) as e:
raise ValueError(f"Failed reading {filename}: {repr(e)}") from e


def is_from_lock_file(deps: dict) -> bool:
return any(deps["source"] == s for s in set(patterns.keys()))
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.29.0"
version = "1.30.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.17.0"
version = "1.18.0"
description = "Python 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 test/components/polylith/distributions/test_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_collect_known_aliases_and_sub_dependencies():

fake_alias = ["hello-world-library=hello"]

res = collect.known_aliases_and_sub_dependencies(fake_deps, fake_alias, {})
res = collect.known_aliases_and_sub_dependencies(fake_deps, fake_alias, {}, False)

assert "typer" in res
assert "typing-extensions" in res
Expand Down