Skip to content

Commit

Permalink
Add hook to sphinx-autoapi to fix sync wrapping (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtomlinson authored Jul 2, 2024
1 parent 501af87 commit fad5440
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,38 @@
}


def remove_async_property(app, what, name, obj, skip, options):
"""Remove async property from sync wrapped methods.
Find all sync classes that inherit from async classes
and remove the async property from their wrapped methods.
Also skip public ``async_`` methods as they are only intended
to be used internally by other sync wrapped objects.
"""
if what == "class" and (
# Infer that the class is a sync wrapped class if it is the kr8s.Api class,
# or is in kr8s.objects and inherits from a class in kr8s._objects.
name == "kr8s.Api"
or ("kr8s.objects" in name and obj.bases and "kr8s._objects" in obj.bases[0])
# FIXME: It would be better to just check if the class is decorated with @sync
# but sphinx-autoapi does not currently keep track of decorators
# See https://github.com/readthedocs/sphinx-autoapi/issues/459
):
for child in obj.children:
if child.type == "method":
if child.name.startswith("async_"):
child.properties.append("private-async-only")
continue
if not child.name.startswith("_"):
if "async" in child.properties:
child.properties.remove("async")

if what == "method" and "private-async-only" in obj.properties:
skip = True
return skip


def setup(app):
app.add_css_file("css/custom.css")
app.connect("autoapi-skip-member", remove_async_property)

0 comments on commit fad5440

Please sign in to comment.