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.
+ For packages, only the main package is listed: sub-packages and sub-modules
+ are not listed. For example, the ``email`` package is listed, but the
+ ``email.mime`` sub-package and the ``email.message`` sub-module are not
+ listed.
See also the :attr:`sys.builtin_module_names` list.
names.add(name)
-def _list_sub_packages(path, names, parent=None):
- for name in os.listdir(path):
+# Packages in Lib/
+def list_packages(names):
+ for name in os.listdir(STDLIB_PATH):
if name in IGNORE:
continue
- package_path = os.path.join(path, name)
+ package_path = os.path.join(STDLIB_PATH, name)
if not os.path.isdir(package_path):
continue
- if not any(package_file.endswith(".py")
- for package_file in os.listdir(package_path)):
- continue
- if parent:
- qualname = f"{parent}.{name}"
- else:
- qualname = name
- if qualname in IGNORE:
- continue
- names.add(qualname)
- _list_sub_packages(package_path, names, qualname)
-
-
-# Packages and sub-packages
-def list_packages(names):
- _list_sub_packages(STDLIB_PATH, names)
+ if any(package_file.endswith(".py")
+ for package_file in os.listdir(package_path)):
+ names.add(name)
# Extension modules built by setup.py