fix: chores (#565)

This commit is contained in:
Jens Bergmann
2025-07-03 15:12:43 +02:00
committed by GitHub
parent 017047ba01
commit 7ff005d18b
5 changed files with 146 additions and 30 deletions

View File

@@ -6,15 +6,21 @@ import os
def abspath(relative_path:str, relative_to:str | None = None) -> str:
"""
Makes a given relative path absolute based on another file/folder
Return a normalized absolute path based on *relative_to*.
If 'relative_path' is already absolute, it is normalized and returned.
Otherwise, the function joins 'relative_path' with 'relative_to' (or the current working directory if not provided),
normalizes the result, and returns the absolute path.
"""
if not relative_to:
return os.path.abspath(relative_path)
if os.path.isabs(relative_path):
return relative_path
return os.path.normpath(relative_path)
if os.path.isfile(relative_to):
relative_to = os.path.dirname(relative_to)
base = os.path.abspath(relative_to)
if os.path.isfile(base):
base = os.path.dirname(base)
return os.path.normpath(os.path.join(relative_to, relative_path))
return os.path.normpath(os.path.join(base, relative_path))