2727import logging
2828import os
2929import pathlib
30+ import pprint
3031import re
3132import sys
3233import sysconfig
118119)
119120
120121parser .add_argument (
121- "--generate-stdlib-info" ,
122- nargs = "?" ,
123- const = True ,
124- help = "Generate file with stdlib module info, with optional config file" ,
122+ "--generate-missing-stdlib-info" ,
123+ action = "store_true" ,
124+ help = "Generate file with stdlib module info" ,
125+ )
126+
127+ parser .add_argument (
128+ "--with-missing-stdlib-config" ,
129+ metavar = "CONFIG_FILE" ,
130+ help = "Path to JSON config file with custom missing module messages" ,
125131)
126132
127133
@@ -289,14 +295,14 @@ def list_module_names(self, *, all: bool = False) -> set[str]:
289295 names .update (WINDOWS_MODULES )
290296 return names
291297
292- def generate_stdlib_info (self , config_path : str | None = None ) -> None :
298+ def generate_missing_stdlib_info (self , config_path : str | None = None ) -> None :
293299 config_messages = {}
294300 if config_path :
295301 try :
296302 with open (config_path , encoding = 'utf-8' ) as f :
297303 config_messages = json .load (f )
298304 except (FileNotFoundError , json .JSONDecodeError ) as e :
299- logger . error ("Failed to load distributor config %s: %s" , config_path , e )
305+ raise RuntimeError ("Failed to load missing stdlib config %s: %s" , config_path , e )
300306
301307 messages = {}
302308 for name in WINDOWS_MODULES :
@@ -313,11 +319,12 @@ def generate_stdlib_info(self, config_path: str | None = None) -> None:
313319 content = f'''\
314320 # Standard library information used by the traceback module for more informative
315321# ModuleNotFound error messages.
322+ # Generated by check_extension_modules.py
316323
317- MISSING_STDLIB_MODULE_MESSAGES = { messages !r }
324+ MISSING_STDLIB_MODULE_MESSAGES = { pprint . pformat ( messages ) }
318325'''
319326
320- output_path = self .builddir / "_stdlib_modules_info .py"
327+ output_path = self .builddir / "_missing_stdlib_module_info .py"
321328 with open (output_path , "w" , encoding = "utf-8" ) as f :
322329 f .write (content )
323330
@@ -539,10 +546,9 @@ def main() -> None:
539546 names = checker .list_module_names (all = True )
540547 for name in sorted (names ):
541548 print (name )
542- elif args .generate_stdlib_info :
549+ elif args .generate_missing_stdlib_info :
543550 checker .check ()
544- config_path = None if args .generate_stdlib_info is True else args .generate_stdlib_info
545- checker .generate_stdlib_info (config_path )
551+ checker .generate_missing_stdlib_info (args .with_missing_stdlib_config )
546552 else :
547553 checker .check ()
548554 checker .summary (verbose = args .verbose )
0 commit comments