mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-13 02:51:49 +01:00
fix: chores (#565)
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user