Skip to content

Commit b27aa17

Browse files
authored
Implement Ansible version cut-off (#76)
* Implement Ansible version cut-off. * Simplify function. * Fix wrong docstring.
1 parent 95f147a commit b27aa17

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
minor_changes:
2+
- "Stop mentioning the version features were added for Ansible if the Ansible version is before 2.7 (https://github.com/ansible-community/antsibull-docs/pull/76)."

src/antsibull_docs/jinja2/tests.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@
1414
from antsibull_core.vendored.collections import is_sequence
1515

1616

17-
# if a module is added in a version of Ansible older than this, don't print the version added
18-
# information in the module documentation because everyone is assumed to be running something newer
19-
# than this already.
20-
TOO_OLD_TO_BE_NOTABLE = '0.0.0'
17+
# The following dictionary maps collection names to cut-off versions. If a version of such a
18+
# collection is mentioned as when a feature was added that is older than the cut-off version,
19+
# we do not print the version.
20+
TOO_OLD_TO_BE_NOTABLE = {
21+
'ansible.builtin': '2.7',
22+
}
2123

2224
test_list: t.Callable[[t.Any], bool] = partial(is_sequence, include_strings=False)
2325

2426

25-
def still_relevant(version, cutoff=TOO_OLD_TO_BE_NOTABLE, collection=None):
27+
def still_relevant(version, collection=None):
2628
"""
2729
Calculates whether the given version is older than a cutoff value
2830
2931
:arg version: Version to check
30-
:arg cutoff: Calculate whether `version` is older than this
31-
:returns: True if the `version` is older than `cutoff` otherwise True.
32+
:returns: False if the `version` is older than the cutoff version, otherwise True.
3233
3334
.. note:: This is similar to the ansible `version_compare` test but needs to handle the
3435
`historical` version and empty version.
@@ -41,13 +42,16 @@ def still_relevant(version, cutoff=TOO_OLD_TO_BE_NOTABLE, collection=None):
4142
if version == 'historical':
4243
return False
4344

45+
cutoff = TOO_OLD_TO_BE_NOTABLE.get(collection)
46+
if cutoff is None:
47+
# If we do not have a cut-off version for the collection, we simply declare it to be
48+
# still relevant
49+
return True
50+
4451
if collection == 'ansible.builtin':
4552
Version = PypiVer
46-
elif collection is not None:
47-
Version = SemVer
4853
else:
49-
# This used to be distutils.version.LooseVersion
50-
Version = PypiVer
54+
Version = SemVer
5155

5256
try:
5357
version = Version(version)

0 commit comments

Comments
 (0)