Compare commits
2 Commits
2025.10.19
...
2025.10.19
| Author | SHA1 | Date | |
|---|---|---|---|
| dfbb0a8c1f | |||
| 472aba5990 |
@@ -31,7 +31,7 @@ def init(target: str, name: str, verbose: bool = False):
|
||||
if target in ["workspace", "ws"]:
|
||||
workspace = Structure.init_workspace("./", name or click.prompt("Workspace name", default="my-workspace"))
|
||||
elif target in PROJECT_TYPES:
|
||||
workspace = Structure.find_workspace_in_path(Path(name or "./").parent, with_parents=True)
|
||||
workspace = Structure.find_workspace_in_path(Path(name or "./").parent)
|
||||
project = Structure.init_project(
|
||||
"./", name or click.prompt("Project name", default=f"my-{target}"), target, workspace, verbose=verbose
|
||||
)
|
||||
|
||||
@@ -44,7 +44,7 @@ def new(type: str, name: str, in_name: str | None, project: list[str] | None, ve
|
||||
path = Path(workspace.path).parent / Path(project[1]).parent
|
||||
project_name = Path(project[1]).stem
|
||||
|
||||
workspace = Structure.find_workspace_in_path(path, with_parents=False)
|
||||
workspace = Structure.find_workspace_in_path(path)
|
||||
if workspace is None:
|
||||
Console.error("No workspace found. Please run 'cpl init workspace' first.")
|
||||
raise SystemExit(1)
|
||||
|
||||
@@ -11,9 +11,13 @@ T = TypeVar("T", bound="CPLStructureModel")
|
||||
|
||||
|
||||
class CPLStructureModel:
|
||||
def __init__(self, path: Optional[str] = None):
|
||||
def __init__(self, path: Optional[str] = None, ignore_fields: Optional[List[str]] = None):
|
||||
self._path = path
|
||||
|
||||
self._ignore = {"_ignore", "_path"}
|
||||
if ignore_fields is not None:
|
||||
self._ignore.update(ignore_fields)
|
||||
|
||||
@property
|
||||
def path(self) -> Optional[str]:
|
||||
return self._path
|
||||
@@ -68,7 +72,7 @@ class CPLStructureModel:
|
||||
def to_json(self) -> Dict[str, Any]:
|
||||
result: Dict[str, Any] = {}
|
||||
for key, value in self.__dict__.items():
|
||||
if not key.startswith("_") or key == "_path":
|
||||
if not key.startswith("_") or key in self._ignore:
|
||||
continue
|
||||
out_key = _self_or_cls_snake_to_camel(key[1:])
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class Workspace(CPLStructureModel):
|
||||
default_project: Optional[str],
|
||||
scripts: Dict[str, str],
|
||||
):
|
||||
CPLStructureModel.__init__(self, path)
|
||||
CPLStructureModel.__init__(self, path, ["_actual_projects", "_project_names"])
|
||||
|
||||
self._name = name
|
||||
self._projects = projects
|
||||
|
||||
@@ -32,11 +32,9 @@ class Structure:
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def find_workspace_in_path(path: Path, with_parents=False) -> Workspace | None:
|
||||
def find_workspace_in_path(path: Path) -> Workspace | None:
|
||||
current_path = path.resolve()
|
||||
paths = [current_path]
|
||||
if with_parents:
|
||||
paths.extend(current_path.parents)
|
||||
paths = [current_path, *current_path.parents]
|
||||
|
||||
for parent in paths:
|
||||
workspace_file = parent / "cpl.workspace.json"
|
||||
@@ -84,7 +82,7 @@ class Structure:
|
||||
|
||||
return Project.from_file(path)
|
||||
|
||||
workspace = Structure.find_workspace_in_path(path.parent, with_parents=True)
|
||||
workspace = Structure.find_workspace_in_path(path.parent)
|
||||
if workspace is None:
|
||||
raise RuntimeError("No workspace found. Please run 'cpl init workspace' first.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user