|
116 | 116 | help="Print a list of module names to stdout and exit", |
117 | 117 | ) |
118 | 118 |
|
| 119 | +parser.add_argument( |
| 120 | + "--generate-stdlib-info", |
| 121 | + action="store_true", |
| 122 | + help="Generate file with stdlib module info", |
| 123 | +) |
| 124 | + |
119 | 125 |
|
120 | 126 | @enum.unique |
121 | 127 | class ModuleState(enum.Enum): |
@@ -281,6 +287,38 @@ def list_module_names(self, *, all: bool = False) -> set[str]: |
281 | 287 | names.update(WINDOWS_MODULES) |
282 | 288 | return names |
283 | 289 |
|
| 290 | + def generate_stdlib_info(self) -> None: |
| 291 | + |
| 292 | + disabled_modules = {modinfo.name for modinfo in self.modules |
| 293 | + if modinfo.state in (ModuleState.DISABLED, ModuleState.DISABLED_SETUP)} |
| 294 | + missing_modules = {modinfo.name for modinfo in self.modules |
| 295 | + if modinfo.state == ModuleState.MISSING} |
| 296 | + na_modules = {modinfo.name for modinfo in self.modules |
| 297 | + if modinfo.state == ModuleState.NA} |
| 298 | + |
| 299 | + content = f'''\ |
| 300 | +# Standard library information used by the traceback module for more informative |
| 301 | +# ModuleNotFound error messages. |
| 302 | +
|
| 303 | +DISABLED_MODULES = {sorted(disabled_modules)!r} |
| 304 | +MISSING_MODULES = {sorted(missing_modules)!r} |
| 305 | +NOT_AVAILABLE_MODULES = {sorted(na_modules)!r} |
| 306 | +WINDOWS_ONLY_MODULES = {sorted(WINDOWS_MODULES)!r} |
| 307 | +
|
| 308 | +MISSING_STDLIB_MODULE_MESSAGES = {{ |
| 309 | + **{{name: f"Windows-only standard library module '{{name}}' was not found" |
| 310 | + for name in WINDOWS_ONLY_MODULES}}, |
| 311 | + **{{name: f"Standard library module disabled during build '{{name}}' was not found" |
| 312 | + for name in DISABLED_MODULES}}, |
| 313 | + **{{name: f"Unsupported platform for standard library module '{{name}}'" |
| 314 | + for name in NOT_AVAILABLE_MODULES}}, |
| 315 | +}} |
| 316 | +''' |
| 317 | + |
| 318 | + output_path = self.builddir / "_stdlib_modules_info.py" |
| 319 | + with open(output_path, "w", encoding="utf-8") as f: |
| 320 | + f.write(content) |
| 321 | + |
284 | 322 | def get_builddir(self) -> pathlib.Path: |
285 | 323 | try: |
286 | 324 | with open(self.pybuilddir_txt, encoding="utf-8") as f: |
@@ -499,6 +537,9 @@ def main() -> None: |
499 | 537 | names = checker.list_module_names(all=True) |
500 | 538 | for name in sorted(names): |
501 | 539 | print(name) |
| 540 | + elif args.generate_stdlib_info: |
| 541 | + checker.check() |
| 542 | + checker.generate_stdlib_info() |
502 | 543 | else: |
503 | 544 | checker.check() |
504 | 545 | checker.summary(verbose=args.verbose) |
|
0 commit comments