From f9b012059c429fb9ccd0701ea9bee95e36ebb32e Mon Sep 17 00:00:00 2001 From: Dylan <52908667+smellycloud@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:42:01 +0100 Subject: [PATCH] cleanup pathmanager --- views_pipeline_core/managers/path_manager.py | 29 ++++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/views_pipeline_core/managers/path_manager.py b/views_pipeline_core/managers/path_manager.py index 4d51ffe..d57357f 100644 --- a/views_pipeline_core/managers/path_manager.py +++ b/views_pipeline_core/managers/path_manager.py @@ -13,6 +13,7 @@ # ============================================================ ModelPath ============================================================ + class ModelPath: """ A class to manage model paths and directories within the ViEWS Pipeline. @@ -128,7 +129,7 @@ def get_model_name_from_path(path: Union[Path, str]) -> str: logger.debug(f"No valid ensemble name found in path {path}") return None return None - + @staticmethod def validate_model_name(name: str) -> bool: """ @@ -164,11 +165,13 @@ def find_project_root(current_path: Path = None, marker=".gitignore") -> Path: if current_path is None: current_path = Path(pyprojroot.here()) if (current_path / marker).exists(): - return current_path + return current_path # Start from the current directory and move up the hierarchy try: current_path = Path(current_path).resolve().parent - while current_path != current_path.parent: # Loop until we reach the root directory + while ( + current_path != current_path.parent + ): # Loop until we reach the root directory if (current_path / marker).exists(): return current_path current_path = current_path.parent @@ -179,9 +182,7 @@ def find_project_root(current_path: Path = None, marker=".gitignore") -> Path: f"{marker} not found in the directory hierarchy. Unable to find project root. {current_path}" ) - def __init__( - self, model_path: Union[str, Path], validate: bool = True - ) -> None: + def __init__(self, model_path: Union[str, Path], validate: bool = True) -> None: """ Initializes a ModelPath instance. @@ -338,8 +339,6 @@ def _initialize_directories(self) -> None: self.data_generated = self._build_absolute_directory(Path("data/generated")) self.data_processed = self._build_absolute_directory(Path("data/processed")) self.reports = self._build_absolute_directory(Path("reports")) - self._sys_paths = None - self._sys_paths = None self._queryset = None # Initialize model-specific directories only if the class is ModelPath if self.__class__.__name__ == "ModelPath": @@ -375,10 +374,12 @@ def _initialize_model_specific_scripts(self) -> None: None """ - self.queryset_path = self._build_absolute_directory(Path("configs/config_queryset.py")) + self.queryset_path = self._build_absolute_directory( + Path("configs/config_queryset.py") + ) self.scripts += [ self.queryset_path, - self._build_absolute_directory(Path("configs/config_sweep.py")) + self._build_absolute_directory(Path("configs/config_sweep.py")), ] def _is_path(self, path_input: Union[str, Path]) -> bool: @@ -413,10 +414,6 @@ def get_queryset(self) -> Optional[Dict[str, str]]: Raises: FileNotFoundError: If the common queryset directory does not exist and validation is enabled. """ - # if self._validate and not self._check_if_dir_exists(self.queryset_path): - # error = f"Common queryset directory {self.common_querysets} does not exist. Please create it first using `make_new_scripts.py` or set validate to `False`." - # logger.error(error) - # raise FileNotFoundError(error) if self._validate and self._check_if_dir_exists(self.queryset_path): try: @@ -593,10 +590,11 @@ def get_scripts(self) -> Dict[str, Optional[str]]: else: scripts[str(path)] = None return scripts - + # ============================================================ EnsemblePath ============================================================ + class EnsemblePath(ModelPath): """ A class to manage ensemble paths and directories within the ViEWS Pipeline. @@ -654,6 +652,7 @@ def _initialize_scripts(self) -> None: """ super()._initialize_scripts() # Initialize ensemble-specific scripts only if the class is EnsemblePath + # if self.__class__.__name__ == "EnsemblePath": # self._initialize_ensemble_specific_scripts()