Source code for gunz_cm.utils.path

"""
Module.

Examples
--------
"""
__author__ = "Yeremia Gunawan Adhisantoso"
__email__ = "adhisant@tnt.uni-hannover.de"
__license__ = "Clear BSD"
__version__ = "1.0.0"
import sys
from pydantic import validate_call
from git.repo import Repo

[docs] @validate_call def get_root_dir() -> str: """ Get the root directory of the Git repository. Notes ----- This function attempts to find the root directory of the Git repository by searching from the current directory upwards. If no Git repository is found, it raises a RuntimeError. Parameters ---------- None Returns ------- str The root directory of the Git repository. Examples -------- Authors ------- - Yeremia G. Adhisantoso (adhisant@tnt.uni-hannover.de) - Osiris v3.0 Examples -------- """ try: repository = Repo('.', search_parent_directories=True) root = repository.working_tree_dir return root except Exception as e: raise RuntimeError(f"Could not find Git repository: {e}")
[docs] @validate_call def append_root_dir() -> None: """ Append the root directory to sys.path. Notes ----- This function first retrieves the root directory of the Git repository using `get_root_dir()`. If the root directory is not already in `sys.path`, it appends it and prints a confirmation message. Parameters ---------- None Returns ------- None Examples -------- Authors ------- - Yeremia G. Adhisantoso (adhisant@tnt.uni-hannover.de) - Osiris v3.0 Examples -------- """ root = get_root_dir() if root not in sys.path: sys.path.append(root) print(f"Added {root} to sys.path")