Skip to content

Commit

Permalink
cleanup pathmanager
Browse files Browse the repository at this point in the history
  • Loading branch information
smellycloud committed Dec 10, 2024
1 parent 80bde5f commit f9b0120
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions views_pipeline_core/managers/path_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# ============================================================ ModelPath ============================================================


class ModelPath:
"""
A class to manage model paths and directories within the ViEWS Pipeline.
Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit f9b0120

Please sign in to comment.