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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
#!/usr/bin/python3
"""
kupfer A convenient command and access tool.
This is launcher that load some useful libraries for development.
Copyright 2007-2023 Ulrik Sverdrup and other Kupfer authors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import sys
try:
import stackprinter
stackprinter.set_excepthook(
style="color",
suppressed_paths=[r"*/site-packages/typeguard/"],
)
except ImportError:
try:
from rich.traceback import install
suppress_modules = []
try:
import typeguard
suppress_modules.append(typeguard)
except ImportError:
pass
install(show_locals=True, suppress=suppress_modules)
print("rich.traceback installed")
except ImportError:
pass
try:
import icecream
icecream.install()
icecream.ic.configureOutput(includeContext=True)
import traceback
def ic_stack(*args, **kwargs):
stack = "".join(tbs.rstrip() for tbs in traceback.format_stack()[:-2])
ic(stack, *args, **kwargs) # type: ignore
import inspect
class ShiftedIceCreamDebugger(icecream.IceCreamDebugger): # type: ignore
def format(self, *args):
# one more frame back
call_frame = inspect.currentframe().f_back.f_back # type: ignore
return self._format(call_frame, *args)
sic = ShiftedIceCreamDebugger()
def ic_trace(func):
def wrapper(*args, **kwargs):
sic(func, args, kwargs)
res = func(*args, **kwargs)
sic(func, res)
return res
return wrapper
import builtins
builtins.ic_stack = ic_stack # type: ignore
builtins.ic_trace = ic_trace # type: ignore
except ImportError: # Graceful fallback if IceCream isn't installed.
pass
try:
if "--debug" in sys.argv:
from typeguard import install_import_hook
install_import_hook("kupfer")
print("WARN! typeguard hook installed")
import typing
typing.TYPE_CHECKING = True # type: ignore
import typeguard._checkers as checkers
checkers.check_protocol = None # agronholm/typeguard#465
except ImportError as err:
print(err)
try:
from pympler import tracker
except ImportError:
tracker = None
if __name__ == "__main__":
from kupfer import main
if tracker:
tr = tracker.SummaryTracker()
print("!!!!!!!!!!!!!! WARN !!!!!!!!!!!!!!")
print(
"Launching Kupfer by kupfer_dev.py is dedicated only for development. "
"This may totally broke some plugins, and some parts may not not "
"work as expected."
)
print("Also Kupfer may run much slower.")
print("Please install and run Kupfer as described in documentation.")
print("!!!!!!!!!!!!!! WARN !!!!!!!!!!!!!!")
main.main()
if tracker:
print("--- TRACKER start ---")
tr.print_diff()
print("--- TRACKER end ---")
|