Get all top-level module names from cpython/Lib/. Includes private modules (_*) that are not hard_deps of other modules. Returns: Sorted list of module names (without .py extension)
(cpython_prefix: str)
| 17 | |
| 18 | |
| 19 | def get_all_modules(cpython_prefix: str) -> list[str]: |
| 20 | """Get all top-level module names from cpython/Lib/. |
| 21 | |
| 22 | Includes private modules (_*) that are not hard_deps of other modules. |
| 23 | |
| 24 | Returns: |
| 25 | Sorted list of module names (without .py extension) |
| 26 | """ |
| 27 | from update_lib.deps import resolve_hard_dep_parent |
| 28 | |
| 29 | lib_dir = pathlib.Path(cpython_prefix) / "Lib" |
| 30 | if not lib_dir.exists(): |
| 31 | return [] |
| 32 | |
| 33 | modules = set() |
| 34 | for entry in lib_dir.iterdir(): |
| 35 | # Skip hidden files |
| 36 | if entry.name.startswith("."): |
| 37 | continue |
| 38 | # Skip test directory |
| 39 | if entry.name == "test": |
| 40 | continue |
| 41 | |
| 42 | if entry.is_file() and entry.suffix == ".py": |
| 43 | name = entry.stem |
| 44 | elif entry.is_dir() and (entry / "__init__.py").exists(): |
| 45 | name = entry.name |
| 46 | else: |
| 47 | continue |
| 48 | |
| 49 | # Skip modules that are hard_deps of other modules |
| 50 | # e.g., _pydatetime is a hard_dep of datetime, pydoc_data is a hard_dep of pydoc |
| 51 | if resolve_hard_dep_parent(name, cpython_prefix) is not None: |
| 52 | continue |
| 53 | |
| 54 | modules.add(name) |
| 55 | |
| 56 | return sorted(modules) |
| 57 | |
| 58 | |
| 59 | def format_deps_tree( |
no test coverage detected