From f78baa13004b8269227e464ee383214aec68d701 Mon Sep 17 00:00:00 2001 From: Branko Majic Date: Fri, 4 Aug 2017 22:10:36 +0200 Subject: [PATCH] Implement ability to limit module documentation building (#24576) * Implement ability to limit module documentation building: - Added new option to plugin_formatter.py to support passing-in a list of modules for which the documentation should be built. - Updated docuemtnation Makefile to allow specifying list of modules via environment variables (defaulting to all modules). - Update instructions for building documentation and module development to include commands and description of limiting module documentation builds. * Updated implementation for limiting module documentation building: - Pass list of modules (or None) to list_modules function instead of string. - Move conversion of module list to argument parsing code. - No special keywords. Default ("") means build all modules. For no modules just specify non-existing module name. - Updated documentation to reflect the changes. * Updated implementation for limiting module documentation building: - Use better default value, and don't treat "" as special case. - Conditionally invoke different variants of command in Makefile instead of using special value "". * Minor edits Wording tweak --- docs/bin/plugin_formatter.py | 17 +++++++++++++---- docs/docsite/Makefile | 5 +++++ docs/docsite/README.md | 6 ++++++ .../developing_modules_documenting.rst | 7 +++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/docs/bin/plugin_formatter.py b/docs/bin/plugin_formatter.py index c6c4a12e605..4d2add33ee2 100755 --- a/docs/bin/plugin_formatter.py +++ b/docs/bin/plugin_formatter.py @@ -117,7 +117,7 @@ def write_data(text, options, outputname, module): print(text) -def list_modules(module_dir, depth=0): +def list_modules(module_dir, depth=0, limit_to_modules=None): ''' returns a hash of categories, each category being a hash of module names to file paths ''' categories = dict() @@ -159,8 +159,11 @@ def list_modules(module_dir, depth=0): aliases[source].add(module) continue - category[module] = module_path - module_info[module] = module_path + # If requested, limit module documentation building only to passed-in + # modules. + if limit_to_modules is None or module.lower() in limit_to_modules: + category[module] = module_path + module_info[module] = module_path # keep module tests out of becoming module docs if 'test' in categories: @@ -185,6 +188,8 @@ def generate_parser(): p.add_option("-v", "--verbose", action='store_true', default=False, help="Verbose") p.add_option("-o", "--output-dir", action="store", dest="output_dir", default=None, help="Output directory for module files") p.add_option("-I", "--includes-file", action="store", dest="includes_file", default=None, help="Create a file containing list of processed modules") + p.add_option("-l", "--limit-to-modules", action="store", dest="limit_to_modules", default=None, + help="Limit building module documentation to comma-separated list of modules. Specify non-existing module name for no modules.") p.add_option('-V', action='version', help='Show version number and exit') return p @@ -435,7 +440,11 @@ def main(): env, template, outputname = jinja2_environment(options.template_dir, options.type) - mod_info, categories, aliases = list_modules(options.module_dir) + # Convert passed-in limit_to_modules to None or list of modules. + if options.limit_to_modules is not None: + options.limit_to_modules = [s.lower() for s in options.limit_to_modules.split(",")] + + mod_info, categories, aliases = list_modules(options.module_dir, limit_to_modules=options.limit_to_modules) categories['all'] = mod_info categories['_aliases'] = aliases category_names = [c for c in categories.keys() if not c.startswith('_')] diff --git a/docs/docsite/Makefile b/docs/docsite/Makefile index 00a716cdbb4..d506c42b56f 100644 --- a/docs/docsite/Makefile +++ b/docs/docsite/Makefile @@ -50,7 +50,12 @@ keywords: $(FORMATTER) ../templates/playbooks_keywords.rst.j2 PYTHONPATH=../../lib $(DUMPER) --template-dir=../templates --output-dir=rst/ -d ./keyword_desc.yml modules: $(FORMATTER) ../templates/plugin.rst.j2 +# Limit building of module documentation if requested. +ifdef MODULES + PYTHONPATH=../../lib $(FORMATTER) -t rst --template-dir=../templates --module-dir=../../lib/ansible/modules -o rst/ -l $(MODULES) +else PYTHONPATH=../../lib $(FORMATTER) -t rst --template-dir=../templates --module-dir=../../lib/ansible/modules -o rst/ +endif testing: $(TESTING_FORMATTER) diff --git a/docs/docsite/README.md b/docs/docsite/README.md index 21985a8f6aa..7ddea776fc6 100644 --- a/docs/docsite/README.md +++ b/docs/docsite/README.md @@ -14,6 +14,12 @@ such as link references, you may install sphinx and build the documentation by r To include module documentation you'll need to run `make webdocs` at the top level of the repository. The generated html files are in docsite/htmlout/. +To limit module documentation building to a specific module, run `MODULES=NAME +make webdocs` instead. This should make testing module documentation syntax much +faster. Instead of a single module, you can also specify a comma-separated list +of modules. In order to skip building documentation for all modules, specify +non-existing module name, for example `MODULES=none make webdocs`. + If you do not want to learn the reStructuredText format, you can also [file issues] about documentation problems on the Ansible GitHub project. diff --git a/docs/docsite/rst/dev_guide/developing_modules_documenting.rst b/docs/docsite/rst/dev_guide/developing_modules_documenting.rst index 4667ff6e8a8..42a5765c83a 100644 --- a/docs/docsite/rst/dev_guide/developing_modules_documenting.rst +++ b/docs/docsite/rst/dev_guide/developing_modules_documenting.rst @@ -383,6 +383,13 @@ Put your completed module file into the ``lib/ansible/modules/$CATEGORY/`` direc run the command: ``make webdocs``. The new 'modules.html' file will be built in the ``docs/docsite/_build/html/$MODULENAME_module.html`` directory. +In order to speed up the build process, you can limit the documentation build to +only include modules you specify, or no modules at all. To do this, run the command: +``MODULES=$MODULENAME make webdocs``. The ``MODULES`` environment variable +accepts a comma-separated list of module names. To skip building +documentation for all modules, specify a non-existent module name, for example: +``MODULES=none make webdocs``. + To test your documentation against your ``argument_spec`` you can use ``validate-modules``. Note that this option isn't currently enabled in Shippable due to the time it takes to run. .. code-block:: bash