From 12db5eaf8ab1abd49307586a6aee488f67fb048c Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Mon, 16 Dec 2024 14:18:12 +0100 Subject: [PATCH] dev/list-plugins: add --root-path argument --- .../dev/list-plugins/list-plugins.py | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/flake-modules/dev/list-plugins/list-plugins.py b/flake-modules/dev/list-plugins/list-plugins.py index 695afdb7..816cc541 100755 --- a/flake-modules/dev/list-plugins/list-plugins.py +++ b/flake-modules/dev/list-plugins/list-plugins.py @@ -1,4 +1,5 @@ import glob +import os import re from argparse import ArgumentParser, RawTextHelpFormatter from dataclasses import dataclass @@ -166,14 +167,16 @@ def parse_file(path: str) -> Optional[Plugin]: with open(path, "r") as f: file_content = f.read() - if path in KNOWN_PATHS: - props: tuple[State, Kind, bool] = KNOWN_PATHS[path] - return Plugin( - path=path, - state=props[0], - kind=props[1], - dep_warnings=props[2], - ) + known_path: str + props: tuple[State, Kind, bool] + for known_path, props in KNOWN_PATHS.items(): + if known_path in path: + return Plugin( + path=path, + state=props[0], + kind=props[1], + dep_warnings=props[2], + ) state: State = State.UNKNOWN kind: Kind @@ -216,7 +219,8 @@ def _is_excluded(path: str) -> bool: def main(args) -> None: - paths: list[str] = glob.glob(pathname="plugins/**/*.nix", recursive=True) + pathname: str = os.path.join(args.root_path, "plugins/**/*.nix") + paths: list[str] = glob.glob(pathname=pathname, recursive=True) filtered_paths: list[str] = list(filter(_is_excluded, paths)) filtered_paths.sort() @@ -251,6 +255,13 @@ if __name__ == "__main__": """, formatter_class=RawTextHelpFormatter, ) + # TODO: consider automatically localizing the flake's root. + parser.add_argument( + "--root-path", + type=str, + default="./", + help="The path to the root of the nixvim repo", + ) parser.add_argument( "-k", "--kind",