diff options
author | Victor Stinner <vstinner@python.org> | 2021-03-10 10:14:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-10 10:14:07 (GMT) |
commit | 307745aa42196ad3fd97fee4a1ae6496bb895596 (patch) | |
tree | ac50f9198da22b1400df4815b6a875fd3364bb70 /Tools/scripts | |
parent | b4f9089d4aa787c5b74134c98e5f0f11d9e63095 (diff) | |
download | cpython-307745aa42196ad3fd97fee4a1ae6496bb895596.zip cpython-307745aa42196ad3fd97fee4a1ae6496bb895596.tar.gz cpython-307745aa42196ad3fd97fee4a1ae6496bb895596.tar.bz2 |
bpo-43445: Add frozen modules to sys.stdlib_module_names (GH-24798)
Add frozen modules to sys.stdlib_module_names. For example, add
"_frozen_importlib" and "_frozen_importlib_external" names.
Add "list_frozen" command to Programs/_testembed.
Diffstat (limited to 'Tools/scripts')
-rw-r--r-- | Tools/scripts/generate_stdlib_module_names.py | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/Tools/scripts/generate_stdlib_module_names.py b/Tools/scripts/generate_stdlib_module_names.py index 379b262..b8afc89 100644 --- a/Tools/scripts/generate_stdlib_module_names.py +++ b/Tools/scripts/generate_stdlib_module_names.py @@ -11,14 +11,16 @@ SRC_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) STDLIB_PATH = os.path.join(SRC_DIR, 'Lib') MODULES_SETUP = os.path.join(SRC_DIR, 'Modules', 'Setup') SETUP_PY = os.path.join(SRC_DIR, 'setup.py') +TEST_EMBED = os.path.join(SRC_DIR, 'Programs', '_testembed') IGNORE = { '__init__', '__pycache__', 'site-packages', - # test modules - '__phello__.foo', + # Test modules and packages + '__hello__', + '__phello__', '_ctypes_test', '_testbuffer', '_testcapi', @@ -103,13 +105,40 @@ def list_modules_setup_extensions(names): names.add(name) +# List frozen modules of the PyImport_FrozenModules list (Python/frozen.c). +# Use the "./Programs/_testembed list_frozen" command. +def list_frozen(names): + args = [TEST_EMBED, 'list_frozen'] + proc = subprocess.run(args, stdout=subprocess.PIPE, text=True) + exitcode = proc.returncode + if exitcode: + cmd = ' '.join(args) + print(f"{cmd} failed with exitcode {exitcode}") + sys.exit(exitcode) + for line in proc.stdout.splitlines(): + name = line.strip() + names.add(name) + + def list_modules(): names = set(sys.builtin_module_names) | set(WINDOWS_MODULES) list_modules_setup_extensions(names) list_setup_extensions(names) list_packages(names) list_python_modules(names) - names -= set(IGNORE) + list_frozen(names) + + # Remove ignored packages and modules + for name in list(names): + package_name = name.split('.')[0] + # package_name can be equal to name + if package_name in IGNORE: + names.discard(name) + + for name in names: + if "." in name: + raise Exception("sub-modules must not be listed") + return names |