@@ -108,27 +108,34 @@ def autofix_docstring(docstring, filename):
108108)
109109
110110
111- def _convert_version_names_to_numbers ( docstring , filename ):
111+ def _handle_convert_version_names_to_numbers_match ( match ):
112112 """
113- Convert Salt version names to their version numbers counterpart
113+ Convert every match with a properly formatted version.
114114 """
115- for match in CONVERT_VERSION_NAMES_TO_NUMBERS_RE .finditer (docstring ):
116- vtype = match .group ("vtype" )
117- version = match .group ("version" )
118- versions = [vs .strip () for vs in version .split ("," )]
119- parsed_versions = []
120- for version in versions :
115+ vtype = match .group ("vtype" )
116+ version = match .group ("version" )
117+ versions = [vs .strip () for vs in version .split ("," )]
118+ parsed_versions = []
119+ for version in versions :
120+ try :
121+ version = SaltStackVersion .from_name (version ).string
122+ except ValueError :
121123 try :
122- version = SaltStackVersion .from_name (version ).string
124+ version = SaltStackVersion .parse (version ).string
123125 except ValueError :
124- try :
125- version = SaltStackVersion .parse (version ).string
126- except ValueError :
127- pass
128- parsed_versions .append (version )
129- replace_contents = ".. {}:: {}" .format (vtype , "," .join (parsed_versions ))
130- docstring = docstring .replace (match .group (0 ), replace_contents .rstrip ())
131- return docstring
126+ pass
127+ parsed_versions .append (version )
128+ replace_contents = ".. {}:: {}" .format (vtype , "," .join (parsed_versions ))
129+ return replace_contents
130+
131+
132+ def _convert_version_names_to_numbers (docstring , filename ):
133+ """
134+ Convert Salt version names to their version numbers counterpart
135+ """
136+ return CONVERT_VERSION_NAMES_TO_NUMBERS_RE .sub (
137+ _handle_convert_version_names_to_numbers_match , docstring
138+ )
132139
133140
134141CLI_EXAMPLE_CASE_AND_SPACING_RE = re .compile (
@@ -157,21 +164,22 @@ def _fix_simple_cli_example_spacing_issues(docstring, filename):
157164)
158165
159166
167+ def _handle_fix_directives_formatting_match (match ):
168+ return (
169+ "\n {}.. {}:: {}" .format (
170+ match .group ("spc1" ) or "" ,
171+ match .group ("directive" ),
172+ match .group ("remaining" ) or "" ,
173+ ).rstrip ()
174+ + "\n "
175+ )
176+
177+
160178def _fix_directives_formatting (docstring , filename ):
161179 """
162180 Fix directive definition spacing
163181 """
164- for match in DIRECTIVES_FORMATTING_RE .finditer (docstring ):
165- replacement = (
166- "\n {}.. {}:: {}" .format (
167- match .group ("spc1" ) or "" ,
168- match .group ("directive" ),
169- match .group ("remaining" ) or "" ,
170- ).rstrip ()
171- + "\n "
172- )
173- docstring = docstring .replace (match .group (0 ), replacement )
174- return docstring
182+ return DIRECTIVES_FORMATTING_RE .sub (_handle_fix_directives_formatting_match , docstring )
175183
176184
177185FIX_CODE_BLOCKS_RE = re .compile (
0 commit comments