- suppresses the warning about over.type
- makes sure traceback handler doesn't cause a crash itself
This commit is contained in:
parent
d0bac63fb3
commit
2dfa580c75
4 changed files with 67 additions and 70 deletions
|
@ -19,6 +19,6 @@ print = text.Output("over.__init__", stream=sys.stderr)
|
|||
core = aux.DeprecationForwarder(sys.modules[__name__], "over.core", "over")
|
||||
textui = aux.DeprecationForwarder(text, "over.core.textui", "over.text")
|
||||
|
||||
for module in [types]:
|
||||
if module.__file__[-2:] == "py":
|
||||
print("<r>unable to load C implementation<.> of <c>%s<.>, falling back to pure Python instead" %(module.__name__), print.tl.warn)
|
||||
#for module in [types]:
|
||||
# if module.__file__[-2:] == "py":
|
||||
# print("<r>unable to load C implementation<.> of <y>%s<.>, falling back to pure Python instead" %(module.__name__), print.tl.warn)
|
||||
|
|
116
over/app.py
116
over/app.py
|
@ -10,6 +10,7 @@ import re
|
|||
import os
|
||||
import shlex
|
||||
import hashlib
|
||||
import traceback
|
||||
|
||||
try:
|
||||
import xdg.BaseDirectory as xdg_bd
|
||||
|
@ -134,11 +135,7 @@ class Option:
|
|||
|
||||
if default:
|
||||
if self.default != Option_sources.none:
|
||||
# default values for aggregated options are wrapped in a list
|
||||
default_values = [self.default] if self.overwrite else self.default
|
||||
|
||||
for default_value in default_values:
|
||||
self.set_value(default_value, Option_sources.default)
|
||||
self.set_value(self.default, Option_sources.default)
|
||||
|
||||
def set_value(self, raw_value, source):
|
||||
"""
|
||||
|
@ -728,75 +725,74 @@ class Main:
|
|||
@while formatting a traceback
|
||||
|
||||
Over Exception handler - prints human readable tracebacks.
|
||||
|
||||
If things go south even here, prints the topmost traceback and gives up in a safe manner.
|
||||
"""
|
||||
|
||||
self.print("<R>uncontained exception<.> <Y>%s<.> raised" %(exception_type.__name__), self.print.tl.fail)
|
||||
|
||||
# todo top level program name
|
||||
# todo final level exception name and text
|
||||
try:
|
||||
tb_lines = ["", "---------------- Stack trace ----------------", "In program <W>%s<.>" %(self.invocation)]
|
||||
|
||||
tb_lines = ["", "---------------- Stack trace ----------------", "In program <W>%s<.>" %(self.invocation)]
|
||||
while trace:
|
||||
frame = trace.tb_frame
|
||||
trace = trace.tb_next
|
||||
method_name = frame.f_code.co_name
|
||||
|
||||
while trace:
|
||||
frame = trace.tb_frame
|
||||
trace = trace.tb_next
|
||||
method_name = frame.f_code.co_name
|
||||
# if there's a "self" in locals, we can get a hold of the method using getattr
|
||||
if "self" in frame.f_locals:
|
||||
method = getattr(frame.f_locals["self"], method_name)
|
||||
method_display_name = "<c>%s<.>.<y>%s<.>" %(method.__self__.__class__.__name__, method_name)
|
||||
method_type = "method"
|
||||
|
||||
# if there's a "self" in locals, we can get a hold of the method using getattr
|
||||
if "self" in frame.f_locals:
|
||||
method = getattr(frame.f_locals["self"], method_name)
|
||||
method_display_name = " <c>%s<.>.<y>%s<.>" %(method.__self__.__class__.__name__, method_name)
|
||||
method_type = "method"
|
||||
# if it's a global function, it's likely going to be here
|
||||
elif method_name in frame.f_globals:
|
||||
method = frame.f_globals[method_name]
|
||||
method_display_name = "<y>%s<.>" %(method_name)
|
||||
method_type = "function"
|
||||
|
||||
# if it's a global function, it's likely going to be here
|
||||
elif method_name in frame.f_globals:
|
||||
method = frame.f_globals[method_name]
|
||||
method_display_name = " <y>%s<.>" %(method_name)
|
||||
method_type = "function"
|
||||
|
||||
# otherwise give up
|
||||
else:
|
||||
method = None
|
||||
method_display_name = ""
|
||||
|
||||
if method_name == "<module>":
|
||||
method_type = "module"
|
||||
elif method_name == "<listcomp>":
|
||||
method_type = "a list comprehension"
|
||||
elif method_name == "<genexpr>":
|
||||
method_type = "a generator expression"
|
||||
# otherwise give up
|
||||
else:
|
||||
method_type = "<r>unknown callable<.>"
|
||||
method_display_name = " <y>%s<.>" %(method_name)
|
||||
method = None
|
||||
method_display_name = "<y>%s<.>" %(method_name)
|
||||
|
||||
# use a docstring-provided action description if available
|
||||
if method and method.__doc__ and "@while" in method.__doc__:
|
||||
action = "while <m>%s<.> " %(re.findall("@while (.+)", method.__doc__)[0].strip())
|
||||
if method_name == "<module>":
|
||||
method_type = "module"
|
||||
else:
|
||||
method_type = "<r>unknown callable<.>"
|
||||
|
||||
# use a docstring-provided action description if available
|
||||
if method and method.__doc__ and "@while" in method.__doc__:
|
||||
action = "while <m>%s<.> " %(re.findall("@while (.+)", method.__doc__)[0].strip())
|
||||
else:
|
||||
action = ""
|
||||
|
||||
tb_lines.append("%sin %s <y>%s<.> at %s:%d," %(action, method_type, method_display_name, frame.f_code.co_filename, frame.f_lineno))
|
||||
|
||||
if hasattr(exception, "description"):
|
||||
reason = ": <R>%s<.>" %(exception.description)
|
||||
elif exception.args:
|
||||
reason = ": <R>%s<.>" %(" ".join(str(a) for a in exception.args))
|
||||
else:
|
||||
action = ""
|
||||
reason = ""
|
||||
|
||||
tb_lines.append("%sin %s%s at %s:%d," %(action, method_type, method_display_name, frame.f_code.co_filename, frame.f_lineno))
|
||||
doc = " [%s]" %(exception.__doc__.strip()) if exception.__doc__ else ""
|
||||
tb_lines.append("exception <Y>%s<.> was raised%s%s" %(exception_type.__name__, reason, doc))
|
||||
|
||||
if hasattr(exception, "description"):
|
||||
reason = ": <R>%s<.>" %(exception.description)
|
||||
elif exception.args:
|
||||
reason = ": <R>%s<.>" %(" ".join(str(a) for a in exception.args))
|
||||
else:
|
||||
reason = ""
|
||||
last_i = len(tb_lines) - 1
|
||||
|
||||
doc = " [%s]" %(exception.__doc__.strip()) if exception.__doc__ else ""
|
||||
tb_lines.append("exception <Y>%s<.> was raised%s%s" %(exception_type.__name__, reason, doc))
|
||||
for i, line in enumerate(tb_lines):
|
||||
if i < 3:
|
||||
format = "<t>"
|
||||
elif i == last_i:
|
||||
format = "%s ⇒ <i><t>" %((i - 3) * " ")
|
||||
else:
|
||||
format = "%s - <i><t>" %((i - 3) * " ")
|
||||
|
||||
last_i = len(tb_lines) - 1
|
||||
self.print(line, format=format, end="\n")
|
||||
|
||||
for i, line in enumerate(tb_lines):
|
||||
if i < 3:
|
||||
format = "<t>"
|
||||
elif i == last_i:
|
||||
format = "%s ⇒ <i><t>" %((i - 3) * " ")
|
||||
else:
|
||||
format = "%s - <i><t>" %((i - 3) * " ")
|
||||
self.print("---------------------------------------------", format="<t>", end="\n")
|
||||
|
||||
self.print(line, format=format, end="\n")
|
||||
|
||||
self.print("---------------------------------------------", format="<t>", end="\n")
|
||||
except:
|
||||
self.print("<R>failed to contain exception<.>", self.print.tl.epic)
|
||||
traceback.print_exc()
|
||||
|
|
|
@ -302,6 +302,7 @@ class Output:
|
|||
note = "<C>NOTE<.>"
|
||||
warn = "<Y>WARN<.>"
|
||||
fail = "<R>FAIL<.>"
|
||||
epic = "<R>EPIC<.>"
|
||||
done = "<G>DONE<.>"
|
||||
|
||||
ts = tag.short
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
major = 1 # VERSION_MAJOR_IDENTIFIER
|
||||
minor = 99 # VERSION_MINOR_IDENTIFIER
|
||||
# VERSION_LAST_MM 1.99
|
||||
patch = 9 # VERSION_PATCH_IDENTIFIER
|
||||
str = ".".join(str(v) for v in (major, minor, patch))
|
||||
patch = 18 # VERSION_PATCH_IDENTIFIER
|
||||
str = "1.99.18" # VERSION_STRING_IDENTIFIER
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue