From e2627cd972a74810b5044201e27d4636923caf24 Mon Sep 17 00:00:00 2001 From: phoffmann Date: Tue, 12 Oct 2021 12:48:18 +0200 Subject: [PATCH 1/2] respect found version_added content --- collection_prep/cmd/update.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/collection_prep/cmd/update.py b/collection_prep/cmd/update.py index d2f8cd5..eaf9dd6 100644 --- a/collection_prep/cmd/update.py +++ b/collection_prep/cmd/update.py @@ -76,7 +76,7 @@ def update_deprecation_notice(documentation): def update_documentation(bodypart): """ - Update the docuementation of the module + Update the documentation of the module :param bodypart: The DOCUMENTATION section of the module """ @@ -91,14 +91,14 @@ def update_documentation(bodypart): update_deprecation_notice(documentation) # remove version added - documentation.pop("version_added", None) + version_added = documentation.pop("version_added", "1.0.0") desc_idx = [ idx for idx, key in enumerate(documentation.keys()) if key == "description" ] # insert version_added after the description - documentation.insert(desc_idx[0] + 1, key="version_added", value="1.0.0") + documentation.insert(desc_idx[0] + 1, key="version_added", value=version_added) repl = ruamel.yaml.dump(documentation, None, ruamel.yaml.RoundTripDumper) # remove version added from anywhere else in the docstring if preceded by 1+ spaces From 1585ec30f7d7e3a00a3fb0d9ce677f6775712119 Mon Sep 17 00:00:00 2001 From: phoffmann Date: Tue, 12 Oct 2021 13:49:54 +0200 Subject: [PATCH 2/2] respect documented version_added value and throw warning if it doesn't exist --- collection_prep/cmd/update.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/collection_prep/cmd/update.py b/collection_prep/cmd/update.py index eaf9dd6..af83afe 100644 --- a/collection_prep/cmd/update.py +++ b/collection_prep/cmd/update.py @@ -91,14 +91,17 @@ def update_documentation(bodypart): update_deprecation_notice(documentation) # remove version added - version_added = documentation.pop("version_added", "1.0.0") - desc_idx = [ - idx - for idx, key in enumerate(documentation.keys()) - if key == "description" - ] - # insert version_added after the description - documentation.insert(desc_idx[0] + 1, key="version_added", value=version_added) + version_added = documentation.pop("version_added", None) + if version_added is not None: + desc_idx = [ + idx + for idx, key in enumerate(documentation.keys()) + if key == "description" + ] + # insert version_added after the description + documentation.insert(desc_idx[0] + 1, key="version_added", value=version_added) + else: + logging.warning("Field 'version_added' not found.") repl = ruamel.yaml.dump(documentation, None, ruamel.yaml.RoundTripDumper) # remove version added from anywhere else in the docstring if preceded by 1+ spaces