add dirs module to get toplevel flake and configuration dir
This commit is contained in:
25
pkgs/clan-cli/clan_cli/dirs.py
Normal file
25
pkgs/clan-cli/clan_cli/dirs.py
Normal 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")))
|
||||||
Reference in New Issue
Block a user