diff --git a/bases/polylith/cli/core.py b/bases/polylith/cli/core.py index d97d825d..1fb5c4d3 100644 --- a/bases/polylith/cli/core.py +++ b/bases/polylith/cli/core.py @@ -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 @@ -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)] @@ -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) @@ -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) diff --git a/bases/polylith/pdm_workspace_hooks/core.py b/bases/polylith/pdm_workspace_hooks/core.py index d58cf3cc..e9df6c79 100644 --- a/bases/polylith/pdm_workspace_hooks/core.py +++ b/bases/polylith/pdm_workspace_hooks/core.py @@ -1,4 +1,6 @@ -import os +from pathlib import Path + +from polylith.pdm.hooks.workspace import build_initialize def pdm_build_initialize(context): @@ -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) diff --git a/components/polylith/bricks/brick.py b/components/polylith/bricks/brick.py index 597fdbe4..f3da7dce 100644 --- a/components/polylith/bricks/brick.py +++ b/components/polylith/bricks/brick.py @@ -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: @@ -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) @@ -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) diff --git a/components/polylith/bricks/component.py b/components/polylith/bricks/component.py index deed2078..128602f2 100644 --- a/components/polylith/bricks/component.py +++ b/components/polylith/bricks/component.py @@ -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 @@ -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 diff --git a/components/polylith/commands/create.py b/components/polylith/commands/create.py index a43973c7..5c0bb401 100644 --- a/components/polylith/commands/create.py +++ b/components/polylith/commands/create.py @@ -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") diff --git a/components/polylith/commands/diff.py b/components/polylith/commands/diff.py index 766b17b2..478223dd 100644 --- a/components/polylith/commands/diff.py +++ b/components/polylith/commands/diff.py @@ -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) diff --git a/components/polylith/commands/info.py b/components/polylith/commands/info.py index a41fd931..85baef2e 100644 --- a/components/polylith/commands/info.py +++ b/components/polylith/commands/info.py @@ -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) diff --git a/components/polylith/configuration/__init__.py b/components/polylith/configuration/__init__.py new file mode 100644 index 00000000..9bbcaa45 --- /dev/null +++ b/components/polylith/configuration/__init__.py @@ -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", +] diff --git a/components/polylith/workspace/parser.py b/components/polylith/configuration/core.py similarity index 100% rename from components/polylith/workspace/parser.py rename to components/polylith/configuration/core.py diff --git a/components/polylith/diff/collect.py b/components/polylith/diff/collect.py index 2257054a..e3e79de0 100644 --- a/components/polylith/diff/collect.py +++ b/components/polylith/diff/collect.py @@ -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: @@ -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}"], diff --git a/components/polylith/libs/grouping.py b/components/polylith/libs/grouping.py index f0db7b90..4b563210 100644 --- a/components/polylith/libs/grouping.py +++ b/components/polylith/libs/grouping.py @@ -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 @@ -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) diff --git a/components/polylith/pdm/hooks/workspace.py b/components/polylith/pdm/hooks/workspace.py new file mode 100644 index 00000000..65e43409 --- /dev/null +++ b/components/polylith/pdm/hooks/workspace.py @@ -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) diff --git a/components/polylith/poetry/commands/check.py b/components/polylith/poetry/commands/check.py index f503ca27..07886450 100644 --- a/components/polylith/poetry/commands/check.py +++ b/components/polylith/poetry/commands/check.py @@ -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 = [ @@ -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)] diff --git a/components/polylith/poetry/commands/libs.py b/components/polylith/poetry/commands/libs.py index 97ba70e5..b63182f0 100644 --- a/components/polylith/poetry/commands/libs.py +++ b/components/polylith/poetry/commands/libs.py @@ -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 @@ -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) diff --git a/components/polylith/poetry/commands/sync.py b/components/polylith/poetry/commands/sync.py index e2c6c1c7..a44434a7 100644 --- a/components/polylith/poetry/commands/sync.py +++ b/components/polylith/poetry/commands/sync.py @@ -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 @@ -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) diff --git a/components/polylith/project/get.py b/components/polylith/project/get.py index c770089b..8cb4b3b3 100644 --- a/components/polylith/project/get.py +++ b/components/polylith/project/get.py @@ -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: @@ -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 [ { diff --git a/components/polylith/sync/update.py b/components/polylith/sync/update.py index 92524b30..a6e5c375 100644 --- a/components/polylith/sync/update.py +++ b/components/polylith/sync/update.py @@ -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 @@ -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"] diff --git a/components/polylith/test/tests.py b/components/polylith/test/tests.py index 475fa46a..ca71b418 100644 --- a/components/polylith/test/tests.py +++ b/components/polylith/test/tests.py @@ -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} @@ -14,7 +14,7 @@ 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"] @@ -22,7 +22,7 @@ def create_test(root: Path, options: dict) -> None: 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) diff --git a/components/polylith/workspace/__init__.py b/components/polylith/workspace/__init__.py index 19aea7eb..f903ad53 100644 --- a/components/polylith/workspace/__init__.py +++ b/components/polylith/workspace/__init__.py @@ -1,3 +1,3 @@ -from polylith.workspace import create, parser, paths +from polylith.workspace import create, paths -__all__ = ["create", "parser", "paths"] +__all__ = ["create", "paths"] diff --git a/components/polylith/workspace/paths.py b/components/polylith/workspace/paths.py index d910748a..a33f62a0 100644 --- a/components/polylith/workspace/paths.py +++ b/components/polylith/workspace/paths.py @@ -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: @@ -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) diff --git a/development/david.py b/development/david.py index a0821834..fb625d2d 100644 --- a/development/david.py +++ b/development/david.py @@ -1,19 +1,31 @@ from pathlib import Path from polylith import ( + alias, bricks, + check, + commands, + configuration, development, diff, dirs, + distributions, files, + hatch, + imports, info, interface, + libs, + parsing, + pdm, poetry, - poetry_plugin, project, readme, repo, + reporting, + sync, test, + toml, workspace, ) @@ -23,7 +35,7 @@ print(repo.projects_dir) root = Path.cwd() -ns = workspace.parser.get_namespace_from_config(root) +ns = configuration.get_namespace_from_config(root) tag = diff.collect.get_latest_tag(root, "release") or "" diff --git a/projects/pdm_polylith_bricks/pyproject.toml b/projects/pdm_polylith_bricks/pyproject.toml index f899c0b0..6c81758b 100644 --- a/projects/pdm_polylith_bricks/pyproject.toml +++ b/projects/pdm_polylith_bricks/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pdm-polylith-bricks" -version = "0.1.1" +version = "0.1.2" description = "a PDM build hook for Polylith" authors = ["David Vujic"] homepage = "https://davidvujic.github.io/python-polylith-docs/" @@ -10,6 +10,7 @@ readme = "README.md" packages = [ {include = "polylith/pdm_project_hooks", from = "../../bases"}, + {include = "polylith/configuration",from = "../../components"}, {include = "polylith/parsing",from = "../../components"}, {include = "polylith/pdm",from = "../../components"}, {include = "polylith/repo",from = "../../components"}, diff --git a/projects/pdm_polylith_workspace/poetry.lock b/projects/pdm_polylith_workspace/poetry.lock index 52548aa4..d89d0459 100644 --- a/projects/pdm_polylith_workspace/poetry.lock +++ b/projects/pdm_polylith_workspace/poetry.lock @@ -1,7 +1,17 @@ # This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. -package = [] + +[[package]] +name = "tomlkit" +version = "0.11.8" +description = "Style preserving TOML library" +optional = false +python-versions = ">=3.7" +files = [ + {file = "tomlkit-0.11.8-py3-none-any.whl", hash = "sha256:8c726c4c202bdb148667835f68d68780b9a003a9ec34167b6c673b38eff2a171"}, + {file = "tomlkit-0.11.8.tar.gz", hash = "sha256:9330fc7faa1db67b541b28e62018c17d20be733177d290a13b24c62d1614e0c3"}, +] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "c595a0588c25d58f3e3834ad7169126836d262b925fe6ca9b5d540dcf301d254" +content-hash = "0d1c25c8e15e0ca2a5cc97fce19b1c931a1fc9aad76a3a3df58d02504fee156f" diff --git a/projects/pdm_polylith_workspace/pyproject.toml b/projects/pdm_polylith_workspace/pyproject.toml index 53c0d783..024670b1 100644 --- a/projects/pdm_polylith_workspace/pyproject.toml +++ b/projects/pdm_polylith_workspace/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pdm-polylith-workspace" -version = "0.1.0" +version = "0.1.1" description = "a PDM build hook for a Polylith workspace" homepage = "https://davidvujic.github.io/python-polylith-docs/" repository = "https://github.com/davidvujic/python-polylith" @@ -8,10 +8,18 @@ authors = ["David Vujic"] license = "MIT" readme = "README.md" -packages = [{include = "polylith/pdm_workspace_hooks", from = "../../bases"}] +packages = [ + {include = "polylith/pdm_workspace_hooks", from = "../../bases"}, + {include = "polylith/configuration",from = "../../components"}, + {include = "polylith/parsing",from = "../../components"}, + {include = "polylith/pdm",from = "../../components"}, + {include = "polylith/repo",from = "../../components"}, + {include = "polylith/toml",from = "../../components"}, +] [tool.poetry.dependencies] python = "^3.9" +tomlkit = "^0.11.5" [tool.poetry.plugins."pdm.build.hook"] polylith-workspace = "pdm_polylith_workspace.polylith.pdm_workspace_hooks.core" diff --git a/projects/poetry_polylith_plugin/pyproject.toml b/projects/poetry_polylith_plugin/pyproject.toml index 84f8aab9..c9715e55 100644 --- a/projects/poetry_polylith_plugin/pyproject.toml +++ b/projects/poetry_polylith_plugin/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "poetry-polylith-plugin" -version = "1.15.0" +version = "1.15.1" description = "A Poetry plugin that adds tooling support for the Polylith Architecture" authors = ["David Vujic"] homepage = "https://davidvujic.github.io/python-polylith-docs/" @@ -14,6 +14,7 @@ packages = [ {include = "polylith/bricks",from = "../../components"}, {include = "polylith/check",from = "../../components"}, {include = "polylith/commands",from = "../../components"}, + {include = "polylith/configuration",from = "../../components"}, {include = "polylith/development",from = "../../components"}, {include = "polylith/diff",from = "../../components"}, {include = "polylith/dirs",from = "../../components"}, diff --git a/projects/polylith_cli/pyproject.toml b/projects/polylith_cli/pyproject.toml index 9f3fadaf..424c0884 100644 --- a/projects/polylith_cli/pyproject.toml +++ b/projects/polylith_cli/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "polylith-cli" -version = "1.2.0" +version = "1.2.1" description = "Python tooling support for the Polylith Architecture" authors = ['David Vujic'] homepage = "https://davidvujic.github.io/python-polylith-docs/" @@ -14,6 +14,7 @@ packages = [ {include = "polylith/bricks",from = "../../components"}, {include = "polylith/check",from = "../../components"}, {include = "polylith/commands",from = "../../components"}, + {include = "polylith/configuration",from = "../../components"}, {include = "polylith/development",from = "../../components"}, {include = "polylith/diff",from = "../../components"}, {include = "polylith/dirs",from = "../../components"}, diff --git a/pyproject.toml b/pyproject.toml index 5b420396..0dbe6c73 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,6 +15,7 @@ packages = [ {include = "polylith/alias",from = "components"}, {include = "polylith/bricks",from = "components"}, {include = "polylith/check",from = "components"}, + {include = "polylith/configuration",from = "components"}, {include = "polylith/commands",from = "components"}, {include = "polylith/development",from = "components"}, {include = "polylith/diff",from = "components"}, diff --git a/test/components/polylith/configuration/__init__.py b/test/components/polylith/configuration/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test/components/polylith/configuration/test_core.py b/test/components/polylith/configuration/test_core.py new file mode 100644 index 00000000..3b2643fe --- /dev/null +++ b/test/components/polylith/configuration/test_core.py @@ -0,0 +1,103 @@ +from pathlib import Path +from typing import Tuple + +import pytest +import tomlkit +from polylith.configuration import core + +config_template = """ +[tool.polylith] +namespace = "my_namespace" + +[tool.polylith.structure] +theme = "{theme}" + +[tool.polylith.tag.patterns] +stable = "stable-*" +release = "v[0-9]*" + +[tool.polylith.test] +enabled = true +""" + + +@pytest.fixture +def use_fake(monkeypatch): + def patch(theme: str): + config = config_template.format(theme=theme) + name = "_load_workspace_config" + + monkeypatch.setattr(core, name, lambda *args: tomlkit.loads(config)) + + return patch + + +@pytest.fixture +def use_loose(use_fake): + use_fake(theme="loose") + + +@pytest.fixture +def use_tdd(use_fake): + use_fake(theme="tdd") + + +fake_path = Path.cwd() + + +def test_get_namespace(use_loose): + res = core.get_namespace_from_config(fake_path) + + assert res == "my_namespace" + + +def test_get_tag_pattern(use_loose): + stable = core.get_tag_pattern_from_config(fake_path, "stable") + release = core.get_tag_pattern_from_config(fake_path, "release") + + assert stable == "stable-*" + assert release == "v[0-9]*" + + +def test_is_test_generation_enabled(use_loose): + res = core.is_test_generation_enabled(fake_path) + + assert res is True + + +def test_is_readme_generation_enabled(use_loose): + res = core.is_readme_generation_enabled(fake_path) + + assert res is False + + +def test_get_theme(use_loose): + res = core.get_theme_from_config(fake_path) + + assert res == "loose" + + +def _get_structure(path: Path) -> Tuple[str, str, str]: + brick = core.get_brick_structure_from_config(path) + test = core.get_tests_structure_from_config(path) + resources = core.get_resources_structure_from_config(path) + + return brick, test, resources + + +def test_get_structure_for_loose_theme(use_loose): + brick, test, resources = _get_structure(fake_path) + + expected = "{brick}/{namespace}/{package}" + + assert brick == expected + assert test == f"test/{expected}" + assert resources == expected + + +def test_get_structure_for_tdd_theme(use_tdd): + brick, test, resources = _get_structure(fake_path) + + assert brick == "{brick}/{package}/src/{namespace}/{package}" + assert test == "{brick}/{package}/test/{namespace}/{package}" + assert resources == "{brick}/{package}" diff --git a/test/components/polylith/pdm/__init__.py b/test/components/polylith/pdm/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test/components/polylith/pdm/test_workspace_hook.py b/test/components/polylith/pdm/test_workspace_hook.py new file mode 100644 index 00000000..4669114a --- /dev/null +++ b/test/components/polylith/pdm/test_workspace_hook.py @@ -0,0 +1,31 @@ +from polylith.pdm.hooks.workspace import parse_paths +from pathlib import Path +import tomlkit + + +root = "/some/path" +namespace = "my_namespace" + +toml_with_tdd_theme = f"""\ +[tool.polylith.bricks] +"bases/one/src/{namespace}/one" = "{namespace}/one" +"components/two/src/{namespace}/two" = "{namespace}/two" + +[build-system] +requires = ["pdm-backend"] +build-backend = "pdm.backend" +""" + + +def test_parse_paths_for_loose_theme(): + res = parse_paths(Path(root), "loose", namespace, {}) + + assert res == {f"{root}/bases", f"{root}/components"} + + +def test_parse_paths_for_tdd_theme(): + data = tomlkit.loads(toml_with_tdd_theme) + + res = parse_paths(Path(root), "tdd", namespace, data) + + assert res == {f"{root}/bases/one/src", f"{root}/components/two/src"}