-
Notifications
You must be signed in to change notification settings - Fork 4
/
pythonstartup
54 lines (50 loc) · 1.39 KB
/
pythonstartup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def autoimport(*modules):
autoimported = set()
for module in modules:
if module.endswith(".*"):
base = module[:-2]
try:
exec(
f"from {base} import *",
globals(),
globals(),
)
except ImportError:
print(f"Failed to import {module}")
autoimported.add(module)
elif "." in module:
base, name = module.rsplit(".", 1)
try:
exec(
f"from {base} import {name}",
globals(),
globals(),
)
except ImportError:
print(f"Failed to import {module}")
autoimported.add(name)
else:
try:
exec(
f"import {module}",
globals(),
globals(),
)
except ImportError:
print(f"Failed to import {module}")
autoimported.add(module)
print("Auto-imported for your convenience:")
print(", ".join(sorted(autoimported)))
import os
if not os.environ.get("IN_REGRTEST"):
autoimport(
"sys",
"os",
"re",
"datetime",
"time",
"asyncio",
"typing.*",
"pathlib.Path",
"dataclasses.dataclass",
)