mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Automatically replace version names by version numbers
This commit is contained in:
parent
06e111ff0a
commit
4245c40cef
1 changed files with 25 additions and 1 deletions
|
@ -185,10 +185,34 @@ def _check_cli_example_proper_formatting(docstring):
|
|||
|
||||
def _autofix_docstring(docstring):
|
||||
return _fix_codeblocks(
|
||||
_fix_directives_formatting(_fix_simple_cli_example_spacing_issues(docstring))
|
||||
_convert_version_names_to_numbers(
|
||||
_fix_directives_formatting(
|
||||
_fix_simple_cli_example_spacing_issues(docstring)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def _convert_version_names_to_numbers(docstring):
|
||||
directive_regex = re.compile(
|
||||
".. ((?P<vtype>(versionadded|versionchanged|deprecated)):: (?P<version>.*))"
|
||||
)
|
||||
for match in directive_regex.finditer(docstring):
|
||||
vtype = match.group("vtype")
|
||||
version = match.group("version")
|
||||
versions = [vs.strip() for vs in version.split(",")]
|
||||
parsed_versions = []
|
||||
for vs in versions:
|
||||
try:
|
||||
vs = SaltStackVersion.from_name(vs).string
|
||||
except ValueError:
|
||||
pass
|
||||
parsed_versions.append(vs)
|
||||
replace_contents = ".. {}:: {}".format(vtype, ", ".join(parsed_versions))
|
||||
docstring = docstring.replace(match.group(0), replace_contents)
|
||||
return docstring
|
||||
|
||||
|
||||
def _fix_simple_cli_example_spacing_issues(docstring):
|
||||
case_and_spacing_regex = re.compile(
|
||||
r"CLI Example(?P<plural>s)?(?:[\s]+)?:(?:[^\n]+)?(?:[\n]+)",
|
||||
|
|
Loading…
Add table
Reference in a new issue