Skip to content

Commit

Permalink
chore: add abspath and relpath hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
robcxyz committed Dec 6, 2024
1 parent 7a44865 commit e96abc0
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions providers/paths/hooks/paths.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from typing import Optional

from tackle import BaseHook, Field

Expand Down Expand Up @@ -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)

0 comments on commit e96abc0

Please sign in to comment.