Skip to content
This repository was archived by the owner on Jun 4, 2021. It is now read-only.

Commit 5aa1a8c

Browse files
committed
updates
1 parent 397d15f commit 5aa1a8c

File tree

10 files changed

+123
-52
lines changed

10 files changed

+123
-52
lines changed

.idea/PyDebug.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

setup.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
data_files = [
88
'PyDebug/*.py'
99
]
10+
1011
setup(
1112
name='PyDebug',
1213
version=version,
@@ -18,30 +19,29 @@
1819
description='A set of helpers for debugging Python 3.x.',
1920
install_requires=[],
2021
classifiers=[
21-
# How mature is this project? Common values are
22-
# 3 - Alpha
23-
# 4 - Beta
24-
# 5 - Production/Stable
25-
'Development Status :: 3 - Alpha',
26-
27-
# Indicate who your project is intended for
28-
'Intended Audience :: Developers',
29-
'Topic :: Software Development :: Build Tools',
30-
31-
# Pick your license as you wish
32-
'License :: Free To Use But Restricted',
33-
34-
# Support platforms
35-
'Operating System :: MacOS',
36-
'Operating System :: Microsoft :: Windows',
37-
'Operating System :: POSIX',
38-
39-
'Programming Language :: Python :: 3',
40-
],
22+
# How mature is this project? Common values are
23+
# 3 - Alpha
24+
# 4 - Beta
25+
# 5 - Production/Stable
26+
'Development Status :: 3 - Alpha',
27+
28+
# Indicate who your project is intended for
29+
'Intended Audience :: Developers',
30+
'Topic :: Software Development :: Build Tools',
31+
32+
# Pick your license as you wish
33+
'License :: Free To Use But Restricted',
34+
35+
# Support platforms
36+
'Operating System :: MacOS',
37+
'Operating System :: Microsoft :: Windows',
38+
'Operating System :: POSIX',
39+
40+
'Programming Language :: Python :: 3',
41+
],
4142
keywords='switch switch-case case',
42-
package_dir={'PyDebug': 'src/PyDebug'},
43+
package_dir={ 'PyDebug': 'src/PyDebug' },
4344
package_data={
4445
'PyDebug': data_files,
45-
},
46+
},
4647
)
47-

src/PyDebug/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from .colors import *
77
from .__version__ import *
88

9-
import PyDebug.chains as Chains
109

1110
def get_size(obj, seen=None):
1211
"""Recursively finds size of objects"""

src/PyDebug/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
version = '1.4.5'
3+
version = '1.5.0'

src/PyDebug/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55

66
DEFAULT_TAG = '\n______________________________________________________________\n"{0}"'
7+
END_TAG = '\n=============================================================\n'
8+
9+
710

811
def GetFuncModule(func: callable) -> str:
912
return func.__module__

src/PyDebug/chains.py

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,97 @@
11
import functools
2-
from .base import GetFunctionName, DEFAULT_TAG
2+
from itertools import count
3+
4+
from .base import GetFunctionName, DEFAULT_TAG, END_TAG
35

46
from .console import getPPrintStr
57

8+
__all__ = ['chain', 'sub']
9+
10+
11+
class _AutoCounter(object):
12+
_counter: count
13+
def __init__(self, *, start: int = 0, step: int = 1):
14+
self._value = start
15+
self.reset(start=start, step=step)
16+
def __call__(self, *args, **kwargs) -> int:
17+
self._value = self._next()
18+
return self._value
19+
@property
20+
def value(self) -> int:
21+
return self._value
22+
def reset(self, *, start: int = 0, step: int = 1):
23+
self._counter = count(start=start, step=step)
24+
self._next = self._counter.__next__
625

726

27+
_counter = _AutoCounter()
828

9-
__all__ = ['top_debug', 'sub_level', ]
1029

11-
def print_chain_signature(func: callable, tag: str, level: int or str, signature: bool, *args, **kwargs):
30+
def _print_chain_signature(func: callable, tag: str, level: int or str, signature: bool, *args, **kwargs):
1231
assert ('{0}' in tag)
1332
name = GetFunctionName(func)
14-
print(tag.format(f'{level}'))
33+
print(tag.format(f'{level} --> {name}'))
1534

1635
if signature and (args or kwargs):
1736
signature = getPPrintStr({ 'kwargs': kwargs, 'args': args, })
1837
print(f"{name}(\n {signature}\n )")
1938
result = func(*args, **kwargs)
2039
print(f"{name} returned: \n{getPPrintStr(result)}\n")
2140

22-
def top_debug(func: callable, tag: str = DEFAULT_TAG):
41+
42+
43+
def chain(start_tag: str = DEFAULT_TAG, end_tag: str = END_TAG, start: int = 1):
2344
"""
2445
Print the function signature and return value
2546
26-
:param func: callable function to be debugged.
27-
:param tag: a unique string to identify the output in the console window.
47+
:param end_tag: a unique string to identify the ENDING of the chain in the console window.
48+
:param start_tag: a unique string to identify the START of the chain in the console window.
2849
:return:
2950
"""
30-
name = GetFunctionName(func)
51+
_counter.reset(start=start)
52+
def top(func: callable):
53+
"""
54+
:param func: callable function to be debugged.
55+
:return:
56+
"""
57+
name = GetFunctionName(func)
3158

32-
@functools.wraps(func)
33-
def wrapper_debug(*args, **kwargs):
34-
print(tag.format(name))
35-
signature = getPPrintStr({ 'kwargs': kwargs, 'args': args, })
36-
print(f"{name}(\n {signature}\n )")
37-
result = func(*args, **kwargs)
38-
print(f"{name} returned: \n{getPPrintStr(result)}\n")
59+
@functools.wraps(func)
60+
def wrapper_debug(*args, **kwargs):
61+
print(start_tag.format(name))
62+
signature = getPPrintStr({ 'kwargs': kwargs, 'args': args, })
63+
print(f"{name}(\n {signature}\n )")
64+
result = func(*args, **kwargs)
65+
print(f"{name} returned: \n{getPPrintStr(result)}\n")
66+
print(end_tag)
3967

40-
return result
41-
return wrapper_debug
68+
return result
69+
return wrapper_debug
70+
return top
71+
72+
# class callback(object):
73+
# def __init__(self, func: callable, name: str, tag: str, signature: bool ):
74+
# self._signature = signature
75+
# self._tag = tag
76+
# self._name = name
77+
# self._func = func
78+
# def __call__(self, *args, **kwargs):
79+
# _print_chain_signature(self._func, self._tag, _counter(), self._signature, *args, **kwargs)
80+
# result = self._func(*args, **kwargs)
81+
# print(f"{self._name} returned {result!r}\n")
82+
# return result
4283

43-
def sub_level(level: str or str, *, tag: str = '-------------- level: {0}', signature: bool = True):
84+
def sub(*, tag: str = '-------------- level: {0}', signature: bool = False):
4485
"""
4586
Print the function signature [Optional] and return value.
4687
47-
:param signature: for sub-level method chains, prints it's signature. defaults to true.
88+
:param signature: for sub-level method chains, prints it's signature. defaults to False.
4889
:param level: the call stack level. f() -> g() -> h() -> etc.
4990
:param tag: a unique string to identify the output in the console window. must have one '{0}' for str.format() support.
5091
:return:
5192
"""
52-
def sub(func: callable):
93+
94+
def wrapped(func: callable):
5395
"""
5496
:param func: callable function to be debugged.
5597
:return:
@@ -58,10 +100,10 @@ def sub(func: callable):
58100

59101
@functools.wraps(func)
60102
def wrapper_debug(*args, **kwargs):
61-
print_chain_signature(func, tag, level, signature, *args, **kwargs)
103+
# return callback(func, name, tag, signature)
104+
_print_chain_signature(func, tag, _counter(), signature, *args, **kwargs)
62105
result = func(*args, **kwargs)
63106
print(f"{name} returned {result!r}\n")
64-
65107
return result
66108
return wrapper_debug
67-
return sub
109+
return wrapped

src/PyDebug/colors.png

1.19 MB
Loading

src/PyDebug/console.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import logging
22
import pprint
3+
import traceback
34

45
pp = pprint.PrettyPrinter(indent=4)
56

6-
__all__ = ['PRINT', 'getPPrintStr', 'pp']
7+
__all__ = ['PRINT', 'getPPrintStr', 'print_exception']
78

89
def PRINT(title: str, Object: any, logger: logging.Logger = None):
910
print(f"\n ---------------- {title} ---------------- \n\r")
1011
pp.pprint(Object)
1112
if logger: logger.debug(f' ---------------- {title} ---------------- \n{pp.pformat(Object)}')
1213

1314

15+
1416
def getPPrintStr(Object: any) -> str:
1517
return f'{pp.pformat(Object)}'
1618

19+
20+
21+
def print_exception(e: Exception):
22+
traceback.print_exception(type(e), e, e.__traceback__)

src/examples.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import time
12
import tkinter as tk
23
from PyDebug import *
34

@@ -7,17 +8,36 @@ class test(object):
78
@pprint_debug
89
def pp_run(self, *args, **kwargs):
910
pass
11+
1012
@debug
1113
def run(self, *args, **kwargs):
1214
pass
15+
1316
@debugTkinterEvent
1417
def tk_run(self, event: tk.Event):
1518
pass
1619

20+
@check_time
21+
def timed(self, *args, **kwargs):
22+
time.sleep(1)
23+
24+
@Chains.chain()
25+
def root(self, *args, **kwargs):
26+
self.sub1(*args, **kwargs)
27+
@Chains.sub()
28+
def sub1(self, *args, **kwargs):
29+
self.sub2(*args, **kwargs)
30+
31+
@Chains.sub()
32+
def sub2(self, *args, **kwargs):
33+
pass
34+
35+
36+
1737
t = test()
1838

1939
t.run()
20-
40+
t.timed()
2141
t.pp_run()
2242

2343
evt = tk.Event()
@@ -26,3 +46,4 @@ def tk_run(self, event: tk.Event):
2646
evt.y = None
2747
t.tk_run(evt)
2848

49+
t.root()

0 commit comments

Comments
 (0)