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
8 changes: 4 additions & 4 deletions bases/polylith/cli/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path

from polylith import commands, info, repo, workspace
from polylith import commands, configuration, info, repo
from polylith.cli import create, options
from typer import Exit, Option, Typer
from typing_extensions import Annotated
Expand Down Expand Up @@ -30,7 +30,7 @@ def check_command(
):
"""Validates the Polylith workspace."""
root = repo.get_workspace_root(Path.cwd())
ns = workspace.parser.get_namespace_from_config(root)
ns = configuration.get_namespace_from_config(root)

all_projects_data = info.get_projects_data(root, ns)
only_projects_data = [p for p in all_projects_data if info.is_project(p)]
Expand Down Expand Up @@ -68,7 +68,7 @@ def libs_command(
):
"""Show third-party libraries used in the workspace."""
root = repo.get_workspace_root(Path.cwd())
ns = workspace.parser.get_namespace_from_config(root)
ns = configuration.get_namespace_from_config(root)

projects_data = info.get_projects_data(root, ns)

Expand All @@ -94,7 +94,7 @@ def sync_command(
):
"""Update pyproject.toml with missing bricks."""
root = repo.get_workspace_root(Path.cwd())
ns = workspace.parser.get_namespace_from_config(root)
ns = configuration.get_namespace_from_config(root)

projects_data = info.get_projects_data(root, ns)

Expand Down
13 changes: 8 additions & 5 deletions bases/polylith/pdm_workspace_hooks/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
from pathlib import Path

from polylith.pdm.hooks.workspace import build_initialize


def pdm_build_initialize(context):
Expand All @@ -8,8 +10,9 @@ def pdm_build_initialize(context):
"""

context.ensure_build_dir()
filepath = os.path.join(context.build_dir, "polylith_workspace.pth")

with open(filepath, "w") as f:
f.write(f"{context.config.root}/bases\n")
f.write(f"{context.config.root}/components\n")
data = context.config.data
build_dir = Path(context.build_dir)
root = Path(context.config.root)

build_initialize(data, build_dir, root)
8 changes: 4 additions & 4 deletions components/polylith/bricks/brick.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from pathlib import Path

from polylith import configuration
from polylith.dirs import create_dir
from polylith.files import create_file
from polylith.interface import create_interface
from polylith.readme import create_brick_readme
from polylith.workspace import parser


def create_brick(root: Path, options: dict) -> None:
Expand All @@ -13,8 +13,8 @@ def create_brick(root: Path, options: dict) -> None:
k: v for k, v in options.items() if k in {"brick", "namespace", "package"}
}

brick_structure = parser.get_brick_structure_from_config(root)
resources_structure = parser.get_resources_structure_from_config(root)
brick_structure = configuration.get_brick_structure_from_config(root)
resources_structure = configuration.get_resources_structure_from_config(root)

brick_path = brick_structure.format(**path_kwargs)
resources_path = resources_structure.format(**path_kwargs)
Expand All @@ -23,5 +23,5 @@ def create_brick(root: Path, options: dict) -> None:
create_file(d, f"{modulename}.py")
create_interface(d, options)

if parser.is_readme_generation_enabled(root):
if configuration.is_readme_generation_enabled(root):
create_brick_readme(root / resources_path, options)
4 changes: 2 additions & 2 deletions components/polylith/bricks/component.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
from typing import List

from polylith import workspace
from polylith import configuration
from polylith.bricks.brick import create_brick
from polylith.repo import components_dir
from polylith.test import create_test
Expand All @@ -20,7 +20,7 @@ def is_brick_dir(p: Path) -> bool:


def get_component_dirs(root: Path, top_dir, ns) -> list:
theme = workspace.parser.get_theme_from_config(root)
theme = configuration.get_theme_from_config(root)
dirs = top_dir if theme == "tdd" else f"{top_dir}/{ns}"

component_dir = root / dirs
Expand Down
5 changes: 3 additions & 2 deletions components/polylith/commands/create.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from pathlib import Path
from typing import Union
from polylith import repo, workspace

from polylith import configuration, repo


def create(name: Union[str, None], description: Union[str, None], fn):
root = repo.get_workspace_root(Path.cwd())
namespace = workspace.parser.get_namespace_from_config(root)
namespace = configuration.get_namespace_from_config(root)

if not name:
raise ValueError("Please add a name by using --name")
Expand Down
6 changes: 3 additions & 3 deletions components/polylith/commands/diff.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from pathlib import Path

from typing import Union
from polylith import diff, info, repo, workspace

from polylith import configuration, diff, info, repo


def print_views(root: Path, tag: str, short: bool, only_bricks: bool) -> None:
ns = workspace.parser.get_namespace_from_config(root)
ns = configuration.get_namespace_from_config(root)
files = diff.collect.get_files(tag)
bases = diff.collect.get_changed_bases(files, ns)
components = diff.collect.get_changed_components(files, ns)
Expand Down
4 changes: 2 additions & 2 deletions components/polylith/commands/info.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from pathlib import Path

from polylith import info, repo, workspace
from polylith import configuration, info, repo


def run(short: bool):
root = repo.get_workspace_root(Path.cwd())

ns = workspace.parser.get_namespace_from_config(root)
ns = configuration.get_namespace_from_config(root)
bases = info.get_bases(root, ns)
components = info.get_components(root, ns)
projects_data = info.get_bricks_in_projects(root, components, bases, ns)
Expand Down
21 changes: 21 additions & 0 deletions components/polylith/configuration/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from polylith.configuration.core import (
get_brick_structure_from_config,
get_namespace_from_config,
get_resources_structure_from_config,
get_tag_pattern_from_config,
get_tests_structure_from_config,
get_theme_from_config,
is_readme_generation_enabled,
is_test_generation_enabled,
)

__all__ = [
"get_brick_structure_from_config",
"get_namespace_from_config",
"get_resources_structure_from_config",
"get_tag_pattern_from_config",
"get_tests_structure_from_config",
"get_theme_from_config",
"is_readme_generation_enabled",
"is_test_generation_enabled",
]
4 changes: 2 additions & 2 deletions components/polylith/diff/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path
from typing import List, Set, Union

from polylith import repo, workspace
from polylith import configuration, repo


def _parse_folder_parts(folder: str, changed_file: Path) -> str:
Expand Down Expand Up @@ -42,7 +42,7 @@ def get_changed_projects(changed_files: List[Path]) -> list:


def get_latest_tag(root: Path, key: Union[str, None]) -> Union[str, None]:
tag_pattern = workspace.parser.get_tag_pattern_from_config(root, key)
tag_pattern = configuration.get_tag_pattern_from_config(root, key)

res = subprocess.run(
["git", "tag", "-l", "--sort=-committerdate", f"{tag_pattern}"],
Expand Down
4 changes: 2 additions & 2 deletions components/polylith/libs/grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path
from typing import Set

from polylith import workspace
from polylith import configuration
from polylith.imports import extract_top_ns, fetch_all_imports
from polylith.libs.stdlib import standard_libs

Expand Down Expand Up @@ -42,7 +42,7 @@ def extract_third_party_imports(all_imports: dict, top_ns: str) -> dict:


def get_third_party_imports(root: Path, paths: Set[Path]) -> dict:
top_ns = workspace.parser.get_namespace_from_config(root)
top_ns = configuration.get_namespace_from_config(root)

all_imports = fetch_all_imports(paths)

Expand Down
38 changes: 38 additions & 0 deletions components/polylith/pdm/hooks/workspace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from pathlib import Path
from typing import Set

from polylith import configuration, toml


def paths_from_config(ns: str, data: dict) -> Set[str]:
packages = toml.get_project_package_includes(ns, data)

return {p["from"] for p in packages}


def parse_paths(root: Path, theme: str, ns: str, data: dict) -> Set[str]:
defaults = {"bases", "components"}

paths = defaults if theme == "loose" else paths_from_config(ns, data)

return {(root / p).as_posix() for p in paths}


def write_pth_file(build_dir: Path, paths: Set[str]) -> None:
filepath = build_dir / "polylith_workspace.pth"

with open(filepath, "w") as f:
for p in paths:
f.write(f"{p}\n")


def build_initialize(config_data: dict, build_dir: Path, root: Path) -> None:
theme = configuration.get_theme_from_config(root)
ns = configuration.get_namespace_from_config(root)

paths = parse_paths(root, theme, ns, config_data)

if not paths:
return

write_pth_file(build_dir, paths)
4 changes: 2 additions & 2 deletions components/polylith/poetry/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from cleo.helpers import option
from poetry.console.commands.command import Command
from polylith import commands, info, repo, workspace
from polylith import commands, configuration, info, repo
from polylith.poetry import internals

command_options = [
Expand Down Expand Up @@ -52,7 +52,7 @@ def print_report(self, root: Path, ns: str, project_data: dict) -> bool:
def handle(self) -> int:
directory = self.option("directory")
root = repo.get_workspace_root(Path.cwd())
ns = workspace.parser.get_namespace_from_config(root)
ns = configuration.get_namespace_from_config(root)

all_projects_data = info.get_projects_data(root, ns)
only_projects_data = [p for p in all_projects_data if info.is_project(p)]
Expand Down
4 changes: 2 additions & 2 deletions components/polylith/poetry/commands/libs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path

from poetry.console.commands.command import Command
from polylith import commands, info, repo, workspace
from polylith import commands, configuration, info, repo
from polylith.poetry.commands.check import command_options
from polylith.poetry.internals import filter_projects_data, find_third_party_libs

Expand Down Expand Up @@ -33,7 +33,7 @@ def print_report(self, root: Path, ns: str, data: dict) -> bool:
def handle(self) -> int:
directory = self.option("directory")
root = repo.get_workspace_root(Path.cwd())
ns = workspace.parser.get_namespace_from_config(root)
ns = configuration.get_namespace_from_config(root)

all_projects_data = info.get_projects_data(root, ns)
projects_data = filter_projects_data(self.poetry, directory, all_projects_data)
Expand Down
4 changes: 2 additions & 2 deletions components/polylith/poetry/commands/sync.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path

from poetry.console.commands.command import Command
from polylith import commands, info, repo, workspace
from polylith import commands, configuration, info, repo
from polylith.poetry.internals import filter_projects_data


Expand All @@ -12,7 +12,7 @@ class SyncCommand(Command):
def handle(self) -> int:
directory = self.option("directory")
root = repo.get_workspace_root(Path.cwd())
ns = workspace.parser.get_namespace_from_config(root)
ns = configuration.get_namespace_from_config(root)

all_projects_data = info.get_projects_data(root, ns)
projects_data = filter_projects_data(self.poetry, directory, all_projects_data)
Expand Down
4 changes: 2 additions & 2 deletions components/polylith/project/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import List

import tomlkit
from polylith import repo, toml, workspace
from polylith import configuration, repo, toml


def get_project_name(data) -> str:
Expand Down Expand Up @@ -43,7 +43,7 @@ def get_toml_files(root: Path) -> List[dict]:

def get_packages_for_projects(root: Path) -> List[dict]:
toml_files = get_toml_files(root)
namespace = workspace.parser.get_namespace_from_config(root)
namespace = configuration.get_namespace_from_config(root)

return [
{
Expand Down
4 changes: 2 additions & 2 deletions components/polylith/sync/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import List, Union

import tomlkit
from polylith import project, repo, workspace
from polylith import configuration, project, repo
from tomlkit.toml_document import TOMLDocument


Expand Down Expand Up @@ -101,7 +101,7 @@ def generate_updated_project(


def to_packages(root: Path, namespace: str, diff: dict) -> List[dict]:
theme = workspace.parser.get_theme_from_config(root)
theme = configuration.get_theme_from_config(root)

is_project = diff["is_project"]

Expand Down
6 changes: 3 additions & 3 deletions components/polylith/test/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from polylith.dirs import create_dir
from polylith.files import create_file
from polylith.workspace import parser
from polylith import configuration

template = """\
from {namespace}.{package} import {modulename}
Expand All @@ -14,15 +14,15 @@ def test_sample():


def create_test(root: Path, options: dict) -> None:
if not parser.is_test_generation_enabled(root):
if not configuration.is_test_generation_enabled(root):
return

brick = options["brick"]
namespace = options["namespace"]
package = options["package"]
modulename = options["modulename"]

dirs_structure = parser.get_tests_structure_from_config(root)
dirs_structure = configuration.get_tests_structure_from_config(root)
dirs = dirs_structure.format(brick=brick, namespace=namespace, package=package)
d = create_dir(root, dirs)

Expand Down
4 changes: 2 additions & 2 deletions components/polylith/workspace/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from polylith.workspace import create, parser, paths
from polylith.workspace import create, paths

__all__ = ["create", "parser", "paths"]
__all__ = ["create", "paths"]
5 changes: 2 additions & 3 deletions components/polylith/workspace/paths.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from pathlib import Path
from typing import Set

from polylith import repo
from polylith.workspace import parser
from polylith import configuration, repo


def get_path(structure: str, brick: str, ns: str, package: str) -> str:
Expand All @@ -14,7 +13,7 @@ def get_paths(structure: str, brick: str, ns: str, packages: Set[str]) -> Set[st


def collect_paths(root: Path, ns: str, brick: str, packages: Set[str]) -> Set[Path]:
structure = parser.get_brick_structure_from_config(root)
structure = configuration.get_brick_structure_from_config(root)

paths = get_paths(structure, brick, ns, packages)

Expand Down
Loading