templates: url add support for home and abspath

This commit is contained in:
Johannes Kirschbauer
2025-07-29 17:04:15 +02:00
parent 7784df8180
commit 2776294de0
2 changed files with 26 additions and 3 deletions

View File

@@ -84,9 +84,10 @@ def transform_url(template_type: str, identifier: str, flake: Flake) -> tuple[st
flake_ref = str(flake.path)
if "#" not in identifier:
# ./ . or ../ .. are relative paths
# Local path references are not transformed
# return flake_ref=identifier, template='default'
if (
identifier.startswith(("./", "../"))
identifier.startswith(("/", "~/", "./", "../"))
or identifier == "."
or identifier == ".."
):

View File

@@ -239,7 +239,7 @@ def test_internal_dot_template() -> None:
assert flake_ref == str(local_path.path)
def test_explizit_path_default() -> None:
def test_explizit_rel_path_default() -> None:
user_input = "./path/to/flake"
expected_selector = "clan.templates.machine.default"
@@ -248,3 +248,25 @@ def test_explizit_path_default() -> None:
)
assert selector == expected_selector
assert flake_ref == user_input
def test_explizit_abs_path_default() -> None:
user_input = "/path/to/flake"
expected_selector = "clan.templates.machine.default"
flake_ref, selector = transform_url(
machine_template_type, user_input, flake=local_path
)
assert selector == expected_selector
assert flake_ref == user_input
def test_explizit_home_path_default() -> None:
user_input = "~/path/to/flake"
expected_selector = "clan.templates.machine.default"
flake_ref, selector = transform_url(
machine_template_type, user_input, flake=local_path
)
assert selector == expected_selector
assert flake_ref == user_input