[Python-checkins] bpo-45189: Drop the "list_frozen" command from _test_embed. (GH-30273)
corona10
webhook-mailer at python.org
Mon Dec 27 21:06:02 EST 2021
https://github.com/python/cpython/commit/196b53eb1e62871ca80dee180e4891b4dd5c52ac
commit: 196b53eb1e62871ca80dee180e4891b4dd5c52ac
branch: main
author: Dong-hee Na <donghee.na at python.org>
committer: corona10 <donghee.na92 at gmail.com>
date: 2021-12-28T11:05:50+09:00
summary:
bpo-45189: Drop the "list_frozen" command from _test_embed. (GH-30273)
files:
M Programs/_testembed.c
M Tools/scripts/generate_stdlib_module_names.py
diff --git a/Programs/_testembed.c b/Programs/_testembed.c
index fc5f44d5eb626..b31781938eb39 100644
--- a/Programs/_testembed.c
+++ b/Programs/_testembed.c
@@ -1827,26 +1827,6 @@ static int test_frozenmain(void)
}
#endif // !MS_WINDOWS
-
-// List frozen modules.
-// Command used by Tools/scripts/generate_stdlib_module_names.py script.
-static int list_frozen(void)
-{
- const struct _frozen *p;
- for (p = _PyImport_FrozenBootstrap; ; p++) {
- if (p->name == NULL)
- break;
- printf("%s\n", p->name);
- }
- for (p = _PyImport_FrozenStdlib; ; p++) {
- if (p->name == NULL)
- break;
- printf("%s\n", p->name);
- }
- return 0;
-}
-
-
static int test_repeated_init_and_inittab(void)
{
// bpo-44441: Py_RunMain() must reset PyImport_Inittab at exit.
@@ -1960,8 +1940,6 @@ static struct TestCase TestCases[] = {
{"test_frozenmain", test_frozenmain},
#endif
- // Command
- {"list_frozen", list_frozen},
{NULL, NULL}
};
diff --git a/Tools/scripts/generate_stdlib_module_names.py b/Tools/scripts/generate_stdlib_module_names.py
index 3e896ba737543..fe1e429ebce17 100644
--- a/Tools/scripts/generate_stdlib_module_names.py
+++ b/Tools/scripts/generate_stdlib_module_names.py
@@ -1,5 +1,6 @@
# This script lists the names of standard library modules
# to update Python/stdlib_mod_names.h
+import _imp
import os.path
import re
import subprocess
@@ -11,7 +12,6 @@
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__',
@@ -117,16 +117,11 @@ def list_modules_setup_extensions(names):
# 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)
submodules = set()
- for line in proc.stdout.splitlines():
- name = line.strip()
+ for name in _imp._frozen_module_names():
+ # To skip __hello__, __hello_alias__ and etc.
+ if name.startswith('__'):
+ continue
if '.' in name:
submodules.add(name)
else:
More information about the Python-checkins
mailing list