Skip to content

gh-89559: Change -X frozen_modules to -X frozen_stdlib. #29301

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ Miscellaneous options
objects and pyc files are desired as well as suppressing the extra visual
location indicators when the interpreter displays tracebacks. See also
:envvar:`PYTHONNODEBUGRANGES`.
* ``-X frozen_modules`` determines whether or not frozen modules are
* ``-X frozen_stdlib`` determines whether or not frozen stdlib modules are
ignored by the import machinery. A value of "on" means they get
imported and "off" means they are ignored. The default is "on"
if this is an installed Python (the normal case). If it's under
Expand Down Expand Up @@ -526,7 +526,7 @@ Miscellaneous options
The ``-X no_debug_ranges`` option.

.. versionadded:: 3.11
The ``-X frozen_modules`` option.
The ``-X frozen_stdlib`` option.


Options you shouldn't use
Expand Down
2 changes: 1 addition & 1 deletion Include/cpython/initconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ typedef struct PyConfig {
int legacy_windows_stdio;
#endif
wchar_t *check_hash_pycs_mode;
int use_frozen_modules;
int use_frozen_stdlib;

/* --- Path configuration inputs ------------ */
int pathconfig_warnings;
Expand Down
4 changes: 2 additions & 2 deletions Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ struct _is {
PyObject *builtins;
// importlib module
PyObject *importlib;
// override for config->use_frozen_modules (for tests)
// override for config->use_frozen_stdlib (for tests)
// (-1: "off", 1: "on", 0: no override)
int override_frozen_modules;
int override_frozen_stdlib;

/* Used in Modules/_threadmodule.c. */
long num_threads;
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/support/import_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ def frozen_modules(enabled=True):
This only applies to modules that haven't been imported yet.
Also, some essential modules will always be imported frozen.
"""
_imp._override_frozen_modules_for_tests(1 if enabled else -1)
_imp._override_frozen_stdlib_for_tests(1 if enabled else -1)
try:
yield
finally:
_imp._override_frozen_modules_for_tests(0)
_imp._override_frozen_stdlib_for_tests(0)


def import_fresh_module(name, fresh=(), blocked=(), *,
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ def run_python(*args):
else:
self.assertEqual(err, b'')

def test_xoption_frozen_modules(self):
def test_xoption_frozen_stdlib(self):
tests = {
('=on', 'FrozenImporter'),
('=off', 'SourceFileLoader'),
('=', 'FrozenImporter'),
('', 'FrozenImporter'),
}
for raw, expected in tests:
cmd = ['-X', f'frozen_modules{raw}',
cmd = ['-X', f'frozen_stdlib{raw}',
#'-c', 'import os; print(os.__spec__.loader.__name__, end="")']
'-c', 'import os; print(os.__spec__.loader, end="")']
with self.subTest(raw):
Expand Down
22 changes: 11 additions & 11 deletions Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'pathconfig_warnings': 1,
'_init_main': 1,
'_isolated_interpreter': 0,
'use_frozen_modules': 1,
'use_frozen_stdlib': 1,
}
if MS_WINDOWS:
CONFIG_COMPAT.update({
Expand Down Expand Up @@ -1149,7 +1149,7 @@ def test_init_setpath(self):
# The current getpath.c doesn't determine the stdlib dir
# in this case.
'stdlib_dir': '',
'use_frozen_modules': -1,
'use_frozen_stdlib': -1,
}
self.default_program_name(config)
env = {'TESTPATH': os.path.pathsep.join(paths)}
Expand All @@ -1173,7 +1173,7 @@ def test_init_setpath_config(self):
# The current getpath.c doesn't determine the stdlib dir
# in this case.
'stdlib_dir': '',
'use_frozen_modules': -1,
'use_frozen_stdlib': -1,
# overridden by PyConfig
'program_name': 'conf_program_name',
'base_executable': 'conf_executable',
Expand Down Expand Up @@ -1271,7 +1271,7 @@ def test_init_setpythonhome(self):
}
self.default_program_name(config)
if not config['executable']:
config['use_frozen_modules'] = -1
config['use_frozen_stdlib'] = -1
env = {'TESTHOME': home, 'PYTHONPATH': paths_str}
self.check_all_configs("test_init_setpythonhome", config,
api=API_COMPAT, env=env)
Expand Down Expand Up @@ -1310,7 +1310,7 @@ def test_init_pybuilddir(self):
# The current getpath.c doesn't determine the stdlib dir
# in this case.
'stdlib_dir': None,
'use_frozen_modules': -1,
'use_frozen_stdlib': -1,
}
env = self.copy_paths_by_env(config)
self.check_all_configs("test_init_compat_config", config,
Expand Down Expand Up @@ -1369,7 +1369,7 @@ def test_init_pyvenv_cfg(self):
config['base_prefix'] = pyvenv_home
config['prefix'] = pyvenv_home
config['stdlib_dir'] = os.path.join(pyvenv_home, 'lib')
config['use_frozen_modules'] = 1
config['use_frozen_stdlib'] = 1

ver = sys.version_info
dll = f'python{ver.major}'
Expand All @@ -1382,7 +1382,7 @@ def test_init_pyvenv_cfg(self):
# The current getpath.c doesn't determine the stdlib dir
# in this case.
config['stdlib_dir'] = None
config['use_frozen_modules'] = -1
config['use_frozen_stdlib'] = -1

env = self.copy_paths_by_env(config)
self.check_all_configs("test_init_compat_config", config,
Expand Down Expand Up @@ -1468,15 +1468,15 @@ def test_get_argc_argv(self):
self.run_embedded_interpreter("test_get_argc_argv")
# ignore output

def test_init_use_frozen_modules(self):
def test_init_use_frozen_stdlib(self):
tests = {
('=on', 1),
('=off', 0),
('=', 1),
('', 1),
}
for raw, expected in tests:
optval = f'frozen_modules{raw}'
optval = f'frozen_stdlib{raw}'
config = {
'parse_argv': 2,
'argv': ['-c'],
Expand All @@ -1485,11 +1485,11 @@ def test_init_use_frozen_modules(self):
'run_command': 'pass\n',
'use_environment': 1,
'xoptions': [optval],
'use_frozen_modules': expected,
'use_frozen_stdlib': expected,
}
env = {'TESTFROZEN': raw[1:]} if raw else None
with self.subTest(repr(raw)):
self.check_all_configs("test_init_use_frozen_modules", config,
self.check_all_configs("test_init_use_frozen_stdlib", config,
api=API_PYTHON, env=env)


Expand Down
4 changes: 2 additions & 2 deletions Misc/NEWS.d/3.11.0a1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ Compiler now removes trailing unused constants from co_consts.
.. nonce: ZPI_3L
.. section: Core and Builtins

Add a new command line option, "-X frozen_modules=[on|off]" to opt out of
Add a new command line option, "-X frozen_stdlib=[on|off]" to opt out of
(or into) using optional frozen modules. This defaults to "on" (or "off" if
it's running out of the source tree).

Expand Down Expand Up @@ -4414,7 +4414,7 @@ before building.

Freeze stdlib modules that are imported during startup. This provides
significant performance improvements to startup. If necessary, use the
previously added "-X frozen_modules=off" commandline option to force
previously added "-X frozen_stdlib=off" commandline option to force
importing the source modules.

..
Expand Down
14 changes: 7 additions & 7 deletions Programs/_testembed.c
Original file line number Diff line number Diff line change
Expand Up @@ -1727,17 +1727,17 @@ static int test_get_argc_argv(void)
}


static int check_use_frozen_modules(const char *rawval)
static int check_use_frozen_stdlib(const char *rawval)
{
wchar_t optval[100];
if (rawval == NULL) {
wcscpy(optval, L"frozen_modules");
wcscpy(optval, L"frozen_stdlib");
}
else if (swprintf(optval, 100,
#if defined(_MSC_VER)
L"frozen_modules=%S",
L"frozen_stdlib=%S",
#else
L"frozen_modules=%s",
L"frozen_stdlib=%s",
#endif
rawval) < 0) {
error("rawval is too long");
Expand All @@ -1764,10 +1764,10 @@ static int check_use_frozen_modules(const char *rawval)
return 0;
}

static int test_init_use_frozen_modules(void)
static int test_init_use_frozen_stdlib(void)
{
const char *envvar = getenv("TESTFROZEN");
return check_use_frozen_modules(envvar);
return check_use_frozen_stdlib(envvar);
}


Expand Down Expand Up @@ -1942,7 +1942,7 @@ static struct TestCase TestCases[] = {
{"test_run_main", test_run_main},
{"test_run_main_loop", test_run_main_loop},
{"test_get_argc_argv", test_get_argc_argv},
{"test_init_use_frozen_modules", test_init_use_frozen_modules},
{"test_init_use_frozen_stdlib", test_init_use_frozen_stdlib},

// Audit
{"test_open_code_hook", test_open_code_hook},
Expand Down
18 changes: 9 additions & 9 deletions Python/clinic/import.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 14 additions & 13 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1071,18 +1071,18 @@ resolve_module_alias(const char *name, const struct _module_alias *aliases,
/* Frozen modules */

static bool
use_frozen(void)
use_frozen_stdlib(void)
{
PyInterpreterState *interp = _PyInterpreterState_GET();
int override = interp->override_frozen_modules;
int override = interp->override_frozen_stdlib;
if (override > 0) {
return true;
}
else if (override < 0) {
return false;
}
else {
return interp->config.use_frozen_modules;
return interp->config.use_frozen_stdlib;
}
}

Expand All @@ -1093,7 +1093,7 @@ list_frozen_module_names()
if (names == NULL) {
return NULL;
}
bool enabled = use_frozen();
bool enabled = use_frozen_stdlib();
const struct _frozen *p;
#define ADD_MODULE(name) \
do { \
Expand Down Expand Up @@ -1170,7 +1170,7 @@ typedef enum {
FROZEN_OKAY,
FROZEN_BAD_NAME, // The given module name wasn't valid.
FROZEN_NOT_FOUND, // It wasn't in PyImport_FrozenModules.
FROZEN_DISABLED, // -X frozen_modules=off (and not essential)
FROZEN_DISABLED, // -X frozen_stdlib=off (and not essential)
FROZEN_EXCLUDED, /* The PyImport_FrozenModules entry has NULL "code"
(module is present but marked as unimportable, stops search). */
FROZEN_INVALID, /* The PyImport_FrozenModules entry is bogus
Expand All @@ -1187,7 +1187,8 @@ set_frozen_error(frozen_status status, PyObject *modname)
err = "No such frozen object named %R";
break;
case FROZEN_DISABLED:
err = "Frozen modules are disabled and the frozen object named %R is not essential";
err = "Non-essential frozen stdlib modules are disabled. " \
"See the '-X frozen_stdlib' documentation.";
break;
case FROZEN_EXCLUDED:
err = "Excluded frozen object named %R";
Expand Down Expand Up @@ -1238,7 +1239,7 @@ look_up_frozen(const char *name)
}
}
// Frozen stdlib modules may be disabled.
if (use_frozen()) {
if (use_frozen_stdlib()) {
for (p = _PyImport_FrozenStdlib; ; p++) {
if (p->name == NULL) {
break;
Expand Down Expand Up @@ -2303,23 +2304,23 @@ _imp__frozen_module_names_impl(PyObject *module)
}

/*[clinic input]
_imp._override_frozen_modules_for_tests
_imp._override_frozen_stdlib_for_tests

override: int
/

(internal-only) Override PyConfig.use_frozen_modules.
(internal-only) Override PyConfig.use_frozen_stdlib.

(-1: "off", 1: "on", 0: no override)
See frozen_modules() in Lib/test/support/import_helper.py.
[clinic start generated code]*/

static PyObject *
_imp__override_frozen_modules_for_tests_impl(PyObject *module, int override)
/*[clinic end generated code: output=36d5cb1594160811 input=8f1f95a3ef21aec3]*/
_imp__override_frozen_stdlib_for_tests_impl(PyObject *module, int override)
/*[clinic end generated code: output=3f769bf38d4fd4cf input=8c1be52885465f03]*/
{
PyInterpreterState *interp = _PyInterpreterState_GET();
interp->override_frozen_modules = override;
interp->override_frozen_stdlib = override;
Py_RETURN_NONE;
}

Expand Down Expand Up @@ -2485,7 +2486,7 @@ static PyMethodDef imp_methods[] = {
_IMP_IS_BUILTIN_METHODDEF
_IMP_IS_FROZEN_METHODDEF
_IMP__FROZEN_MODULE_NAMES_METHODDEF
_IMP__OVERRIDE_FROZEN_MODULES_FOR_TESTS_METHODDEF
_IMP__OVERRIDE_FROZEN_STDLIB_FOR_TESTS_METHODDEF
_IMP_CREATE_DYNAMIC_METHODDEF
_IMP_EXEC_DYNAMIC_METHODDEF
_IMP_EXEC_BUILTIN_METHODDEF
Expand Down
Loading