diff --git a/components/polylith/commands/create.py b/components/polylith/commands/create.py index 8488de30..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 in workspace.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/repo.py b/components/polylith/repo/repo.py index 55fc74a3..37894d51 100644 --- a/components/polylith/repo/repo.py +++ b/components/polylith/repo/repo.py @@ -2,6 +2,7 @@ from typing import Union workspace_file = "workspace.toml" +root_file = ".git" default_toml = "pyproject.toml" readme_file = "README.md" @@ -16,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() @@ -43,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, workspace_file) + 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: @@ -51,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 workspace.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/parser.py b/components/polylith/workspace/parser.py index 02559eed..b0ae2fba 100644 --- a/components/polylith/workspace/parser.py +++ b/components/polylith/workspace/parser.py @@ -10,6 +10,9 @@ def _load_workspace_config(path: Path) -> tomlkit.TOMLDocument: fullpath = path / repo.workspace_file + if not fullpath.exists(): + fullpath = path / repo.default_toml + content = fullpath.read_text() return tomlkit.loads(content)