MCPcopy
hub / github.com/saltstack/salt / check_module_indexes

Function check_module_indexes

tools/precommit/docs.py:255–376  ·  view source on GitHub ↗
(ctx: Context, files: list[pathlib.Path])

Source from the content-addressed store, hash-verified

253
254
255def check_module_indexes(ctx: Context, files: list[pathlib.Path]) -> int:
256 exitcode = 0
257 files = build_docs_paths(files)
258 for path in files:
259 if path.name != "index.rst":
260 continue
261 contents = path.read_text()
262 if ".. autosummary::" not in contents:
263 continue
264 module_index_block = re.search(
265 r"""
266 \.\.\s+autosummary::\s*\n
267 (\s+:[a-z]+:.*\n)*
268 (\s*\n)+
269 (?P<mods>(\s*[a-z0-9_\.]+\s*\n)+)
270 """,
271 contents,
272 flags=re.VERBOSE,
273 )
274
275 if not module_index_block:
276 continue
277
278 module_index = re.findall(
279 r"""\s*([a-z0-9_\.]+)\s*\n""", module_index_block.group("mods")
280 )
281 if module_index != sorted(module_index):
282 exitcode += 1
283 ctx.error(
284 f"The autosummary mods in {path} are not properly sorted. Please sort them.",
285 )
286
287 module_index_duplicates = [
288 mod for mod, count in collections.Counter(module_index).items() if count > 1
289 ]
290 if module_index_duplicates:
291 exitcode += 1
292 ctx.error(
293 f"Module index {path} contains duplicates: {module_index_duplicates}"
294 )
295 # Let's check if all python modules are included in the index
296 path_parts = list(path.parts)
297 # drop doc
298 path_parts.pop(0)
299 # drop ref
300 path_parts.pop(0)
301 # drop "index.rst"
302 path_parts.pop()
303 # drop "all"
304 path_parts.pop()
305 package = path_parts.pop(0)
306 if package == "clouds":
307 package = "cloud"
308 if package == "file_server":
309 package = "fileserver"
310 if package == "configuration" and path_parts == ["logging"]:
311 package = "log_handlers"
312 path_parts = []

Callers 1

checkFunction · 0.85

Calls 11

build_docs_pathsFunction · 0.85
groupMethod · 0.80
listFunction · 0.50
setFunction · 0.50
read_textMethod · 0.45
searchMethod · 0.45
errorMethod · 0.45
itemsMethod · 0.45
popMethod · 0.45
joinpathMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected