| 1 |
"""Helper script to obtain a list of available attributes for each modules. |
| 2 |
|
| 3 |
This is not meant to be imported anywhere. |
| 4 |
|
| 5 |
The output is shown in the console. It should be saved in |
| 6 |
modules_attributes.py located in this directory. |
| 7 |
""" |
| 8 |
|
| 9 |
import sys |
| 10 |
from pprint import pprint |
| 11 |
|
| 12 |
from stdlib_modules import names |
| 13 |
|
| 14 |
all_attributes = {} |
| 15 |
for mod_name in names: |
| 16 |
|
| 17 |
if mod_name in [ |
| 18 |
"antigravity", |
| 19 |
"binhex", |
| 20 |
"formatter", |
| 21 |
"imp", |
| 22 |
"parser", |
| 23 |
"symbol", |
| 24 |
"this", |
| 25 |
]: |
| 26 |
continue |
| 27 |
try: |
| 28 |
imported_mod = __import__(mod_name) |
| 29 |
except ImportError: |
| 30 |
continue |
| 31 |
for attr_name in dir(imported_mod): |
| 32 |
if attr_name.startswith("_") or len(attr_name) == 1: |
| 33 |
continue |
| 34 |
elif attr_name in names and attr_name != mod_name: |
| 35 |
continue |
| 36 |
elif attr_name in all_attributes: |
| 37 |
all_attributes[attr_name].append(mod_name) |
| 38 |
else: |
| 39 |
all_attributes[attr_name] = [mod_name] |
| 40 |
|
| 41 |
with open("modules_attributes.py", "w") as f: |
| 42 |
f.write(f"# Created with {sys.version_info}\n") |
| 43 |
f.write("attribute_names = ") |
| 44 |
pprint(all_attributes, stream=f, indent=4) |