pretty-debugger 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pretty_debugger-0.1.0/LICENSE +21 -0
- pretty_debugger-0.1.0/PKG-INFO +78 -0
- pretty_debugger-0.1.0/README.md +61 -0
- pretty_debugger-0.1.0/pretty_debugger/__init__.py +6 -0
- pretty_debugger-0.1.0/pretty_debugger/cache.py +30 -0
- pretty_debugger-0.1.0/pretty_debugger/utils.py +16 -0
- pretty_debugger-0.1.0/pretty_debugger/wrapper.py +90 -0
- pretty_debugger-0.1.0/pretty_debugger.egg-info/PKG-INFO +78 -0
- pretty_debugger-0.1.0/pretty_debugger.egg-info/SOURCES.txt +11 -0
- pretty_debugger-0.1.0/pretty_debugger.egg-info/dependency_links.txt +1 -0
- pretty_debugger-0.1.0/pretty_debugger.egg-info/top_level.txt +1 -0
- pretty_debugger-0.1.0/pyproject.toml +29 -0
- pretty_debugger-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PyCrow
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pretty_debugger
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python package for easy and convenient debugging
|
|
5
|
+
Author: PyCrow
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/PyCrow/pretty_debugger/
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/PyCrow/pretty_debugger/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Topic :: System :: Logging
|
|
13
|
+
Requires-Python: >=3.7
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
Wraps a function to log its execution, including all args, kwargs,
|
|
19
|
+
execution result, and errors.
|
|
20
|
+
|
|
21
|
+
Wrapper does not make any changes that affect the result of
|
|
22
|
+
code execution or errors.
|
|
23
|
+
|
|
24
|
+
Usage:
|
|
25
|
+
```python
|
|
26
|
+
import logging
|
|
27
|
+
from pretty_debugger import pretty_wrapper
|
|
28
|
+
|
|
29
|
+
logger = logging.getLogger(__name__)
|
|
30
|
+
|
|
31
|
+
@pretty_wrapper(logger)
|
|
32
|
+
def foo(bar):
|
|
33
|
+
return f"Hello, {bar}"
|
|
34
|
+
|
|
35
|
+
foo("world")
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Corresponding output:
|
|
39
|
+
```
|
|
40
|
+
┯
|
|
41
|
+
├─►foo(
|
|
42
|
+
│ bar=world,
|
|
43
|
+
│ )
|
|
44
|
+
┊ └► Hello, world (0.0000s)
|
|
45
|
+
┷
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Output when using nested wrapped functions:
|
|
49
|
+
```
|
|
50
|
+
┯
|
|
51
|
+
├─►foobar(
|
|
52
|
+
│ some_arg=0,
|
|
53
|
+
│ )
|
|
54
|
+
┊ ├─►plus_one(
|
|
55
|
+
┊ │ some_arg=0,
|
|
56
|
+
┊ │ )
|
|
57
|
+
┊ ┊ └► 1 (1.0011s)
|
|
58
|
+
┊ ├─►exception_func(
|
|
59
|
+
┊ │ this_is_kwarg=True,
|
|
60
|
+
┊ │ )
|
|
61
|
+
┊ ┊ └X <Exception('SOME TEST EXCEPTION')> (0.0000s)
|
|
62
|
+
┊ └X <Exception('SOME TEST EXCEPTION')> (1.0022s)
|
|
63
|
+
┷
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Param `logger`: Logger object must contain the 'level' attribute,
|
|
67
|
+
the 'log' method, and HAVE THE 'utf-8' ENCODING.
|
|
68
|
+
|
|
69
|
+
Param `debug_level`: Custom debug level. If not specified, the
|
|
70
|
+
logger debug level or WARNING level is used, whichever is higher.
|
|
71
|
+
|
|
72
|
+
Param `round_exec_time`: Round the execution time to N after the decimal point
|
|
73
|
+
|
|
74
|
+
Returns: Wrapped function
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
Zero-dependency: Package does not require installation of additional libraries
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Wraps a function to log its execution, including all args, kwargs,
|
|
2
|
+
execution result, and errors.
|
|
3
|
+
|
|
4
|
+
Wrapper does not make any changes that affect the result of
|
|
5
|
+
code execution or errors.
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
```python
|
|
9
|
+
import logging
|
|
10
|
+
from pretty_debugger import pretty_wrapper
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
@pretty_wrapper(logger)
|
|
15
|
+
def foo(bar):
|
|
16
|
+
return f"Hello, {bar}"
|
|
17
|
+
|
|
18
|
+
foo("world")
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Corresponding output:
|
|
22
|
+
```
|
|
23
|
+
┯
|
|
24
|
+
├─►foo(
|
|
25
|
+
│ bar=world,
|
|
26
|
+
│ )
|
|
27
|
+
┊ └► Hello, world (0.0000s)
|
|
28
|
+
┷
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Output when using nested wrapped functions:
|
|
32
|
+
```
|
|
33
|
+
┯
|
|
34
|
+
├─►foobar(
|
|
35
|
+
│ some_arg=0,
|
|
36
|
+
│ )
|
|
37
|
+
┊ ├─►plus_one(
|
|
38
|
+
┊ │ some_arg=0,
|
|
39
|
+
┊ │ )
|
|
40
|
+
┊ ┊ └► 1 (1.0011s)
|
|
41
|
+
┊ ├─►exception_func(
|
|
42
|
+
┊ │ this_is_kwarg=True,
|
|
43
|
+
┊ │ )
|
|
44
|
+
┊ ┊ └X <Exception('SOME TEST EXCEPTION')> (0.0000s)
|
|
45
|
+
┊ └X <Exception('SOME TEST EXCEPTION')> (1.0022s)
|
|
46
|
+
┷
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Param `logger`: Logger object must contain the 'level' attribute,
|
|
50
|
+
the 'log' method, and HAVE THE 'utf-8' ENCODING.
|
|
51
|
+
|
|
52
|
+
Param `debug_level`: Custom debug level. If not specified, the
|
|
53
|
+
logger debug level or WARNING level is used, whichever is higher.
|
|
54
|
+
|
|
55
|
+
Param `round_exec_time`: Round the execution time to N after the decimal point
|
|
56
|
+
|
|
57
|
+
Returns: Wrapped function
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
Zero-dependency: Package does not require installation of additional libraries
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class PrettyCache:
|
|
2
|
+
_instance = None
|
|
3
|
+
|
|
4
|
+
@classmethod
|
|
5
|
+
def __new__(cls, *args, **kwargs):
|
|
6
|
+
if cls._instance is None:
|
|
7
|
+
cls._instance = super().__new__(cls)
|
|
8
|
+
return cls._instance
|
|
9
|
+
|
|
10
|
+
def __init__(self):
|
|
11
|
+
self.__level = 0
|
|
12
|
+
|
|
13
|
+
@property
|
|
14
|
+
def level(self):
|
|
15
|
+
return self.__level
|
|
16
|
+
@level.setter
|
|
17
|
+
def level(self, level):
|
|
18
|
+
self.__level = level
|
|
19
|
+
|
|
20
|
+
@staticmethod
|
|
21
|
+
def is_logger(logger) -> bool:
|
|
22
|
+
""" Checks if 'logger' has logging functionality:
|
|
23
|
+
1. 'level' attribute
|
|
24
|
+
2. 'log' method
|
|
25
|
+
"""
|
|
26
|
+
return (
|
|
27
|
+
hasattr(logger, 'level')
|
|
28
|
+
and hasattr(logger, 'log')
|
|
29
|
+
and callable(logger.log)
|
|
30
|
+
)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from logging import makeLogRecord
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
non_expo = lambda n, round_to: f"%.{round_to}f" % n
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
log = lambda logger, level, msg, *args: logger.handle(
|
|
8
|
+
makeLogRecord({
|
|
9
|
+
'args': args,
|
|
10
|
+
'levelname': "PRETTY",
|
|
11
|
+
'levelno': level,
|
|
12
|
+
'lineno': 0,
|
|
13
|
+
'msg': msg,
|
|
14
|
+
'name': "PRETTY", # Logger name
|
|
15
|
+
})
|
|
16
|
+
)
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
from logging import Logger, WARNING
|
|
3
|
+
from time import time
|
|
4
|
+
|
|
5
|
+
from .cache import PrettyCache
|
|
6
|
+
from .utils import log, non_expo
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def pretty_wrapper(
|
|
10
|
+
logger: Logger,
|
|
11
|
+
debug_level: int = None,
|
|
12
|
+
round_exec_time: int = 4,
|
|
13
|
+
):
|
|
14
|
+
"""
|
|
15
|
+
Wraps a function to log its execution, including all args, kwargs,
|
|
16
|
+
execution result, and errors.
|
|
17
|
+
|
|
18
|
+
Wrapper does not make any changes that affect the result of
|
|
19
|
+
code execution or errors.
|
|
20
|
+
|
|
21
|
+
:param logger: Logger object must contain the 'level' attribute,
|
|
22
|
+
the 'log' method, and HAVE THE 'utf-8' ENCODING.
|
|
23
|
+
|
|
24
|
+
:param debug_level: Custom debug level. If not specified, the
|
|
25
|
+
logger debug level or WARNING level is used, whichever is higher.
|
|
26
|
+
|
|
27
|
+
:param round_exec_time: Round the execution time to N after the decimal point
|
|
28
|
+
|
|
29
|
+
:returns: Wrapped function
|
|
30
|
+
"""
|
|
31
|
+
# Validate logger
|
|
32
|
+
if not PrettyCache.is_logger(logger):
|
|
33
|
+
raise TypeError("Logger object must contain a 'level' attribute"
|
|
34
|
+
" and a 'log' method.")
|
|
35
|
+
if debug_level is None:
|
|
36
|
+
debug_level = max(logger.level, WARNING)
|
|
37
|
+
|
|
38
|
+
def _wrapper(func):
|
|
39
|
+
cache = PrettyCache()
|
|
40
|
+
|
|
41
|
+
sep = ' '
|
|
42
|
+
|
|
43
|
+
def _logged_function(*args, **kwargs):
|
|
44
|
+
nonlocal logger, debug_level
|
|
45
|
+
|
|
46
|
+
get_prefix = lambda: f"┊{sep}" * cache.level
|
|
47
|
+
prefix = get_prefix()
|
|
48
|
+
|
|
49
|
+
# Start line
|
|
50
|
+
if cache.level == 0:
|
|
51
|
+
log(logger, debug_level, "┯")
|
|
52
|
+
|
|
53
|
+
# Print args and kwargs
|
|
54
|
+
if not args and not kwargs:
|
|
55
|
+
log(logger, debug_level, f"{prefix}├─►{func.__name__}()")
|
|
56
|
+
else:
|
|
57
|
+
log(logger, debug_level, f"{prefix}├─►{func.__name__}(")
|
|
58
|
+
args_kwargs = dict(zip(
|
|
59
|
+
list(inspect.signature(func).parameters.keys()),
|
|
60
|
+
args
|
|
61
|
+
))
|
|
62
|
+
args_kwargs.update(kwargs)
|
|
63
|
+
for k, v in args_kwargs.items():
|
|
64
|
+
log(logger, debug_level, f"{prefix}│{sep * 2}{k}={v},")
|
|
65
|
+
log(logger, debug_level, f"{prefix}│{sep})")
|
|
66
|
+
cache.level += 1
|
|
67
|
+
|
|
68
|
+
# Execution
|
|
69
|
+
start_time = time()
|
|
70
|
+
msg = "<pretty_wrapper: UNHANDLED EXCEPTION OCCURRED>" # var to avoid NameError
|
|
71
|
+
try:
|
|
72
|
+
result = func(*args, **kwargs)
|
|
73
|
+
except Exception as e:
|
|
74
|
+
msg = f"X <{repr(e)}>"
|
|
75
|
+
raise
|
|
76
|
+
else:
|
|
77
|
+
msg = f"► {result}"
|
|
78
|
+
finally:
|
|
79
|
+
stop_time = non_expo(time() - start_time, round_exec_time)
|
|
80
|
+
log(logger, debug_level, f"{get_prefix()}└{msg} ({stop_time}s)")
|
|
81
|
+
|
|
82
|
+
cache.level -= 1
|
|
83
|
+
|
|
84
|
+
# Finish line
|
|
85
|
+
if cache.level == 0:
|
|
86
|
+
log(logger, debug_level, "┷")
|
|
87
|
+
|
|
88
|
+
return result
|
|
89
|
+
return _logged_function
|
|
90
|
+
return _wrapper
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pretty_debugger
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python package for easy and convenient debugging
|
|
5
|
+
Author: PyCrow
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/PyCrow/pretty_debugger/
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/PyCrow/pretty_debugger/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Topic :: System :: Logging
|
|
13
|
+
Requires-Python: >=3.7
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
Wraps a function to log its execution, including all args, kwargs,
|
|
19
|
+
execution result, and errors.
|
|
20
|
+
|
|
21
|
+
Wrapper does not make any changes that affect the result of
|
|
22
|
+
code execution or errors.
|
|
23
|
+
|
|
24
|
+
Usage:
|
|
25
|
+
```python
|
|
26
|
+
import logging
|
|
27
|
+
from pretty_debugger import pretty_wrapper
|
|
28
|
+
|
|
29
|
+
logger = logging.getLogger(__name__)
|
|
30
|
+
|
|
31
|
+
@pretty_wrapper(logger)
|
|
32
|
+
def foo(bar):
|
|
33
|
+
return f"Hello, {bar}"
|
|
34
|
+
|
|
35
|
+
foo("world")
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Corresponding output:
|
|
39
|
+
```
|
|
40
|
+
┯
|
|
41
|
+
├─►foo(
|
|
42
|
+
│ bar=world,
|
|
43
|
+
│ )
|
|
44
|
+
┊ └► Hello, world (0.0000s)
|
|
45
|
+
┷
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Output when using nested wrapped functions:
|
|
49
|
+
```
|
|
50
|
+
┯
|
|
51
|
+
├─►foobar(
|
|
52
|
+
│ some_arg=0,
|
|
53
|
+
│ )
|
|
54
|
+
┊ ├─►plus_one(
|
|
55
|
+
┊ │ some_arg=0,
|
|
56
|
+
┊ │ )
|
|
57
|
+
┊ ┊ └► 1 (1.0011s)
|
|
58
|
+
┊ ├─►exception_func(
|
|
59
|
+
┊ │ this_is_kwarg=True,
|
|
60
|
+
┊ │ )
|
|
61
|
+
┊ ┊ └X <Exception('SOME TEST EXCEPTION')> (0.0000s)
|
|
62
|
+
┊ └X <Exception('SOME TEST EXCEPTION')> (1.0022s)
|
|
63
|
+
┷
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Param `logger`: Logger object must contain the 'level' attribute,
|
|
67
|
+
the 'log' method, and HAVE THE 'utf-8' ENCODING.
|
|
68
|
+
|
|
69
|
+
Param `debug_level`: Custom debug level. If not specified, the
|
|
70
|
+
logger debug level or WARNING level is used, whichever is higher.
|
|
71
|
+
|
|
72
|
+
Param `round_exec_time`: Round the execution time to N after the decimal point
|
|
73
|
+
|
|
74
|
+
Returns: Wrapped function
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
Zero-dependency: Package does not require installation of additional libraries
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
pretty_debugger/__init__.py
|
|
5
|
+
pretty_debugger/cache.py
|
|
6
|
+
pretty_debugger/utils.py
|
|
7
|
+
pretty_debugger/wrapper.py
|
|
8
|
+
pretty_debugger.egg-info/PKG-INFO
|
|
9
|
+
pretty_debugger.egg-info/SOURCES.txt
|
|
10
|
+
pretty_debugger.egg-info/dependency_links.txt
|
|
11
|
+
pretty_debugger.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pretty_debugger
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pretty_debugger"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "PyCrow" },
|
|
10
|
+
]
|
|
11
|
+
description = "A Python package for easy and convenient debugging"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.7"
|
|
14
|
+
license = { text = "MIT" }
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Topic :: System :: Logging",
|
|
20
|
+
]
|
|
21
|
+
dependencies = []
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
"Homepage" = "https://github.com/PyCrow/pretty_debugger/"
|
|
25
|
+
"Bug Tracker" = "https://github.com/PyCrow/pretty_debugger/issues"
|
|
26
|
+
|
|
27
|
+
[tool.setuptools.packages.find]
|
|
28
|
+
where = ["."]
|
|
29
|
+
include = ["pretty_debugger*"]
|