Skip to content

Commit 6ee2002

Browse files
authored
feat(poly check, poly libs): use strict mode when dependencies origin from lock file (#268)
* feat(poly check, poly libs): use strict-mode when deps origin from lock-file * bump CLI to 1.30.0 * bump Poetry plugin to 1.18.0
1 parent 58461f4 commit 6ee2002

File tree

8 files changed

+23
-12
lines changed

8 files changed

+23
-12
lines changed

components/polylith/commands/check.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,21 @@ def run(root: Path, ns: str, project_data: dict, options: dict) -> bool:
5555
deps = project_data["deps"]
5656
alias = options["alias"]
5757

58+
from_lock_file = libs.is_from_lock_file(deps)
59+
5860
collected_imports = check.report.collect_all_imports(root, ns, project_data)
5961
collected_libs = distributions.known_aliases_and_sub_dependencies(
60-
deps, alias, options
62+
deps,
63+
alias,
64+
options,
65+
from_lock_file,
6166
)
6267

6368
details = check.report.create_report(
6469
project_data,
6570
collected_imports,
6671
collected_libs,
67-
is_strict,
72+
is_strict or from_lock_file,
6873
)
6974

7075
res = all([not details["brick_diff"], not details["libs_diff"]])

components/polylith/commands/libs.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import List, Set
44

55
from polylith import distributions
6-
from polylith.libs import report
6+
from polylith.libs import is_from_lock_file, report
77

88

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

1616
brick_imports = imports[name]
1717

18+
from_lock_file = is_from_lock_file(deps)
19+
1820
libs = distributions.known_aliases_and_sub_dependencies(
19-
deps, library_alias, options
21+
deps, library_alias, options, from_lock_file
2022
)
2123

2224
return report.print_missing_installed_libs(
2325
brick_imports,
2426
libs,
2527
name,
26-
is_strict,
28+
is_strict or from_lock_file,
2729
)
2830

2931

components/polylith/distributions/collect.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,22 @@ def extract_library_names(deps: dict) -> Set[str]:
3030

3131

3232
def known_aliases_and_sub_dependencies(
33-
deps: dict, library_alias: list, options: dict
33+
deps: dict, library_alias: list, options: dict, from_lock_file: bool,
3434
) -> Set[str]:
3535
"""Collect known aliases (packages) for third-party libraries.
3636
3737
When the library origin is not from a lock-file:
3838
collect sub-dependencies and distribution top-namespace for each library, and append to the result.
3939
"""
4040

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

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

4746
dist_packages = distributions_packages(dists)
4847
custom_aliases = alias.parse(library_alias)
49-
sub_deps = distributions_sub_packages(dists) if not lock_file else {}
48+
sub_deps = distributions_sub_packages(dists) if not from_lock_file else {}
5049

5150
a = alias.pick(dist_packages, third_party_libs)
5251
b = alias.pick(custom_aliases, third_party_libs)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from polylith.libs import report
22
from polylith.libs.grouping import extract_third_party_imports, get_third_party_imports
3-
from polylith.libs.lock_files import extract_libs, pick_lock_file
3+
from polylith.libs.lock_files import extract_libs, is_from_lock_file, pick_lock_file
44

55
__all__ = [
66
"report",
77
"extract_third_party_imports",
88
"get_third_party_imports",
99
"extract_libs",
10+
"is_from_lock_file",
1011
"pick_lock_file",
1112
]

components/polylith/libs/lock_files.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,7 @@ def extract_libs(project_data: dict, filename: str, filetype: str) -> dict:
7171
return extract_lib_names_from_txt(path)
7272
except (IndexError, KeyError, ValueError) as e:
7373
raise ValueError(f"Failed reading {filename}: {repr(e)}") from e
74+
75+
76+
def is_from_lock_file(deps: dict) -> bool:
77+
return any(deps["source"] == s for s in set(patterns.keys()))

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.29.0"
3+
version = "1.30.0"
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.17.0"
3+
version = "1.18.0"
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/distributions/test_collect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_collect_known_aliases_and_sub_dependencies():
3838

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

41-
res = collect.known_aliases_and_sub_dependencies(fake_deps, fake_alias, {})
41+
res = collect.known_aliases_and_sub_dependencies(fake_deps, fake_alias, {}, False)
4242

4343
assert "typer" in res
4444
assert "typing-extensions" in res

0 commit comments

Comments
 (0)