mirror of
https://github.com/cool-RR/PySnooper.git
synced 2026-01-24 02:24:55 +00:00
Compare commits
23 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0561a89c0e | ||
|
|
05212d3092 | ||
|
|
3c0f9eb65a | ||
|
|
eee41b20f8 | ||
|
|
2931e1374a | ||
|
|
8bf06d25a1 | ||
|
|
57472b4677 | ||
|
|
d91fd2b255 | ||
|
|
05f1359427 | ||
|
|
ac74c8f020 | ||
|
|
f2c60de87f | ||
|
|
0b96becd1b | ||
|
|
591341e973 | ||
|
|
206ae83b4f | ||
|
|
8c35d81835 | ||
|
|
23d3e43f0e | ||
|
|
e1a927311b | ||
|
|
60775ff71f | ||
|
|
4224cf9694 | ||
|
|
caf4ec584a | ||
|
|
231969074e | ||
|
|
1ad8ae08b0 | ||
|
|
7ca28af18d |
9 changed files with 113 additions and 30 deletions
4
AUTHORS
4
AUTHORS
|
|
@ -24,3 +24,7 @@ Itamar.Raviv
|
|||
iory
|
||||
Mark Blakeney
|
||||
Yael Mintz
|
||||
Lumír 'Frenzy' Balhar
|
||||
Lukas Klenk
|
||||
sizhky
|
||||
Andrej730
|
||||
|
|
|
|||
32
README.md
32
README.md
|
|
@ -1,4 +1,4 @@
|
|||
# PySnooper - Never use print for debugging again #
|
||||
# PySnooper - Never use print for debugging again
|
||||
|
||||
**PySnooper** is a poor man's debugger. If you've used Bash, it's like `set -x` for Python, except it's fancier.
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ Most people would use `print` lines, in strategic locations, some of them showin
|
|||
|
||||
What makes **PySnooper** stand out from all other code intelligence tools? You can use it in your shitty, sprawling enterprise codebase without having to do any setup. Just slap the decorator on, as shown below, and redirect the output to a dedicated log file by specifying its path as the first argument.
|
||||
|
||||
# Example #
|
||||
## Example
|
||||
|
||||
We're writing a function that converts a number to binary, by returning a list of bits. Let's snoop on it by adding the `@pysnooper.snoop()` decorator:
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ New var:....... mid = 453.0
|
|||
Elapsed time: 00:00:00.000344
|
||||
```
|
||||
|
||||
# Features #
|
||||
## Features
|
||||
|
||||
If stderr is not easily accessible for you, you can redirect the output to a file:
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ Show snoop lines for functions that your function calls:
|
|||
**See [Advanced Usage](https://github.com/cool-RR/PySnooper/blob/master/ADVANCED_USAGE.md) for more options.** <------
|
||||
|
||||
|
||||
# Installation with Pip #
|
||||
## Installation with Pip
|
||||
|
||||
The best way to install **PySnooper** is with Pip:
|
||||
|
||||
|
|
@ -105,7 +105,7 @@ The best way to install **PySnooper** is with Pip:
|
|||
$ pip install pysnooper
|
||||
```
|
||||
|
||||
# Other installation options #
|
||||
## Other installation options
|
||||
|
||||
Conda with conda-forge channel:
|
||||
|
||||
|
|
@ -125,12 +125,30 @@ Fedora Linux:
|
|||
$ dnf install python3-pysnooper
|
||||
```
|
||||
|
||||
# License #
|
||||
|
||||
## Citing PySnooper
|
||||
|
||||
If you use PySnooper in academic work, please use this citation format:
|
||||
|
||||
```bibtex
|
||||
@software{rachum2019pysnooper,
|
||||
title={PySnooper: Never use print for debugging again},
|
||||
author={Rachum, Ram and Hall, Alex and Yanokura, Iori and others},
|
||||
year={2019},
|
||||
month={jun},
|
||||
publisher={PyCon Israel},
|
||||
doi={10.5281/zenodo.10462459},
|
||||
url={https://github.com/cool-RR/PySnooper}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Copyright (c) 2019 Ram Rachum and collaborators, released under the MIT license.
|
||||
|
||||
|
||||
# Media Coverage #
|
||||
## Media Coverage
|
||||
|
||||
[Hacker News thread](https://news.ycombinator.com/item?id=19717786)
|
||||
and [/r/Python Reddit thread](https://www.reddit.com/r/Python/comments/bg0ida/pysnooper_never_use_print_for_debugging_again/) (22 April 2019)
|
||||
|
|
|
|||
|
|
@ -1,26 +1,27 @@
|
|||
#!wing
|
||||
#!version=7.0
|
||||
#!version=11.0
|
||||
##################################################################
|
||||
# Wing project file #
|
||||
##################################################################
|
||||
[project attributes]
|
||||
proj.directory-list = [{'dirloc': loc('../..'),
|
||||
'excludes': [u'PySnooper.egg-info',
|
||||
u'dist',
|
||||
u'build'],
|
||||
'excludes': ['dist',
|
||||
'.tox',
|
||||
'htmlcov',
|
||||
'build',
|
||||
'.ipynb_checkpoints',
|
||||
'PySnooper.egg-info'],
|
||||
'filter': '*',
|
||||
'include_hidden': False,
|
||||
'recursive': True,
|
||||
'watch_for_changes': True}]
|
||||
proj.file-type = 'shared'
|
||||
proj.home-dir = loc('../..')
|
||||
proj.launch-config = {loc('../../../../../../../Program Files/Python37/Scripts/pasteurize-script.py'): ('p'\
|
||||
'roject',
|
||||
(u'"c:\\Users\\Administrator\\Documents\\Python Projects\\PySnooper\\pysnooper" "c:\\Users\\Administrator\\Documents\\Python Projects\\PySnooper\\tests"',
|
||||
proj.launch-config = {loc('../../../../../../Program Files/Python37/Scripts/pasteurize-script.py'): ('project',
|
||||
('"c:\\Users\\Administrator\\Documents\\Python Projects\\PySnooper\\pysnooper" "c:\\Users\\Administrator\\Documents\\Python Projects\\PySnooper\\tests"',
|
||||
'')),
|
||||
loc('../../../../../Dropbox/Scripts and shortcuts/_simplify3d_add_m600.py'): ('p'\
|
||||
'roject',
|
||||
(u'"C:\\Users\\Administrator\\Dropbox\\Desktop\\foo.gcode"',
|
||||
loc('../../../../../Dropbox/Scripts and shortcuts/_simplify3d_add_m600.py'): ('project',
|
||||
('"C:\\Users\\Administrator\\Dropbox\\Desktop\\foo.gcode"',
|
||||
''))}
|
||||
testing.auto-test-file-specs = (('regex',
|
||||
'pysnooper/tests.*/test[^./]*.py.?$'),)
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ You probably want to run it this way:
|
|||
import subprocess
|
||||
import sys
|
||||
|
||||
# This is used for people who show up more than once:
|
||||
deny_list = frozenset((
|
||||
'Lumir Balhar',
|
||||
))
|
||||
|
||||
|
||||
def drop_recurrences(iterable):
|
||||
s = set()
|
||||
|
|
@ -37,10 +42,10 @@ def iterate_authors_by_chronological_order(branch):
|
|||
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||
)
|
||||
log_lines = log_call.stdout.decode('utf-8').split('\n')
|
||||
|
||||
return drop_recurrences(
|
||||
(line.strip().split(";")[1] for line in log_lines)
|
||||
)
|
||||
|
||||
authors = tuple(line.strip().split(";")[1] for line in log_lines)
|
||||
authors = (author for author in authors if author not in deny_list)
|
||||
return drop_recurrences(authors)
|
||||
|
||||
|
||||
def print_authors(branch):
|
||||
|
|
|
|||
3
pyproject.toml
Normal file
3
pyproject.toml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[build-system]
|
||||
requires = ["setuptools"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
|
@ -24,7 +24,7 @@ import collections
|
|||
__VersionInfo = collections.namedtuple('VersionInfo',
|
||||
('major', 'minor', 'micro'))
|
||||
|
||||
__version__ = '1.1.1'
|
||||
__version__ = '1.2.3'
|
||||
__version_info__ = __VersionInfo(*(map(int, __version__.split('.'))))
|
||||
|
||||
del collections, __VersionInfo # Avoid polluting the namespace
|
||||
|
|
|
|||
|
|
@ -21,6 +21,12 @@ if pycompat.PY2:
|
|||
|
||||
ipython_filename_pattern = re.compile('^<ipython-input-([0-9]+)-.*>$')
|
||||
ansible_filename_pattern = re.compile(r'^(.+\.zip)[/|\\](ansible[/|\\]modules[/|\\].+\.py)$')
|
||||
ipykernel_filename_pattern = re.compile(r'^/var/folders/.*/ipykernel_[0-9]+/[0-9]+.py$')
|
||||
RETURN_OPCODES = {
|
||||
'RETURN_GENERATOR', 'RETURN_VALUE', 'RETURN_CONST',
|
||||
'INSTRUMENTED_RETURN_GENERATOR', 'INSTRUMENTED_RETURN_VALUE',
|
||||
'INSTRUMENTED_RETURN_CONST', 'YIELD_VALUE', 'INSTRUMENTED_YIELD_VALUE'
|
||||
}
|
||||
|
||||
|
||||
def get_local_reprs(frame, watch=(), custom_repr=(), max_length=None, normalize=False):
|
||||
|
|
@ -69,7 +75,15 @@ def get_path_and_source_from_frame(frame):
|
|||
if source is None:
|
||||
ipython_filename_match = ipython_filename_pattern.match(file_name)
|
||||
ansible_filename_match = ansible_filename_pattern.match(file_name)
|
||||
if ipython_filename_match:
|
||||
ipykernel_filename_match = ipykernel_filename_pattern.match(file_name)
|
||||
if ipykernel_filename_match:
|
||||
try:
|
||||
import linecache
|
||||
_, _, source, _ = linecache.cache.get(file_name)
|
||||
source = [line.rstrip() for line in source] # remove '\n' at the end
|
||||
except Exception:
|
||||
pass
|
||||
elif ipython_filename_match:
|
||||
entry_number = int(ipython_filename_match.group(1))
|
||||
try:
|
||||
import IPython
|
||||
|
|
@ -211,7 +225,9 @@ class Tracer:
|
|||
|
||||
@pysnooper.snoop(relative_time=True)
|
||||
|
||||
The output is colored for easy viewing by default, except on Windows.
|
||||
The output is colored for easy viewing by default, except on Windows
|
||||
(but can be enabled by setting `color=True`).
|
||||
|
||||
Disable colors like so:
|
||||
|
||||
@pysnooper.snoop(color=False)
|
||||
|
|
@ -220,7 +236,7 @@ class Tracer:
|
|||
def __init__(self, output=None, watch=(), watch_explode=(), depth=1,
|
||||
prefix='', overwrite=False, thread_info=False, custom_repr=(),
|
||||
max_variable_length=100, normalize=False, relative_time=False,
|
||||
color=True):
|
||||
color=sys.platform in ('linux', 'linux2', 'cygwin', 'darwin')):
|
||||
self._write = get_write_function(output, overwrite)
|
||||
|
||||
self.watch = [
|
||||
|
|
@ -248,8 +264,7 @@ class Tracer:
|
|||
self.max_variable_length = max_variable_length
|
||||
self.normalize = normalize
|
||||
self.relative_time = relative_time
|
||||
self.color = color and sys.platform in ('linux', 'linux2', 'cygwin',
|
||||
'darwin')
|
||||
self.color = color and (output is None)
|
||||
|
||||
if self.color:
|
||||
self._FOREGROUND_BLUE = '\x1b[34m'
|
||||
|
|
@ -467,7 +482,7 @@ class Tracer:
|
|||
"thread_info")
|
||||
current_thread = threading.current_thread()
|
||||
thread_info = "{ident}-{name} ".format(
|
||||
ident=current_thread.ident, name=current_thread.getName())
|
||||
ident=current_thread.ident, name=current_thread.name)
|
||||
thread_info = self.set_thread_info_padding(thread_info)
|
||||
|
||||
### Reporting newish and modified variables: ##########################
|
||||
|
|
@ -527,8 +542,7 @@ class Tracer:
|
|||
ended_by_exception = (
|
||||
event == 'return'
|
||||
and arg is None
|
||||
and (opcode.opname[code_byte]
|
||||
not in ('RETURN_VALUE', 'YIELD_VALUE'))
|
||||
and opcode.opname[code_byte] not in RETURN_OPCODES
|
||||
)
|
||||
|
||||
if ended_by_exception:
|
||||
|
|
|
|||
37
setup.cfg
Normal file
37
setup.cfg
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
[metadata]
|
||||
name = PySnooper
|
||||
version = attr: pysnooper.__version__
|
||||
author = Ram Rachum
|
||||
author_email = ram@rachum.com
|
||||
description = A poor man's debugger for Python.
|
||||
url = https://github.com/cool-RR/PySnooper
|
||||
long_description = file: README.md
|
||||
long_description_content_type = text/markdown
|
||||
classifiers =
|
||||
Environment :: Console
|
||||
Intended Audience :: Developers
|
||||
Programming Language :: Python :: 2.7
|
||||
Programming Language :: Python :: 3.4
|
||||
Programming Language :: Python :: 3.5
|
||||
Programming Language :: Python :: 3.6
|
||||
Programming Language :: Python :: 3.7
|
||||
Programming Language :: Python :: 3.8
|
||||
Programming Language :: Python :: 3.9
|
||||
Programming Language :: Python :: 3.10
|
||||
Programming Language :: Python :: 3.11
|
||||
Programming Language :: Python :: 3.12
|
||||
Programming Language :: Python :: Implementation :: CPython
|
||||
Programming Language :: Python :: Implementation :: PyPy
|
||||
License :: OSI Approved :: MIT License
|
||||
Operating System :: OS Independent
|
||||
Topic :: Software Development :: Debuggers
|
||||
|
||||
[options]
|
||||
packages = find:
|
||||
install_requires = file: requirements.in
|
||||
|
||||
[options.packages.find]
|
||||
exclude = tests*
|
||||
|
||||
[options.extras_require]
|
||||
tests = pytest
|
||||
1
setup.py
1
setup.py
|
|
@ -38,6 +38,7 @@ setuptools.setup(
|
|||
'Programming Language :: Python :: 3.8',
|
||||
'Programming Language :: Python :: 3.9',
|
||||
'Programming Language :: Python :: 3.10',
|
||||
'Programming Language :: Python :: 3.11',
|
||||
'Programming Language :: Python :: Implementation :: CPython',
|
||||
'Programming Language :: Python :: Implementation :: PyPy',
|
||||
'License :: OSI Approved :: MIT License',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue