mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 19:31:26 -07:00
add metadata to doc support (#18802)
fix broken module docs change doc AST id extraction to use == instead of in
This commit is contained in:
parent
5628e260f2
commit
cb1888125d
6 changed files with 42 additions and 10 deletions
|
@ -60,6 +60,7 @@ def get_docstring(filename, verbose=False):
|
|||
doc = None
|
||||
plainexamples = None
|
||||
returndocs = None
|
||||
metadata = None
|
||||
|
||||
try:
|
||||
# Thank you, Habbie, for this bit of code :-)
|
||||
|
@ -74,7 +75,7 @@ def get_docstring(filename, verbose=False):
|
|||
display.warning("Failed to assign id for %s on %s, skipping" % (t, filename))
|
||||
continue
|
||||
|
||||
if 'DOCUMENTATION' in theid:
|
||||
if 'DOCUMENTATION' == theid:
|
||||
doc = AnsibleLoader(child.value.s, file_name=filename).get_single_data()
|
||||
fragments = doc.get('extends_documentation_fragment', [])
|
||||
|
||||
|
@ -120,15 +121,34 @@ def get_docstring(filename, verbose=False):
|
|||
else:
|
||||
raise Exception("Attempt to extend a documentation fragement of unknown type")
|
||||
|
||||
elif 'EXAMPLES' in theid:
|
||||
elif 'EXAMPLES' == theid:
|
||||
plainexamples = child.value.s[1:] # Skip first empty line
|
||||
|
||||
elif 'RETURN' in theid:
|
||||
elif 'RETURN' == theid:
|
||||
returndocs = child.value.s[1:]
|
||||
|
||||
elif 'ANSIBLE_METADATA' == theid:
|
||||
metadata = child.value
|
||||
if type(metadata).__name__ == 'Dict':
|
||||
metadata = ast.literal_eval(child.value)
|
||||
else:
|
||||
display.warning("Non-dict metadata detected in %s, skipping" % filename)
|
||||
metadata = dict()
|
||||
|
||||
except:
|
||||
display.error("unable to parse %s" % filename)
|
||||
if verbose == True:
|
||||
display.display("unable to parse %s" % filename)
|
||||
raise
|
||||
return doc, plainexamples, returndocs
|
||||
|
||||
if not metadata:
|
||||
metadata = dict()
|
||||
|
||||
# ensure metadata defaults
|
||||
# FUTURE: extract this into its own class for use by runtime metadata
|
||||
metadata['version'] = metadata.get('version', '1.0')
|
||||
metadata['status'] = metadata.get('status', ['preview'])
|
||||
metadata['supported_by'] = metadata.get('supported_by', 'community')
|
||||
|
||||
return doc, plainexamples, returndocs, metadata
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue