From e284cbef924f4c45659891f4e4c7b44bbde8297d Mon Sep 17 00:00:00 2001 From: GH-maggio Date: Thu, 1 Feb 2024 15:04:56 -0800 Subject: [PATCH 1/3] merge workspace.toml into pyproject.toml --- components/polylith/commands/create.py | 2 +- components/polylith/repo/__init__.py | 2 -- components/polylith/repo/repo.py | 5 ++--- components/polylith/workspace/create.py | 2 +- components/polylith/workspace/parser.py | 2 +- pyproject.toml | 13 +++++++++++++ test/components/polylith/bricks/test_base.py | 4 +--- test/conftest.py | 4 ++-- test/test_data/{workspace.toml => pyproject.toml} | 0 9 files changed, 21 insertions(+), 13 deletions(-) rename test/test_data/{workspace.toml => pyproject.toml} (100%) diff --git a/components/polylith/commands/create.py b/components/polylith/commands/create.py index 8488de30..bd35c8f4 100644 --- a/components/polylith/commands/create.py +++ b/components/polylith/commands/create.py @@ -12,7 +12,7 @@ def create(name: Union[str, None], description: Union[str, None], fn): if not namespace: raise ValueError( - "Didn't find a namespace. Expected to find it in workspace.toml." + "Didn't find a namespace. Expected to find it under [tool.polylith] in pyproject.toml." ) options = { diff --git a/components/polylith/repo/__init__.py b/components/polylith/repo/__init__.py index c05041e7..8b2a10c0 100644 --- a/components/polylith/repo/__init__.py +++ b/components/polylith/repo/__init__.py @@ -11,7 +11,6 @@ is_poetry, projects_dir, readme_file, - workspace_file, ) __all__ = [ @@ -28,5 +27,4 @@ "is_poetry", "projects_dir", "readme_file", - "workspace_file", ] diff --git a/components/polylith/repo/repo.py b/components/polylith/repo/repo.py index 55fc74a3..9ed6b5a8 100644 --- a/components/polylith/repo/repo.py +++ b/components/polylith/repo/repo.py @@ -1,7 +1,6 @@ from pathlib import Path from typing import Union -workspace_file = "workspace.toml" default_toml = "pyproject.toml" readme_file = "README.md" @@ -43,7 +42,7 @@ def find_upwards_dir(cwd: Path, name: str) -> Union[Path, None]: def find_workspace_root(cwd: Path) -> Union[Path, None]: - return find_upwards_dir(cwd, workspace_file) + return find_upwards_dir(cwd, default_toml) def get_workspace_root(cwd: Path) -> Path: @@ -51,7 +50,7 @@ def get_workspace_root(cwd: Path) -> Path: if not root: raise ValueError( - "Didn't find the workspace root. Expected to find a workspace.toml file." + "Didn't find the workspace root. Expected to find a pyproject.toml file." ) return root diff --git a/components/polylith/workspace/create.py b/components/polylith/workspace/create.py index 648d10b8..91ea7cba 100644 --- a/components/polylith/workspace/create.py +++ b/components/polylith/workspace/create.py @@ -29,7 +29,7 @@ def create_workspace_config(path: Path, namespace: str, theme: str) -> None: formatted = template.format(namespace=namespace, theme=theme) content: dict = tomlkit.loads(formatted) - fullpath = path / repo.workspace_file + fullpath = path / repo.default_toml with fullpath.open("w", encoding="utf-8") as f: f.write(tomlkit.dumps(content)) diff --git a/components/polylith/workspace/parser.py b/components/polylith/workspace/parser.py index 02559eed..6031ebae 100644 --- a/components/polylith/workspace/parser.py +++ b/components/polylith/workspace/parser.py @@ -8,7 +8,7 @@ @lru_cache def _load_workspace_config(path: Path) -> tomlkit.TOMLDocument: - fullpath = path / repo.workspace_file + fullpath = path / repo.default_toml content = fullpath.read_text() diff --git a/pyproject.toml b/pyproject.toml index 5b420396..06df6d99 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,3 +68,16 @@ build-backend = "poetry.core.masonry.api" [tool.pytest.ini_options] addopts = "-sv" + +[tool.polylith] +namespace = "polylith" + +[tool.polylith.structure] +theme = "loose" + +[tool.polylith.tag.patterns] +stable = "stable-*" +release = "v[0-9]*" + +[tool.polylith.test] +enabled = true diff --git a/test/components/polylith/bricks/test_base.py b/test/components/polylith/bricks/test_base.py index 75e76b0e..92a2307d 100644 --- a/test/components/polylith/bricks/test_base.py +++ b/test/components/polylith/bricks/test_base.py @@ -32,9 +32,7 @@ def test_create_base(handle_workspace_files, id, expected_dirs, expected_dir_str } create_base(path=handle_workspace_files, options=options) - results = [ - x for x in handle_workspace_files.iterdir() if x.name != "workspace.toml" - ] + results = [x for x in handle_workspace_files.iterdir()] assert all([item.is_dir() for item in results if item in expected_dirs]) assert ( diff --git a/test/conftest.py b/test/conftest.py index 290fe73d..ab846e33 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -14,9 +14,9 @@ def handle_workspace_files(): """ temp_dir = Path("test/temp") temp_dir.mkdir(parents=True, exist_ok=True) - workspace_file = temp_dir / "workspace.toml" + workspace_file = temp_dir / "pyproject.toml" workspace_file.touch() - source_file = Path("test/test_data/workspace.toml") + source_file = Path("test/test_data/pyproject.toml") workspace_file.write_text(source_file.read_text()) yield temp_dir shutil.rmtree(temp_dir) diff --git a/test/test_data/workspace.toml b/test/test_data/pyproject.toml similarity index 100% rename from test/test_data/workspace.toml rename to test/test_data/pyproject.toml From 9f8ce6ba7182e992d30342faf5b65c554df4b7de Mon Sep 17 00:00:00 2001 From: GH-maggio Date: Fri, 2 Feb 2024 12:52:06 -0800 Subject: [PATCH 2/3] if workspace.toml missing, refers to root pyproject.toml --- components/polylith/commands/create.py | 2 +- components/polylith/repo/__init__.py | 2 ++ components/polylith/repo/repo.py | 11 ++++++++--- components/polylith/workspace/create.py | 2 +- components/polylith/workspace/parser.py | 5 ++++- test/conftest.py | 4 ++-- test/test_data/{pyproject.toml => workspace.toml} | 0 7 files changed, 18 insertions(+), 8 deletions(-) rename test/test_data/{pyproject.toml => workspace.toml} (100%) diff --git a/components/polylith/commands/create.py b/components/polylith/commands/create.py index bd35c8f4..a43973c7 100644 --- a/components/polylith/commands/create.py +++ b/components/polylith/commands/create.py @@ -12,7 +12,7 @@ def create(name: Union[str, None], description: Union[str, None], fn): if not namespace: raise ValueError( - "Didn't find a namespace. Expected to find it under [tool.polylith] in pyproject.toml." + "Didn't find a namespace. Expected to find it under [tool.polylith] in workspace.toml or pyproject.toml." ) options = { diff --git a/components/polylith/repo/__init__.py b/components/polylith/repo/__init__.py index 8b2a10c0..c05041e7 100644 --- a/components/polylith/repo/__init__.py +++ b/components/polylith/repo/__init__.py @@ -11,6 +11,7 @@ is_poetry, projects_dir, readme_file, + workspace_file, ) __all__ = [ @@ -27,4 +28,5 @@ "is_poetry", "projects_dir", "readme_file", + "workspace_file", ] diff --git a/components/polylith/repo/repo.py b/components/polylith/repo/repo.py index 9ed6b5a8..37894d51 100644 --- a/components/polylith/repo/repo.py +++ b/components/polylith/repo/repo.py @@ -1,6 +1,8 @@ from pathlib import Path from typing import Union +workspace_file = "workspace.toml" +root_file = ".git" default_toml = "pyproject.toml" readme_file = "README.md" @@ -15,7 +17,7 @@ def is_drive_root(cwd: Path) -> bool: def is_repo_root(cwd: Path) -> bool: - fullpath = cwd / ".git" + fullpath = cwd / root_file return fullpath.exists() @@ -42,7 +44,10 @@ def find_upwards_dir(cwd: Path, name: str) -> Union[Path, None]: def find_workspace_root(cwd: Path) -> Union[Path, None]: - return find_upwards_dir(cwd, default_toml) + workspace_root = find_upwards_dir(cwd, workspace_file) + if workspace_root: + return workspace_root + return find_upwards_dir(cwd, root_file) def get_workspace_root(cwd: Path) -> Path: @@ -50,7 +55,7 @@ def get_workspace_root(cwd: Path) -> Path: if not root: raise ValueError( - "Didn't find the workspace root. Expected to find a pyproject.toml file." + "Didn't find the workspace root. Expected to find a workspace.toml or .git file." ) return root diff --git a/components/polylith/workspace/create.py b/components/polylith/workspace/create.py index 91ea7cba..648d10b8 100644 --- a/components/polylith/workspace/create.py +++ b/components/polylith/workspace/create.py @@ -29,7 +29,7 @@ def create_workspace_config(path: Path, namespace: str, theme: str) -> None: formatted = template.format(namespace=namespace, theme=theme) content: dict = tomlkit.loads(formatted) - fullpath = path / repo.default_toml + fullpath = path / repo.workspace_file with fullpath.open("w", encoding="utf-8") as f: f.write(tomlkit.dumps(content)) diff --git a/components/polylith/workspace/parser.py b/components/polylith/workspace/parser.py index 6031ebae..b0ae2fba 100644 --- a/components/polylith/workspace/parser.py +++ b/components/polylith/workspace/parser.py @@ -8,7 +8,10 @@ @lru_cache def _load_workspace_config(path: Path) -> tomlkit.TOMLDocument: - fullpath = path / repo.default_toml + fullpath = path / repo.workspace_file + + if not fullpath.exists(): + fullpath = path / repo.default_toml content = fullpath.read_text() diff --git a/test/conftest.py b/test/conftest.py index ab846e33..290fe73d 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -14,9 +14,9 @@ def handle_workspace_files(): """ temp_dir = Path("test/temp") temp_dir.mkdir(parents=True, exist_ok=True) - workspace_file = temp_dir / "pyproject.toml" + workspace_file = temp_dir / "workspace.toml" workspace_file.touch() - source_file = Path("test/test_data/pyproject.toml") + source_file = Path("test/test_data/workspace.toml") workspace_file.write_text(source_file.read_text()) yield temp_dir shutil.rmtree(temp_dir) diff --git a/test/test_data/pyproject.toml b/test/test_data/workspace.toml similarity index 100% rename from test/test_data/pyproject.toml rename to test/test_data/workspace.toml From 286f7ae231179be18e65a9f3c02cf9a4d4ac880a Mon Sep 17 00:00:00 2001 From: GH-maggio Date: Fri, 2 Feb 2024 12:57:35 -0800 Subject: [PATCH 3/3] restore test, pyproject.toml --- pyproject.toml | 13 ------------- test/components/polylith/bricks/test_base.py | 4 +++- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 06df6d99..5b420396 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,16 +68,3 @@ build-backend = "poetry.core.masonry.api" [tool.pytest.ini_options] addopts = "-sv" - -[tool.polylith] -namespace = "polylith" - -[tool.polylith.structure] -theme = "loose" - -[tool.polylith.tag.patterns] -stable = "stable-*" -release = "v[0-9]*" - -[tool.polylith.test] -enabled = true diff --git a/test/components/polylith/bricks/test_base.py b/test/components/polylith/bricks/test_base.py index 92a2307d..75e76b0e 100644 --- a/test/components/polylith/bricks/test_base.py +++ b/test/components/polylith/bricks/test_base.py @@ -32,7 +32,9 @@ def test_create_base(handle_workspace_files, id, expected_dirs, expected_dir_str } create_base(path=handle_workspace_files, options=options) - results = [x for x in handle_workspace_files.iterdir()] + results = [ + x for x in handle_workspace_files.iterdir() if x.name != "workspace.toml" + ] assert all([item.is_dir() for item in results if item in expected_dirs]) assert (