11#!/usr/bin/env python
22# PYTHON_ARGCOMPLETE_OK
33
4- """ doc generator
5- """
4+ """Generate or update collection documentation."""
65import ast
76import logging
87import os
7170
7271
7372def ensure_list (value ):
74- """Ensure the value is a list
73+ """Ensure the value is a list.
7574
7675 :param value: The value to check
7776 :type value: Unknown
@@ -83,7 +82,7 @@ def ensure_list(value):
8382
8483
8584def convert_descriptions (data ):
86- """Convert the descriptions for doc into lists
85+ """Convert the descriptions for doc into lists.
8786
8887 :param data: the chunk from the doc
8988 :type data: dict
@@ -99,7 +98,7 @@ def convert_descriptions(data):
9998
10099
101100def jinja_environment ():
102- """Define the jinja environment
101+ """Define the jinja environment.
103102
104103 :return: A jinja template, with the env set
105104 """
@@ -121,12 +120,10 @@ def jinja_environment():
121120
122121
123122def update_readme (content , path , gh_url , branch_name ):
124- """Update the README.md in the repository
123+ """Update the README.md in the repository.
125124
126125 :param content: The dict containing the content
127126 :type content: dict
128- :param collection: The full collection name
129- :type collection: str
130127 :param path: The path to the collection
131128 :type path: str
132129 :param gh_url: The url to the GitHub repository
@@ -193,9 +190,7 @@ def update_readme(content, path, gh_url, branch_name):
193190
194191
195192def handle_simple (collection , fullpath , kind ):
196- """Grab each plugin from a plugin file and
197- use the def comment if available. Intended for use
198- with "simple" plugins, like filter or tests
193+ """Process "simple" plugins like filter or test.
199194
200195 :param collection: The full collection name
201196 :type collection: str
@@ -276,9 +271,7 @@ def handle_simple(collection, fullpath, kind):
276271 simple_map = dict (zip (keys , values ))
277272 for name , func in simple_map .items ():
278273 if func in function_definitions :
279- comment = function_definitions [func ] or "{collection} {name} {kind} plugin" .format (
280- collection = collection , name = name , kind = kind
281- )
274+ comment = function_definitions [func ] or f"{ collection } { name } { kind } plugin"
282275
283276 # Get the first line from the docstring for the description and
284277 # make that the short description.
@@ -288,13 +281,13 @@ def handle_simple(collection, fullpath, kind):
288281
289282
290283def process (collection : str , path : Path ): # pylint: disable-msg=too-many-locals
291- """
292- Process the files in each subdirectory
284+ """Process the files in each subdirectory.
293285
294286 :param collection: The collection name
295287 :type collection: str
296288 :param path: The path to the collection
297- :type path: str
289+ :type path: Path
290+ :return: A mapping of plugins to plugin types
298291 """
299292 template = jinja_environment ()
300293 docs_path = Path (path , "docs" )
@@ -377,7 +370,7 @@ def process(collection: str, path: Path): # pylint: disable-msg=too-many-locals
377370
378371
379372def load_galaxy (path ):
380- """Load collection details from the galaxy.yml file in the collection
373+ """Load collection details from the galaxy.yml file in the collection.
381374
382375 :param path: The path the collection
383376 :return: The collection name and gh url
@@ -395,7 +388,7 @@ def load_galaxy(path):
395388
396389
397390def load_runtime (path ):
398- """Load runtime details from the runtime.yml file in the collection
391+ """Load runtime details from the runtime.yml file in the collection.
399392
400393 :param path: The path the collection
401394 :return: The runtime dict
@@ -413,14 +406,14 @@ def load_runtime(path):
413406
414407
415408def link_collection (path : Path , galaxy : dict , collection_root : Optional [Path ] = None ):
416- """Link the provided collection into the Ansible default collection path
409+ """Link the provided collection into the Ansible default collection path.
417410
418411 :param path: A path
419- :type path: str
412+ :type path: Path
420413 :param galaxy: The galaxy.yml contents
421414 :type galaxy: dict
415+ :param collection_root: The root collections path
422416 """
423-
424417 if collection_root is None :
425418 collection_root = Path (Path .home (), ".ansible/collections/ansible_collections" )
426419
@@ -448,7 +441,12 @@ def link_collection(path: Path, galaxy: dict, collection_root: Optional[Path] =
448441
449442
450443def add_collection (path : Path , galaxy : dict ) -> Optional [tempfile .TemporaryDirectory ]:
451- """Add path to collections dir so we can find local doc_fragments"""
444+ """Add path to collections dir so we can find local doc_fragments.
445+
446+ :param path: The collections path
447+ :param galaxy: The contents of galaxy.yml
448+ :return: A temporary alternate directory if the collection is not in a valid location
449+ """
452450 collections_path = None
453451 tempdir = None
454452
@@ -480,7 +478,7 @@ def add_collection(path: Path, galaxy: dict) -> Optional[tempfile.TemporaryDirec
480478
481479
482480def add_ansible_compatibility (runtime , path ):
483- """Add ansible compatibility information to README
481+ """Add ansible compatibility information to README.
484482
485483 :param runtime: runtime.yml contents
486484 :type runtime: dict
@@ -515,9 +513,7 @@ def add_ansible_compatibility(runtime, path):
515513
516514
517515def main ():
518- """
519- The entry point
520- """
516+ """Run the script."""
521517 parser = ArgumentParser ()
522518 parser .add_argument (
523519 "-p" ,
0 commit comments