Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-139707: Add mechanism for distributors to supply error messages for missing stdlib modules#140783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
gh-139707: Add mechanism for distributors to supply error messages for missing stdlib modules #140783
Changes from all commits
105d551c3d802b6b2d9347f10e66a0dd99b7a3685062ffb398d5ca01185e890902274c9c74f692ed0eb3f9b66b39ac50d9faea0924c0c0bbFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Add configure option :option:`--with-missing-stdlib-config=FILE` allows | ||
| which distributors to pass a `JSON <https://www.json.org/json-en.html>`_ | ||
| configuration file containing custom error messages for missing | ||
| :term:`standard library` modules. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -23,9 +23,11 @@ | ||
| import _imp | ||
| import argparse | ||
| import enum | ||
| import json | ||
| import logging | ||
| import os | ||
| import pathlib | ||
| import pprint | ||
| import re | ||
| import sys | ||
| import sysconfig | ||
| @@ -116,6 +118,18 @@ | ||
| help="Print a list of module names to stdout and exit", | ||
| ) | ||
| parser.add_argument( | ||
| "--generate-missing-stdlib-info", | ||
| action="store_true", | ||
| help="Generate file with stdlib module info", | ||
| ) | ||
| parser.add_argument( | ||
| "--with-missing-stdlib-config", | ||
| metavar="CONFIG_FILE", | ||
| help="Path to JSON config file with custom missing module messages", | ||
| ) | ||
| @enum.unique | ||
| class ModuleState(enum.Enum): | ||
| @@ -281,6 +295,39 @@ def list_module_names(self, *, all: bool = False) -> set[str]: | ||
| names.update(WINDOWS_MODULES) | ||
| return names | ||
| def generate_missing_stdlib_info(self, config_path: str | None = None) -> None: | ||
| config_messages = {} | ||
| if config_path: | ||
| try: | ||
| with open(config_path, encoding='utf-8') as f: | ||
| config_messages = json.load(f) | ||
| except (FileNotFoundError, json.JSONDecodeError) as e: | ||
| raise RuntimeError(f"Failed to load missing stdlib config {config_path!r}") from e | ||
| messages = {} | ||
| for name in WINDOWS_MODULES: | ||
| messages[name] = f"Unsupported platform for Windows-only standard library module {name!r}" | ||
| for modinfo in self.modules: | ||
| if modinfo.state in (ModuleState.DISABLED, ModuleState.DISABLED_SETUP): | ||
| messages[modinfo.name] = f"Standard library module disabled during build {modinfo.name!r} was not found" | ||
| elif modinfo.state == ModuleState.NA: | ||
| messages[modinfo.name] = f"Unsupported platform for standard library module {modinfo.name!r}" | ||
| messages.update(config_messages) | ||
| content = f'''\ | ||
StanFromIreland marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| # Standard library information used by the traceback module for more informative | ||
| # ModuleNotFound error messages. | ||
| # Generated by check_extension_modules.py | ||
| _MISSING_STDLIB_MODULE_MESSAGES = {pprint.pformat(messages)} | ||
| ''' | ||
| output_path = self.builddir / "_missing_stdlib_info.py" | ||
| with open(output_path, "w", encoding="utf-8") as f: | ||
| f.write(content) | ||
| def get_builddir(self) -> pathlib.Path: | ||
| try: | ||
| with open(self.pybuilddir_txt, encoding="utf-8") as f: | ||
| @@ -499,6 +546,9 @@ def main() -> None: | ||
| names = checker.list_module_names(all=True) | ||
| for name in sorted(names): | ||
| print(name) | ||
| elif args.generate_missing_stdlib_info: | ||
| checker.check() | ||
| checker.generate_missing_stdlib_info(args.with_missing_stdlib_config) | ||
| else: | ||
| checker.check() | ||
| checker.summary(verbose=args.verbose) | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -307,6 +307,15 @@ if test "$with_pkg_config" = yes -a -z "$PKG_CONFIG"; then | ||
| AC_MSG_ERROR([pkg-config is required])] | ||
| fi | ||
| dnl Allow distributors to provide custom missing stdlib module error messages | ||
| AC_ARG_WITH([missing-stdlib-config], | ||
StanFromIreland marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| [AS_HELP_STRING([--with-missing-stdlib-config=FILE], | ||
| [File with custom module error messages for missing stdlib modules])], | ||
| [MISSING_STDLIB_CONFIG="$withval"], | ||
| [MISSING_STDLIB_CONFIG=""] | ||
| ) | ||
| AC_SUBST([MISSING_STDLIB_CONFIG]) | ||
| # Set name for machine-dependent library files | ||
| AC_ARG_VAR([MACHDEP], [name for machine-dependent library files]) | ||
| AC_MSG_CHECKING([MACHDEP]) | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.