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

Function build_path_cache

tools/precommit/docs.py:62–138  ·  view source on GitHub ↗

Build a python module to doc module cache

()

Source from the content-addressed store, hash-verified

60
61
62def build_path_cache():
63 """
64 Build a python module to doc module cache
65 """
66
67 for path in SALT_CODE_DIR.rglob("*.py"):
68 path = path.resolve().relative_to(tools.utils.REPO_ROOT)
69 strpath = str(path)
70 # Resource type packages document their __init__.py at the
71 # ``doc/ref/resources/all/salt.resources.<rtype>.rst`` stub.
72 # Allow that one __init__.py through the filter below.
73 is_resource_type_init = (
74 strpath.startswith("salt/resources/")
75 and strpath.endswith("/__init__.py")
76 and strpath.count("/") == 3
77 )
78 if strpath.endswith("__init__.py") and not is_resource_type_init:
79 continue
80 if not strpath.startswith(CHECK_PATHS):
81 continue
82 if strpath.startswith(EXCLUDE_PATHS):
83 continue
84
85 parts = list(path.parts)
86 stub_path = DOCS_DIR / "ref"
87 # Remove salt from parts
88 parts.pop(0)
89 # Remove the package from parts
90 package = parts.pop(0)
91 # Remove the module from parts
92 module = parts.pop()
93
94 if is_resource_type_init:
95 # parts after pops: [<rtype>]; module is "__init__.py".
96 # Map to doc/ref/resources/all/salt.resources.<rtype>.rst.
97 rtype = parts[0] if parts else None
98 if rtype:
99 stub_path = (
100 stub_path / "resources" / "all" / f"salt.resources.{rtype}.rst"
101 )
102 stub_path = stub_path.relative_to(tools.utils.REPO_ROOT)
103 PYTHON_MODULE_TO_DOC_PATH[path] = stub_path
104 if path.exists():
105 DOC_PATH_TO_PYTHON_MODULE[stub_path] = path
106 continue
107
108 if package == "cloud":
109 package = "clouds"
110 if package == "fileserver":
111 package = "file_server"
112 if package == "netapi":
113 # These are handled differently
114 if not parts:
115 # This is rest_wsgi
116 stub_path = (
117 stub_path
118 / package
119 / "all"

Callers 1

docs.pyFile · 0.85

Calls 4

listFunction · 0.50
countMethod · 0.45
popMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected