mirror of
https://github.com/python/cpython
synced 2024-10-14 09:01:41 +00:00
bpo-42955: Rename module_names to sys.stdlib_module_names (GH-24332)
* Rename _Py_module_names to _Py_stdlib_module_names. * Rename Python/module_names.h to Python/stdlib_module_names.h.
This commit is contained in:
parent
501d4a51e3
commit
9852cb3811
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
|
@ -63,7 +63,7 @@ jobs:
|
||||||
# Build Python with the libpython dynamic library
|
# Build Python with the libpython dynamic library
|
||||||
./configure --with-pydebug --enable-shared
|
./configure --with-pydebug --enable-shared
|
||||||
make -j4 regen-all
|
make -j4 regen-all
|
||||||
make regen-module-names
|
make regen-stdlib-module-names
|
||||||
- name: Check for changes
|
- name: Check for changes
|
||||||
run: |
|
run: |
|
||||||
changes=$(git status --porcelain)
|
changes=$(git status --porcelain)
|
||||||
|
|
|
@ -172,7 +172,7 @@ before_script:
|
||||||
- eval "$(pyenv init -)"
|
- eval "$(pyenv init -)"
|
||||||
- pyenv global 3.8
|
- pyenv global 3.8
|
||||||
- PYTHON_FOR_REGEN=python3.8 make -j4 regen-all
|
- PYTHON_FOR_REGEN=python3.8 make -j4 regen-all
|
||||||
- make regen-module-names
|
- make regen-stdlib-module-names
|
||||||
- changes=`git status --porcelain`
|
- changes=`git status --porcelain`
|
||||||
- |
|
- |
|
||||||
# Check for changes in regenerated files
|
# Check for changes in regenerated files
|
||||||
|
|
|
@ -157,7 +157,7 @@ always available.
|
||||||
Python interpreter. (This information is not available in any other way ---
|
Python interpreter. (This information is not available in any other way ---
|
||||||
``modules.keys()`` only lists the imported modules.)
|
``modules.keys()`` only lists the imported modules.)
|
||||||
|
|
||||||
See also the :attr:`sys.module_names` list.
|
See also the :attr:`sys.stdlib_module_names` list.
|
||||||
|
|
||||||
|
|
||||||
.. function:: call_tracing(func, args)
|
.. function:: call_tracing(func, args)
|
||||||
|
@ -1062,24 +1062,6 @@ always available.
|
||||||
This is still called as a fallback if a :data:`meta_path` entry doesn't
|
This is still called as a fallback if a :data:`meta_path` entry doesn't
|
||||||
have a :meth:`~importlib.abc.MetaPathFinder.find_spec` method.
|
have a :meth:`~importlib.abc.MetaPathFinder.find_spec` method.
|
||||||
|
|
||||||
.. data:: module_names
|
|
||||||
|
|
||||||
A frozenset of strings containing the names of standard library modules.
|
|
||||||
|
|
||||||
It is the same on all platforms. Modules which are not available on
|
|
||||||
some platforms and modules disabled at Python build are also listed.
|
|
||||||
All module kinds are listed: pure Python, built-in, frozen and extension
|
|
||||||
modules. Test modules are excluded.
|
|
||||||
|
|
||||||
For packages, only sub-packages are listed, not sub-modules. For example,
|
|
||||||
``concurrent`` package and ``concurrent.futures`` sub-package are listed,
|
|
||||||
but not ``concurrent.futures.base`` sub-module.
|
|
||||||
|
|
||||||
See also the :attr:`sys.builtin_module_names` list.
|
|
||||||
|
|
||||||
.. versionadded:: 3.10
|
|
||||||
|
|
||||||
|
|
||||||
.. data:: modules
|
.. data:: modules
|
||||||
|
|
||||||
This is a dictionary that maps module names to modules which have already been
|
This is a dictionary that maps module names to modules which have already been
|
||||||
|
@ -1584,6 +1566,24 @@ always available.
|
||||||
to a console and Python apps started with :program:`pythonw`.
|
to a console and Python apps started with :program:`pythonw`.
|
||||||
|
|
||||||
|
|
||||||
|
.. data:: stdlib_module_names
|
||||||
|
|
||||||
|
A frozenset of strings containing the names of standard library modules.
|
||||||
|
|
||||||
|
It is the same on all platforms. Modules which are not available on
|
||||||
|
some platforms and modules disabled at Python build are also listed.
|
||||||
|
All module kinds are listed: pure Python, built-in, frozen and extension
|
||||||
|
modules. Test modules are excluded.
|
||||||
|
|
||||||
|
For packages, only sub-packages are listed, not sub-modules. For example,
|
||||||
|
``concurrent`` package and ``concurrent.futures`` sub-package are listed,
|
||||||
|
but not ``concurrent.futures.base`` sub-module.
|
||||||
|
|
||||||
|
See also the :attr:`sys.builtin_module_names` list.
|
||||||
|
|
||||||
|
.. versionadded:: 3.10
|
||||||
|
|
||||||
|
|
||||||
.. data:: thread_info
|
.. data:: thread_info
|
||||||
|
|
||||||
A :term:`named tuple` holding information about the thread
|
A :term:`named tuple` holding information about the thread
|
||||||
|
|
|
@ -396,7 +396,7 @@ Add :data:`sys.orig_argv` attribute: the list of the original command line
|
||||||
arguments passed to the Python executable.
|
arguments passed to the Python executable.
|
||||||
(Contributed by Victor Stinner in :issue:`23427`.)
|
(Contributed by Victor Stinner in :issue:`23427`.)
|
||||||
|
|
||||||
Add :data:`sys.module_names`, containing the list of the standard library
|
Add :data:`sys.stdlib_module_names`, containing the list of the standard library
|
||||||
module names.
|
module names.
|
||||||
(Contributed by Victor Stinner in :issue:`42955`.)
|
(Contributed by Victor Stinner in :issue:`42955`.)
|
||||||
|
|
||||||
|
|
|
@ -581,7 +581,7 @@ def test_fatal_error(self):
|
||||||
not_expected = ('_testcapi',)
|
not_expected = ('_testcapi',)
|
||||||
code = textwrap.dedent('''
|
code = textwrap.dedent('''
|
||||||
import _testcapi, sys
|
import _testcapi, sys
|
||||||
sys.module_names = frozenset({"_testcapi"})
|
sys.stdlib_module_names = frozenset({"_testcapi"})
|
||||||
_testcapi.fatal_error(b"MESSAGE")
|
_testcapi.fatal_error(b"MESSAGE")
|
||||||
''')
|
''')
|
||||||
self.check_fatal_error(code, expected)
|
self.check_fatal_error(code, expected)
|
||||||
|
|
|
@ -336,7 +336,7 @@ def test_dump_ext_modules(self):
|
||||||
import faulthandler
|
import faulthandler
|
||||||
import sys
|
import sys
|
||||||
# Don't filter stdlib module names
|
# Don't filter stdlib module names
|
||||||
sys.module_names = frozenset()
|
sys.stdlib_module_names = frozenset()
|
||||||
faulthandler.enable()
|
faulthandler.enable()
|
||||||
faulthandler._sigsegv()
|
faulthandler._sigsegv()
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -987,8 +987,8 @@ def test_orig_argv(self):
|
||||||
proc)
|
proc)
|
||||||
|
|
||||||
def test_module_names(self):
|
def test_module_names(self):
|
||||||
self.assertIsInstance(sys.module_names, frozenset)
|
self.assertIsInstance(sys.stdlib_module_names, frozenset)
|
||||||
for name in sys.module_names:
|
for name in sys.stdlib_module_names:
|
||||||
self.assertIsInstance(name, str)
|
self.assertIsInstance(name, str)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -760,7 +760,7 @@ regen-all: regen-opcode regen-opcode-targets regen-typeslots \
|
||||||
regen-token regen-ast regen-keyword regen-importlib clinic \
|
regen-token regen-ast regen-keyword regen-importlib clinic \
|
||||||
regen-pegen-metaparser regen-pegen
|
regen-pegen-metaparser regen-pegen
|
||||||
@echo
|
@echo
|
||||||
@echo "Note: make regen-module-names and autoconf should be run manually"
|
@echo "Note: make regen-stdlib-module-names and autoconf should be run manually"
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
# Special rules for object files
|
# Special rules for object files
|
||||||
|
@ -900,14 +900,14 @@ regen-keyword:
|
||||||
$(srcdir)/Lib/keyword.py.new
|
$(srcdir)/Lib/keyword.py.new
|
||||||
$(UPDATE_FILE) $(srcdir)/Lib/keyword.py $(srcdir)/Lib/keyword.py.new
|
$(UPDATE_FILE) $(srcdir)/Lib/keyword.py $(srcdir)/Lib/keyword.py.new
|
||||||
|
|
||||||
.PHONY: regen-module-names
|
.PHONY: regen-stdlib-module-names
|
||||||
regen-module-names: build_all
|
regen-stdlib-module-names: build_all
|
||||||
# Regenerate Python/module_names.h
|
# Regenerate Python/stdlib_module_names.h
|
||||||
# using Tools/scripts/generate_module_names.py
|
# using Tools/scripts/generate_stdlib_module_names.py
|
||||||
$(RUNSHARED) ./$(BUILDPYTHON) \
|
$(RUNSHARED) ./$(BUILDPYTHON) \
|
||||||
$(srcdir)/Tools/scripts/generate_module_names.py \
|
$(srcdir)/Tools/scripts/generate_stdlib_module_names.py \
|
||||||
> $(srcdir)/Python/module_names.h.new
|
> $(srcdir)/Python/stdlib_module_names.h.new
|
||||||
$(UPDATE_FILE) $(srcdir)/Python/module_names.h $(srcdir)/Python/module_names.h.new
|
$(UPDATE_FILE) $(srcdir)/Python/stdlib_module_names.h $(srcdir)/Python/stdlib_module_names.h.new
|
||||||
|
|
||||||
Python/compile.o Python/symtable.o Python/ast_unparse.o Python/ast.o Python/future.o: $(srcdir)/Include/Python-ast.h
|
Python/compile.o Python/symtable.o Python/ast_unparse.o Python/ast.o Python/future.o: $(srcdir)/Include/Python-ast.h
|
||||||
|
|
||||||
|
@ -1160,7 +1160,7 @@ PYTHON_HEADERS= \
|
||||||
$(srcdir)/Include/internal/pycore_warnings.h \
|
$(srcdir)/Include/internal/pycore_warnings.h \
|
||||||
$(DTRACE_HEADERS) \
|
$(DTRACE_HEADERS) \
|
||||||
\
|
\
|
||||||
$(srcdir)/Python/module_names.h
|
$(srcdir)/Python/stdlib_module_names.h
|
||||||
|
|
||||||
$(LIBRARY_OBJS) $(MODOBJS) Programs/python.o: $(PYTHON_HEADERS)
|
$(LIBRARY_OBJS) $(MODOBJS) Programs/python.o: $(PYTHON_HEADERS)
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
Add :data:`sys.module_names`, containing the list of the standard library
|
Add :data:`sys.stdlib_module_names`, containing the list of the standard library
|
||||||
module names. Patch by Victor Stinner.
|
module names. Patch by Victor Stinner.
|
||||||
|
|
|
@ -291,7 +291,7 @@
|
||||||
<ClInclude Include="..\Python\ceval_gil.h" />
|
<ClInclude Include="..\Python\ceval_gil.h" />
|
||||||
<ClInclude Include="..\Python\condvar.h" />
|
<ClInclude Include="..\Python\condvar.h" />
|
||||||
<ClInclude Include="..\Python\importdl.h" />
|
<ClInclude Include="..\Python\importdl.h" />
|
||||||
<ClInclude Include="..\Python\module_names.h" />
|
<ClInclude Include="..\Python\stdlib_module_names.h" />
|
||||||
<ClInclude Include="..\Python\thread_nt.h" />
|
<ClInclude Include="..\Python\thread_nt.h" />
|
||||||
<ClInclude Include="..\Python\wordcode_helpers.h" />
|
<ClInclude Include="..\Python\wordcode_helpers.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -360,7 +360,7 @@
|
||||||
<ClInclude Include="..\Python\importdl.h">
|
<ClInclude Include="..\Python\importdl.h">
|
||||||
<Filter>Python</Filter>
|
<Filter>Python</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\Python\module_names.h">
|
<ClInclude Include="..\Python\stdlib_module_names.h">
|
||||||
<Filter>Python</Filter>
|
<Filter>Python</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\Python\thread_nt.h">
|
<ClInclude Include="..\Python\thread_nt.h">
|
||||||
|
|
|
@ -2497,7 +2497,7 @@ fatal_error_exit(int status)
|
||||||
|
|
||||||
|
|
||||||
// Dump the list of extension modules of sys.modules, excluding stdlib modules
|
// Dump the list of extension modules of sys.modules, excluding stdlib modules
|
||||||
// (sys.module_names), into fd file descriptor.
|
// (sys.stdlib_module_names), into fd file descriptor.
|
||||||
//
|
//
|
||||||
// This function is called by a signal handler in faulthandler: avoid memory
|
// This function is called by a signal handler in faulthandler: avoid memory
|
||||||
// allocations and keep the implementation simple. For example, the list is not
|
// allocations and keep the implementation simple. For example, the list is not
|
||||||
|
@ -2519,19 +2519,19 @@ _Py_DumpExtensionModules(int fd, PyInterpreterState *interp)
|
||||||
// Avoid PyDict_GetItemString() which calls PyUnicode_FromString(),
|
// Avoid PyDict_GetItemString() which calls PyUnicode_FromString(),
|
||||||
// memory cannot be allocated on the heap in a signal handler.
|
// memory cannot be allocated on the heap in a signal handler.
|
||||||
// Iterate on the dict instead.
|
// Iterate on the dict instead.
|
||||||
PyObject *module_names = NULL;
|
PyObject *stdlib_module_names = NULL;
|
||||||
pos = 0;
|
pos = 0;
|
||||||
while (PyDict_Next(interp->sysdict, &pos, &key, &value)) {
|
while (PyDict_Next(interp->sysdict, &pos, &key, &value)) {
|
||||||
if (PyUnicode_Check(key)
|
if (PyUnicode_Check(key)
|
||||||
&& PyUnicode_CompareWithASCIIString(key, "module_names") == 0) {
|
&& PyUnicode_CompareWithASCIIString(key, "stdlib_module_names") == 0) {
|
||||||
module_names = value;
|
stdlib_module_names = value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If we failed to get sys.module_names or it's not a frozenset,
|
// If we failed to get sys.stdlib_module_names or it's not a frozenset,
|
||||||
// don't exclude stdlib modules.
|
// don't exclude stdlib modules.
|
||||||
if (module_names != NULL && !PyFrozenSet_Check(module_names)) {
|
if (stdlib_module_names != NULL && !PyFrozenSet_Check(stdlib_module_names)) {
|
||||||
module_names = NULL;
|
stdlib_module_names = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// List extensions
|
// List extensions
|
||||||
|
@ -2547,13 +2547,13 @@ _Py_DumpExtensionModules(int fd, PyInterpreterState *interp)
|
||||||
}
|
}
|
||||||
// Use the module name from the sys.modules key,
|
// Use the module name from the sys.modules key,
|
||||||
// don't attempt to get the module object name.
|
// don't attempt to get the module object name.
|
||||||
if (module_names != NULL) {
|
if (stdlib_module_names != NULL) {
|
||||||
int is_stdlib_ext = 0;
|
int is_stdlib_ext = 0;
|
||||||
|
|
||||||
Py_ssize_t i;
|
Py_ssize_t i = 0;
|
||||||
PyObject *item;
|
PyObject *item;
|
||||||
Py_hash_t hash;
|
Py_hash_t hash;
|
||||||
for (i=0; _PySet_NextEntry(module_names, &i, &item, &hash); ) {
|
while (_PySet_NextEntry(stdlib_module_names, &i, &item, &hash)) {
|
||||||
if (PyUnicode_Check(item)
|
if (PyUnicode_Check(item)
|
||||||
&& PyUnicode_Compare(key, item) == 0)
|
&& PyUnicode_Compare(key, item) == 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Auto-generated by Tools/scripts/generate_module_names.py.
|
// Auto-generated by Tools/scripts/generate_stdlib_module_names.py.
|
||||||
// List used to create sys.module_names.
|
// List used to create sys.stdlib_module_names.
|
||||||
|
|
||||||
static const char* _Py_module_names[] = {
|
static const char* _Py_stdlib_module_names[] = {
|
||||||
"__future__",
|
"__future__",
|
||||||
"_abc",
|
"_abc",
|
||||||
"_aix_support",
|
"_aix_support",
|
|
@ -29,7 +29,7 @@ Data members:
|
||||||
#include "frameobject.h" // PyFrame_GetBack()
|
#include "frameobject.h" // PyFrame_GetBack()
|
||||||
#include "pydtrace.h"
|
#include "pydtrace.h"
|
||||||
#include "osdefs.h" // DELIM
|
#include "osdefs.h" // DELIM
|
||||||
#include "module_names.h" // _Py_module_names
|
#include "stdlib_module_names.h" // _Py_stdlib_module_names
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
|
@ -2054,16 +2054,16 @@ list_builtin_module_names(void)
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
list_module_names(void)
|
list_stdlib_module_names(void)
|
||||||
{
|
{
|
||||||
Py_ssize_t len = Py_ARRAY_LENGTH(_Py_module_names);
|
Py_ssize_t len = Py_ARRAY_LENGTH(_Py_stdlib_module_names);
|
||||||
PyObject *names = PyTuple_New(len);
|
PyObject *names = PyTuple_New(len);
|
||||||
if (names == NULL) {
|
if (names == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Py_ssize_t i = 0; i < len; i++) {
|
for (Py_ssize_t i = 0; i < len; i++) {
|
||||||
PyObject *name = PyUnicode_FromString(_Py_module_names[i]);
|
PyObject *name = PyUnicode_FromString(_Py_stdlib_module_names[i]);
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
Py_DECREF(names);
|
Py_DECREF(names);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -2784,7 +2784,7 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
|
||||||
SET_SYS("hash_info", get_hash_info(tstate));
|
SET_SYS("hash_info", get_hash_info(tstate));
|
||||||
SET_SYS("maxunicode", PyLong_FromLong(0x10FFFF));
|
SET_SYS("maxunicode", PyLong_FromLong(0x10FFFF));
|
||||||
SET_SYS("builtin_module_names", list_builtin_module_names());
|
SET_SYS("builtin_module_names", list_builtin_module_names());
|
||||||
SET_SYS("module_names", list_module_names());
|
SET_SYS("stdlib_module_names", list_stdlib_module_names());
|
||||||
#if PY_BIG_ENDIAN
|
#if PY_BIG_ENDIAN
|
||||||
SET_SYS_FROM_STRING("byteorder", "big");
|
SET_SYS_FROM_STRING("byteorder", "big");
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# This script lists the names of standard library modules
|
# This script lists the names of standard library modules
|
||||||
# to update Python/module_names.h
|
# to update Python/stdlib_mod_names.h
|
||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -126,10 +126,11 @@ def list_modules():
|
||||||
|
|
||||||
|
|
||||||
def write_modules(fp, names):
|
def write_modules(fp, names):
|
||||||
print("// Auto-generated by Tools/scripts/generate_module_names.py.", file=fp)
|
print("// Auto-generated by Tools/scripts/generate_stdlib_module_names.py.",
|
||||||
print("// List used to create sys.module_names.", file=fp)
|
file=fp)
|
||||||
|
print("// List used to create sys.stdlib_module_names.", file=fp)
|
||||||
print(file=fp)
|
print(file=fp)
|
||||||
print("static const char* _Py_module_names[] = {", file=fp)
|
print("static const char* _Py_stdlib_module_names[] = {", file=fp)
|
||||||
for name in sorted(names):
|
for name in sorted(names):
|
||||||
print(f'"{name}",', file=fp)
|
print(f'"{name}",', file=fp)
|
||||||
print("};", file=fp)
|
print("};", file=fp)
|
Loading…
Reference in a new issue