Skip to content

Commit

Permalink
make regen-stdlib-module-names rejects test modules (#105921)
Browse files Browse the repository at this point in the history
Make sure that sys.stdlib_module_names doesn't contain test modules.
  • Loading branch information
vstinner authored Jun 20, 2023
1 parent cb388c9 commit 155577d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions Tools/build/generate_stdlib_module_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@
'xxsubtype',
}

ALLOW_TEST_MODULES = {
'doctest',
'unittest',
}

# Built-in modules
def list_builtin_modules(names):
names |= set(sys.builtin_module_names)


# Pure Python modules (Lib/*.py)
def list_python_modules(names):
for filename in os.listdir(STDLIB_PATH):
Expand Down Expand Up @@ -93,7 +103,9 @@ def list_frozen(names):


def list_modules():
names = set(sys.builtin_module_names)
names = set()

list_builtin_modules(names)
list_modules_setup_extensions(names)
list_packages(names)
list_python_modules(names)
Expand All @@ -106,9 +118,12 @@ def list_modules():
if package_name in IGNORE:
names.discard(name)

# Sanity checks
for name in names:
if "." in name:
raise Exception("sub-modules must not be listed")
raise Exception(f"sub-modules must not be listed: {name}")
if ("test" in name or "xx" in name) and name not in ALLOW_TEST_MODULES:
raise Exception(f"test modules must not be listed: {name}")

return names

Expand Down

0 comments on commit 155577d

Please sign in to comment.