templates: url add support for home and abspath
This commit is contained in:
@@ -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 == ".."
|
||||
):
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user