feat: use settings for paths in cli and add tests
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
from pathlib import Path
|
||||
|
||||
from pydantic import DirectoryPath, FilePath
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
from core.utils import get_git_root
|
||||
|
||||
REPO_ROOT = get_git_root(__file__)
|
||||
|
||||
|
||||
class Paths(BaseSettings):
|
||||
# fmt: off
|
||||
repo_root: DirectoryPath = REPO_ROOT
|
||||
|
||||
service_registry_file: FilePath = repo_root / "config" / "services_registry.yml"
|
||||
iocs_overview_filename: FilePath = repo_root / "docs" / "user" / "ioc" / "ioc_overview.md"
|
||||
master_hla_names_file: FilePath = repo_root / "services" / "master" / "current" / "app" / "config" / "hla_names.yml"
|
||||
master_ioc_subs_file: FilePath = repo_root / "services" / "master" / "current" / "ioc" / "AGEBD-CPCL-MASTER_main.subs"
|
||||
service_manager_ui_file: FilePath = repo_root / "qt" / "A_BD_ServiceManager.ui"
|
||||
# fmt: on
|
||||
|
||||
def relative(self, path: Path) -> str:
|
||||
"""
|
||||
Convert any absolute path into a string path relative to repo_root.
|
||||
"""
|
||||
return str(path.relative_to(self.repo_root))
|
||||
|
||||
def get_service_dir(self, service_dir_name: str) -> Path:
|
||||
"""
|
||||
Helper to get a service path dynamically.
|
||||
"""
|
||||
return self.repo_root / "services" / service_dir_name / "current"
|
||||
|
||||
|
||||
paths = Paths()
|
||||
+7
-21
@@ -1,27 +1,13 @@
|
||||
import re
|
||||
import xml.etree.ElementTree as ET
|
||||
from pathlib import Path
|
||||
from typing import Any, ClassVar
|
||||
|
||||
import yaml
|
||||
from pydantic import BaseModel, ConfigDict, field_validator
|
||||
|
||||
from config.paths import paths
|
||||
from core.enums import ServiceStatus
|
||||
from core.utils import get_git_root
|
||||
|
||||
REPO_ROOT = get_git_root(__file__)
|
||||
CONFIG_DIR = REPO_ROOT / "config"
|
||||
SERVICE_REGISTRY_FILENAME = CONFIG_DIR / "services_registry.yml"
|
||||
|
||||
MASTER_SERVICE_DIR = REPO_ROOT / "services" / "master" / "current"
|
||||
MASTER_SERVICE_CONFIG_DIR = MASTER_SERVICE_DIR / "app" / "config"
|
||||
MASTER_HLA_NAMES_FILENAME = MASTER_SERVICE_CONFIG_DIR / "hla_names.yml"
|
||||
|
||||
IOCS_OVERVIEW_FILENAME = REPO_ROOT / "docs" / "ioc" / "user" / "ioc_overview.md"
|
||||
|
||||
SERVICE_MANAGER_UI_FILENAME = REPO_ROOT / "qt" / "A_BD_ServiceManager.ui"
|
||||
|
||||
MASTER_SERVICE_DIR = REPO_ROOT / "services" / "master" / "current"
|
||||
MASTER_IOC_SUBS_FILE = MASTER_SERVICE_DIR / "ioc" / "AGEBD-CPCL-MASTER_main.subs"
|
||||
|
||||
|
||||
class Service(BaseModel):
|
||||
@@ -60,7 +46,7 @@ class Service(BaseModel):
|
||||
|
||||
|
||||
class ServiceRegistry(BaseModel):
|
||||
config_path: ClassVar[str] = str(SERVICE_REGISTRY_FILENAME)
|
||||
config_path: ClassVar[Path] = paths.service_registry_file
|
||||
|
||||
next_available_ioc_port: int
|
||||
services: list[dict]
|
||||
@@ -101,7 +87,7 @@ class ServiceRegistry(BaseModel):
|
||||
|
||||
|
||||
class MasterHLANames(BaseModel):
|
||||
config_path: ClassVar[str] = str(MASTER_HLA_NAMES_FILENAME)
|
||||
config_path: ClassVar[Path] = paths.master_hla_names_file
|
||||
|
||||
hla_apps: list[str]
|
||||
|
||||
@@ -122,7 +108,7 @@ class MasterHLANames(BaseModel):
|
||||
|
||||
|
||||
class IocsOverview(BaseModel):
|
||||
config_path: ClassVar[str] = str(IOCS_OVERVIEW_FILENAME)
|
||||
config_path: ClassVar[Path] = paths.iocs_overview_filename
|
||||
|
||||
content: str
|
||||
|
||||
@@ -148,7 +134,7 @@ class IocsOverview(BaseModel):
|
||||
|
||||
|
||||
class MasterIocSubs(BaseModel):
|
||||
config_path: ClassVar[str] = str(MASTER_IOC_SUBS_FILE)
|
||||
config_path: ClassVar[Path] = paths.master_ioc_subs_file
|
||||
|
||||
content: str
|
||||
|
||||
@@ -193,7 +179,7 @@ class MasterIocSubs(BaseModel):
|
||||
# TODO: maybe separate models into their own files
|
||||
class ServiceManagerUI(BaseModel):
|
||||
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||
config_path: ClassVar[str] = str(SERVICE_MANAGER_UI_FILENAME)
|
||||
config_path: ClassVar[Path] = paths.service_manager_ui_file
|
||||
|
||||
tree: Any
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ from pathlib import Path
|
||||
import copier
|
||||
import git
|
||||
|
||||
from config.paths import paths
|
||||
from core.exceptions import UVError
|
||||
from core.git import (
|
||||
assert_clean_repo,
|
||||
@@ -30,9 +31,6 @@ SERVICE_TEMPLATES_DIR = REPO_ROOT / "templates" / "service"
|
||||
SERVICE_DEST_DIR = REPO_ROOT / "services"
|
||||
|
||||
|
||||
# TODO: lots of hardcoded paths. Create config object?
|
||||
|
||||
|
||||
class ServiceCreator:
|
||||
def __init__(self, user: str, ioc_description: str, ui_name: str, ui_filename: str) -> None:
|
||||
self.user = user
|
||||
@@ -81,12 +79,12 @@ class ServiceCreator:
|
||||
service_manager.write_to_file()
|
||||
|
||||
files_to_stage = [
|
||||
f"services/{service.dir_name}/current",
|
||||
"config/services_registry.yml",
|
||||
"services/master/current/app/config/hla_names.yml",
|
||||
"services/master/current/ioc/AGEBD-CPCL-MASTER_main.subs",
|
||||
"docs/ioc/user/ioc_overview.md",
|
||||
"qt/A_BD_ServiceManager.ui",
|
||||
paths.relative(paths.get_service_dir(service.dir_name)),
|
||||
paths.relative(paths.service_registry_file),
|
||||
paths.relative(paths.master_hla_names_file),
|
||||
paths.relative(paths.master_ioc_subs_file),
|
||||
paths.relative(paths.iocs_overview_filename),
|
||||
paths.relative(paths.service_manager_ui_file),
|
||||
]
|
||||
# TODO: can't push if branch already exists in remote
|
||||
git_push_changes(
|
||||
|
||||
Reference in New Issue
Block a user