memory-graph 0.3.66__tar.gz → 0.3.67__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 (41) hide show
  1. {memory_graph-0.3.66 → memory_graph-0.3.67}/PKG-INFO +2 -1
  2. {memory_graph-0.3.66 → memory_graph-0.3.67}/README.md +1 -0
  3. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/__init__.py +102 -1
  4. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph.egg-info/PKG-INFO +2 -1
  5. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph.egg-info/SOURCES.txt +0 -1
  6. {memory_graph-0.3.66 → memory_graph-0.3.67}/pyproject.toml +1 -1
  7. memory_graph-0.3.66/setup.py +0 -7
  8. {memory_graph-0.3.66 → memory_graph-0.3.67}/LICENSE.txt +0 -0
  9. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/call_stack.py +0 -0
  10. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/config.py +0 -0
  11. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/config_default.py +0 -0
  12. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/config_helpers.py +0 -0
  13. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/extension_numpy.py +0 -0
  14. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/extension_pandas.py +0 -0
  15. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/extension_torch.py +0 -0
  16. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/html_table.py +0 -0
  17. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/list_view.py +0 -0
  18. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/memory_to_nodes.py +0 -0
  19. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/node_base.py +0 -0
  20. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/node_key_value.py +0 -0
  21. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/node_leaf.py +0 -0
  22. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/node_linear.py +0 -0
  23. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/node_table.py +0 -0
  24. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/sequence.py +0 -0
  25. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/slicer.py +0 -0
  26. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/slices.py +0 -0
  27. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/slices_iterator.py +0 -0
  28. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/slices_table_iterator.py +0 -0
  29. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/test.py +0 -0
  30. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/test_max_graph_depth.py +0 -0
  31. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/test_memory_graph.py +0 -0
  32. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/test_memory_to_nodes.py +0 -0
  33. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/test_sequence.py +0 -0
  34. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/test_slicer.py +0 -0
  35. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/test_slices.py +0 -0
  36. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/test_slices_iterator.py +0 -0
  37. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph/utils.py +0 -0
  38. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph.egg-info/dependency_links.txt +0 -0
  39. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph.egg-info/requires.txt +0 -0
  40. {memory_graph-0.3.66 → memory_graph-0.3.67}/memory_graph.egg-info/top_level.txt +0 -0
  41. {memory_graph-0.3.66 → memory_graph-0.3.67}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: memory_graph
3
- Version: 0.3.66
3
+ Version: 0.3.67
4
4
  Summary: Teaching tool and debugging aid in context of references, mutable data types, and shallow and deep copy.
5
5
  Author-email: Bas Terwijn <bterwijn@gmail.com>
6
6
  License-Expression: BSD-2-Clause
@@ -500,6 +500,7 @@ The ```mg.stack()``` doesn't work well in **watch** context in most debuggers be
500
500
  |:---|:---|
501
501
  | [pdb](https://docs.python.org/3/library/pdb.html), [pudb](https://pypi.org/project/pudb/) | `mg.stack_pdb()` |
502
502
  | [Visual Studio Code](https://code.visualstudio.com/docs/languages/python) | `mg.stack_vscode()` |
503
+ | [Jupyter Notebooks in VS Code](https://code.visualstudio.com/docs/datascience/jupyter-notebooks) | `mg.stack_vscode_jupyter()` |
503
504
  | [Cursor AI](https://www.cursor.com/) | `mg.stack_cursor()` |
504
505
  | [PyCharm](https://www.jetbrains.com/pycharm/) | `mg.stack_pycharm()` |
505
506
  | [Wing](https://wingware.com/) | `mg.stack_wing()` |
@@ -480,6 +480,7 @@ The ```mg.stack()``` doesn't work well in **watch** context in most debuggers be
480
480
  |:---|:---|
481
481
  | [pdb](https://docs.python.org/3/library/pdb.html), [pudb](https://pypi.org/project/pudb/) | `mg.stack_pdb()` |
482
482
  | [Visual Studio Code](https://code.visualstudio.com/docs/languages/python) | `mg.stack_vscode()` |
483
+ | [Jupyter Notebooks in VS Code](https://code.visualstudio.com/docs/datascience/jupyter-notebooks) | `mg.stack_vscode_jupyter()` |
483
484
  | [Cursor AI](https://www.cursor.com/) | `mg.stack_cursor()` |
484
485
  | [PyCharm](https://www.jetbrains.com/pycharm/) | `mg.stack_pycharm()` |
485
486
  | [Wing](https://wingware.com/) | `mg.stack_wing()` |
@@ -2,7 +2,7 @@
2
2
  # Copyright (c) 2023, Bas Terwijn.
3
3
  # SPDX-License-Identifier: BSD-2-Clause
4
4
 
5
- __version__ = "0.3.66"
5
+ __version__ = "0.3.67"
6
6
  __author__ = 'Bas Terwijn'
7
7
 
8
8
  import memory_graph.memory_to_nodes as memory_to_nodes
@@ -241,6 +241,51 @@ def stack_slice(begin_functions : List[Tuple[str, int]] = [],
241
241
  end_index = stack_end_index(stack_functions, begin_index, end_functions)
242
242
  return stack_frames_to_dict(reversed(frameInfos[begin_index+stack_index:end_index+1]))
243
243
 
244
+ def stack_multi_slice(drop_functions : List[Tuple[str, int]] = [],
245
+ end_functions : List[str] = ["<module>"],
246
+ stack_index : int = 0,
247
+ frameInfos : List[inspect.FrameInfo] = None,
248
+ ignore_frame_condition = None):
249
+ """
250
+ Returns a slice of the call stack, dropping all occurrences of the specified drop_functions.
251
+ Parameters:
252
+ drop_functions - list of (function-name, offset), drops all matching 'function-name' frames
253
+ including 'offset' number of parent frames for each match.
254
+ end_functions - list of function-names, ends at the index of the first 'function-name'
255
+ that is found in the call stack after stack index (inclusive),
256
+ otherwise ends at the last index
257
+ stack_index - number of frames removed from the beginning
258
+ ignore_frame_condition - optional callable that takes an inspect.FrameInfo and returns True if the frame should be dropped
259
+ """
260
+ if frameInfos is None:
261
+ frameInfos = inspect.stack()
262
+
263
+ stack_functions = [s.function for s in frameInfos]
264
+
265
+ # establish where to start (skipping innermost debugger eval frames)
266
+ begin_index = stack_begin_index(stack_functions, drop_functions)
267
+ if begin_index == 0:
268
+ begin_index += stack_index
269
+
270
+ end_index = stack_end_index(stack_functions, begin_index, end_functions)
271
+
272
+ drop_indices = set()
273
+ for drop_func, offset in drop_functions:
274
+ for i, func in enumerate(stack_functions[begin_index:end_index+1]):
275
+ actual_i = i + begin_index
276
+ if func == drop_func:
277
+ for j in range(actual_i, actual_i + offset):
278
+ drop_indices.add(j)
279
+
280
+ if ignore_frame_condition:
281
+ for i in range(begin_index, end_index + 1):
282
+ if i not in drop_indices and ignore_frame_condition(frameInfos[i]):
283
+ drop_indices.add(i)
284
+
285
+ filtered_frames = [frameInfos[i] for i in range(begin_index, end_index + 1) if i not in drop_indices]
286
+
287
+ return stack_frames_to_dict(reversed(filtered_frames))
288
+
244
289
  def stack(end_functions=["<module>"], stack_index=0):
245
290
  return stack_slice([], end_functions, stack_index+2)
246
291
 
@@ -275,6 +320,56 @@ def stack_wing(begin_functions=[("_py_line_event",1), ("_py_return_event",1)],
275
320
  return stack_slice(begin_functions, end_functions, stack_index)
276
321
 
277
322
 
323
+ banned_vscode_jupyter_strings = ['pydevd', 'debugpy', 'ipython', 'ipykernel', 'asyncio', 'tornado', 'traitlets', 'runpy']
324
+
325
+ def is_vscode_jupyter_banned(frameInfo):
326
+ module_name = frameInfo.frame.f_globals.get('__name__', '')
327
+ filename = frameInfo.filename
328
+ func_name = frameInfo.function
329
+
330
+ module_name_lower = module_name.lower()
331
+ func_name_lower = func_name.lower()
332
+ filename_lower = filename.lower()
333
+
334
+ # Exempt user notebook/cell code from being banned.
335
+ if module_name == '__main__' or filename_lower.startswith('<ipython-input'):
336
+ return False
337
+
338
+ for b in banned_vscode_jupyter_strings:
339
+ if b in module_name_lower or b in func_name_lower or b in filename_lower:
340
+ return True
341
+
342
+ return False
343
+
344
+ def stack_vscode_jupyter(drop_functions=[("trace_dispatch",1), ("_line_event",1), ("_return_event",1), ("do_wait_suspend",1), ("_do_wait_suspend",2)],
345
+ end_functions=["<module>"],
346
+ stack_index=0):
347
+ """ Get the call stack natively in a 'vscode' debugging 'jupyter' notebook session,
348
+ filtering out the noisy environment specific functions and modules that pollute the graph. """
349
+ # stack_index + 2 to account for stack_vscode_jupyter and stack_multi_slice
350
+ call_stack_dict = stack_multi_slice(drop_functions, end_functions, stack_index + 2, ignore_frame_condition=is_vscode_jupyter_banned)
351
+
352
+ for level_key, local_dict in call_stack_dict.items():
353
+ if '__pydevd_ret_val_dict' in local_dict:
354
+ ret_vals = local_dict.pop('__pydevd_ret_val_dict')
355
+ if isinstance(ret_vals, dict):
356
+ for k, v in ret_vals.items():
357
+ # filter out Jupyter internal return values, particularly I/O stream writes
358
+ if not any(b in k.lower() for b in banned_vscode_jupyter_strings) and 'write' not in k.lower():
359
+ # Place return value in the function's own frame if it is still on the stack
360
+ target_dict = local_dict
361
+ for l_key, l_dict in call_stack_dict.items():
362
+ if ": " in l_key and l_key.split(": ", 1)[1] == k:
363
+ target_dict = l_dict
364
+ break
365
+ target_dict[f"<return> {k}"] = v
366
+
367
+ if "<module>" in level_key:
368
+ call_stack_dict[level_key] = jupyter_locals_filter(local_dict)
369
+
370
+ return call_stack_dict
371
+
372
+
278
373
  def save_call_stack(filename):
279
374
  """ Saves the call stack to 'filename' for inspection to see what functions need to be
280
375
  filtered out to create the desired graph. """
@@ -310,6 +405,12 @@ def wing(filename=None, data=None):
310
405
  data = stack_wing()
311
406
  render(data, filename)
312
407
 
408
+ def vscode_jupyter(filename=None, data=None):
409
+ if data is None:
410
+ # stack_index=1 since this function counts as an extra stack frame
411
+ data = stack_vscode_jupyter(stack_index=1)
412
+ render(data, filename)
413
+
313
414
  def locals_filter(locals, keys):
314
415
  """ Filter out the jupyter specific keys that polute the graph. """
315
416
  return {k:v for k,v in utils.filter_dict(jupyter_locals)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: memory_graph
3
- Version: 0.3.66
3
+ Version: 0.3.67
4
4
  Summary: Teaching tool and debugging aid in context of references, mutable data types, and shallow and deep copy.
5
5
  Author-email: Bas Terwijn <bterwijn@gmail.com>
6
6
  License-Expression: BSD-2-Clause
@@ -500,6 +500,7 @@ The ```mg.stack()``` doesn't work well in **watch** context in most debuggers be
500
500
  |:---|:---|
501
501
  | [pdb](https://docs.python.org/3/library/pdb.html), [pudb](https://pypi.org/project/pudb/) | `mg.stack_pdb()` |
502
502
  | [Visual Studio Code](https://code.visualstudio.com/docs/languages/python) | `mg.stack_vscode()` |
503
+ | [Jupyter Notebooks in VS Code](https://code.visualstudio.com/docs/datascience/jupyter-notebooks) | `mg.stack_vscode_jupyter()` |
503
504
  | [Cursor AI](https://www.cursor.com/) | `mg.stack_cursor()` |
504
505
  | [PyCharm](https://www.jetbrains.com/pycharm/) | `mg.stack_pycharm()` |
505
506
  | [Wing](https://wingware.com/) | `mg.stack_wing()` |
@@ -1,7 +1,6 @@
1
1
  LICENSE.txt
2
2
  README.md
3
3
  pyproject.toml
4
- setup.py
5
4
  memory_graph/__init__.py
6
5
  memory_graph/call_stack.py
7
6
  memory_graph/config.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "memory_graph"
7
- version = "0.3.66"
7
+ version = "0.3.67"
8
8
  description = "Teaching tool and debugging aid in context of references, mutable data types, and shallow and deep copy."
9
9
  authors = [
10
10
  {name = "Bas Terwijn", email = "bterwijn@gmail.com"}
@@ -1,7 +0,0 @@
1
- from setuptools import setup
2
-
3
- setup(
4
- name="memory-graph",
5
- version="0.3.30",
6
- packages=["memory_graph"],
7
- )
File without changes
File without changes