Skip to content

Commit 1441411

Browse files
authored
Fix brick usage via interface (#456)
* fix: poly brick communication via interfaces * fix: move functions from the bricks component, to avoid circular dependencies * bump PDM brick hook to 1.3.10 * bump PDM workspace hook to 1.3.10 * bump Poetry plugin to 1.52.2 * bump CLI to 1.48.3
1 parent db142fa commit 1441411

24 files changed

Lines changed: 77 additions & 66 deletions

File tree

bases/polylith/cli/create.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pathlib import Path
22

33
from polylith import interactive, project
4-
from polylith.bricks import base, component
4+
from polylith.bricks import create_base, create_component
55
from polylith.cli import options
66
from polylith.commands.create import create
77
from polylith.workspace.create import create_workspace
@@ -26,7 +26,7 @@ def base_command(
2626
description: Annotated[str, Option(help="Description of the base.")] = "",
2727
):
2828
"""Creates a Polylith base."""
29-
_try_create(name, description, base.create_base)
29+
_try_create(name, description, create_base)
3030

3131

3232
@app.command("component")
@@ -35,7 +35,7 @@ def component_command(
3535
description: Annotated[str, Option(help="Description of the component.")] = "",
3636
):
3737
"""Creates a Polylith component."""
38-
_try_create(name, description, component.create_component)
38+
_try_create(name, description, create_component)
3939

4040

4141
def _create_project(root: Path, options: dict):
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
from polylith.bricks.base import create_base, get_bases_data
2-
from polylith.bricks.component import create_component, get_components_data
1+
from polylith.bricks.base import create_base
2+
from polylith.bricks.component import create_component
33

44
__all__ = [
55
"create_base",
66
"create_component",
7-
"get_bases_data",
8-
"get_components_data",
97
]

components/polylith/bricks/base.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from pathlib import Path
2-
from typing import List
32

4-
from polylith.bricks import component
53
from polylith.bricks.brick import create_brick
64
from polylith.repo import bases_dir
75
from polylith.test import create_test
@@ -13,7 +11,3 @@ def create_base(path: Path, options: dict) -> None:
1311

1412
create_brick(path, base_options)
1513
create_test(path, base_options)
16-
17-
18-
def get_bases_data(path: Path, ns: str) -> List[dict]:
19-
return component.get_components_data(path, ns, bases_dir)
Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from pathlib import Path
2-
from typing import List
32

4-
from polylith import configuration
53
from polylith.bricks.brick import create_brick
64
from polylith.repo import components_dir
75
from polylith.test import create_test
@@ -13,27 +11,3 @@ def create_component(path: Path, options: dict) -> None:
1311

1412
create_brick(path, component_options)
1513
create_test(path, component_options)
16-
17-
18-
def is_brick_dir(p: Path) -> bool:
19-
return p.is_dir() and p.name not in {"__pycache__", ".venv", ".mypy_cache"}
20-
21-
22-
def get_component_dirs(root: Path, top_dir, ns) -> list:
23-
theme = configuration.get_theme_from_config(root)
24-
dirs = top_dir if theme == "tdd" else f"{top_dir}/{ns}"
25-
26-
component_dir = root / dirs
27-
28-
if not component_dir.exists():
29-
return []
30-
31-
return [f for f in component_dir.iterdir() if is_brick_dir(f)]
32-
33-
34-
def get_components_data(
35-
root: Path, ns: str, top_dir: str = components_dir
36-
) -> List[dict]:
37-
dirs = get_component_dirs(root, top_dir, ns)
38-
39-
return [{"name": d.name} for d in dirs]

components/polylith/check/report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ def extract_collected_imports(
7878
ns: str, imports_in_bases: dict, imports_in_components: dict
7979
) -> dict:
8080
brick_imports = {
81-
"bases": imports.grouping.extract_brick_imports(imports_in_bases, ns),
82-
"components": imports.grouping.extract_brick_imports(imports_in_components, ns),
81+
"bases": imports.extract_brick_imports(imports_in_bases, ns),
82+
"components": imports.extract_brick_imports(imports_in_components, ns),
8383
}
8484

8585
third_party_imports = {

components/polylith/commands/deps.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from pathlib import Path
22
from typing import List, Set
33

4-
from polylith import bricks, deps, info, interface
4+
from polylith import deps, info, interface
5+
from polylith.dirs import get_bases_data, get_components_data
56

67

78
def get_imports(root: Path, ns: str, bricks: dict) -> dict:
@@ -20,14 +21,14 @@ def get_bases(root: Path, ns: str, project_data: dict) -> Set[str]:
2021
if project_data:
2122
return set(project_data.get("bases", []))
2223

23-
return pick_name(bricks.get_bases_data(root, ns))
24+
return pick_name(get_bases_data(root, ns))
2425

2526

2627
def get_components(root: Path, ns: str, project_data: dict) -> Set[str]:
2728
if project_data:
2829
return set(project_data.get("components", []))
2930

30-
return pick_name(bricks.get_components_data(root, ns))
31+
return pick_name(get_components_data(root, ns))
3132

3233

3334
def used_by_as_bricks(bricks: dict, brick_deps: dict) -> dict:

components/polylith/commands/diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def flatten_dependent_bricks(
2828
changed_bricks: Set[str], bases: Set[str], components: Set[str], import_data: dict
2929
) -> Set[str]:
3030
matrix = [
31-
deps.core.sorted_used_by(brick, bases, components, import_data)
31+
deps.sorted_used_by(brick, bases, components, import_data)
3232
for brick in changed_bricks
3333
]
3434

components/polylith/commands/test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pathlib import Path
22
from typing import List, Set, Tuple, Union
33

4-
from polylith import bricks, configuration, diff, info, test
4+
from polylith import configuration, diff, dirs, info, test
55

66

77
def get_imported_bricks_in_tests(
@@ -22,8 +22,8 @@ def get_affected_bricks(
2222
) -> Tuple[Set[str], Set[str]]:
2323
found = get_imported_bricks_in_tests(root, ns, tag_name, theme)
2424

25-
bases = extract_brick_names(bricks.get_bases_data(root, ns), found)
26-
components = extract_brick_names(bricks.get_components_data(root, ns), found)
25+
bases = extract_brick_names(dirs.get_bases_data(root, ns), found)
26+
components = extract_brick_names(dirs.get_components_data(root, ns), found)
2727

2828
return bases, components
2929

components/polylith/deps/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
calculate_brick_deps,
33
find_bricks_with_circular_dependencies,
44
get_brick_imports,
5+
sorted_used_by,
56
)
67
from polylith.deps.report import (
78
print_brick_deps,
@@ -14,6 +15,7 @@
1415
"calculate_brick_deps",
1516
"find_bricks_with_circular_dependencies",
1617
"get_brick_imports",
18+
"sorted_used_by",
1719
"print_brick_deps",
1820
"print_brick_with_circular_deps",
1921
"print_bricks_with_circular_deps",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from polylith.dirs.dirs import create_dir
1+
from polylith.dirs.dirs import create_dir, get_bases_data, get_components_data
22

3-
__all__ = ["create_dir"]
3+
__all__ = ["create_dir", "get_bases_data", "get_components_data"]

0 commit comments

Comments
 (0)