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
3 changes: 2 additions & 1 deletion components/polylith/bricks/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from typing import List

from polylith.bricks import component
from polylith.bricks.brick import create_brick
Expand All @@ -11,5 +12,5 @@ def create_base(path: Path, namespace: str, package: str) -> None:
create_test(path, bases_dir, namespace, package)


def get_bases_data(path: Path, ns: str) -> list[dict]:
def get_bases_data(path: Path, ns: str) -> List[dict]:
return component.get_components_data(path, ns, bases_dir)
5 changes: 3 additions & 2 deletions components/polylith/bricks/component.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from pathlib import Path
from typing import List

from polylith import workspace
from polylith.bricks.brick import create_brick
from polylith.repo import components_dir
from polylith.test import create_test
from polylith import workspace


def create_component(path: Path, namespace: str, package: str) -> None:
Expand All @@ -25,7 +26,7 @@ def get_component_dirs(root: Path, top_dir, ns) -> list:

def get_components_data(
root: Path, ns: str, top_dir: str = components_dir
) -> list[dict]:
) -> List[dict]:
dirs = get_component_dirs(root, top_dir, ns)

return [{"name": d.name} for d in dirs]
3 changes: 1 addition & 2 deletions components/polylith/diff/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from polylith.diff import collect
from polylith.diff import report
from polylith.diff import collect, report

__all__ = ["collect", "report"]
14 changes: 7 additions & 7 deletions components/polylith/diff/collect.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import subprocess
from pathlib import Path
from typing import Union
from typing import List, Union

from polylith import repo, workspace


def _get_changed(folder: str, changed_files: list[Path]) -> set:
def _get_changed(folder: str, changed_files: List[Path]) -> set:
return {p.parent.name for p in changed_files if folder in p.as_posix()}


def _get_changed_bricks(root: Path, top_dir: str, changed_files: list[Path]) -> list:
def _get_changed_bricks(root: Path, top_dir: str, changed_files: List[Path]) -> list:
namespace = workspace.parser.get_namespace_from_config(root)
d = f"{top_dir}/{namespace}"

return sorted(_get_changed(d, changed_files))


def get_changed_components(root: Path, changed_files: list[Path]) -> list:
def get_changed_components(root: Path, changed_files: List[Path]) -> list:
return _get_changed_bricks(root, repo.components_dir, changed_files)


def get_changed_bases(root: Path, changed_files: list[Path]) -> list:
def get_changed_bases(root: Path, changed_files: List[Path]) -> list:
return _get_changed_bricks(root, repo.bases_dir, changed_files)


def get_changed_projects(changed_files: list[Path]) -> list:
def get_changed_projects(changed_files: List[Path]) -> list:
res = _get_changed(repo.projects_dir, changed_files)
filtered = {p for p in res if p != repo.projects_dir}
return sorted(filtered)
Expand All @@ -41,7 +41,7 @@ def get_latest_tag(root: Path) -> Union[str, None]:
return next((tag for tag in res.stdout.decode("utf-8").split()), None)


def get_files(tag: str) -> list[Path]:
def get_files(tag: str) -> List[Path]:
res = subprocess.run(
["git", "diff", tag, "--stat", "--name-only"],
capture_output=True,
Expand Down
10 changes: 5 additions & 5 deletions components/polylith/diff/report.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import List

from rich import box
from rich.columns import Columns
from rich.console import Console
Expand All @@ -22,7 +24,7 @@ def brick_status(brick, bricks) -> str:


def print_diff_details(
projects_data: list[dict], bases: list[str], components: list[str]
projects_data: List[dict], bases: List[str], components: List[str]
) -> None:
console = Console(theme=info_theme)
table = Table(box=box.SIMPLE_HEAD)
Expand All @@ -43,7 +45,7 @@ def print_diff_details(
console.print(table, overflow="ellipsis")


def print_detected_changes_in_projects(projects: list[str]) -> None:
def print_detected_changes_in_projects(projects: List[str]) -> None:
if not projects:
return

Expand All @@ -53,9 +55,7 @@ def print_detected_changes_in_projects(projects: list[str]) -> None:
console.print(f"[data]:gear: Changes found in [/][proj]{project}[/]")


def print_diff_summary(
tag: str, bases: list[str], components: list[str]
) -> None:
def print_diff_summary(tag: str, bases: List[str], components: List[str]) -> None:
console = Console(theme=info_theme)

console.print(Padding(f"[data]Diff: based on the {tag} tag[/]", (1, 0, 1, 0)))
Expand Down
2 changes: 1 addition & 1 deletion components/polylith/dirs/dirs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path
from polylith.files import create_file

from polylith.files import create_file

keep_file_name = ".keep"

Expand Down
6 changes: 5 additions & 1 deletion components/polylith/info/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from polylith.info.collect import get_bricks_in_projects
from polylith.info.report import print_bricks_in_projects, print_workspace_summary

__all__ = ["get_bricks_in_projects", "print_bricks_in_projects", "print_workspace_summary"]
__all__ = [
"get_bricks_in_projects",
"print_bricks_in_projects",
"print_workspace_summary",
]
9 changes: 5 additions & 4 deletions components/polylith/info/collect.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
from pathlib import Path
from typing import List

from polylith import workspace
from polylith.bricks import base, component
from polylith.project import get_packages_for_projects, parse_package_paths


def get_matching_bricks(
paths: list[Path], bricks: list[str], namespace: str
) -> list[str]:
paths: List[Path], bricks: List[str], namespace: str
) -> List[str]:
paths_in_namespace = (p.name for p in paths if p.parent.name == namespace)

res = set(bricks).intersection(paths_in_namespace)

return sorted(list(res))


def get_project_bricks(project_packages: list[dict], components, bases, namespace: str):
def get_project_bricks(project_packages: List[dict], components, bases, namespace: str):
paths = parse_package_paths(project_packages)

components_in_project = get_matching_bricks(paths, components, namespace)
Expand All @@ -24,7 +25,7 @@ def get_project_bricks(project_packages: list[dict], components, bases, namespac
return {"components": components_in_project, "bases": bases_in_project}


def get_bricks_in_projects(root: Path) -> list[dict]:
def get_bricks_in_projects(root: Path) -> List[dict]:
namespace = workspace.parser.get_namespace_from_config(root)

packages_for_projects = get_packages_for_projects(root)
Expand Down
6 changes: 4 additions & 2 deletions components/polylith/info/report.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import List

from rich import box
from rich.columns import Columns
from rich.console import Console
Expand All @@ -22,7 +24,7 @@ def brick_status(brick, bricks) -> str:


def print_bricks_in_projects(
projects_data: list[dict], bases_data: list[dict], components_data: list[dict]
projects_data: List[dict], bases_data: List[dict], components_data: List[dict]
) -> None:
if not components_data and not bases_data:
return
Expand Down Expand Up @@ -50,7 +52,7 @@ def print_bricks_in_projects(


def print_workspace_summary(
projects_data: list[dict], bases_data: list[dict], components_data: list[dict]
projects_data: List[dict], bases_data: List[dict], components_data: List[dict]
) -> None:
console = Console(theme=info_theme)

Expand Down
2 changes: 1 addition & 1 deletion components/polylith/poetry/commands/create_project.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from cleo.helpers import option
from poetry.console.commands.command import Command
from polylith.poetry.commands.create import create
from polylith import project
from polylith.poetry.commands.create import create

command_name = "poly create project"

Expand Down
2 changes: 1 addition & 1 deletion components/polylith/project/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from polylith.project.create import create_project
from polylith.project.get import get_project_names, get_packages_for_projects
from polylith.project.get import get_packages_for_projects, get_project_names
from polylith.project.parser import parse_package_paths

__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion components/polylith/project/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import tomlkit
from polylith import repo
from polylith.repo import projects_dir
from polylith.dirs import create_dir
from polylith.repo import projects_dir

template = """\
[tool.poetry]
Expand Down
9 changes: 5 additions & 4 deletions components/polylith/project/get.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from collections.abc import Generator
from pathlib import Path
from typing import List

import tomlkit
from polylith.repo import default_toml


def get_project_package_includes(data) -> list[dict]:
def get_project_package_includes(data) -> List[dict]:
return data["tool"]["poetry"]["packages"]


Expand All @@ -22,19 +23,19 @@ def get_project_files(root: Path) -> Generator:
return root.glob(f"projects/**/{default_toml}")


def get_toml_files(root: Path) -> list[tomlkit.TOMLDocument]:
def get_toml_files(root: Path) -> List[tomlkit.TOMLDocument]:
project_files = get_project_files(root)

return [get_toml(p) for p in project_files]


def get_project_names(root: Path) -> list[str]:
def get_project_names(root: Path) -> List[str]:
tomls = get_toml_files(root)

return [get_project_name(d) for d in tomls]


def get_packages_for_projects(root: Path) -> list[dict]:
def get_packages_for_projects(root: Path) -> List[dict]:
tomls = get_toml_files(root)

return [
Expand Down
3 changes: 2 additions & 1 deletion components/polylith/project/parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from typing import List


def to_path(package: dict) -> Path:
Expand All @@ -8,7 +9,7 @@ def to_path(package: dict) -> Path:
return Path(f"{from_path}/{include}") if from_path else Path(include)


def parse_package_paths(packages: list[dict]) -> list[Path]:
def parse_package_paths(packages: List[dict]) -> List[Path]:
sorted_packages = sorted(packages, key=lambda p: (p["from"], p["include"]))

return [to_path(p) for p in sorted_packages]
1 change: 0 additions & 1 deletion components/polylith/readme/readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from polylith import log, repo


template = """\
# A Python Polylith repo

Expand Down
2 changes: 1 addition & 1 deletion development/david.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from pathlib import Path

from polylith import (
poetry_plugin,
bricks,
development,
diff,
Expand All @@ -11,6 +10,7 @@
interface,
log,
poetry,
poetry_plugin,
project,
readme,
repo,
Expand Down