# common/path_utils.py
from pathlib import Path
from typing import Union
[docs]
def validate_path(target_path: Union[str, Path, None]) -> Path:
"""Validates the given paths.
:param target_path: The target path to validate.
:return: The absolute path for target.
"""
if not target_path:
raise ValueError("ERROR: Please specify a valid path.")
path = Path(target_path).expanduser().resolve()
try:
path.mkdir(parents=True, exist_ok=True)
except (OSError, PermissionError) as e:
raise ValueError(f"ERROR: Invalid path '{path}': {e}") from e
return path