-
-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TOC broken when selecting non-modules #65
Comments
Try this: # API
-----
::: datadog_checks.base.AgentCheck
rendering:
show_root_heading: yes
selection:
members:
- gauge
- count
- monotonic_count
- rate
- histogram
- historate
- service_check
- event
::: datadog_checks.base.stubs.aggregator.AggregatorStub
rendering:
show_root_heading: yes
selection:
members:
- assert_metric
- assert_metric_has_tag
- assert_metric_has_tag_prefix
- assert_service_check
- assert_event
- assert_all_metrics_covered
- assert_no_duplicate_metrics
- assert_no_duplicate_service_checks
- assert_no_duplicate_all
- reset
::: datadog_checks.base.stubs.datadog_agent.DatadogAgentStub
rendering:
show_root_heading: yes Of course if you are writing your API docs like this everwhere, you can set this as default in plugins:
- mkdocstrings:
handlers:
python:
rendering:
show_root_heading: yes Here's how the template works:
However I agree that the ToC seems broken: it's because I used All the options are here: https://pawamoy.github.io/mkdocstrings/reference/handlers/python/#mkdocstrings.handlers.python.PythonRenderer.DEFAULT_CONFIG |
This is amazing, everything looks so beautiful and It seems like dynamically generated (at import time though) methods aren't detected:
Same for simple properties:
The root header shows up of course, but no members at all. Am I missing an option? |
Hmmm interesting. Indeed I never tried with dynamically added things. I'll play a bit with your example to see why mkdocstrings (pytkdocs really) does not detect the dynamically set members. |
Ah, found it.
but then here: there are no attributes b/c we parse using the AST of the source code rather than inspecting |
This is what I was suspecting for attributes. But the dynamically added members you're missing are methods no? They should be recognized as such in the If not, and your dynamic members are indeed attributes, yes, Python does not allow to attach a docstring to a variable so we have to parse them using AST, therefore dynamic stuff won't work (code is never executed while parsing attributes and their docstrings). |
Yup basically we want to document def a():
"""method a"""
def b():
"""method b"""
class Foo(object):
pass
setattr(Foo, 'a', a)
setattr(Foo, 'b', b) |
Keep in mind though that |
When I write "attribute" I mean "variable", sorry if this wasn't clear :) Since you're setting methods with |
As far as I can tell it comes down to you re-parsing source code vs simply inspecting the loaded object that is already in memory ( |
OK I found why nothing appears. The attributes you set dynamically with When An idea that popped to mind is that we could inspect the object to see if it has a Is there a reason you do not attach directly the transformer instead of creating an object just to store its
|
I was trying to avoid displaying a signature so it appears like an Enum, but yeah I'll do your way for now. Though I can't get the other case to work. DEFAULT_TIMEOUT = 10
STANDARD_FIELDS = {
'auth_type': 'basic',
'aws_host': None,
'aws_region': None,
'aws_service': None,
'connect_timeout': None,
'extra_headers': None,
'headers': None,
'kerberos_auth': None,
'kerberos_cache': None,
'kerberos_delegate': False,
'kerberos_force_initiate': False,
'kerberos_hostname': None,
'kerberos_keytab': None,
'kerberos_principal': None,
'log_requests': False,
'ntlm_domain': None,
'password': None,
'persist_connections': False,
'proxy': None,
'read_timeout': None,
'skip_proxy': False,
'tls_ca_cert': None,
'tls_cert': None,
'tls_ignore_warning': False,
'tls_private_key': None,
'tls_verify': True,
'timeout': DEFAULT_TIMEOUT,
'username': None,
}
class StandardFields(object):
pass
for field, value in sorted(STANDARD_FIELDS.items()):
setattr(StandardFields, field, value) |
Why are you setting the attributes that way, and not in the class itself? DEFAULT_TIMEOUT = 10
class StandardFields(object):
auth_type = 'basic'
aws_host = None
aws_region = None
aws_service = None
connect_timeout = None
extra_headers = None
headers = None
kerberos_auth = None
kerberos_cache = None
kerberos_delegate = False
kerberos_force_initiate = False
kerberos_hostname = None
kerberos_keytab = None
kerberos_principal = None
log_requests = False
ntlm_domain = None
password = None
persist_connections = False
proxy = None
read_timeout = None
skip_proxy = False
tls_ca_cert = None
tls_cert = None
tls_ignore_warning = False
tls_private_key = None
tls_verify = True
timeout = DEFAULT_TIMEOUT
username = None |
I need to iterate through all the defined attributes |
@pawamoy Also, just at a high level, I think we should support the idea that anything can happen at load time, same as other tools like the extension we're coming from and Sphinx. Can you explain what exactly we need to use the |
It's already supported. We do import the code, so module scoped code is executed, and we can inspect it.
To get docstrings for attributes. Python has no way of attaching a docstring to a variable, so we must parse the code to get these pairs. |
FYI I just tried @StephenBrown2's way, and that also does not work |
nor does stdlib's |
Got it! class StandardFields(object):
pass
StandardFields.__doc__ = '\n'.join('- `{}`'.format(field) for field in STANDARD_FIELDS) |
Nice! The things you tried didn't work because |
The text was updated successfully, but these errors were encountered: