From 9a7fa8bd88752ca1a074179db3a4c7fc41b68028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Sun, 28 Nov 2021 19:58:21 +0100 Subject: [PATCH] feat: Allow passing extensions config as JSON on the CLI --- src/griffe/agents/extensions/__init__.py | 4 ++-- src/griffe/cli.py | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/griffe/agents/extensions/__init__.py b/src/griffe/agents/extensions/__init__.py index 86824eb7..d0520ef9 100644 --- a/src/griffe/agents/extensions/__init__.py +++ b/src/griffe/agents/extensions/__init__.py @@ -1,5 +1,5 @@ """This module is the public interface to import elements from the base.""" -from griffe.agents.extensions.base import Extension, Extensions, When, load_extensions +from griffe.agents.extensions.base import Extension, Extensions, When, load_extension, load_extensions -__all__ = ["Extensions", "Extension", "When", "load_extensions"] # noqa: WPS410 +__all__ = ["Extensions", "Extension", "When", "load_extension", "load_extensions"] # noqa: WPS410 diff --git a/src/griffe/cli.py b/src/griffe/cli.py index a89f58b4..e92c8327 100644 --- a/src/griffe/cli.py +++ b/src/griffe/cli.py @@ -22,6 +22,7 @@ from typing import Any, Sequence from griffe.agents.extensions import Extensions +from griffe.agents.extensions.base import load_extensions from griffe.docstrings.parsers import Parser from griffe.encoders import Encoder from griffe.loader import AsyncGriffeLoader, GriffeLoader @@ -108,6 +109,13 @@ def get_parser() -> argparse.ArgumentParser: action="store_true", help="Whether to append sys.path to search paths specified with -s.", ) + parser.add_argument( + "-e", + "--extensions", + default={}, + type=json.loads, + help="A list of extensions to use.", + ) parser.add_argument( "-f", "--full", @@ -180,7 +188,7 @@ def main(args: list[str] | None = None) -> int: # noqa: WPS231 if opts.append_sys_path: search.extend(sys.path) - extensions = Extensions() + extensions = load_extensions(opts.extensions) if opts.async_loader: loop = asyncio.get_event_loop()