Compare commits

...

23 commits

Author SHA1 Message Date
Ram Rachum
0561a89c0e Bump version to 1.2.3 2025-05-31 16:21:24 -07:00
Ram Rachum
05212d3092 Don't write color escape characters to file 2025-05-31 16:21:06 -07:00
Ram Rachum
3c0f9eb65a Include Andrej730 in AUTHORS 2025-04-10 23:56:22 +03:00
Ram Rachum
eee41b20f8 Bump version to 1.2.2 2025-04-10 23:54:31 +03:00
Ram Rachum
2931e1374a Upgrade Wing to 11 2025-04-10 23:53:59 +03:00
Andrej730
8bf06d25a1 Allow forcing color output on Windows using color=True 2025-04-10 23:52:31 +03:00
Ram Rachum
57472b4677 Bump version to 1.2.1 2024-09-09 10:41:35 +03:00
Ram Rachum
d91fd2b255 Update authors 2024-09-09 10:41:10 +03:00
sizhky
05f1359427 Compatibility with jupyter notebooks 2024-09-09 10:39:53 +03:00
Ram Rachum
ac74c8f020 Upgrade to Wing 10 2024-09-09 10:36:47 +03:00
Ram Rachum
f2c60de87f
Fix citation 2024-01-13 09:27:19 -08:00
Ram Rachum
0b96becd1b Change tabs to spaces 2024-01-06 12:07:35 +02:00
Ram Rachum
591341e973 Add citation 2024-01-06 12:04:17 +02:00
Ram Rachum
206ae83b4f Fix title formatting 2024-01-06 12:02:49 +02:00
Ram Rachum
8c35d81835 Add Python 3.12 to trove classifiers 2023-07-15 16:04:46 +01:00
Ram Rachum
23d3e43f0e Bring back setup.py for universal wheels 2023-07-15 16:02:46 +01:00
Ram Rachum
e1a927311b Version bump 2023-07-15 15:58:35 +01:00
Ram Rachum
60775ff71f Use Thread.name instead of deprecated getName 2023-07-15 17:57:35 +03:00
Ram Rachum
4224cf9694 Python 3.12 compat: Include new return opcodes 2023-07-15 17:53:09 +03:00
Ram Rachum
caf4ec584a Upgrade to Wing 9 2023-04-12 12:10:26 +03:00
Lumir Balhar
231969074e Add pyproject.toml and switch setup.py to setup.cfg 2023-01-03 15:15:29 +02:00
Ram Rachum
1ad8ae08b0
Add Trove classifier for Python 3.11 2022-12-11 15:01:28 +02:00
Ram Rachum
7ca28af18d Update authors 2022-04-02 16:07:32 +01:00
9 changed files with 113 additions and 30 deletions

View file

@ -24,3 +24,7 @@ Itamar.Raviv
iory
Mark Blakeney
Yael Mintz
Lumír 'Frenzy' Balhar
Lukas Klenk
sizhky
Andrej730

View file

@ -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)

View file

@ -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.?$'),)

View file

@ -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
View file

@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

View file

@ -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

View file

@ -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
View 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

View file

@ -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',