diff --git a/tsdb/utils/file.py b/tsdb/utils/file.py index 2f2bd58..c1ad4c4 100644 --- a/tsdb/utils/file.py +++ b/tsdb/utils/file.py @@ -15,6 +15,29 @@ from .logging import logger +def check_path(path: str) -> str: + """Check the given path and return the absolute path. + + Parameters + ---------- + path : + The path to be checked. + + Returns + ------- + checked_path: + The absolute path of the given path. + """ + # expand the home dir if the path starts with "~" + if path.startswith("~"): + checked_path = path.replace("~", os.path.expanduser("~")) + else: + checked_path = path + + checked_path = os.path.abspath(checked_path) + return checked_path + + def pickle_dump(data: object, path: str) -> Optional[str]: """Pickle the given object.