From 2dfa580c75a431c6501fb9847a20579de4ed2d90 Mon Sep 17 00:00:00 2001 From: Martinez Date: Thu, 16 Feb 2017 12:50:07 +0100 Subject: [PATCH] - suppresses the warning about over.type - makes sure traceback handler doesn't cause a crash itself --- over/__init__.py | 6 +-- over/app.py | 126 +++++++++++++++++++++++------------------------ over/text.py | 1 + over/version.py | 4 +- 4 files changed, 67 insertions(+), 70 deletions(-) diff --git a/over/__init__.py b/over/__init__.py index 8591133..f6305cb 100644 --- a/over/__init__.py +++ b/over/__init__.py @@ -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("unable to load C implementation<.> of %s<.>, falling back to pure Python instead" %(module.__name__), print.tl.warn) +#for module in [types]: +# if module.__file__[-2:] == "py": +# print("unable to load C implementation<.> of %s<.>, falling back to pure Python instead" %(module.__name__), print.tl.warn) diff --git a/over/app.py b/over/app.py index 6769422..f700f86 100644 --- a/over/app.py +++ b/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("uncontained exception<.> %s<.> raised" %(exception_type.__name__), self.print.tl.fail) - # todo top level program name - # todo final level exception name and text - - tb_lines = ["", "---------------- Stack trace ----------------", "In program %s<.>" %(self.invocation)] - - while trace: - frame = trace.tb_frame - trace = trace.tb_next - method_name = frame.f_code.co_name + try: + tb_lines = ["", "---------------- Stack trace ----------------", "In program %s<.>" %(self.invocation)] - # 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 = " %s<.>.%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 = " %s<.>" %(method_name) - method_type = "function" - - # otherwise give up - else: - method = None - method_display_name = "" + while trace: + frame = trace.tb_frame + trace = trace.tb_next + method_name = frame.f_code.co_name - if method_name == "": - method_type = "module" - elif method_name == "": - method_type = "a list comprehension" - elif method_name == "": - method_type = "a generator expression" + # 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 = "%s<.>.%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 = "%s<.>" %(method_name) + method_type = "function" + + # otherwise give up else: - method_type = "unknown callable<.>" - method_display_name = " %s<.>" %(method_name) + method = None + method_display_name = "%s<.>" %(method_name) + + if method_name == "": + method_type = "module" + else: + method_type = "unknown callable<.>" + + # use a docstring-provided action description if available + if method and method.__doc__ and "@while" in method.__doc__: + action = "while %s<.> " %(re.findall("@while (.+)", method.__doc__)[0].strip()) + else: + action = "" + + tb_lines.append("%sin %s %s<.> at %s:%d," %(action, method_type, method_display_name, frame.f_code.co_filename, frame.f_lineno)) - # use a docstring-provided action description if available - if method and method.__doc__ and "@while" in method.__doc__: - action = "while %s<.> " %(re.findall("@while (.+)", method.__doc__)[0].strip()) + if hasattr(exception, "description"): + reason = ": %s<.>" %(exception.description) + elif exception.args: + reason = ": %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)) - - if hasattr(exception, "description"): - reason = ": %s<.>" %(exception.description) - elif exception.args: - reason = ": %s<.>" %(" ".join(str(a) for a in exception.args)) - else: - reason = "" - - doc = " [%s]" %(exception.__doc__.strip()) if exception.__doc__ else "" - tb_lines.append("exception %s<.> was raised%s%s" %(exception_type.__name__, reason, doc)) - - last_i = len(tb_lines) - 1 - - for i, line in enumerate(tb_lines): - if i < 3: - format = "" - elif i == last_i: - format = "%s ⇒ " %((i - 3) * " ") - else: - format = "%s - " %((i - 3) * " ") + doc = " [%s]" %(exception.__doc__.strip()) if exception.__doc__ else "" + tb_lines.append("exception %s<.> was raised%s%s" %(exception_type.__name__, reason, doc)) - self.print(line, format=format, end="\n") + last_i = len(tb_lines) - 1 + + for i, line in enumerate(tb_lines): + if i < 3: + format = "" + elif i == last_i: + format = "%s ⇒ " %((i - 3) * " ") + else: + format = "%s - " %((i - 3) * " ") + + self.print(line, format=format, end="\n") + + self.print("---------------------------------------------", format="", end="\n") - self.print("---------------------------------------------", format="", end="\n") + except: + self.print("failed to contain exception<.>", self.print.tl.epic) + traceback.print_exc() diff --git a/over/text.py b/over/text.py index 255f6b4..761220a 100644 --- a/over/text.py +++ b/over/text.py @@ -302,6 +302,7 @@ class Output: note = "NOTE<.>" warn = "WARN<.>" fail = "FAIL<.>" + epic = "EPIC<.>" done = "DONE<.>" ts = tag.short diff --git a/over/version.py b/over/version.py index bb5dc3d..09972bb 100644 --- a/over/version.py +++ b/over/version.py @@ -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