diff --git a/pkgs/clan-app/clan_app/app.py b/pkgs/clan-app/clan_app/app.py index 063e5e9b9..e8179af6d 100644 --- a/pkgs/clan-app/clan_app/app.py +++ b/pkgs/clan-app/clan_app/app.py @@ -7,8 +7,8 @@ import os from dataclasses import dataclass from pathlib import Path -from clan_cli.custom_logger import setup_logging from clan_lib.api import API, ErrorDataClass, SuccessDataClass +from clan_lib.custom_logger import setup_logging from clan_app.api.file_gtk import open_file from clan_app.deps.webview.webview import Size, SizeHint, Webview diff --git a/pkgs/clan-app/clan_app/deps/webview/webview.py b/pkgs/clan-app/clan_app/deps/webview/webview.py index 70c66035c..81a2ee7b5 100644 --- a/pkgs/clan-app/clan_app/deps/webview/webview.py +++ b/pkgs/clan-app/clan_app/deps/webview/webview.py @@ -8,7 +8,6 @@ from dataclasses import dataclass from enum import IntEnum from typing import Any -from clan_cli.async_run import set_should_cancel from clan_lib.api import ( ApiError, ErrorDataClass, @@ -16,6 +15,7 @@ from clan_lib.api import ( dataclass_to_dict, from_dict, ) +from clan_lib.async_run import set_should_cancel from ._webview_ffi import _encode_c_string, _webview_lib diff --git a/pkgs/clan-app/tests/conftest.py b/pkgs/clan-app/tests/conftest.py index 21e30af95..a9edb0832 100644 --- a/pkgs/clan-app/tests/conftest.py +++ b/pkgs/clan-app/tests/conftest.py @@ -5,7 +5,7 @@ import subprocess from pathlib import Path import pytest -from clan_cli.custom_logger import setup_logging +from clan_lib.custom_logger import setup_logging from clan_lib.nix import nix_shell pytest_plugins = [ diff --git a/pkgs/clan-app/tests/helpers/cli.py b/pkgs/clan-app/tests/helpers/cli.py index 3bd1f5f62..cddfea6df 100644 --- a/pkgs/clan-app/tests/helpers/cli.py +++ b/pkgs/clan-app/tests/helpers/cli.py @@ -3,7 +3,7 @@ import os import shlex from clan_app import main -from clan_cli.custom_logger import get_callers +from clan_lib.custom_logger import get_callers log = logging.getLogger(__name__) diff --git a/pkgs/clan-cli/clan_cli/__init__.py b/pkgs/clan-cli/clan_cli/__init__.py index 6d685e217..b95c5baa1 100644 --- a/pkgs/clan-cli/clan_cli/__init__.py +++ b/pkgs/clan-cli/clan_cli/__init__.py @@ -14,6 +14,7 @@ from .clan import show, update # API endpoints that are not used in the cli. __all__ = ["directory", "disk", "mdns_discovery", "modules", "update"] +from clan_lib.custom_logger import setup_logging from clan_lib.dirs import get_clan_flake_toplevel_or_env from clan_lib.errors import ClanError from clan_lib.flake import Flake @@ -26,7 +27,6 @@ from . import ( state, vms, ) -from .custom_logger import setup_logging from .facts import cli as facts from .flash import cli as flash_cli from .hyperlink import help_hyperlink diff --git a/pkgs/clan-cli/clan_cli/clan/create.py b/pkgs/clan-cli/clan_cli/clan/create.py index d07eff10f..c4a3ae916 100644 --- a/pkgs/clan-cli/clan_cli/clan/create.py +++ b/pkgs/clan-cli/clan_cli/clan/create.py @@ -11,8 +11,7 @@ from clan_lib.flake import Flake from clan_lib.nix import nix_command, nix_metadata, nix_shell from clan_lib.nix_models.inventory import Inventory from clan_lib.persist.inventory_store import InventoryStore - -from clan_cli.templates import ( +from clan_lib.templates import ( InputPrio, TemplateName, copy_from_nixstore, diff --git a/pkgs/clan-cli/clan_cli/clan/list.py b/pkgs/clan-cli/clan_cli/clan/list.py index 7594a6311..ff80c20f1 100644 --- a/pkgs/clan-cli/clan_cli/clan/list.py +++ b/pkgs/clan-cli/clan_cli/clan/list.py @@ -1,7 +1,7 @@ import argparse import logging -from clan_cli.templates import list_templates +from clan_lib.templates import list_templates log = logging.getLogger(__name__) diff --git a/pkgs/clan-cli/clan_cli/machines/create.py b/pkgs/clan-cli/clan_cli/machines/create.py index c9b4f228a..c758b0216 100644 --- a/pkgs/clan-cli/clan_cli/machines/create.py +++ b/pkgs/clan-cli/clan_cli/machines/create.py @@ -17,16 +17,16 @@ from clan_lib.nix_models.inventory import ( ) from clan_lib.persist.inventory_store import InventoryStore from clan_lib.persist.util import apply_patch - -from clan_cli.completions import add_dynamic_completer, complete_tags -from clan_cli.machines.list import list_machines -from clan_cli.templates import ( +from clan_lib.templates import ( InputPrio, TemplateName, copy_from_nixstore, get_template, ) +from clan_cli.completions import add_dynamic_completer, complete_tags +from clan_cli.machines.list import list_machines + log = logging.getLogger(__name__) diff --git a/pkgs/clan-cli/clan_cli/machines/update.py b/pkgs/clan-cli/clan_cli/machines/update.py index 6efcebf92..ecc3af02d 100644 --- a/pkgs/clan-cli/clan_cli/machines/update.py +++ b/pkgs/clan-cli/clan_cli/machines/update.py @@ -8,12 +8,12 @@ import sys from contextlib import ExitStack from clan_lib.api import API +from clan_lib.async_run import AsyncContext, AsyncOpts, AsyncRuntime, is_async_cancelled from clan_lib.cmd import Log, MsgColor, RunOpts, run from clan_lib.colors import AnsiColor from clan_lib.errors import ClanError from clan_lib.nix import nix_command, nix_config, nix_metadata -from clan_cli.async_run import AsyncContext, AsyncOpts, AsyncRuntime, is_async_cancelled from clan_cli.completions import ( add_dynamic_completer, complete_machines, diff --git a/pkgs/clan-cli/clan_cli/ssh/deploy_info.py b/pkgs/clan-cli/clan_cli/ssh/deploy_info.py index 88e1ad053..4528b568b 100644 --- a/pkgs/clan-cli/clan_cli/ssh/deploy_info.py +++ b/pkgs/clan-cli/clan_cli/ssh/deploy_info.py @@ -6,11 +6,11 @@ from dataclasses import dataclass from pathlib import Path from typing import Any +from clan_lib.async_run import AsyncRuntime from clan_lib.cmd import run from clan_lib.errors import ClanError from clan_lib.nix import nix_shell -from clan_cli.async_run import AsyncRuntime from clan_cli.completions import ( add_dynamic_completer, complete_machines, diff --git a/pkgs/clan-cli/clan_cli/ssh/tor.py b/pkgs/clan-cli/clan_cli/ssh/tor.py index 6b5cb57f4..3a87f1d11 100755 --- a/pkgs/clan-cli/clan_cli/ssh/tor.py +++ b/pkgs/clan-cli/clan_cli/ssh/tor.py @@ -7,12 +7,11 @@ import struct import time from dataclasses import dataclass +from clan_lib.async_run import AsyncRuntime from clan_lib.cmd import Log, RunOpts, run from clan_lib.errors import TorConnectionError, TorSocksError from clan_lib.nix import nix_shell -from clan_cli.async_run import AsyncRuntime - log = logging.getLogger(__name__) diff --git a/pkgs/clan-cli/clan_cli/tests/helpers/cli.py b/pkgs/clan-cli/clan_cli/tests/helpers/cli.py index 2e9e1dd91..1b180da9e 100644 --- a/pkgs/clan-cli/clan_cli/tests/helpers/cli.py +++ b/pkgs/clan-cli/clan_cli/tests/helpers/cli.py @@ -3,7 +3,7 @@ import logging import shlex from clan_cli import create_parser -from clan_cli.custom_logger import print_trace +from clan_lib.custom_logger import print_trace log = logging.getLogger(__name__) diff --git a/pkgs/clan-cli/clan_cli/tests/runtime.py b/pkgs/clan-cli/clan_cli/tests/runtime.py index a13a992ff..e305ac527 100644 --- a/pkgs/clan-cli/clan_cli/tests/runtime.py +++ b/pkgs/clan-cli/clan_cli/tests/runtime.py @@ -1,5 +1,5 @@ import pytest -from clan_cli.async_run import AsyncRuntime +from clan_lib.async_run import AsyncRuntime @pytest.fixture diff --git a/pkgs/clan-cli/clan_cli/tests/test_clan_nix_attrset.py b/pkgs/clan-cli/clan_cli/tests/test_clan_nix_attrset.py index 68619963c..a732c69f9 100644 --- a/pkgs/clan-cli/clan_cli/tests/test_clan_nix_attrset.py +++ b/pkgs/clan-cli/clan_cli/tests/test_clan_nix_attrset.py @@ -5,7 +5,13 @@ from pathlib import Path from typing import Any import pytest -from clan_cli.templates import ( +from clan_cli.tests.fixtures_flakes import FlakeForTest +from clan_lib.cmd import run +from clan_lib.flake import Flake +from clan_lib.git import commit_file +from clan_lib.locked_open import locked_open +from clan_lib.nix import nix_command +from clan_lib.templates import ( ClanExports, InputName, TemplateName, @@ -14,12 +20,6 @@ from clan_cli.templates import ( get_template, list_templates, ) -from clan_cli.tests.fixtures_flakes import FlakeForTest -from clan_lib.cmd import run -from clan_lib.flake import Flake -from clan_lib.git import commit_file -from clan_lib.locked_open import locked_open -from clan_lib.nix import nix_command # Function to write clan attributes to a file diff --git a/pkgs/clan-cli/clan_cli/tests/test_ssh_local.py b/pkgs/clan-cli/clan_cli/tests/test_ssh_local.py index 91f2c0dbf..ba2183945 100644 --- a/pkgs/clan-cli/clan_cli/tests/test_ssh_local.py +++ b/pkgs/clan-cli/clan_cli/tests/test_ssh_local.py @@ -1,5 +1,5 @@ -from clan_cli.async_run import AsyncRuntime from clan_cli.ssh.host import Host +from clan_lib.async_run import AsyncRuntime from clan_lib.cmd import ClanCmdTimeoutError, Log, RunOpts host = Host("some_host") diff --git a/pkgs/clan-cli/clan_cli/tests/test_ssh_remote.py b/pkgs/clan-cli/clan_cli/tests/test_ssh_remote.py index 6f42ef6f3..289a8ecab 100644 --- a/pkgs/clan-cli/clan_cli/tests/test_ssh_remote.py +++ b/pkgs/clan-cli/clan_cli/tests/test_ssh_remote.py @@ -4,10 +4,10 @@ from collections.abc import Generator from typing import Any, NamedTuple import pytest -from clan_cli.async_run import AsyncRuntime from clan_cli.ssh.host import Host from clan_cli.ssh.host_key import HostKeyCheck from clan_cli.ssh.parse import parse_deployment_address +from clan_lib.async_run import AsyncRuntime from clan_lib.cmd import ClanCmdTimeoutError, Log, RunOpts from clan_lib.errors import ClanError, CmdOut diff --git a/pkgs/clan-cli/clan_cli/async_run.py b/pkgs/clan-cli/clan_lib/async_run/__init__.py similarity index 100% rename from pkgs/clan-cli/clan_cli/async_run.py rename to pkgs/clan-cli/clan_lib/async_run/__init__.py diff --git a/pkgs/clan-cli/clan_lib/cmd/__init__.py b/pkgs/clan-cli/clan_lib/cmd/__init__.py index cfdb57226..a5f131654 100644 --- a/pkgs/clan-cli/clan_lib/cmd/__init__.py +++ b/pkgs/clan-cli/clan_lib/cmd/__init__.py @@ -18,10 +18,9 @@ from enum import Enum from pathlib import Path from typing import IO, Any -from clan_cli.async_run import get_async_ctx, is_async_cancelled -from clan_cli.custom_logger import print_trace - +from clan_lib.async_run import get_async_ctx, is_async_cancelled from clan_lib.colors import Color +from clan_lib.custom_logger import print_trace from clan_lib.errors import ClanCmdError, ClanError, CmdOut, indent_command cmdlog = logging.getLogger(__name__) diff --git a/pkgs/clan-cli/clan_cli/custom_logger.py b/pkgs/clan-cli/clan_lib/custom_logger/__init__.py similarity index 100% rename from pkgs/clan-cli/clan_cli/custom_logger.py rename to pkgs/clan-cli/clan_lib/custom_logger/__init__.py diff --git a/pkgs/clan-cli/clan_lib/dirs/__init__.py b/pkgs/clan-cli/clan_lib/dirs/__init__.py index c00519ede..c7e9f9be5 100644 --- a/pkgs/clan-cli/clan_lib/dirs/__init__.py +++ b/pkgs/clan-cli/clan_lib/dirs/__init__.py @@ -65,7 +65,7 @@ def clan_templates(template_type: TemplateType | None = None) -> Path: if template_path.exists(): return template_path - template_path = module_root() / "templates" + template_path = module_root() / "clan_core_templates" if template_type is not None: template_path /= template_type.value diff --git a/pkgs/clan-cli/clan_lib/flake/flake_test.py b/pkgs/clan-cli/clan_lib/flake/flake_test.py index 0c665b0c8..3e182618d 100644 --- a/pkgs/clan-cli/clan_lib/flake/flake_test.py +++ b/pkgs/clan-cli/clan_lib/flake/flake_test.py @@ -1,3 +1,4 @@ +import contextlib import logging import subprocess from pathlib import Path @@ -373,7 +374,8 @@ def test_cache_gc(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setenv("NIX_STORE_DIR", str(tempdir / "store")) monkeypatch.setenv("NIX_CACHE_HOME", str(tempdir / "cache")) monkeypatch.setenv("HOME", str(tempdir / "home")) - monkeypatch.delenv("CLAN_TEST_STORE") + with contextlib.suppress(KeyError): + monkeypatch.delenv("CLAN_TEST_STORE") monkeypatch.setenv("NIX_BUILD_TOP", str(tempdir / "build")) test_file = tempdir / "flake" / "testfile" diff --git a/pkgs/clan-cli/clan_cli/jsonrpc.py b/pkgs/clan-cli/clan_lib/jsonrpc/__init__.py similarity index 100% rename from pkgs/clan-cli/clan_cli/jsonrpc.py rename to pkgs/clan-cli/clan_lib/jsonrpc/__init__.py diff --git a/pkgs/clan-cli/clan_lib/locked_open/__init__.py b/pkgs/clan-cli/clan_lib/locked_open/__init__.py index bf881614d..34b1ba44d 100644 --- a/pkgs/clan-cli/clan_lib/locked_open/__init__.py +++ b/pkgs/clan-cli/clan_lib/locked_open/__init__.py @@ -5,9 +5,8 @@ from contextlib import contextmanager from pathlib import Path from typing import Any -from clan_cli.jsonrpc import ClanJSONEncoder - from clan_lib.dirs import user_history_file +from clan_lib.jsonrpc import ClanJSONEncoder @contextmanager diff --git a/pkgs/clan-cli/clan_cli/templates.py b/pkgs/clan-cli/clan_lib/templates/__init__.py similarity index 100% rename from pkgs/clan-cli/clan_cli/templates.py rename to pkgs/clan-cli/clan_lib/templates/__init__.py diff --git a/pkgs/clan-cli/conftest.py b/pkgs/clan-cli/conftest.py index 16b11874d..5bb8d63d2 100644 --- a/pkgs/clan-cli/conftest.py +++ b/pkgs/clan-cli/conftest.py @@ -1,7 +1,7 @@ import logging import pytest -from clan_cli.custom_logger import setup_logging +from clan_lib.custom_logger import setup_logging # Every fixture registered here will be available in clan_cli and clan_lib pytest_plugins = [ diff --git a/pkgs/clan-cli/default.nix b/pkgs/clan-cli/default.nix index a8a1ba7e7..f6cd2dc14 100644 --- a/pkgs/clan-cli/default.nix +++ b/pkgs/clan-cli/default.nix @@ -73,7 +73,7 @@ let --replace-fail '@select_hash@' "$(jq -r '.nodes."nix-select".locked.narHash' ${../../flake.lock})" ln -sf ${nixpkgs'} $out/clan_lib/nixpkgs ln -sf ${nix-select} $out/clan_lib/select - cp -r ${../../templates} $out/clan_lib/templates + cp -r ${../../templates} $out/clan_lib/clan_core_templates ''; sourceWithoutTests = cliSource ( diff --git a/pkgs/clan-cli/pyproject.toml b/pkgs/clan-cli/pyproject.toml index b60ed1ea6..621200187 100644 --- a/pkgs/clan-cli/pyproject.toml +++ b/pkgs/clan-cli/pyproject.toml @@ -21,12 +21,12 @@ exclude = ["clan_lib.nixpkgs*", "result"] [tool.setuptools.package-data] clan_cli = [ "py.typed", - "templates/**/*", "vms/mimetypes/**/*", "webui/assets/**/*", "flash/*.sh", ] clan_lib = [ + "clan_core_templates/**/*", "**/allowed-packages.json", ] diff --git a/pkgs/clan-vm-manager/clan_vm_manager/app.py b/pkgs/clan-vm-manager/clan_vm_manager/app.py index 4aaab58f4..beb57df5f 100644 --- a/pkgs/clan-vm-manager/clan_vm_manager/app.py +++ b/pkgs/clan-vm-manager/clan_vm_manager/app.py @@ -10,7 +10,7 @@ from clan_vm_manager.singletons.toast import InfoToast, ToastOverlay gi.require_version("Gtk", "4.0") gi.require_version("Adw", "1") -from clan_cli.custom_logger import setup_logging +from clan_lib.custom_logger import setup_logging from gi.repository import Adw, Gdk, Gio, Gtk from clan_vm_manager.components.interfaces import ClanConfig diff --git a/pkgs/clan-vm-manager/tests/conftest.py b/pkgs/clan-vm-manager/tests/conftest.py index 27154d15b..8252cfc1a 100644 --- a/pkgs/clan-vm-manager/tests/conftest.py +++ b/pkgs/clan-vm-manager/tests/conftest.py @@ -4,7 +4,7 @@ import sys from pathlib import Path import pytest -from clan_cli.custom_logger import setup_logging +from clan_lib.custom_logger import setup_logging from clan_lib.nix import nix_shell sys.path.append(str(Path(__file__).parent / "helpers")) diff --git a/pkgs/clan-vm-manager/tests/helpers/cli.py b/pkgs/clan-vm-manager/tests/helpers/cli.py index 9f95e4abc..aa0baee89 100644 --- a/pkgs/clan-vm-manager/tests/helpers/cli.py +++ b/pkgs/clan-vm-manager/tests/helpers/cli.py @@ -2,7 +2,7 @@ import logging import os import shlex -from clan_cli.custom_logger import get_callers +from clan_lib.custom_logger import get_callers from clan_vm_manager import main log = logging.getLogger(__name__)