From 6a4455ff54aae85eeac0a3c7c41029bcf3ee5437 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 2 Jun 2020 17:07:34 +0200 Subject: [PATCH] Update plugin_formatter to understand tagged version_added (#69797) * Update version_added handling for plugin_formatter w.r.t. #69680. * Update hacking/build_library/build_ansible/command_plugins/plugin_formatter.py Co-authored-by: Abhijeet Kasurde Co-authored-by: Abhijeet Kasurde --- .../command_plugins/plugin_formatter.py | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/hacking/build_library/build_ansible/command_plugins/plugin_formatter.py b/hacking/build_library/build_ansible/command_plugins/plugin_formatter.py index 784225e1b81..e6cb3913db6 100644 --- a/hacking/build_library/build_ansible/command_plugins/plugin_formatter.py +++ b/hacking/build_library/build_ansible/command_plugins/plugin_formatter.py @@ -222,7 +222,8 @@ def get_plugin_info(module_dir, limit_to=None, verbose=False): show_progress(module_index) # use ansible core library to parse out doc metadata YAML and plaintext examples - doc, examples, returndocs, metadata = plugin_docs.get_docstring(module_path, fragment_loader, verbose=verbose) + doc, examples, returndocs, metadata = plugin_docs.get_docstring( + module_path, fragment_loader, verbose=verbose, collection_name='ansible.builtin') if metadata and 'removed' in metadata.get('status', []): continue @@ -333,6 +334,17 @@ def jinja2_environment(template_dir, typ, plugin_type): return templates +def process_version_added(version_added): + if not isinstance(version_added, string_types): + return version_added + if ':' not in version_added: + return version_added + # Strip tag from version_added. It suffices to do this here since + # this is only used for ansible-base, and there the only valid tag + # is `ansible.builtin:`. + return version_added[version_added.index(':') + 1:] + + def too_old(added): if not added: return False @@ -377,8 +389,10 @@ def process_options(module, options, full_key=None): raise AnsibleError("Invalid required value '%s' for parameter '%s' in '%s' (must be truthy)" % (required_value, k, module)) # Strip old version_added information for options - if 'version_added' in v and too_old(v['version_added']): - del v['version_added'] + if 'version_added' in v: + v['version_added'] = process_version_added(v['version_added']) + if too_old(v['version_added']): + del v['version_added'] if 'suboptions' in v and v['suboptions']: if isinstance(v['suboptions'], dict): @@ -403,6 +417,12 @@ def process_returndocs(returndocs, full_key=None): full_key_k = full_key + [k] v['full_key'] = full_key_k + # Strip old version_added information for options + if 'version_added' in v: + v['version_added'] = process_version_added(v['version_added']) + if too_old(v['version_added']): + del v['version_added'] + # Process suboptions suboptions = v.get('contains') if suboptions: @@ -435,7 +455,7 @@ def process_plugins(module_map, templates, outputname, output_dir, ansible_versi # add some defaults for plugins that dont have most of the info doc['module'] = doc.get('module', module) - doc['version_added'] = doc.get('version_added', 'historical') + doc['version_added'] = process_version_added(doc.get('version_added', 'historical')) doc['plugin_type'] = plugin_type @@ -462,6 +482,7 @@ def process_plugins(module_map, templates, outputname, output_dir, ansible_versi doc['description'] = [] if 'version_added' not in doc: + # Will never happen, since it has been explicitly inserted above. raise AnsibleError("*** ERROR: missing version_added in: %s ***\n" % module) #