| 1 |
|
| 2 |
|
| 3 |
import os |
| 4 |
from pypy import pypydir |
| 5 |
|
| 6 |
STDLIB_PATH = os.path.join(pypydir, '..', 'lib-python', '3') |
| 7 |
|
| 8 |
IGNORE = { |
| 9 |
'__init__', |
| 10 |
'__pycache__', |
| 11 |
'site-packages', |
| 12 |
|
| 13 |
|
| 14 |
'__hello__', |
| 15 |
'__phello__', |
| 16 |
'_ctypes_test', |
| 17 |
'_testbuffer', |
| 18 |
'_testcapi', |
| 19 |
'_testconsole', |
| 20 |
'_testimportmultiple', |
| 21 |
'_testinternalcapi', |
| 22 |
'_testmultiphase', |
| 23 |
'_xxsubinterpreters', |
| 24 |
'_xxtestfuzz', |
| 25 |
'distutils.tests', |
| 26 |
'idlelib.idle_test', |
| 27 |
'lib2to3.tests', |
| 28 |
'test', |
| 29 |
'xxlimited', |
| 30 |
'xxlimited_35', |
| 31 |
'xxsubtype', |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
WINDOWS_MODULES = ( |
| 36 |
'_msi', |
| 37 |
'_overlapped', |
| 38 |
'_testconsole', |
| 39 |
'_winapi', |
| 40 |
'msvcrt', |
| 41 |
'nt', |
| 42 |
'winreg', |
| 43 |
'winsound' |
| 44 |
) |
| 45 |
|
| 46 |
|
| 47 |
MACOS_MODULES = ( |
| 48 |
'_scproxy', |
| 49 |
) |
| 50 |
|
| 51 |
LIB_PYPY_MODULES = ( |
| 52 |
'audioop', |
| 53 |
'_codecs_cn', |
| 54 |
'_codecs_hk', |
| 55 |
'_codecs_iso2022', |
| 56 |
'_codecs_jp', |
| 57 |
'_codecs_kr', |
| 58 |
'_codecs_tw', |
| 59 |
'_collections', |
| 60 |
'_contextvars', |
| 61 |
'ctypes_support', |
| 62 |
'_curses_panel', |
| 63 |
'_curses', |
| 64 |
'_dbm', |
| 65 |
|
| 66 |
'faulthandler', |
| 67 |
'_ffi', |
| 68 |
'future_builtins', |
| 69 |
'_gdbm', |
| 70 |
'greenlet', |
| 71 |
'grp', |
| 72 |
'identity_dict', |
| 73 |
'_immutables_map', |
| 74 |
'__init__', |
| 75 |
'_lzma', |
| 76 |
'_marshal', |
| 77 |
'marshal', |
| 78 |
'_md5', |
| 79 |
'msvcrt', |
| 80 |
'_overlapped', |
| 81 |
'_posixshmem', |
| 82 |
'_pypy_generic_alias', |
| 83 |
'_pypy_interact', |
| 84 |
'_pypy_irc_topic', |
| 85 |
'_pypy_util_cffi', |
| 86 |
'_pypy_wait', |
| 87 |
'_pypy_winbase_cffi64', |
| 88 |
'_pypy_winbase_cffi', |
| 89 |
'readline', |
| 90 |
'resource', |
| 91 |
'_scproxy', |
| 92 |
'_sha1', |
| 93 |
'_sha256', |
| 94 |
'_sha512', |
| 95 |
'_sqlite3', |
| 96 |
'stackless', |
| 97 |
'_structseq', |
| 98 |
'_sysconfigdata', |
| 99 |
'syslog', |
| 100 |
'_testcapi', |
| 101 |
'tputil', |
| 102 |
'_winapi', |
| 103 |
) |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
def list_python_modules(names): |
| 108 |
for filename in os.listdir(STDLIB_PATH): |
| 109 |
if not filename.endswith(".py"): |
| 110 |
continue |
| 111 |
name = filename[:-3] |
| 112 |
names.add(name) |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
def list_packages(names): |
| 117 |
for name in os.listdir(STDLIB_PATH): |
| 118 |
if name in IGNORE: |
| 119 |
continue |
| 120 |
package_path = os.path.join(STDLIB_PATH, name) |
| 121 |
if not os.path.isdir(package_path): |
| 122 |
continue |
| 123 |
if any(package_file.endswith(".py") |
| 124 |
for package_file in os.listdir(package_path)): |
| 125 |
names.add(name) |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
def list_modules_cffi(names): |
| 130 |
for name in LIB_PYPY_MODULES: |
| 131 |
names.add(name) |
| 132 |
|
| 133 |
|
| 134 |
def list_modules(): |
| 135 |
names = set(WINDOWS_MODULES) | set(MACOS_MODULES) |
| 136 |
list_modules_cffi(names) |
| 137 |
list_packages(names) |
| 138 |
list_python_modules(names) |
| 139 |
|
| 140 |
|
| 141 |
for name in list(names): |
| 142 |
package_name = name.split('.')[0] |
| 143 |
|
| 144 |
if package_name in IGNORE: |
| 145 |
names.discard(name) |
| 146 |
|
| 147 |
for name in names: |
| 148 |
if "." in name: |
| 149 |
raise Exception("sub-module '%s' must not be listed" % name) |
| 150 |
|
| 151 |
return names |
| 152 |
|
| 153 |
|
| 154 |
def get_stdlib_names(): |
| 155 |
return list(list_modules()) |
| 156 |
|
| 157 |
|
| 158 |
if __name__ == "__main__": |
| 159 |
import pprint |
| 160 |
modules = get_stdlib_names() |
| 161 |
pprint.pprint(modules) |
| 162 |
print('got %d modules' % len(modules)) |