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

Function check_docstrings

tools/precommit/docstrings.py:852–1073  ·  view source on GitHub ↗

Check salt's docstrings

(
    ctx: Context,
    files: list[pathlib.Path],
    suppress_warnings: bool = False,
    check_proper_formatting: bool = False,
    error_on_known_failures: bool = False,
)

Source from the content-addressed store, hash-verified

850 },
851)
852def check_docstrings(
853 ctx: Context,
854 files: list[pathlib.Path],
855 suppress_warnings: bool = False,
856 check_proper_formatting: bool = False,
857 error_on_known_failures: bool = False,
858) -> None:
859 """
860 Check salt's docstrings
861 """
862 if not files:
863 _files = list(SALT_CODE_DIR.rglob("*.py"))
864 else:
865 _files = [fpath.resolve() for fpath in files if fpath.suffix == ".py"]
866
867 errors = 0
868 exitcode = 0
869 warnings = 0
870 for path in _files:
871 if str(path).startswith(str(tools.utils.REPO_ROOT / "salt" / "ext")):
872 continue
873 contents = path.read_text()
874 try:
875 module = ast.parse(path.read_text(), filename=str(path))
876 module_docstring = ast.get_docstring(module, clean=False)
877 if module_docstring:
878 error = _check_valid_versions_on_docstrings(module_docstring)
879 if error:
880 errors += 1
881 exitcode = 1
882 ctx.error(
883 "The module '{}' does not provide a proper `{}` version: {!r} is not valid.".format(
884 path.relative_to(tools.utils.REPO_ROOT),
885 *error,
886 )
887 )
888
889 for funcdef in [
890 node for node in module.body if isinstance(node, ast.FunctionDef)
891 ]:
892 docstring = ast.get_docstring(funcdef, clean=False)
893 if docstring:
894 error = _check_valid_versions_on_docstrings(docstring)
895 if error:
896 errors += 1
897 exitcode = 1
898 ctx.error(
899 "The module '{}' does not provide a proper `{}` version: {!r} is not valid.".format(
900 path,
901 *error,
902 )
903 )
904 annotate(
905 ctx,
906 "error",
907 path,
908 funcdef.lineno,
909 funcdef.body[0].lineno,

Callers

nothing calls this directly

Calls 13

annotateFunction · 0.85
formatMethod · 0.80
exitMethod · 0.80
listFunction · 0.50
openFunction · 0.50
read_textMethod · 0.45
parseMethod · 0.45
errorMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected