metadata and doc generator optimization and fixes

* Fix ansible-doc traceback when a plugin doesn't parse correctly
* Change extract_metadata ivocation to take either an ast or source
  code.  When given source code, it can find file offsets for the start
  and end of dict.  When given the ast, it is quicker as it doesn't have
  to reparse the source.  Requires changing the call to the function to
  use a keyword arg.
* Fix reading of metadata to find the last occurrence of
  ANSIBLE_METADATA instead of the first.
* Add some more unittests to get closer to complete coverage
This commit is contained in:
Toshio Kuratomi 2017-07-03 15:27:15 -07:00
parent 785ed2cfc0
commit 3ee997b720
5 changed files with 96 additions and 27 deletions

View file

@ -155,7 +155,7 @@ def get_docstring(filename, verbose=False):
data[varkey] = child.value.s
display.debug('assigned :%s' % varkey)
data['metadata'] = extract_metadata(b_module_data)[0]
data['metadata'] = extract_metadata(module_ast=M)[0]
# add fragments to documentation
if data['doc']:
add_fragments(data['doc'], filename)
@ -165,7 +165,7 @@ def get_docstring(filename, verbose=False):
for x in ('version', 'metadata_version'):
if x in data['metadata']:
del data['metadata'][x]
except:
except Exception as e:
display.error("unable to parse %s" % filename)
if verbose is True:
display.display("unable to parse %s" % filename)