From 85b990286d391cce9a41d72cf4303637a7b43a10 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Sun, 15 Dec 2024 10:05:51 -0600 Subject: [PATCH] flake-modules/new-plugin: find project root --- flake-modules/dev/new-plugin.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/flake-modules/dev/new-plugin.py b/flake-modules/dev/new-plugin.py index 4be6abd6..01fc1e0e 100644 --- a/flake-modules/dev/new-plugin.py +++ b/flake-modules/dev/new-plugin.py @@ -91,6 +91,18 @@ def write_to_file(file_path, content: str): f.write(content) +def find_project_root(root_identifier): + current_path = os.getcwd() + while True: + if root_identifier in os.listdir(current_path): + return current_path + parent_path = os.path.dirname(current_path) + if parent_path == current_path: + return None + os.chdir("..") + current_path = os.getcwd() + + # TODO: support interactive unmanaged args def main(): """ @@ -109,8 +121,11 @@ def main(): name = kebab_case(args.originalName) # Define paths - plugin_path = f"plugins/by-name/{name}/default.nix" - test_path = f"tests/test-sources/plugins/by-name/{name}/default.nix" + root_identifier = "flake.nix" + root_dir = find_project_root(root_identifier) + + plugin_path = f"{root_dir}/plugins/by-name/{name}/default.nix" + test_path = f"{root_dir}/tests/test-sources/plugins/by-name/{name}/default.nix" # Create files create_nix_file(