Skip to content

Commit

Permalink
rename; prepare for pypi
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-landy committed Oct 27, 2020
1 parent d182523 commit cf639f0
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 70 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Andrey Lyashko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Add the variable values to the standard traceback.
## Add variable values to the standard traceback.

###
###
Expand All @@ -7,19 +7,19 @@
#### Tired of putting all your variables in debug exception messages? Just stop it. Go clean your code.

```diff
+ from rich_traceback import rich_traceback
+ from traceback_with_variables import traceback_with_variables

def main():
sizes_str = sys.argv[1]
h1, w1, h2, w2 = map(int, sizes_str.split())
- try:
+ with rich_traceback():
+ with traceback_with_variables():
return get_avg_ratio([h1, w1], [h2, w2])
- except:
- logger.error(f'something happened :(, locals = {locals()[:1000]}')
- logger.error(f'something happened :(, variables = {variables()[:1000]}')
- raise
- # or
- raise MyToolException(f'something happened :(, locals = {locals()[:1000]}')
- raise MyToolException(f'something happened :(, variables = {variables()[:1000]}')

def get_avg_ratio(size1, size2):
- try:
Expand All @@ -41,7 +41,7 @@
```

```
Rich traceback (most recent call last):
Traceback with variables (most recent call last):
File "./temp.py", line 7, in main
return get_avg_ratio([h1, w1], [h2, w2])
sizes_str = '300 200 300 0'
Expand Down Expand Up @@ -70,15 +70,15 @@ builtins.ZeroDivisionError: division by zero
```python
def main():
...
with rich_traceback(
with traceback_with_variables(
file_=LoggerAsFile(logging.getLogger('main')),
reraise=False
):
...
```

```
2020-03-30 18:24:31 main ERROR Rich traceback (most recent call last):
2020-03-30 18:24:31 main ERROR Traceback with variables (most recent call last):
2020-03-30 18:24:31 main ERROR File "./temp.py", line 7, in main
2020-03-30 18:24:31 main ERROR return get_avg_ratio([h1, w1], [h2, w2])
2020-03-30 18:24:31 main ERROR sizes_str = '300 200 300 0'
Expand Down Expand Up @@ -133,8 +133,7 @@ def make_a_cake(sugar, eggs, milk, flour, salt, water):
#### Installation (simple checkout)

```
mkdir temp
(cd temp; git clone https://github.com/andy-landy/rich_traceback.git)
cp -r temp/rich_traceback/rich_traceback path/to/your/libs
rm -r temp
git clone https://github.com/andy-landy/traceback_with_variables.git
cp -r traceback_with_variables/traceback_with_variables path/to/your/libs
rm -r traceback_with_variables
```
25 changes: 25 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import setuptools

with open('README.md', 'r') as in_:
long_description=in_.read()

setuptools.setup(
name='traceback-with-variables',
version='1.0.0',
author='Andrey Lyashko',
author_email='[email protected]',
description='traceback with variables added, simple to use',
long_description=long_description,
long_description_content_type="text/markdown",
url='https://github.com/andy-landy/rich_traceback',
packages=setuptools.find_packages(),
classifiers=[
'Programming Language :: Python :: 3',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Intended Audience :: Developers',
'Topic :: Software Development :: Debuggers',
'Topic :: Software Development :: Libraries',
],
python_requires='>=3.4',
)
31 changes: 13 additions & 18 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,58 @@

import pytest

from rich_traceback import rich_traceback, LoggerAsFile
from traceback_with_variables import traceback_with_variables, LoggerAsFile


def test_file():
out = StringIO()
with rich_traceback(reraise=False, file_=out):
with traceback_with_variables(reraise=False, file_=out):
f(10001)

assert_smart_equals_ref('test_file', out.getvalue())


def test_ellipsis():
out = StringIO()
with rich_traceback(reraise=False, file_=out, ellipsis='*'):
with traceback_with_variables(reraise=False, file_=out, ellipsis='*'):
f(10000)

assert_smart_equals_ref('test_ellipsis', out.getvalue())


def test_max_value_str_len():
out = StringIO()
with rich_traceback(reraise=False, file_=out, max_value_str_len=10):
with traceback_with_variables(reraise=False, file_=out, max_value_str_len=10):
f(10000)

assert_smart_equals_ref('test_max_value_str_len', out.getvalue())


def test_max_exc_str_len():
out = StringIO()
with rich_traceback(reraise=False, file_=out, max_exc_str_len=10):
with traceback_with_variables(reraise=False, file_=out, max_exc_str_len=10):
f(10000)

assert_smart_equals_ref('test_max_exc_str_len', out.getvalue())


def test_reraise():
out = StringIO()

with pytest.raises(ZeroDivisionError):
with rich_traceback(reraise=True, file_=out):
with traceback_with_variables(reraise=True, file_=out):
f(10000)

assert_smart_equals_ref('test_reraise', out.getvalue())


def test_logger(caplog):
with rich_traceback(reraise=False, file_=LoggerAsFile(logging.getLogger('test-logger'))):
with traceback_with_variables(reraise=False, file_=LoggerAsFile(logging.getLogger('test-logger'))):
f(10000)

assert_smart_equals_ref('test_logger', caplog.text)

# - playground - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# - playground - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

def f(n: int) -> int:
s1 = 'short string with n={}'.format(n)
Expand Down Expand Up @@ -96,13 +95,9 @@ def assert_equals_ref(name: str, value: str) -> None:
assert value == in_.read()


def hide_paths(text: str) -> str:
return text.replace(os.path.abspath(os.path.curdir), '.')


def hide_objs(text: str) -> str:
return re.sub(r'object at 0x\w+', 'object at 0x???', text)


def assert_smart_equals_ref(name: str, value: str) -> None:
assert_equals_ref(name, hide_objs(hide_paths(value)))
for dir_ in ['traceback_with_variables', 'tests']:
value = re.sub(r'(File ").*(/{}/)'.format(dir_), r'\1...\2', value)
value = re.sub(r'(object at 0x)\w+', r'\1...', value)

assert_equals_ref(name, value)
12 changes: 6 additions & 6 deletions tests/test_ellipsis.dump.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Rich traceback (most recent call last):
File "./tests/test_all.py", line 22, in test_ellipsis
Traceback with variables (most recent call last):
File ".../tests/test_all.py", line 22, in test_ellipsis
f(10000)
out = <_io.StringIO object at 0x???>
File "./tests/test_all.py", line 68, in f
out = <_io.StringIO object at 0x...>
File ".../tests/test_all.py", line 67, in f
return 1 // (n * 0)
n = 10000
s1 = 'short string with n=10000'
l1 = 'long string with 0..n: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 2*
us = <exception while printing> Traceback (most recent call last):
File "./rich_traceback/__init__.py", line 60, in _to_cropped_str
File ".../traceback_with_variables/__init__.py", line 60, in _to_cropped_str
return _crop(repr(obj), max_value_str_len, ellipsis)
File "./tests/test_all.py", line 82, in __repr__
File ".../tests/test_all.py", line 81, in __repr__
raise ValueError("please don't print me")
ValueError: please don't print me

Expand Down
18 changes: 9 additions & 9 deletions tests/test_file.dump.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
Rich traceback (most recent call last):
File "./tests/test_all.py", line 14, in test_file
Traceback with variables (most recent call last):
File ".../tests/test_all.py", line 14, in test_file
f(10001)
out = <_io.StringIO object at 0x???>
File "./tests/test_all.py", line 73, in f
out = <_io.StringIO object at 0x...>
File ".../tests/test_all.py", line 72, in f
return f(
n = 10001
s1 = 'short string with n=10001'
l1 = 'long string with 0..n: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 2...
us = <exception while printing> Traceback (most recent call last):
File "./rich_traceback/__init__.py", line 60, in _to_cropped_str
File ".../traceback_with_variables/__init__.py", line 60, in _to_cropped_str
return _crop(repr(obj), max_value_str_len, ellipsis)
File "./tests/test_all.py", line 82, in __repr__
File ".../tests/test_all.py", line 81, in __repr__
raise ValueError("please don't print me")
ValueError: please don't print me

File "./tests/test_all.py", line 68, in f
File ".../tests/test_all.py", line 67, in f
return 1 // (n * 0)
n = 10000
s1 = 'short string with n=10000'
l1 = 'long string with 0..n: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 2...
us = <exception while printing> Traceback (most recent call last):
File "./rich_traceback/__init__.py", line 60, in _to_cropped_str
File ".../traceback_with_variables/__init__.py", line 60, in _to_cropped_str
return _crop(repr(obj), max_value_str_len, ellipsis)
File "./tests/test_all.py", line 82, in __repr__
File ".../tests/test_all.py", line 81, in __repr__
raise ValueError("please don't print me")
ValueError: please don't print me

Expand Down
12 changes: 6 additions & 6 deletions tests/test_logger.dump.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
ERROR test-logger:__init__.py:18 Rich traceback (most recent call last):
ERROR test-logger:__init__.py:18 File "./tests/test_all.py", line 55, in test_logger
ERROR test-logger:__init__.py:18 Traceback with variables (most recent call last):
ERROR test-logger:__init__.py:18 File ".../tests/test_all.py", line 54, in test_logger
ERROR test-logger:__init__.py:18 f(10000)
ERROR test-logger:__init__.py:18 caplog = <_pytest.logging.LogCaptureFixture object at 0x???>
ERROR test-logger:__init__.py:18 File "./tests/test_all.py", line 68, in f
ERROR test-logger:__init__.py:18 caplog = <_pytest.logging.LogCaptureFixture object at 0x...>
ERROR test-logger:__init__.py:18 File ".../tests/test_all.py", line 67, in f
ERROR test-logger:__init__.py:18 return 1 // (n * 0)
ERROR test-logger:__init__.py:18 n = 10000
ERROR test-logger:__init__.py:18 s1 = 'short string with n=10000'
ERROR test-logger:__init__.py:18 l1 = 'long string with 0..n: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 2...
ERROR test-logger:__init__.py:18 us = <exception while printing> Traceback (most recent call last):
ERROR test-logger:__init__.py:18 File "./rich_traceback/__init__.py", line 60, in _to_cropped_str
ERROR test-logger:__init__.py:18 File ".../traceback_with_variables/__init__.py", line 60, in _to_cropped_str
ERROR test-logger:__init__.py:18 return _crop(repr(obj), max_value_str_len, ellipsis)
ERROR test-logger:__init__.py:18 File "./tests/test_all.py", line 82, in __repr__
ERROR test-logger:__init__.py:18 File ".../tests/test_all.py", line 81, in __repr__
ERROR test-logger:__init__.py:18 raise ValueError("please don't print me")
ERROR test-logger:__init__.py:18 ValueError: please don't print me
ERROR test-logger:__init__.py:18
Expand Down
8 changes: 4 additions & 4 deletions tests/test_max_exc_str_len.dump.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Rich traceback (most recent call last):
File "./tests/test_all.py", line 38, in test_max_exc_str_len
Traceback with variables (most recent call last):
File ".../tests/test_all.py", line 38, in test_max_exc_str_len
f(10000)
out = <_io.StringIO object at 0x???>
File "./tests/test_all.py", line 68, in f
out = <_io.StringIO object at 0x...>
File ".../tests/test_all.py", line 67, in f
return 1 // (n * 0)
n = 10000
s1 = 'short string with n=10000'
Expand Down
10 changes: 5 additions & 5 deletions tests/test_max_value_str_len.dump.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Rich traceback (most recent call last):
File "./tests/test_all.py", line 30, in test_max_value_str_len
Traceback with variables (most recent call last):
File ".../tests/test_all.py", line 30, in test_max_value_str_len
f(10000)
out = <_io.Strin...
File "./tests/test_all.py", line 68, in f
File ".../tests/test_all.py", line 67, in f
return 1 // (n * 0)
n = 10000
s1 = 'short str...
l1 = 'long stri...
us = <exception while printing> Traceback (most recent call last):
File "./rich_traceback/__init__.py", line 60, in _to_cropped_str
File ".../traceback_with_variables/__init__.py", line 60, in _to_cropped_str
return _crop(repr(obj), max_value_str_len, ellipsis)
File "./tests/test_all.py", line 82, in __repr__
File ".../tests/test_all.py", line 81, in __repr__
raise ValueError("please don't print me")
ValueError: please don't print me

Expand Down
12 changes: 6 additions & 6 deletions tests/test_reraise.dump.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Rich traceback (most recent call last):
File "./tests/test_all.py", line 48, in test_reraise
Traceback with variables (most recent call last):
File ".../tests/test_all.py", line 47, in test_reraise
f(10000)
out = <_io.StringIO object at 0x???>
File "./tests/test_all.py", line 68, in f
out = <_io.StringIO object at 0x...>
File ".../tests/test_all.py", line 67, in f
return 1 // (n * 0)
n = 10000
s1 = 'short string with n=10000'
l1 = 'long string with 0..n: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 2...
us = <exception while printing> Traceback (most recent call last):
File "./rich_traceback/__init__.py", line 60, in _to_cropped_str
File ".../traceback_with_variables/__init__.py", line 60, in _to_cropped_str
return _crop(repr(obj), max_value_str_len, ellipsis)
File "./tests/test_all.py", line 82, in __repr__
File ".../tests/test_all.py", line 81, in __repr__
raise ValueError("please don't print me")
ValueError: please don't print me

Expand Down
8 changes: 8 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[tox]
envlist = py34,py39

[testenv]
deps = pytest
commands = pytest {posargs}


Loading

0 comments on commit cf639f0

Please sign in to comment.