Build a python module to doc module cache
()
| 60 | |
| 61 | |
| 62 | def 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" |