MCPcopy Index your code
hub / github.com/saltstack/salt / check_virtual

Function check_virtual

tools/precommit/docs.py:223–252  ·  view source on GitHub ↗

Check if .rst files for each module contains the text ".. _virtual" indicating it is a virtual doc page, and, in case a module exists by the same name, it's going to be shaddowed and not accessible

(ctx: Context, files: list[pathlib.Path])

Source from the content-addressed store, hash-verified

221
222
223def check_virtual(ctx: Context, files: list[pathlib.Path]) -> int:
224 """
225 Check if .rst files for each module contains the text ".. _virtual"
226 indicating it is a virtual doc page, and, in case a module exists by
227 the same name, it's going to be shaddowed and not accessible
228 """
229 exitcode = 0
230 files = build_docs_paths(files)
231 for path in files:
232 if path.name == "index.rst":
233 continue
234 try:
235 contents = path.read_text()
236 except Exception as exc: # pylint: disable=broad-except
237 ctx.error(f"Error while processing '{path}': {exc}")
238 exitcode += 1
239 continue
240 if ".. _virtual-" in contents:
241 try:
242 python_module = DOC_PATH_TO_PYTHON_MODULE[path]
243 ctx.error(
244 f"The doc file at {path} indicates that it's virtual, yet, "
245 f"there's a python module at {python_module} that will "
246 "shaddow it.",
247 )
248 exitcode += 1
249 except KeyError:
250 # This is what we're expecting
251 continue
252 return exitcode
253
254
255def check_module_indexes(ctx: Context, files: list[pathlib.Path]) -> int:

Callers 1

checkFunction · 0.70

Calls 3

build_docs_pathsFunction · 0.85
read_textMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected