Skip to content

Commit

Permalink
Remake autodoc property and signal documenter
Browse files Browse the repository at this point in the history
Could not fix the old code because accessing the properties
and signals from class no longer causes errors which old
code relied on.
  • Loading branch information
igo95862 committed Aug 10, 2022
1 parent 012f0dd commit 0b22970
Showing 1 changed file with 40 additions and 25 deletions.
65 changes: 40 additions & 25 deletions src/sdbus/autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@

from __future__ import annotations

from typing import Any, Dict, List
from typing import Any, Dict

from sphinx.application import Sphinx
from sphinx.ext.autodoc import AttributeDocumenter, MethodDocumenter
from sphinx.util.docstrings import prepare_docstring

from .dbus_proxy_async_interfaces import DbusInterfaceCommonAsync
from .dbus_proxy_async_method import DbusMethodAsyncBinded
from .dbus_proxy_async_property import DbusPropertyAsyncBinded
from .dbus_proxy_async_signal import DbusSignalBinded
from .dbus_proxy_async_property import (
DbusPropertyAsync,
DbusPropertyAsyncBinded,
)
from .dbus_proxy_async_signal import DbusSignalAsync, DbusSignalBinded


class DbusMethodDocumenter(MethodDocumenter):
Expand Down Expand Up @@ -71,26 +72,33 @@ class DbusPropertyDocumenter(AttributeDocumenter):
def can_document_member(cls, member: Any, *args: Any) -> bool:
return isinstance(member, DbusPropertyAsyncBinded)

def update_annotations(self,
parent: DbusInterfaceCommonAsync) -> None:

assert isinstance(self.object, DbusPropertyAsyncBinded)
property_annotation = \
self.object.dbus_property.property_getter.__annotations__['return']

parent.__annotations__[self.object_name] = property_annotation
def import_object(self, raiseerror: bool = False) -> bool:

def get_doc(self) -> List[List[str]]:
return [prepare_docstring(self.object.__doc__)]
self.objpath.append('dbus_property')
ret = super().import_object(raiseerror)
self.objpath.pop()
return ret

def add_content(self,
*args: Any, **kwargs: Any,
) -> None:

assert isinstance(self.object, DbusPropertyAsync)
python_type = self.object.property_getter.__annotations__['return']
dbus_type = self.object.property_signature

source_name = self.get_sourcename()
self.add_line('', source_name)
self.add_line('**D-Bus property**', source_name)
self.add_line('', source_name)
self.add_line(
f"**Python type**: *{python_type}*", source_name
)
self.add_line('', source_name)
self.add_line(
f"**D-Bus type**: {dbus_type}", source_name
)
self.add_line('', source_name)

super().add_content(*args, **kwargs)

Expand All @@ -105,26 +113,33 @@ class DbusSignalDocumenter(AttributeDocumenter):
def can_document_member(cls, member: Any, *args: Any) -> bool:
return isinstance(member, DbusSignalBinded)

def update_annotations(self,
parent: DbusInterfaceCommonAsync) -> None:

assert isinstance(self.object, DbusSignalBinded)
signal_annotation = \
self.object.dbus_signal.__annotations__['return']

parent.__annotations__[self.object_name] = signal_annotation
def import_object(self, raiseerror: bool = False) -> bool:

def get_doc(self) -> List[List[str]]:
return [prepare_docstring(self.object.__doc__)]
self.objpath.append('dbus_signal')
ret = super().import_object(raiseerror)
self.objpath.pop()
return ret

def add_content(self,
*args: Any, **kwargs: Any,
) -> None:

assert isinstance(self.object, DbusSignalAsync)
python_type = self.object.__annotations__['return']
dbus_type = self.object.signal_signature

source_name = self.get_sourcename()
self.add_line('', source_name)
self.add_line('**D-Bus signal**', source_name)
self.add_line('', source_name)
self.add_line(
f"**Python type**: *{python_type}*", source_name
)
self.add_line('', source_name)
self.add_line(
f"**D-Bus type**: {dbus_type}", source_name
)
self.add_line('', source_name)

super().add_content(*args, **kwargs)

Expand Down

0 comments on commit 0b22970

Please sign in to comment.