Skip to content

Commit

Permalink
Use correct docs for functions, attributes
Browse files Browse the repository at this point in the history
Fixes #170
  • Loading branch information
nyalldawson committed Sep 11, 2024
1 parent 2e16026 commit 7995014
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
8 changes: 2 additions & 6 deletions rst/qgis_pydoc_template.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. package: qgis\.$PACKAGE

Class: $CLASS
$OBJECT_TYPE: $CLASS
..............................................................................................

.. py:module:: $CLASS
Expand All @@ -9,8 +9,4 @@ $HEADER_CONTENT

$TABLE_OF_CONTENTS

.. autoclass:: qgis.$PACKAGE.$CLASS
:special-members: __init__
:members:
:undoc-members:
:exclude-members: $EXCLUDE_METHODS
$CONTENT
31 changes: 31 additions & 0 deletions scripts/make_api_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 7995014

Please sign in to comment.