cli machines update: find flake dir automatic if not provided, support flake as path

This commit is contained in:
lassulus
2023-10-29 20:48:09 +01:00
parent 3e7a866ea1
commit 0600278122
2 changed files with 25 additions and 20 deletions

View File

@@ -2,6 +2,7 @@ import logging
import os
import sys
from pathlib import Path
from typing import Optional
from .errors import ClanError
from .types import FlakeName
@@ -9,27 +10,27 @@ from .types import FlakeName
log = logging.getLogger(__name__)
# def _get_clan_flake_toplevel() -> Path:
# return find_toplevel([".clan-flake", ".git", ".hg", ".svn", "flake.nix"])
def get_clan_flake_toplevel() -> Path:
return find_toplevel([".clan-flake", ".git", ".hg", ".svn", "flake.nix"])
# def find_git_repo_root() -> Optional[Path]:
# try:
# return find_toplevel([".git"])
# except ClanError:
# return None
def find_git_repo_root() -> Optional[Path]:
try:
return find_toplevel([".git"])
except ClanError:
return None
# def find_toplevel(top_level_files: list[str]) -> Path:
# """Returns the path to the toplevel of the clan flake"""
# for project_file in top_level_files:
# initial_path = Path(os.getcwd())
# path = Path(initial_path)
# while path.parent != path:
# if (path / project_file).exists():
# return path
# path = path.parent
# raise ClanError("Could not find clan flake toplevel directory")
def find_toplevel(top_level_files: list[str]) -> Path:
"""Returns the path to the toplevel of the clan flake"""
for project_file in top_level_files:
initial_path = Path(os.getcwd())
path = Path(initial_path)
while path.parent != path:
if (path / project_file).exists():
return path
path = path.parent
raise ClanError("Could not find clan flake toplevel directory")
def user_config_dir() -> Path: