From 16d8360f6fd0bab1dc6edb0d5b8fdecf71977f50 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 11 Sep 2024 11:47:25 +1000 Subject: [PATCH] Use correct docs for functions, attributes Fixes #170 --- rst/qgis_pydoc_template.txt | 8 ++------ scripts/make_api_rst.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/rst/qgis_pydoc_template.txt b/rst/qgis_pydoc_template.txt index aea580c0d5fd..85660efb392d 100644 --- a/rst/qgis_pydoc_template.txt +++ b/rst/qgis_pydoc_template.txt @@ -1,6 +1,6 @@ .. package: qgis\.$PACKAGE -Class: $CLASS +$OBJECT_TYPE: $CLASS .............................................................................................. .. py:module:: $CLASS @@ -9,8 +9,4 @@ $HEADER_CONTENT $TABLE_OF_CONTENTS -.. autoclass:: qgis.$PACKAGE.$CLASS - :special-members: __init__ - :members: - :undoc-members: - :exclude-members: $EXCLUDE_METHODS +$CONTENT diff --git a/scripts/make_api_rst.py b/scripts/make_api_rst.py index 659172425fc5..f7ad4ff64e74 100755 --- a/scripts/make_api_rst.py +++ b/scripts/make_api_rst.py @@ -212,6 +212,22 @@ def _recursive_substitute(self, **kws): :exclude-members: $EXCLUDE_METHODS """ +AUTO_CLASS = """ +.. autoclass:: qgis.$PACKAGE.$CLASS + :special-members: __init__ + :members: + :undoc-members: + :exclude-members: $EXCLUDE_METHODS +""" + +AUTO_FUNCTION = """ +.. autofunction:: qgis.$PACKAGE.$CLASS +""" + +AUTO_ATTRIBUTE = """ +.. autoattribute:: qgis.$PACKAGE.$CLASS +""" + MODULE_TOC_MAX_COLUMN_SIZES = [300, 500] @@ -408,12 +424,27 @@ def export_bases(_b): # print(getattr(base, method).__doc__) pass + if isinstance(_class, (str, int, float)): + content = AUTO_ATTRIBUTE + object_type = "Attribute" + elif ( + inspect.isfunction(_class) + or _class.__class__.__name__ == "builtin_function_or_method" + ): + content = AUTO_FUNCTION + object_type = "Function" + else: + content = AUTO_CLASS + object_type = "Class" + substitutions = { "PACKAGE": package_name, "CLASS": class_name, "EXCLUDE_METHODS": ",".join(exclude_methods), "HEADER_CONTENT": header, "TABLE_OF_CONTENTS": toc, + "CONTENT": content, + "OBJECT_TYPE": object_type, } class_template = template.substitute(**substitutions) class_rst = open(f"api/{qgis_version}/{package_name}/{class_name}.rst", "w")