From ace91d39aa6ce304a6898cf25151bd15fd9a4dcc Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Dec 12 2014 18:02:58 +0000 Subject: - Add prettyprint of values - Make the tracing decorator more transparent --- diff --git a/.gitignore b/.gitignore index 9e3c7a9..aee567e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1 @@ -/q-1.1.tar.gz -/q-2.3.tar.gz -/q-2.4.tar.gz -/q-2.5.tar.gz +q-2.5.tar.gz diff --git a/1.diff b/1.diff new file mode 100644 index 0000000..8293da1 --- /dev/null +++ b/1.diff @@ -0,0 +1,16 @@ +diff --git a/q.py b/q.py +index 1bf76d0..fcff4c9 100644 +--- a/q.py ++++ b/q.py +@@ -294,8 +294,9 @@ def __call__(self, *args): + lines = info.code_context[:info.index + 1] + + # If we see "@q" on a single line, behave like a trace decorator. +- if lines[-1].strip().startswith('@') and args: +- return self.trace(args[0]) ++ for line in lines: ++ if line.strip() in ('@q', '@q()') and args: ++ return self.trace(args[0]) + + # Otherwise, search for the beginning of the call expression; once it + # parses, use the expressions in the call to label the debugging output. diff --git a/11.diff b/11.diff deleted file mode 100644 index 7753157..0000000 --- a/11.diff +++ /dev/null @@ -1,16 +0,0 @@ -Index: q-2.5/q.py -=================================================================== ---- q-2.5.orig/q.py -+++ q-2.5/q.py -@@ -294,8 +294,9 @@ class Q(object): - lines = info.code_context[:info.index + 1] - - # If we see "@q" on a single line, behave like a trace decorator. -- if lines[-1].strip().startswith('@') and args: -- return self.trace(args[0]) -+ for line in lines: -+ if line.strip() in ('@q', '@q()') and args: -+ return self.trace(args[0]) - - # Otherwise, search for the beginning of the call expression; once it - # parses, use the expressions in the call to label the debugging output. diff --git a/2.diff b/2.diff new file mode 100644 index 0000000..33b19ed --- /dev/null +++ b/2.diff @@ -0,0 +1,49 @@ +diff --git a/q.py b/q.py +index 1bf76d0..5a05ecb 100644 +--- a/q.py ++++ b/q.py +@@ -66,7 +66,7 @@ + class Q(object): + __doc__ = __doc__ # from the module's __doc__ above + +- import ast, code, inspect, os, pydoc, sys, random, re, time ++ import ast, code, inspect, os, pydoc, sys, random, re, time, pprint + + # The debugging log will go to this file; temporary files will also have + # this path as a prefix, followed by a random number. +@@ -177,6 +177,13 @@ def unindent(self, lines): + indent = min(len(self.re.match(r'^ *', line).group()) for line in lines) + return [line[indent:].rstrip() for line in lines] + ++ def save_large_value(self, value): ++ if isinstance(value, self.TEXT_TYPES): ++ value = value.encode('utf-8') ++ path = self.OUTPUT_PATH + '%08d.txt' % self.random.randrange(1e8) ++ self.FileWriter(path).write('w', value) ++ return path ++ + def safe_repr(self, value): + # TODO: Use colour to distinguish '...' elision from actual '...' chars. + # TODO: Show a nicer repr for SRE.Match objects. +@@ -184,11 +191,17 @@ def safe_repr(self, value): + result = self.TEXT_REPR.repr(value) + if isinstance(value, self.BASESTRING_TYPES) and len(value) > 80: + # If the string is big, save it to a file for later examination. +- if isinstance(value, self.TEXT_TYPES): +- value = value.encode('utf-8') +- path = self.OUTPUT_PATH + '%08d.txt' % self.random.randrange(1e8) +- self.FileWriter(path).write('w', value) ++ path = self.save_large_value(value) + result += ' (file://' + path + ')' ++ else: ++ # Use pretty print if no specific choices were found ++ pp = self.pprint.PrettyPrinter(indent=1) ++ formatted = pp.pformat(value) ++ if len(formatted) > 80: ++ path = self.save_large_value(formatted) ++ result += ' (file://' + path + ')' ++ else: ++ result = formatted + return result + + def get_call_exprs(self, line): diff --git a/fix-introspection.patch b/fix-introspection.patch new file mode 100644 index 0000000..05b55c9 --- /dev/null +++ b/fix-introspection.patch @@ -0,0 +1,22 @@ +Index: q-2.5/q.py +=================================================================== +--- q-2.5.orig/q.py ++++ q-2.5/q.py +@@ -66,7 +66,7 @@ else: + class Q(object): + __doc__ = __doc__ # from the module's __doc__ above + +- import ast, code, inspect, os, pydoc, sys, random, re, time, pprint ++ import ast, code, inspect, functools, os, pydoc, sys, random, re, time, pprint + + # The debugging log will go to this file; temporary files will also have + # this path as a prefix, followed by a random number. +@@ -293,7 +293,7 @@ class Q(object): + self.NORMAL]) + self.writer.write(s.chunks) + return result +- return wrapper ++ return self.functools.update_wrapper(wrapper, func) + + def __call__(self, *args): + """If invoked as a decorator on a function, adds tracing output to the diff --git a/python-q.spec b/python-q.spec index 2893afd..d087231 100644 --- a/python-q.spec +++ b/python-q.spec @@ -6,15 +6,20 @@ Name: python-q Version: 2.5 -Release: 1%{?dist} +Release: 2%{?dist} Summary: Quick and dirty python debugging output License: ASL 2.0 URL: https://pypi.python.org/pypi/q Source0: https://pypi.python.org/packages/source/q/q/q-%{version}.tar.gz # Fix for using @q decorator -# Submitted upstream: https://github.com/zestyping/q/pull/11 -Patch0: https://github.com/zestyping/q/pull/11.diff +# Submitted upstream: https://github.com/mithro/q/pull/1 +Patch0: https://github.com/mithro/q/pull/1.diff +# Prettyprint dicts and other builtins +# Submitted upstream: https://github.com/mithro/q/pull/2 +Patch1: https://github.com/mithro/q/pull/2.diff +# mentioned here: https://github.com/zestyping/q/pull/15 to judge interest +Patch2: fix-introspection.patch BuildArch: noarch BuildRequires: python2-devel BuildRequires: python-setuptools @@ -57,6 +62,8 @@ This package contains the q module for python3 %setup -q -n q-%{version} %patch0 -p1 +%patch1 -p1 +%patch2 -p1 %if 0%{?with_python3} rm -rf %{py3dir} @@ -93,6 +100,10 @@ popd %endif # with_python3 %changelog +* Fri Dec 12 2014 Toshio Kuratomi - 2.5-2 +- Add prettyprint of values +- Make the tracing decorator more transparent + * Fri Dec 5 2014 Toshio Kuratomi - 2.5-1 - New upstream version