Resolve module path, trying file or directory. Args: name: Module name (e.g., "dataclasses", "json") prefix: CPython directory prefix prefer: "file" to try .py first, "dir" to try directory first
(
name: str, prefix: str = "cpython", prefer: str = "file"
)
| 143 | |
| 144 | |
| 145 | def resolve_module_path( |
| 146 | name: str, prefix: str = "cpython", prefer: str = "file" |
| 147 | ) -> pathlib.Path: |
| 148 | """ |
| 149 | Resolve module path, trying file or directory. |
| 150 | |
| 151 | Args: |
| 152 | name: Module name (e.g., "dataclasses", "json") |
| 153 | prefix: CPython directory prefix |
| 154 | prefer: "file" to try .py first, "dir" to try directory first |
| 155 | """ |
| 156 | file_path = pathlib.Path(f"{prefix}/Lib/{name}.py") |
| 157 | dir_path = pathlib.Path(f"{prefix}/Lib/{name}") |
| 158 | |
| 159 | if prefer == "file": |
| 160 | if file_path.exists(): |
| 161 | return file_path |
| 162 | if dir_path.exists(): |
| 163 | return dir_path |
| 164 | return file_path |
| 165 | else: |
| 166 | if dir_path.exists(): |
| 167 | return dir_path |
| 168 | if file_path.exists(): |
| 169 | return file_path |
| 170 | return dir_path |
| 171 | |
| 172 | |
| 173 | def construct_lib_path(prefix: str, *parts: str) -> pathlib.Path: |
no test coverage detected