From e96abc049cf2c0aa3ba6b8b10a7c4db8ff881c8f Mon Sep 17 00:00:00 2001 From: Rob Cannon Date: Fri, 6 Dec 2024 15:04:37 +0700 Subject: [PATCH] chore: add abspath and relpath hooks --- providers/paths/hooks/paths.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/providers/paths/hooks/paths.py b/providers/paths/hooks/paths.py index 37d3342c..f3d5fa21 100644 --- a/providers/paths/hooks/paths.py +++ b/providers/paths/hooks/paths.py @@ -1,4 +1,5 @@ import os +from typing import Optional from tackle import BaseHook, Field @@ -85,3 +86,36 @@ class PathDirNameHook(BaseHook): def exec(self): return os.path.dirname(self.path) + + +class PathAbsPathHook(BaseHook): + """Hook for getting the absolute path from a path.""" + + hook_name = 'abspath' + path: str = Field( + ..., + description="Path to the file/directory to get the absolute path of.", + render_by_default=True, + ) + + args: list = ['path'] + + def exec(self): + return os.path.abspath(self.path) + + +class PathRelPathHook(BaseHook): + """Hook for getting the absolute path from a path.""" + + hook_name = 'relpath' + path: str = Field( + ..., + description="Path to the file/directory to get the absolute path of.", + render_by_default=True, + ) + start: Optional[str] = None + + args: list = ['path'] + + def exec(self): + return os.path.relpath(self.path, start=self.start)