add dirs module to get toplevel flake and configuration dir

This commit is contained in:
Jörg Thalheim
2023-07-26 14:34:39 +02:00
parent 20dc480123
commit a61d0c5a42

View File

@@ -0,0 +1,25 @@
import os
import sys
from pathlib import Path
def get_clan_flake_toplevel() -> Path:
"""Returns the path to the toplevel of the clan flake"""
initial_path = Path(os.getcwd())
path = Path(initial_path)
while path.parent == path:
project_files = [".clan-flake"]
for project_file in project_files:
if (path / project_file).exists():
return path
path = path.parent
return initial_path
def user_data_dir() -> Path:
if sys.platform == "win32":
raise NotImplementedError("Windows is not supported")
elif sys.platform == "darwin":
return Path(os.path.expanduser("~/Library/Application Support/"))
else:
return Path(os.getenv("XDG_DATA_HOME", os.path.expanduser("~/.local/share")))