cli: default template url should come from the package itself rather than our gitea

This allow easier testing and also forks.
This commit is contained in:
Jörg Thalheim
2024-07-21 22:06:26 +02:00
parent 527002bb0b
commit 1e43a471d2
6 changed files with 68 additions and 40 deletions

View File

@@ -9,12 +9,10 @@ from clan_cli.arg_actions import AppendOptionAction
from clan_cli.inventory import Meta, load_inventory, save_inventory
from ..cmd import CmdOut, run
from ..dirs import clan_templates
from ..errors import ClanError
from ..nix import nix_command, nix_shell
default_template_url: str = "git+https://git.clan.lol/clan/clan-core"
minimal_template_url: str = "git+https://git.clan.lol/clan/clan-core#templates.minimal"
@dataclass
class CreateClanResponse:
@@ -33,7 +31,7 @@ class CreateOptions:
# Metadata can be shown with `clan show`
meta: Meta | None = None
# URL to the template to use. Defaults to the "minimal" template
template_url: str = minimal_template_url
template: str = "minimal"
def git_command(directory: Path, *args: str) -> list[str]:
@@ -43,7 +41,7 @@ def git_command(directory: Path, *args: str) -> list[str]:
@API.register
def create_clan(options: CreateOptions) -> CreateClanResponse:
directory = Path(options.directory).resolve()
template_url = options.template_url
template_url = f"{clan_templates()}#{options.template}"
if not directory.exists():
directory.mkdir()
else:
@@ -112,10 +110,11 @@ def create_clan(options: CreateOptions) -> CreateClanResponse:
def register_create_parser(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"--url",
"--template",
type=str,
help="url to the clan template",
default=default_template_url,
choices=["default", "minimal"],
help="Clan template name",
default="default",
)
parser.add_argument(
@@ -135,7 +134,7 @@ def register_create_parser(parser: argparse.ArgumentParser) -> None:
create_clan(
CreateOptions(
directory=args.path,
template_url=args.url,
template=args.template,
)
)

View File

@@ -4,6 +4,8 @@ import sys
import urllib
from pathlib import Path
from .errors import ClanError
log = logging.getLogger(__name__)
@@ -41,6 +43,18 @@ def find_toplevel(top_level_files: list[str]) -> Path | None:
return None
def clan_templates() -> Path:
template_path = module_root().parent.parent / "templates"
if template_path.exists():
return template_path
else:
template_path = module_root() / "templates"
if not template_path.exists():
msg = f"BUG! clan core not found at {template_path}. This is an issue with packaging the cli"
raise ClanError(msg)
return template_path
def user_config_dir() -> Path:
if sys.platform == "win32":
return Path(os.getenv("APPDATA", os.path.expanduser("~\\AppData\\Roaming\\")))

View File

@@ -63,6 +63,7 @@ let
rm $out/clan_cli/config/jsonschema
ln -sf ${nixpkgs'} $out/clan_cli/nixpkgs
cp -r ${../../lib/jsonschema} $out/clan_cli/config/jsonschema
cp -r ${../../templates} $out/clan_cli/templates
${classgen}/bin/classgen ${inventory-schema}/schema.json $out/clan_cli/inventory/classes.py
'';

View File

@@ -18,7 +18,14 @@ Repository = "https://git.clan.lol/clan/clan-core"
exclude = ["clan_cli.nixpkgs*", "result"]
[tool.setuptools.package-data]
clan_cli = ["py.typed", "config/jsonschema/*", "webui/assets/**/*", "vms/mimetypes/**/*", "**/allowed-programs.json"]
clan_cli = [
"**/allowed-programs.json",
"config/jsonschema/*",
"py.typed",
"templates/**/*",
"vms/mimetypes/**/*",
"webui/assets/**/*",
]
[tool.pytest.ini_options]
testpaths = "tests"