From cb2145be65b6ec8faa24ed659aa05ba804952bca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 10 Nov 2023 12:46:15 +0100 Subject: [PATCH 1/4] drop unused ClanDataPath --- pkgs/clan-cli/clan_cli/webui/api_inputs.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/webui/api_inputs.py b/pkgs/clan-cli/clan_cli/webui/api_inputs.py index 105c82273..be3cd0990 100644 --- a/pkgs/clan-cli/clan_cli/webui/api_inputs.py +++ b/pkgs/clan-cli/clan_cli/webui/api_inputs.py @@ -4,21 +4,13 @@ from typing import Any from pydantic import AnyUrl, BaseModel, Extra, validator -from ..dirs import clan_data_dir, clan_flakes_dir +from ..dirs import clan_flakes_dir from ..flakes.create import DEFAULT_URL from ..types import validate_path log = logging.getLogger(__name__) -class ClanDataPath(BaseModel): - directory: Path - - @validator("directory") - def check_directory(cls: Any, v: Path) -> Path: # noqa - return validate_path(clan_data_dir(), v) - - class ClanFlakePath(BaseModel): flake_name: Path From 48d7968cf9d47f70199cb907c4944850d0d50de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 10 Nov 2023 12:50:11 +0100 Subject: [PATCH 2/4] move flake configuration to .config/clan/flakes rather than $XDG_DATA_DIRS --- pkgs/clan-cli/clan_cli/dirs.py | 2 +- pkgs/clan-cli/tests/fixtures_flakes.py | 2 +- pkgs/clan-cli/tests/temporary_dir.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/dirs.py b/pkgs/clan-cli/clan_cli/dirs.py index 172d29c78..553f0f720 100644 --- a/pkgs/clan-cli/clan_cli/dirs.py +++ b/pkgs/clan-cli/clan_cli/dirs.py @@ -68,7 +68,7 @@ def clan_config_dir() -> Path: def clan_flakes_dir() -> Path: - path = clan_data_dir() / "flake" + path = clan_config_dir() / "flakes" if not path.exists(): log.debug(f"Creating path with parents {path}") path.mkdir(parents=True) diff --git a/pkgs/clan-cli/tests/fixtures_flakes.py b/pkgs/clan-cli/tests/fixtures_flakes.py index cc0ce0738..c50b382b7 100644 --- a/pkgs/clan-cli/tests/fixtures_flakes.py +++ b/pkgs/clan-cli/tests/fixtures_flakes.py @@ -55,7 +55,7 @@ def create_flake( template = Path(__file__).parent / flake_name # copy the template to a new temporary location - flake = temporary_home / ".local/share/clan/flake" / flake_name + flake = temporary_home / ".config/clan/flakes" / flake_name shutil.copytree(template, flake) # lookup the requested machines in ./test_machines and include them diff --git a/pkgs/clan-cli/tests/temporary_dir.py b/pkgs/clan-cli/tests/temporary_dir.py index 026998206..7bd2e656c 100644 --- a/pkgs/clan-cli/tests/temporary_dir.py +++ b/pkgs/clan-cli/tests/temporary_dir.py @@ -21,6 +21,7 @@ def temporary_home(monkeypatch: pytest.MonkeyPatch) -> Iterator[Path]: else: with tempfile.TemporaryDirectory(prefix="pytest-") as dirpath: monkeypatch.setenv("HOME", str(dirpath)) + monkeypatch.setenv("XDG_CONFIG_HOME", str(Path(dirpath) / ".config")) monkeypatch.setenv("XDG_DATA_HOME", str(Path(dirpath) / ".local/share")) monkeypatch.chdir(str(dirpath)) log.debug("Temp HOME directory: %s", str(dirpath)) From 2924e3e912058da35ca7e041a7e93630e9cbd884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 10 Nov 2023 12:53:13 +0100 Subject: [PATCH 3/4] drop unused clan_data_dir --- pkgs/clan-cli/clan_cli/dirs.py | 17 ----------------- pkgs/clan-cli/tests/temporary_dir.py | 1 - 2 files changed, 18 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/dirs.py b/pkgs/clan-cli/clan_cli/dirs.py index 553f0f720..7330a9b5c 100644 --- a/pkgs/clan-cli/clan_cli/dirs.py +++ b/pkgs/clan-cli/clan_cli/dirs.py @@ -42,23 +42,6 @@ def user_config_dir() -> Path: return Path(os.getenv("XDG_CONFIG_HOME", os.path.expanduser("~/.config"))) -def user_data_dir() -> Path: - if sys.platform == "win32": - return Path(os.getenv("APPDATA", os.path.expanduser("~\\AppData\\Roaming\\"))) - 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"))) - - -def clan_data_dir() -> Path: - path = user_data_dir() / "clan" - if not path.exists(): - log.debug(f"Creating path with parents {path}") - path.mkdir(parents=True) - return path.resolve() - - def clan_config_dir() -> Path: path = user_config_dir() / "clan" if not path.exists(): diff --git a/pkgs/clan-cli/tests/temporary_dir.py b/pkgs/clan-cli/tests/temporary_dir.py index 7bd2e656c..841952d0a 100644 --- a/pkgs/clan-cli/tests/temporary_dir.py +++ b/pkgs/clan-cli/tests/temporary_dir.py @@ -22,7 +22,6 @@ def temporary_home(monkeypatch: pytest.MonkeyPatch) -> Iterator[Path]: with tempfile.TemporaryDirectory(prefix="pytest-") as dirpath: monkeypatch.setenv("HOME", str(dirpath)) monkeypatch.setenv("XDG_CONFIG_HOME", str(Path(dirpath) / ".config")) - monkeypatch.setenv("XDG_DATA_HOME", str(Path(dirpath) / ".local/share")) monkeypatch.chdir(str(dirpath)) log.debug("Temp HOME directory: %s", str(dirpath)) yield Path(dirpath) From ba305a946e1458603b4883215d393ed5824dc647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 10 Nov 2023 12:53:38 +0100 Subject: [PATCH 4/4] dirs: opportuniscally create directories --- pkgs/clan-cli/clan_cli/dirs.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/dirs.py b/pkgs/clan-cli/clan_cli/dirs.py index 7330a9b5c..be8beb59d 100644 --- a/pkgs/clan-cli/clan_cli/dirs.py +++ b/pkgs/clan-cli/clan_cli/dirs.py @@ -44,17 +44,13 @@ def user_config_dir() -> Path: def clan_config_dir() -> Path: path = user_config_dir() / "clan" - if not path.exists(): - log.debug(f"Creating path with parents {path}") - path.mkdir(parents=True) + path.mkdir(parents=True, exist_ok=True) return path.resolve() def clan_flakes_dir() -> Path: path = clan_config_dir() / "flakes" - if not path.exists(): - log.debug(f"Creating path with parents {path}") - path.mkdir(parents=True) + path.mkdir(parents=True, exist_ok=True) return path.resolve()