mirror of
https://github.com/cool-RR/PySnooper.git
synced 2026-01-23 10:15:11 +00:00
Rename for coolness
This commit is contained in:
parent
a0ff31dd8a
commit
b805ea0dc4
6 changed files with 32 additions and 30 deletions
|
|
@ -75,10 +75,10 @@ If stderr is not easily accessible for you, you can redirect the output to a fil
|
|||
|
||||
You can also pass a stream or a callable instead, and they'll be used.
|
||||
|
||||
See values of some variables that aren't local variables:
|
||||
See values of some expressions that aren't local variables:
|
||||
|
||||
```python
|
||||
@pysnooper.snoop(variables=('foo.bar', 'self.whatever'))
|
||||
@pysnooper.snoop(watch=('foo.bar', 'self.x["whatever"]'))
|
||||
```
|
||||
|
||||
Expand values to see all their attributes or items of lists/dictionaries:
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
# This program is distributed under the MIT license.
|
||||
|
||||
from .pysnooper import snoop
|
||||
from .variables import Attrs, Exploded, Indices, Keys
|
||||
from .variables import Attrs, Exploding, Indices, Keys
|
||||
import collections
|
||||
|
||||
__VersionInfo = collections.namedtuple('VersionInfo',
|
||||
('major', 'minor', 'micro'))
|
||||
|
||||
__version__ = '0.0.26'
|
||||
__version__ = '0.0.27'
|
||||
__version_info__ = __VersionInfo(*(map(int, __version__.split('.'))))
|
||||
|
||||
del collections, __VersionInfo # Avoid polluting the namespace
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ def get_write_and_truncate_functions(output):
|
|||
return (write, truncate)
|
||||
|
||||
|
||||
def snoop(output=None, variables=(), exploded_variables=(), depth=1, prefix='', overwrite=False):
|
||||
def snoop(output=None, watch=(), watch_explode=(), depth=1,
|
||||
prefix='', overwrite=False):
|
||||
'''
|
||||
Snoop on the function, writing everything it's doing to stderr.
|
||||
|
||||
|
|
@ -54,9 +55,9 @@ def snoop(output=None, variables=(), exploded_variables=(), depth=1, prefix='',
|
|||
|
||||
@pysnooper.snoop('/my/log/file.log')
|
||||
|
||||
See values of some variables that aren't local variables::
|
||||
See values of some expressions that aren't local variables::
|
||||
|
||||
@pysnooper.snoop(variables=('foo.bar', 'self.whatever'))
|
||||
@pysnooper.snoop(watch=('foo.bar', 'self.x["whatever"]'))
|
||||
|
||||
Expand values to see all their attributes or items of lists/dictionaries:
|
||||
|
||||
|
|
@ -79,10 +80,11 @@ def snoop(output=None, variables=(), exploded_variables=(), depth=1, prefix='',
|
|||
"content to file.")
|
||||
def decorate(function):
|
||||
target_code_object = function.__code__
|
||||
tracer = Tracer(target_code_object=target_code_object, write=write,
|
||||
truncate=truncate, variables=variables, depth=depth,
|
||||
prefix=prefix, overwrite=overwrite,
|
||||
exploded_variables=exploded_variables)
|
||||
tracer = Tracer(
|
||||
target_code_object=target_code_object, write=write,
|
||||
truncate=truncate, watch=watch, watch_explode=watch_explode,
|
||||
depth=depth, prefix=prefix, overwrite=overwrite
|
||||
)
|
||||
|
||||
def inner(function_, *args, **kwargs):
|
||||
with tracer:
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import collections
|
|||
import datetime as datetime_module
|
||||
import itertools
|
||||
|
||||
from .variables import CommonVariable, Exploded, BaseVariable
|
||||
from .variables import CommonVariable, Exploding, BaseVariable
|
||||
from .third_party import six
|
||||
from . import utils
|
||||
|
||||
|
|
@ -15,10 +15,10 @@ from . import utils
|
|||
ipython_filename_pattern = re.compile('^<ipython-input-([0-9]+)-.*>$')
|
||||
|
||||
|
||||
def get_local_reprs(frame, variables=()):
|
||||
def get_local_reprs(frame, watch=()):
|
||||
result = {key: utils.get_shortish_repr(value) for key, value
|
||||
in frame.f_locals.items()}
|
||||
for variable in variables:
|
||||
for variable in watch:
|
||||
result.update(variable.items(frame))
|
||||
return result
|
||||
|
||||
|
|
@ -99,17 +99,17 @@ def get_source_from_frame(frame):
|
|||
|
||||
|
||||
class Tracer:
|
||||
def __init__(self, target_code_object, write, truncate, variables=(),
|
||||
exploded_variables=(), depth=1, prefix='', overwrite=False):
|
||||
def __init__(self, target_code_object, write, truncate, watch=(),
|
||||
watch_explode=(), depth=1, prefix='', overwrite=False):
|
||||
self.target_code_object = target_code_object
|
||||
self._write = write
|
||||
self.truncate = truncate
|
||||
self.variables = [
|
||||
self.watch = [
|
||||
v if isinstance(v, BaseVariable) else CommonVariable(v)
|
||||
for v in utils.ensure_tuple(variables)
|
||||
for v in utils.ensure_tuple(watch)
|
||||
] + [
|
||||
v if isinstance(v, BaseVariable) else Exploded(v)
|
||||
for v in utils.ensure_tuple(exploded_variables)
|
||||
v if isinstance(v, BaseVariable) else Exploding(v)
|
||||
for v in utils.ensure_tuple(watch_explode)
|
||||
]
|
||||
self.frame_to_old_local_reprs = collections.defaultdict(lambda: {})
|
||||
self.frame_to_local_reprs = collections.defaultdict(lambda: {})
|
||||
|
|
@ -168,7 +168,7 @@ class Tracer:
|
|||
self.frame_to_old_local_reprs[frame] = old_local_reprs = \
|
||||
self.frame_to_local_reprs[frame]
|
||||
self.frame_to_local_reprs[frame] = local_reprs = \
|
||||
get_local_reprs(frame, variables=self.variables)
|
||||
get_local_reprs(frame, watch=self.watch)
|
||||
|
||||
modified_local_reprs = {}
|
||||
newish_local_reprs = {}
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ class Indices(Keys):
|
|||
return result
|
||||
|
||||
|
||||
class Exploded(BaseVariable):
|
||||
class Exploding(BaseVariable):
|
||||
def _items(self, main_value):
|
||||
if isinstance(main_value, Mapping):
|
||||
cls = Keys
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ def test_callable():
|
|||
|
||||
|
||||
|
||||
def test_variables():
|
||||
def test_watch():
|
||||
|
||||
class Foo(object):
|
||||
def __init__(self):
|
||||
|
|
@ -83,7 +83,7 @@ def test_variables():
|
|||
def square(self):
|
||||
self.x **= 2
|
||||
|
||||
@pysnooper.snoop(variables=(
|
||||
@pysnooper.snoop(watch=(
|
||||
'foo.x',
|
||||
'io.__name__',
|
||||
'len(foo.__dict__["x"] * "abc")',
|
||||
|
|
@ -125,14 +125,14 @@ def test_variables():
|
|||
)
|
||||
|
||||
|
||||
def test_exploded_variables():
|
||||
def test_watch_explode():
|
||||
class Foo:
|
||||
def __init__(self, x, y):
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
|
||||
@pysnooper.snoop(exploded_variables=('_d', '_point', 'lst'))
|
||||
@pysnooper.snoop(watch_explode=('_d', '_point', 'lst'))
|
||||
def my_function():
|
||||
_d = {'a': 1, 'b': 2, 'c': 'ignore'}
|
||||
_point = Foo(x=3, y=4)
|
||||
|
|
@ -180,7 +180,7 @@ def test_variables_classes():
|
|||
self.x = 3
|
||||
self.y = 4
|
||||
|
||||
@pysnooper.snoop(variables=(
|
||||
@pysnooper.snoop(watch=(
|
||||
pysnooper.Keys('_d', exclude='c'),
|
||||
pysnooper.Attrs('_d'), # doesn't have attributes
|
||||
pysnooper.Attrs('_s'),
|
||||
|
|
@ -221,7 +221,7 @@ def test_variables_classes():
|
|||
|
||||
|
||||
|
||||
def test_single_variable_no_comma():
|
||||
def test_single_watch_no_comma():
|
||||
|
||||
class Foo(object):
|
||||
def __init__(self):
|
||||
|
|
@ -230,7 +230,7 @@ def test_single_variable_no_comma():
|
|||
def square(self):
|
||||
self.x **= 2
|
||||
|
||||
@pysnooper.snoop(variables='foo')
|
||||
@pysnooper.snoop(watch='foo')
|
||||
def my_function():
|
||||
foo = Foo()
|
||||
for i in range(2):
|
||||
|
|
@ -376,7 +376,7 @@ def test_method_and_prefix():
|
|||
def __init__(self):
|
||||
self.x = 2
|
||||
|
||||
@pysnooper.snoop(variables=('self.x',), prefix='ZZZ')
|
||||
@pysnooper.snoop(watch=('self.x',), prefix='ZZZ')
|
||||
def square(self):
|
||||
foo = 7
|
||||
self.x **= 2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue