Consolidate handling of resources paths

* constants.py should remain the central place where a root path
   is determined based on source file location
 * SerenaPaths should consistently use strings
This commit is contained in:
Dominik Jain authored and Dominik Jain committed 2026-05-21 15:27:49 +02:00
1 parent 1b1522d46d
commit 981f560fa3
3 files changed
+20 -13

No files matched your search

+8 -3
View File
@@ -26,6 +26,7 @@ from serena.constants import (
PROJECT_LOCAL_TEMPLATE_FILE,
PROJECT_TEMPLATE_FILE,
REPO_ROOT,
RESOURCES_DIR,
SERENA_CONFIG_TEMPLATE_FILE,
SERENA_FILE_ENCODING,
SERENA_MANAGED_DIR_NAME,
@@ -61,9 +62,10 @@ class SerenaPaths:
home_dir = str(Path.home() / SERENA_MANAGED_DIR_NAME)
else:
home_dir = home_dir.strip()
self.serena_pkg_path = Path(__file__).parent.parent.resolve()
self.serena_resources_path = self.serena_pkg_path / "resources"
self.resources_dir: str = RESOURCES_DIR
"""
the resources directory (within the `serena` package)
"""
self.serena_user_home_dir: str = home_dir
"""
the path to the Serena home directory, where the user's configuration/data is stored.
@@ -128,6 +130,9 @@ class SerenaPaths:
self.last_returned_log_file_path = os.path.join(log_dir, prefix + "_" + datetime_tag() + f"_{os.getpid()}" + ".txt")
return self.last_returned_log_file_path
def get_resource_path(self, *path_elems: str) -> Path:
return Path(os.path.join(self.resources_dir, *path_elems))
# TODO: Paths from constants.py should be moved here
+11 -9
View File
@@ -2,20 +2,22 @@ from pathlib import Path
_repo_root_path = Path(__file__).parent.parent.parent.resolve()
_serena_pkg_path = Path(__file__).parent.resolve()
_resources_path = _serena_pkg_path / "resources"
SERENA_MANAGED_DIR_NAME = ".serena"
# TODO: Path-related constants should be moved to SerenaPaths; don't add further constants here.
REPO_ROOT = str(_repo_root_path)
PROMPT_TEMPLATES_DIR_INTERNAL = str(_serena_pkg_path / "resources" / "config" / "prompt_templates")
SERENAS_OWN_CONTEXT_YAMLS_DIR = str(_serena_pkg_path / "resources" / "config" / "contexts")
RESOURCES_DIR = str(_resources_path)
PROMPT_TEMPLATES_DIR_INTERNAL = str(_resources_path / "config" / "prompt_templates")
SERENAS_OWN_CONTEXT_YAMLS_DIR = str(_resources_path / "config" / "contexts")
"""The contexts that are shipped with the Serena package, i.e. the default contexts."""
SERENAS_OWN_MODE_YAMLS_DIR = str(_serena_pkg_path / "resources" / "config" / "modes")
SERENAS_OWN_MODE_YAMLS_DIR = str(_resources_path / "config" / "modes")
"""The modes that are shipped with the Serena package, i.e. the default modes."""
INTERNAL_MODE_YAMLS_DIR = str(_serena_pkg_path / "resources" / "config" / "internal_modes")
INTERNAL_MODE_YAMLS_DIR = str(_resources_path / "config" / "internal_modes")
"""Internal modes, never overridden by user modes."""
SERENA_DASHBOARD_DIR = str(_serena_pkg_path / "resources" / "dashboard")
SERENA_ICON_DIR = str(_serena_pkg_path / "resources" / "icons")
SERENA_DASHBOARD_DIR = str(_resources_path / "dashboard")
SERENA_ICON_DIR = str(_resources_path / "icons")
DEFAULT_SOURCE_FILE_ENCODING = "utf-8"
"""The default encoding assumed for project source files."""
@@ -24,9 +26,9 @@ DEFAULT_CONTEXT = "desktop-app"
SERENA_FILE_ENCODING = "utf-8"
"""The encoding used for Serena's own files, such as configuration files and memories."""
PROJECT_TEMPLATE_FILE = str(_serena_pkg_path / "resources" / "project.template.yml")
PROJECT_LOCAL_TEMPLATE_FILE = str(_serena_pkg_path / "resources" / "project.local.template.yml")
SERENA_CONFIG_TEMPLATE_FILE = str(_serena_pkg_path / "resources" / "serena_config.template.yml")
PROJECT_TEMPLATE_FILE = str(_resources_path / "project.template.yml")
PROJECT_LOCAL_TEMPLATE_FILE = str(_resources_path / "project.local.template.yml")
SERENA_CONFIG_TEMPLATE_FILE = str(_resources_path / "serena_config.template.yml")
SERENA_LOG_FORMAT = "%(levelname)-5s %(asctime)-15s [%(threadName)s] %(name)s:%(funcName)s:%(lineno)d - %(message)s"
+1 -1
View File
@@ -84,7 +84,7 @@ class MemoryManager:
return cls._MEMORY_REF_PREFIX + name
MEMORY_MAINTENANCE_NAME: str = "memory_maintenance"
_MEMORY_MAINTENANCE_TEMPLATE_PATH: Path = SerenaPaths().serena_resources_path / "memory_maintenance.md"
_MEMORY_MAINTENANCE_TEMPLATE_PATH: Path = SerenaPaths().get_resource_path("memory_maintenance.md")
def ensure_memory_maintenance_memory(self) -> str:
"""