Skip to content

Commit

Permalink
fix(task): use global defaults for task name and root, add properties…
Browse files Browse the repository at this point in the history
… for project directory and project workspace directory, change task root derivation logic
  • Loading branch information
entelecheia committed Aug 6, 2023
1 parent a948d3a commit a98dbf0
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/hyfi/path/task.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from pathlib import Path

from hyfi.main.config import global_config
from hyfi.utils.logging import LOGGING

from .base import BasePathConfig

logger = LOGGING.getLogger(__name__)

__default_task_name__ = "demo-task"
__default_task_root__ = "workspace"


class TaskPathConfig(BasePathConfig):
_config_name_: str = "__task__"

task_name: str = "demo-task"
task_root: str = "workspace"
task_name: str = __default_task_name__
task_root: str = __default_task_root__

@property
def name(self) -> str:
Expand All @@ -20,6 +24,14 @@ def name(self) -> str:
"""
return self.task_name

@property
def project_dir(self) -> Path:
return global_config.project_dir

@property
def project_workspace_dir(self) -> Path:
return global_config.project_workspace_dir

@property
def root_dir(self) -> Path:
"""
Expand All @@ -29,7 +41,12 @@ def root_dir(self) -> Path:
an path to the task root directory or None if it doesn't exist or cannot be converted to a path object
"""
# return as an path
path_ = Path(self.task_root)
if self.task_root == __default_task_root__:
path_ = self.project_workspace_dir
else:
path_ = Path(self.task_root)
if not path_.is_absolute():
path_ = self.project_dir / path_
path_.mkdir(parents=True, exist_ok=True)
return path_

Expand Down

0 comments on commit a98dbf0

Please sign in to comment.