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
2 changes: 1 addition & 1 deletion components/polylith/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
10 changes: 7 additions & 3 deletions components/polylith/repo/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Union

workspace_file = "workspace.toml"
root_file = ".git"
default_toml = "pyproject.toml"
readme_file = "README.md"

Expand All @@ -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()

Expand All @@ -43,15 +44,18 @@ 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:
root = find_workspace_root(cwd)

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
Expand Down
3 changes: 3 additions & 0 deletions components/polylith/workspace/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down