From 785baa04e3081fcf80756f56dddb95a00cb9b025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 26 Oct 2023 17:23:37 +0200 Subject: [PATCH] refactor: Expose parser enuemration and parser functions in top-level module --- scripts/gen_griffe_json.py | 18 +++++------------- src/griffe/__init__.py | 5 +++++ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/scripts/gen_griffe_json.py b/scripts/gen_griffe_json.py index 5b61737e..ee733298 100644 --- a/scripts/gen_griffe_json.py +++ b/scripts/gen_griffe_json.py @@ -1,21 +1,13 @@ """Generate the credits page.""" -import json - import mkdocs_gen_files -from griffe.docstrings.parsers import Parser -from griffe.encoders import JSONEncoder -from griffe.loader import GriffeLoader +import griffe -griffe = GriffeLoader().load_module("griffe") -serialized = json.dumps( - griffe, - cls=JSONEncoder, - indent=0, - full=True, - docstring_parser=Parser.google, +data = griffe.load( + "griffe", + docstring_parser=griffe.Parser.google, docstring_options={"ignore_init_summary": True}, ) with mkdocs_gen_files.open("griffe.json", "w") as fd: - fd.write(serialized) + fd.write(data.as_json(full=True, indent=0)) diff --git a/src/griffe/__init__.py b/src/griffe/__init__.py index 76e1ffc3..17c94136 100644 --- a/src/griffe/__init__.py +++ b/src/griffe/__init__.py @@ -10,6 +10,7 @@ from griffe.agents.nodes import ObjectNode from griffe.dataclasses import Attribute, Class, Docstring, Function, Module, Object from griffe.diff import find_breaking_changes +from griffe.docstrings.parsers import Parser, parse_google, parse_numpy, parse_sphinx from griffe.extensions import Extension, load_extensions from griffe.git import load_git from griffe.importer import dynamic_import @@ -31,4 +32,8 @@ "Module", "Object", "ObjectNode", + "Parser", + "parse_google", + "parse_numpy", + "parse_sphinx", ]