summaryrefslogtreecommitdiffstats
path: root/Tools/scripts/generate_stdlib_module_names.py
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2022-07-05 07:25:45 (GMT)
committerGitHub <noreply@github.com>2022-07-05 07:25:45 (GMT)
commit7bd67d1d88383bb6d156ac9ca816e56085ca5ec8 (patch)
treee29942647ee609224c51357526618797c8d7f2ac /Tools/scripts/generate_stdlib_module_names.py
parentfd76eb547dd5d2c8307a89422049b6c3c80541ab (diff)
downloadcpython-7bd67d1d88383bb6d156ac9ca816e56085ca5ec8.zip
cpython-7bd67d1d88383bb6d156ac9ca816e56085ca5ec8.tar.gz
cpython-7bd67d1d88383bb6d156ac9ca816e56085ca5ec8.tar.bz2
gh-93939: Add script to check extension modules (#94545)
Add script ``Tools/scripts/check_modules.py`` to check and validate builtin and shared extension modules. The script also handles ``Modules/Setup`` and will eventually replace ``setup.py``. Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@protonmail.com>
Diffstat (limited to 'Tools/scripts/generate_stdlib_module_names.py')
-rw-r--r--Tools/scripts/generate_stdlib_module_names.py47
1 files changed, 7 insertions, 40 deletions
diff --git a/Tools/scripts/generate_stdlib_module_names.py b/Tools/scripts/generate_stdlib_module_names.py
index 6f864c3..82f1094 100644
--- a/Tools/scripts/generate_stdlib_module_names.py
+++ b/Tools/scripts/generate_stdlib_module_names.py
@@ -7,10 +7,11 @@ import subprocess
import sys
import sysconfig
+from check_extension_modules import ModuleChecker
+
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')
IGNORE = {
@@ -41,23 +42,6 @@ IGNORE = {
'xxsubtype',
}
-# Windows extension modules
-WINDOWS_MODULES = (
- '_msi',
- '_overlapped',
- '_testconsole',
- '_winapi',
- 'msvcrt',
- 'nt',
- 'winreg',
- 'winsound'
-)
-
-# macOS extension modules
-MACOS_MODULES = (
- '_scproxy',
-)
-
# Pure Python modules (Lib/*.py)
def list_python_modules(names):
for filename in os.listdir(STDLIB_PATH):
@@ -89,28 +73,11 @@ def list_setup_extensions(names):
names |= set(extensions)
-# Built-in and extension modules built by Modules/Setup
+# Built-in and extension modules built by Modules/Setup*
+# includes Windows and macOS extensions.
def list_modules_setup_extensions(names):
- assign_var = re.compile("^[A-Z]+=")
-
- with open(MODULES_SETUP, encoding="utf-8") as modules_fp:
- for line in modules_fp:
- # Strip comment
- line = line.partition("#")[0]
- line = line.rstrip()
- if not line:
- continue
- if assign_var.match(line):
- # Ignore "VAR=VALUE"
- continue
- if line in ("*disabled*", "*shared*"):
- continue
- parts = line.split()
- if len(parts) < 2:
- continue
- # "errno errnomodule.c" => write "errno"
- name = parts[0]
- names.add(name)
+ checker = ModuleChecker()
+ names.update(checker.list_module_names(all=True))
# List frozen modules of the PyImport_FrozenModules list (Python/frozen.c).
@@ -134,7 +101,7 @@ def list_frozen(names):
def list_modules():
- names = set(sys.builtin_module_names) | set(WINDOWS_MODULES) | set(MACOS_MODULES)
+ names = set(sys.builtin_module_names)
list_modules_setup_extensions(names)
list_setup_extensions(names)
list_packages(names)