mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 04:40:22 -07:00
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:
parent
785ed2cfc0
commit
3ee997b720
5 changed files with 96 additions and 27 deletions
|
@ -205,7 +205,8 @@ def write_metadata(filename, new_metadata, version=None, overwrite=False):
|
|||
module_data = f.read()
|
||||
|
||||
try:
|
||||
current_metadata, start_line, start_col, end_line, end_col, targets = extract_metadata(module_data)
|
||||
current_metadata, start_line, start_col, end_line, end_col, targets = \
|
||||
extract_metadata(module_data=module_data, offsets=True)
|
||||
except SyntaxError:
|
||||
if filename.endswith('.py'):
|
||||
raise
|
||||
|
@ -257,7 +258,7 @@ def return_metadata(plugins):
|
|||
if name not in metadata or metadata[name] is not None:
|
||||
with open(filename, 'rb') as f:
|
||||
module_data = f.read()
|
||||
metadata[name] = extract_metadata(module_data)[0]
|
||||
metadata[name] = extract_metadata(module_data=module_data, offsets=True)[0]
|
||||
return metadata
|
||||
|
||||
|
||||
|
@ -408,7 +409,7 @@ def upgrade_metadata(version=None):
|
|||
# For each plugin, read the existing metadata
|
||||
with open(filename, 'rb') as f:
|
||||
module_data = f.read()
|
||||
metadata = extract_metadata(module_data)[0]
|
||||
metadata = extract_metadata(module_data=module_data, offsets=True)[0]
|
||||
|
||||
# If the metadata isn't the requested version, convert it to the new
|
||||
# version
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue