templates: fix urls for relative file paths
This commit is contained in:
@@ -84,6 +84,14 @@ def transform_url(template_type: str, identifier: str, flake: Flake) -> tuple[st
|
|||||||
flake_ref = str(flake.path)
|
flake_ref = str(flake.path)
|
||||||
|
|
||||||
if "#" not in identifier:
|
if "#" not in identifier:
|
||||||
|
# ./ . or ../ .. are relative paths
|
||||||
|
if (
|
||||||
|
identifier.startswith(("./", "../"))
|
||||||
|
or identifier == "."
|
||||||
|
or identifier == ".."
|
||||||
|
):
|
||||||
|
return (identifier, f"clan.templates.{template_type}.default")
|
||||||
|
|
||||||
# No fragment, so we assume its a builtin template
|
# No fragment, so we assume its a builtin template
|
||||||
return (flake_ref, f'clanInternals.templates.{template_type}."{selector}"')
|
return (flake_ref, f'clanInternals.templates.{template_type}."{selector}"')
|
||||||
|
|
||||||
|
|||||||
@@ -182,3 +182,69 @@ def test_locked_input_template_no_dot() -> None:
|
|||||||
)
|
)
|
||||||
assert selector == expected_selector
|
assert selector == expected_selector
|
||||||
assert flake_ref == str(local_path.path)
|
assert flake_ref == str(local_path.path)
|
||||||
|
|
||||||
|
|
||||||
|
def test_explizit_path_default_minimal_rel_1() -> None:
|
||||||
|
user_input = "."
|
||||||
|
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_path_default_minimal_rel_2() -> None:
|
||||||
|
user_input = "./"
|
||||||
|
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_path_default_minimal_parent_1() -> None:
|
||||||
|
user_input = ".."
|
||||||
|
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_path_default_minimal_parent_2() -> None:
|
||||||
|
user_input = "../"
|
||||||
|
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_internal_dot_template() -> None:
|
||||||
|
user_input = ".internal"
|
||||||
|
expected_selector = 'clanInternals.templates.machine.".internal"'
|
||||||
|
|
||||||
|
flake_ref, selector = transform_url(
|
||||||
|
machine_template_type, user_input, flake=local_path
|
||||||
|
)
|
||||||
|
assert selector == expected_selector
|
||||||
|
assert flake_ref == str(local_path.path)
|
||||||
|
|
||||||
|
|
||||||
|
def test_explizit_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
|
||||||
|
|||||||
Reference in New Issue
Block a user