mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-11 09:05:07 +00:00
pybricks._common.Motor: Fix nested attributes.
Now we can use relative paths, which should help when sharing the motor class contents.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
"""Provides the ``autonestedmethod`` directive.
|
||||
|
||||
Like ``automethod``, but resolves dotted names such as ``control.limits``
|
||||
relative to the class documented by the enclosing ``autoclass`` directive.
|
||||
Plain ``automethod`` treats everything before the last dot as a module/class
|
||||
path, so ``control.limits`` would be looked up as an attribute of the current
|
||||
*module* instead of the current class. Resolving the class here keeps shared
|
||||
include fragments module-neutral.
|
||||
"""
|
||||
|
||||
from sphinx.util import logging
|
||||
from sphinx.util.docutils import SphinxDirective
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AutoNestedMethodDirective(SphinxDirective):
|
||||
required_arguments = 1
|
||||
has_content = False
|
||||
|
||||
def run(self):
|
||||
current = self.env.current_document
|
||||
module = current.autodoc_module or self.env.ref_context.get("py:module")
|
||||
cls = current.autodoc_class or self.env.ref_context.get("py:class")
|
||||
|
||||
if not module or not cls:
|
||||
logger.warning(
|
||||
"autonestedmethod:: %s used outside of an autoclass context",
|
||||
self.arguments[0],
|
||||
location=self.get_location(),
|
||||
)
|
||||
return []
|
||||
|
||||
return self.parse_text_to_nodes(
|
||||
f".. automethod:: {module}::{cls}.{self.arguments[0]}"
|
||||
)
|
||||
|
||||
|
||||
def setup(app):
|
||||
app.add_directive("autonestedmethod", AutoNestedMethodDirective)
|
||||
return {"parallel_read_safe": True}
|
||||
Reference in New Issue
Block a user