py4web-debug-tools 1.2.2__tar.gz → 1.3.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.
Files changed (21) hide show
  1. {py4web_debug_tools-1.2.2 → py4web_debug_tools-1.3.0}/CHANGELOG.md +6 -0
  2. {py4web_debug_tools-1.2.2 → py4web_debug_tools-1.3.0}/PKG-INFO +3 -3
  3. py4web_debug_tools-1.3.0/src/py4web_debug/__about__.py +1 -0
  4. {py4web_debug_tools-1.2.2 → py4web_debug_tools-1.3.0}/src/py4web_debug/__init__.py +2 -1
  5. {py4web_debug_tools-1.2.2 → py4web_debug_tools-1.3.0}/src/py4web_debug/dumping.py +39 -0
  6. py4web_debug_tools-1.2.2/src/py4web_debug/__about__.py +0 -1
  7. {py4web_debug_tools-1.2.2 → py4web_debug_tools-1.3.0}/.gitignore +0 -0
  8. {py4web_debug_tools-1.2.2 → py4web_debug_tools-1.3.0}/README.md +0 -0
  9. {py4web_debug_tools-1.2.2 → py4web_debug_tools-1.3.0}/pyproject.toml +0 -0
  10. {py4web_debug_tools-1.2.2 → py4web_debug_tools-1.3.0}/src/py4web_debug/_internals.py +0 -0
  11. {py4web_debug_tools-1.2.2 → py4web_debug_tools-1.3.0}/src/py4web_debug/core.py +0 -0
  12. {py4web_debug_tools-1.2.2 → py4web_debug_tools-1.3.0}/src/py4web_debug/debugbar.py +0 -0
  13. {py4web_debug_tools-1.2.2 → py4web_debug_tools-1.3.0}/src/py4web_debug/env.py +0 -0
  14. {py4web_debug_tools-1.2.2 → py4web_debug_tools-1.3.0}/src/py4web_debug/internals.py +0 -0
  15. {py4web_debug_tools-1.2.2 → py4web_debug_tools-1.3.0}/src/py4web_debug/py.typed +0 -0
  16. {py4web_debug_tools-1.2.2 → py4web_debug_tools-1.3.0}/src/py4web_debug/templates/debugbar.html +0 -0
  17. {py4web_debug_tools-1.2.2 → py4web_debug_tools-1.3.0}/src/py4web_debug/templates/dumpdie.html +0 -0
  18. {py4web_debug_tools-1.2.2 → py4web_debug_tools-1.3.0}/src/py4web_debug/templates/error_default.html +0 -0
  19. {py4web_debug_tools-1.2.2 → py4web_debug_tools-1.3.0}/src/py4web_debug/templates/fancy_dumpdie.html +0 -0
  20. {py4web_debug_tools-1.2.2 → py4web_debug_tools-1.3.0}/src/py4web_debug/types.py +0 -0
  21. {py4web_debug_tools-1.2.2 → py4web_debug_tools-1.3.0}/src/py4web_debug/wsgi.py +0 -0
@@ -2,6 +2,12 @@
2
2
 
3
3
  <!--next-version-placeholder-->
4
4
 
5
+ ## v1.3.0 (2025-04-01)
6
+
7
+ ### Feature
8
+
9
+ * Add `dbg` helper ([`b7529e3`](https://github.com/trialandsuccess/py4web-debug-tools/commit/b7529e32bcaa88a237fa505d26afe3f013d0bdf2))
10
+
5
11
  ## v1.2.2 (2024-11-20)
6
12
 
7
13
  ### Fix
@@ -1,12 +1,12 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: py4web-debug-tools
3
- Version: 1.2.2
3
+ Version: 1.3.0
4
4
  Summary: Debug Tools for py4web
5
5
  Project-URL: Documentation, https://github.com/trialandsuccess/py4web-debug-tools#readme
6
6
  Project-URL: Issues, https://github.com/trialandsuccess/py4web-debug-tools/issues
7
7
  Project-URL: Source, https://github.com/trialandsuccess/py4web-debug-tools
8
8
  Author-email: Robin van der Noord <contact@trialandsuccess.nl>
9
- License: MIT
9
+ License-Expression: MIT
10
10
  Classifier: Development Status :: 4 - Beta
11
11
  Classifier: Programming Language :: Python
12
12
  Classifier: Programming Language :: Python :: 3.10
@@ -0,0 +1 @@
1
+ __version__ = "1.3.0"
@@ -2,13 +2,14 @@
2
2
 
3
3
  from .core import tools
4
4
  from .debugbar import catch
5
- from .dumping import dd, dump
5
+ from .dumping import dbg, dd, dump
6
6
  from .env import is_debug
7
7
  from .wsgi import wsgi
8
8
 
9
9
  __all__ = [
10
10
  "tools",
11
11
  "catch",
12
+ "dbg",
12
13
  "dd",
13
14
  "dump",
14
15
  "is_debug",
@@ -1,5 +1,7 @@
1
+ import ast
1
2
  import json
2
3
  import sys
4
+ import traceback
3
5
  import typing
4
6
 
5
7
  import pydal.objects
@@ -152,3 +154,40 @@ def dd(*data: typing.Any, fancy: bool = True, api: bool = False) -> None:
152
154
  raise FancyDumpDieError(_json)
153
155
  else:
154
156
  raise DumpDieError(_json)
157
+
158
+
159
+ T = typing.TypeVar("T")
160
+
161
+
162
+ def dbg(value: T) -> T:
163
+ """
164
+ Helper inspired by Rust's `dbg!`.
165
+
166
+ Prints out the file, line, variable name, type and value.
167
+ Also returns the original value.
168
+ """
169
+ value_type = type(value).__name__
170
+
171
+ frame = traceback.extract_stack()[-2] # Get caller frame info
172
+ file_name = frame.filename.split("/")[-1]
173
+ line_number = frame.lineno
174
+
175
+ try:
176
+ with open(frame.filename, "r") as f:
177
+ source_code = f.readlines()
178
+
179
+ line = source_code[line_number - 1].strip()
180
+ tree = ast.parse(line)
181
+
182
+ var_name = None
183
+ if isinstance(tree, ast.Module) and isinstance(tree.body[0], ast.Expr):
184
+ call = tree.body[0].value
185
+ if isinstance(call, ast.Call) and call.func.id == "dbg":
186
+ var_name = ast.unparse(call.args[0]) # Extract the first argument as a string
187
+
188
+ except Exception:
189
+ var_name = "?"
190
+
191
+ print(f"[{file_name}:{line_number}] {value_type}({var_name}) = {value}", file=sys.stderr)
192
+
193
+ return value
@@ -1 +0,0 @@
1
- __version__ = "1.2.2"