diff --git a/changes/unreleased.md b/changes/unreleased.md index 373eb99..2aa77f0 100644 --- a/changes/unreleased.md +++ b/changes/unreleased.md @@ -1,2 +1,5 @@ +## Changes -No changes. +- Support relative filesystem world paths in workspace configs. + - Default workspace configs emit relative filesystem world paths for project and session worlds. + - Filesystem world resolution expands `~` and resolves relative paths against the workspace root. diff --git a/donna/workspaces/config.py b/donna/workspaces/config.py index d645092..552e726 100644 --- a/donna/workspaces/config.py +++ b/donna/workspaces/config.py @@ -46,7 +46,7 @@ def _default_sources() -> list[SourceConfig]: ] -def _create_default_worlds(project_dir: pathlib.Path) -> list[WorldConfig]: +def _create_default_worlds() -> list[WorldConfig]: return [ WorldConfig.model_validate( { @@ -63,7 +63,7 @@ def _create_default_worlds(project_dir: pathlib.Path) -> list[WorldConfig]: "kind": "donna.lib.worlds.filesystem", "readonly": True, "session": False, - "path": pathlib.Path.home() / DONNA_DIR_NAME / DONNA_WORLD_HOME_DIR_NAME, + "path": f"~/{DONNA_DIR_NAME}/{DONNA_WORLD_HOME_DIR_NAME}", } ), WorldConfig.model_validate( @@ -72,7 +72,7 @@ def _create_default_worlds(project_dir: pathlib.Path) -> list[WorldConfig]: "kind": "donna.lib.worlds.filesystem", "readonly": False, "session": False, - "path": project_dir / DONNA_DIR_NAME / DONNA_WORLD_PROJECT_DIR_NAME, + "path": pathlib.Path(DONNA_DIR_NAME) / DONNA_WORLD_PROJECT_DIR_NAME, } ), WorldConfig.model_validate( @@ -81,14 +81,14 @@ def _create_default_worlds(project_dir: pathlib.Path) -> list[WorldConfig]: "kind": "donna.lib.worlds.filesystem", "readonly": False, "session": True, - "path": project_dir / DONNA_DIR_NAME / DONNA_WORLD_SESSION_DIR_NAME, + "path": pathlib.Path(DONNA_DIR_NAME) / DONNA_WORLD_SESSION_DIR_NAME, } ), ] def _default_worlds() -> list[WorldConfig]: - return _create_default_worlds(project_dir()) + return _create_default_worlds() class Config(BaseEntity): diff --git a/donna/workspaces/worlds/filesystem.py b/donna/workspaces/worlds/filesystem.py index 300a05a..a537ee5 100644 --- a/donna/workspaces/worlds/filesystem.py +++ b/donna/workspaces/worlds/filesystem.py @@ -195,9 +195,15 @@ def construct_world(self, config: "WorldConfig") -> World: if path_value is None: raise ValueError(f"World config '{config.id}' does not define a filesystem path") + from donna.workspaces.config import project_dir + + path = pathlib.Path(path_value).expanduser() + if not path.is_absolute(): + path = project_dir() / path + return World( id=config.id, - path=pathlib.Path(path_value), + path=path.resolve(), readonly=config.readonly, session=config.session, )