-
Notifications
You must be signed in to change notification settings - Fork 0
/
sitecustomize.py
111 lines (82 loc) · 2.3 KB
/
sitecustomize.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import builtins
import asyncio
import sys
from functools import partial
from collections import *
from pprint import pprint as pretty_print
from inspect import getmembers, ismethod, stack
import logging
import __main__
if not hasattr(__main__, "__file__"):
logging.getLogger("asyncio").setLevel("ERROR")
STDLIB_COLLECTIONS = (
str,
bytes,
int,
float,
complex,
memoryview,
dict,
tuple,
set,
bool,
bytearray,
frozenset,
slice,
deque,
defaultdict,
OrderedDict,
Counter,
)
def is_public_attribute(obj, name, methods=()):
return not name.startswith("_") and name not in methods and hasattr(obj, name)
def attributes(obj):
members = getmembers(type(obj))
methods = {name for name, val in members if callable(val)}
is_allowed = partial(is_public_attribute, methods=methods)
return {name: getattr(obj, name) for name in dir(obj) if is_allowed(obj, name)}
try:
import chime
chime.theme("material")
chime.notify_exceptions()
except ImportError:
pass
try:
if sys.__excepthook__ is sys.excepthook:
from rich.pretty import install
install()
from rich.traceback import install
replaced_hook = install(show_locals=True)
current_hook = sys.excepthook
def hook(*args, **kwargs):
print("na")
replaced_hook(*args, **kwargs)
current_hook(*args, **kwargs)
sys.excepthook = hook
from rich.pretty import pprint
class Printer(float):
def __call__(self, *args, **kwargs):
pprint(*args, **kwargs)
def __truediv__(self, other):
pprint(other)
def __rtruediv__(self, other):
pprint(other)
builtins.pp = builtins.pprint = Printer()
except ImportError:
pass
def inspect(obj):
if isinstance(obj, STDLIB_COLLECTIONS):
pretty_print(obj)
else:
try:
name = "class " + obj.__name__
except AttributeError:
name = obj.__class__.__name__ + "()"
class_name = obj.__class__.__name__
print(name + ":")
attrs = attributes(obj)
if not attrs:
print(" <No attributes>")
for name, val in attributes(obj).items():
print(" ", name, "=", val)
builtins.inspect = inspect