memory-graph 0.3.93__tar.gz → 0.3.95__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 (43) hide show
  1. {memory_graph-0.3.93/memory_graph.egg-info → memory_graph-0.3.95}/PKG-INFO +19 -5
  2. memory_graph-0.3.93/PKG-INFO → memory_graph-0.3.95/README.md +18 -24
  3. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/__init__.py +2 -2
  4. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/config.py +3 -0
  5. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/config_default.py +9 -0
  6. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/extension_numpy.py +2 -1
  7. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/html_table.py +1 -1
  8. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/memory_to_nodes.py +3 -3
  9. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/utils.py +45 -7
  10. memory_graph-0.3.93/README.md → memory_graph-0.3.95/memory_graph.egg-info/PKG-INFO +38 -4
  11. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph.egg-info/SOURCES.txt +1 -0
  12. {memory_graph-0.3.93 → memory_graph-0.3.95}/pyproject.toml +1 -1
  13. memory_graph-0.3.95/setup.py +7 -0
  14. {memory_graph-0.3.93 → memory_graph-0.3.95}/LICENSE.txt +0 -0
  15. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/call_stack.py +0 -0
  16. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/config_helpers.py +0 -0
  17. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/extension_pandas.py +0 -0
  18. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/extension_polars.py +0 -0
  19. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/extension_sqlite3.py +0 -0
  20. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/extension_torch.py +0 -0
  21. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/list_view.py +0 -0
  22. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/node_base.py +0 -0
  23. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/node_key_value.py +0 -0
  24. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/node_leaf.py +0 -0
  25. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/node_linear.py +0 -0
  26. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/node_table.py +0 -0
  27. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/sequence.py +0 -0
  28. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/slicer.py +0 -0
  29. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/slices.py +0 -0
  30. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/slices_iterator.py +0 -0
  31. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/slices_table_iterator.py +0 -0
  32. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/test.py +0 -0
  33. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/test_max_graph_depth.py +0 -0
  34. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/test_memory_graph.py +0 -0
  35. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/test_memory_to_nodes.py +0 -0
  36. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/test_sequence.py +0 -0
  37. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/test_slicer.py +0 -0
  38. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/test_slices.py +0 -0
  39. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph/test_slices_iterator.py +0 -0
  40. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph.egg-info/dependency_links.txt +0 -0
  41. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph.egg-info/requires.txt +0 -0
  42. {memory_graph-0.3.93 → memory_graph-0.3.95}/memory_graph.egg-info/top_level.txt +0 -0
  43. {memory_graph-0.3.93 → memory_graph-0.3.95}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: memory_graph
3
- Version: 0.3.93
3
+ Version: 0.3.95
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
@@ -1098,6 +1098,9 @@ Different aspects of memory_graph can be configured. The default configuration c
1098
1098
  - ***mg.config.max_string_length*** : int
1099
1099
  - The maximum length of strings shown in the graph. Longer strings will be truncated.
1100
1100
 
1101
+ - ***mg.config.precision*** : int
1102
+ - Round floats to this number of decimals, default None (no rouding).
1103
+
1101
1104
  - ***mg.config.embedded_types*** : set[type]
1102
1105
  - Holds all types for which no separate node is drawn but that are embedded in their parent Node.
1103
1106
 
@@ -1142,15 +1145,21 @@ Different aspects of memory_graph can be configured. The default configuration c
1142
1145
 
1143
1146
  ## Functions ##
1144
1147
 
1145
- - **mg.layout(horizontal: bool = None)**
1146
- - Set graph layout to 'True' for horizontal, 'False' for vertical, or 'None' to toggle.
1147
-
1148
1148
  - **mg.dark_mode(b: bool = None)**
1149
1149
  - Set dark mode to 'True' or 'False', or 'None' to toggle.
1150
1150
 
1151
+ - **mg.layout(horizontal: bool = None)**
1152
+ - Set graph layout to 'True' for horizontal, 'False' for vertical, or 'None' to toggle.
1153
+
1151
1154
  - **mg.transparent_background(b: bool = None)**
1152
1155
  - Set transparent background to 'True' or 'False', or 'None' to toggle.
1153
1156
 
1157
+ - **mg.splines(splines: str = None)**
1158
+ - Set the graphviz [splines attribute](https://graphviz.org/docs/attrs/splines/) (e.g. 'polyline', 'ortho', 'curved', 'line', 'spline'), 'None' restores the default.
1159
+
1160
+ - **mg.ranksep(ranksep: str = None)**
1161
+ - Set the graphviz [ranksep attribute](https://graphviz.org/docs/attrs/ranksep/) (separation between ranks, say "2.0"), 'None' restores the default.
1162
+
1154
1163
  ## Simplified Graph ##
1155
1164
  Memory_graph simplifies the visualization (and the viewer's mental model) by **not** showing separate nodes for immutable types like `bool`, `int`, `float`, `complex`, and `str` by default. This simplification can sometimes be slightly misleading. As in the example below, after a shallow copy, lists `a` and `b` technically share their `int` values, but the graph makes it appear as though `a` and `b` each have their own copies. However, since `int` is immutable, this simplification will never lead to unexpected changes (changing `a`'s ints won’t affect `b`) so will never result in bugs.
1156
1165
 
@@ -1421,7 +1430,7 @@ mg.show(locals())
1421
1430
 
1422
1431
  ### Images
1423
1432
 
1424
- Including the `<IMG>` tag that allows for showing local image files only, but that currently doesn't work in the Memory Graph Web Debugger, that uses 'Viz.js' for graph rendering, unfortunately.
1433
+ Including the `<IMG>` tag that allows showing local image files only.
1425
1434
 
1426
1435
  ```python
1427
1436
  import memory_graph as mg
@@ -1443,6 +1452,10 @@ mg.show(locals())
1443
1452
  ```
1444
1453
  ![html_str_image.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/html_str_image.png)
1445
1454
 
1455
+ Or see it in the [Memory Graph Web Debugger](https://memory-graph.com/#micropip=matplotlib&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/matplotlib.py&timestep=0.1&play).
1456
+
1457
+ As Matplotlib can be slow, consider [creating your own SVG file](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/plot_svg.py&timestep=0.001&play&play_button=step_over) for speed, or [use Pillow to create images](https://memory-graph.com/#micropip=pillow&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/bounce_circles.py&breakpoints=26&timestep=0&play&play_button=continue), or use many other ways.
1458
+
1446
1459
  ## Collapse Type ##
1447
1460
 
1448
1461
  Sometimes a type has too many attributes or too many child nodes in the graph for it to stay readable. We use type 'MyClass' as an example here:
@@ -1564,6 +1577,7 @@ import memory_graph as mg
1564
1577
  import numpy as np
1565
1578
  mg.extend_numpy()
1566
1579
  np.random.seed(0) # use same random numbers each run
1580
+ mg.config.precision = 3 # round floats to just 3 decimals
1567
1581
 
1568
1582
  matrix = np.matrix([[i*5+j for j in range(4)] for i in range(5)])
1569
1583
  ndarray_1d = np.array([1.1, 2, 3, 4, 5])
@@ -1,23 +1,3 @@
1
- Metadata-Version: 2.4
2
- Name: memory_graph
3
- Version: 0.3.93
4
- Summary: Teaching tool and debugging aid in context of references, mutable data types, and shallow and deep copy.
5
- Author-email: Bas Terwijn <bterwijn@gmail.com>
6
- License-Expression: BSD-2-Clause
7
- Project-URL: Homepage, https://github.com/bterwijn/memory_graph
8
- Project-URL: Repository, https://github.com/bterwijn/memory_graph.git
9
- Classifier: Development Status :: 4 - Beta
10
- Classifier: Intended Audience :: Education
11
- Classifier: Intended Audience :: Developers
12
- Classifier: Programming Language :: Python :: 3
13
- Classifier: Topic :: Education
14
- Classifier: Topic :: Software Development :: Debuggers
15
- Requires-Python: >=3.7
16
- Description-Content-Type: text/markdown
17
- License-File: LICENSE.txt
18
- Requires-Dist: graphviz
19
- Dynamic: license-file
20
-
21
1
  # Installation #
22
2
  Install (or upgrade) `memory_graph` using pip:
23
3
  ```
@@ -1098,6 +1078,9 @@ Different aspects of memory_graph can be configured. The default configuration c
1098
1078
  - ***mg.config.max_string_length*** : int
1099
1079
  - The maximum length of strings shown in the graph. Longer strings will be truncated.
1100
1080
 
1081
+ - ***mg.config.precision*** : int
1082
+ - Round floats to this number of decimals, default None (no rouding).
1083
+
1101
1084
  - ***mg.config.embedded_types*** : set[type]
1102
1085
  - Holds all types for which no separate node is drawn but that are embedded in their parent Node.
1103
1086
 
@@ -1142,15 +1125,21 @@ Different aspects of memory_graph can be configured. The default configuration c
1142
1125
 
1143
1126
  ## Functions ##
1144
1127
 
1145
- - **mg.layout(horizontal: bool = None)**
1146
- - Set graph layout to 'True' for horizontal, 'False' for vertical, or 'None' to toggle.
1147
-
1148
1128
  - **mg.dark_mode(b: bool = None)**
1149
1129
  - Set dark mode to 'True' or 'False', or 'None' to toggle.
1150
1130
 
1131
+ - **mg.layout(horizontal: bool = None)**
1132
+ - Set graph layout to 'True' for horizontal, 'False' for vertical, or 'None' to toggle.
1133
+
1151
1134
  - **mg.transparent_background(b: bool = None)**
1152
1135
  - Set transparent background to 'True' or 'False', or 'None' to toggle.
1153
1136
 
1137
+ - **mg.splines(splines: str = None)**
1138
+ - Set the graphviz [splines attribute](https://graphviz.org/docs/attrs/splines/) (e.g. 'polyline', 'ortho', 'curved', 'line', 'spline'), 'None' restores the default.
1139
+
1140
+ - **mg.ranksep(ranksep: str = None)**
1141
+ - Set the graphviz [ranksep attribute](https://graphviz.org/docs/attrs/ranksep/) (separation between ranks, say "2.0"), 'None' restores the default.
1142
+
1154
1143
  ## Simplified Graph ##
1155
1144
  Memory_graph simplifies the visualization (and the viewer's mental model) by **not** showing separate nodes for immutable types like `bool`, `int`, `float`, `complex`, and `str` by default. This simplification can sometimes be slightly misleading. As in the example below, after a shallow copy, lists `a` and `b` technically share their `int` values, but the graph makes it appear as though `a` and `b` each have their own copies. However, since `int` is immutable, this simplification will never lead to unexpected changes (changing `a`'s ints won’t affect `b`) so will never result in bugs.
1156
1145
 
@@ -1421,7 +1410,7 @@ mg.show(locals())
1421
1410
 
1422
1411
  ### Images
1423
1412
 
1424
- Including the `<IMG>` tag that allows for showing local image files only, but that currently doesn't work in the Memory Graph Web Debugger, that uses 'Viz.js' for graph rendering, unfortunately.
1413
+ Including the `<IMG>` tag that allows showing local image files only.
1425
1414
 
1426
1415
  ```python
1427
1416
  import memory_graph as mg
@@ -1443,6 +1432,10 @@ mg.show(locals())
1443
1432
  ```
1444
1433
  ![html_str_image.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/html_str_image.png)
1445
1434
 
1435
+ Or see it in the [Memory Graph Web Debugger](https://memory-graph.com/#micropip=matplotlib&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/matplotlib.py&timestep=0.1&play).
1436
+
1437
+ As Matplotlib can be slow, consider [creating your own SVG file](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/plot_svg.py&timestep=0.001&play&play_button=step_over) for speed, or [use Pillow to create images](https://memory-graph.com/#micropip=pillow&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/bounce_circles.py&breakpoints=26&timestep=0&play&play_button=continue), or use many other ways.
1438
+
1446
1439
  ## Collapse Type ##
1447
1440
 
1448
1441
  Sometimes a type has too many attributes or too many child nodes in the graph for it to stay readable. We use type 'MyClass' as an example here:
@@ -1564,6 +1557,7 @@ import memory_graph as mg
1564
1557
  import numpy as np
1565
1558
  mg.extend_numpy()
1566
1559
  np.random.seed(0) # use same random numbers each run
1560
+ mg.config.precision = 3 # round floats to just 3 decimals
1567
1561
 
1568
1562
  matrix = np.matrix([[i*5+j for j in range(4)] for i in range(5)])
1569
1563
  ndarray_1d = np.array([1.1, 2, 3, 4, 5])
@@ -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.93"
5
+ __version__ = "0.3.95"
6
6
  __author__ = 'Bas Terwijn'
7
7
 
8
8
  import memory_graph.memory_to_nodes as memory_to_nodes
@@ -26,7 +26,7 @@ if not hasattr(builtins, "mg"):
26
26
  builtins.mg = mg
27
27
 
28
28
  # re-exports for shorter names
29
- from .config_default import layout, dark_mode, transparent_background, set_colors
29
+ from .config_default import layout, spline, splines, ranksep, dark_mode, transparent_background, set_colors
30
30
  from .slicer import Slicer
31
31
  from .node_leaf import Node_Leaf
32
32
  from .node_linear import Node_Linear
@@ -30,6 +30,9 @@ type_to_string = { }
30
30
  type_to_node = { }
31
31
 
32
32
  horizontal = False
33
+ precision = None
34
+ splines = 'spline'
35
+ ranksep = None
33
36
  color_mode_dark = False
34
37
  transparent_background = False
35
38
  foreground_color = None
@@ -115,6 +115,15 @@ def layout(horizontal = None):
115
115
  else:
116
116
  config.horizontal = horizontal
117
117
 
118
+ def splines(splines = None):
119
+ """ Set the graphviz 'splines' attribute (e.g. 'polyline', 'ortho', 'curved', 'line', 'spline'), None restores the default. """
120
+ config.splines = 'spline' if splines is None else splines
121
+ spline = splines # alias for backward compatibility
122
+
123
+ def ranksep(ranksep = None):
124
+ """ Set the graphviz 'ranksep' attribute (separation between ranks in inches), None restores the default. """
125
+ config.ranksep = '0.5' if ranksep is None else str(ranksep)
126
+
118
127
  def reset():
119
128
 
120
129
  set_colors(config.color_mode_dark, config.transparent_background)
@@ -32,7 +32,8 @@ def extend_numpy():
32
32
  import numpy as np
33
33
 
34
34
  config.embedded_types |= get_numpy_immutables()
35
- config.type_to_node[np.matrix] = lambda data : Node_Table(data, np.asarray(data)) # convert to ndarray to avoid infinite recursion due to index issue
35
+ # np.asarray converts matrix to ndarray to avoid infinite recursion due to index issue
36
+ config.type_to_node[np.matrix] = lambda data : ndarray_to_node(data, np.asarray(data))
36
37
  config.type_to_node[np.ndarray] = lambda data : ndarray_to_node(data, data)
37
38
 
38
39
  config_default.type_to_color_light[np.ndarray] = "hotpink1"
@@ -9,7 +9,7 @@ import memory_graph.utils as utils
9
9
  def format_string(value, quote_str):
10
10
  """ Helper function to format 'value' to be shown in the graph. We escape html characters and convert newlines to <BR/> tags. """
11
11
  to_string = config_helpers.get_to_string(value)
12
- s = to_string(value)
12
+ s = to_string(utils.round_float(value, config.precision))
13
13
  if quote_str and isinstance(value, (str, utils.full_str)):
14
14
  s = utils.quote_string(s)
15
15
  if not isinstance(value, utils.html_str): # <IMG> can't have padding in Graphviz
@@ -26,7 +26,7 @@ def read_nodes(data):
26
26
  if (to_node):
27
27
  return to_node(data)
28
28
  elif utils.has_dict_attributes(data): # for user defined classes
29
- return Node_Key_Value(data, utils.filter_dict(utils.get_dict_attributes(data)) )
29
+ return Node_Key_Value(data, utils.filter_class_dict(utils.get_dict_attributes(data)) )
30
30
  elif utils.is_finite_iterable(data): # for lists, tuples, sets, ...
31
31
  return Node_Linear(data, data)
32
32
  else:
@@ -266,8 +266,8 @@ def memory_to_nodes(data):
266
266
  'fontsize': config.fontsize,
267
267
  'fontcolor': config.foreground_color,
268
268
  'bgcolor': config.background_color,
269
- #'splines': 'polyline',
270
- #'ordering': 'out',
269
+ 'splines': str(config.splines),
270
+ 'ranksep': str(config.ranksep),
271
271
  }
272
272
  graphviz_node_attr = {'fontname': config.fontname,
273
273
  'fontsize': config.fontsize,
@@ -133,19 +133,44 @@ def is_not_state(obj):
133
133
  'method-wrapper',
134
134
  }
135
135
 
136
+ def is_own_function_definition(key, value):
137
+ """ Returns 'True' if 'value' is a function/method defined under its own name 'key', e.g. a
138
+ module-level 'def add(): ...' binds the name 'add' to a function whose '__name__' is also
139
+ 'add'. Such a binding is just a normal function definition, not state. A variable that
140
+ references a function under a different name (e.g. 'a = add') is still considered state. """
141
+ if not isinstance(value, (types.FunctionType, types.MethodType,
142
+ types.BuiltinFunctionType, types.BuiltinMethodType)):
143
+ return False
144
+ return getattr(value, '__name__', None) == key
145
+
136
146
  def filter_dict(dictionary):
137
- """ Filters out the unwanted dict attributes. """
138
- if '__name__' in dictionary:
139
- return [ # filter classes and modules, no non-state allowed as values
147
+ """ Filters out the unwanted dunder attributes of a plain 'dictionary' or stack frame
148
+ (locals()/globals()). Non-state values like functions are allowed since a dictionary or
149
+ stack frame is considered state, e.g. a variable can point to a function. Modules are
150
+ assumed to have no state and are never shown. If 'dictionary' looks like a module namespace
151
+ (has a '__name__' key, e.g. the global '<module>' stack frame) functions bound under their
152
+ own name are also filtered out, since those are normal function definitions rather than
153
+ variables (state) referencing a function. """
154
+ is_module_namespace = '__name__' in dictionary
155
+ return [
140
156
  (k,v) for k, v in dictionary.items() if
141
157
  not (type(k) is str and k.startswith('__')) and
142
158
  not isinstance(v,types.ModuleType) and
159
+ not (is_module_namespace and is_own_function_definition(k, v))
160
+ ]
161
+
162
+ def filter_class_dict(dictionary):
163
+ """ Filters out the unwanted attributes of a class' or module's '__dict__'. If 'dictionary'
164
+ looks like a class or module namespace (has a '__name__' key) then non-state values such as
165
+ functions and methods are also filtered out, since there can be too many of them to show and
166
+ they are not considered state. Otherwise (e.g. a plain instance's '__dict__') behaves like
167
+ 'filter_dict'. """
168
+ if '__name__' in dictionary:
169
+ return [ # filter classes and modules, no non-state allowed as values
170
+ (k,v) for k, v in filter_dict(dictionary) if
143
171
  not is_not_state(v)
144
172
  ]
145
- return [ # filter dictionaries, non-state allowed as values
146
- (k,v) for k, v in dictionary.items() if
147
- not (type(k) is str and k.startswith('__'))
148
- ]
173
+ return filter_dict(dictionary)
149
174
 
150
175
  def filter_type_attributes(tuples):
151
176
  """ Filters out the unwanted type attributes (class/static methods). """
@@ -199,6 +224,19 @@ def my_round(value):
199
224
  """ Rounds the value to the nearest integer rounding '.5' up consistantly. """
200
225
  return math.floor(value + 0.5)
201
226
 
227
+ def round_float(value, precision):
228
+ """ Rounds float and complex values (including numpy scalars) to 'precision' digits after the decimal point, other values are returned unchanged. """
229
+ if precision is None:
230
+ return value
231
+ if isinstance(value, float):
232
+ return round(value, precision)
233
+ if isinstance(value, complex):
234
+ return complex(round(value.real, precision), round(value.imag, precision))
235
+ dtype = getattr(value, 'dtype', None)
236
+ if dtype is not None and dtype.kind in 'fc' and getattr(value, 'shape', None) == ():
237
+ return value.round(precision)
238
+ return value
239
+
202
240
  def generator_has_data(generator):
203
241
  """ Returns 'True' if the generator has data. """
204
242
  try:
@@ -1,3 +1,23 @@
1
+ Metadata-Version: 2.4
2
+ Name: memory_graph
3
+ Version: 0.3.95
4
+ Summary: Teaching tool and debugging aid in context of references, mutable data types, and shallow and deep copy.
5
+ Author-email: Bas Terwijn <bterwijn@gmail.com>
6
+ License-Expression: BSD-2-Clause
7
+ Project-URL: Homepage, https://github.com/bterwijn/memory_graph
8
+ Project-URL: Repository, https://github.com/bterwijn/memory_graph.git
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Education
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Education
14
+ Classifier: Topic :: Software Development :: Debuggers
15
+ Requires-Python: >=3.7
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE.txt
18
+ Requires-Dist: graphviz
19
+ Dynamic: license-file
20
+
1
21
  # Installation #
2
22
  Install (or upgrade) `memory_graph` using pip:
3
23
  ```
@@ -1078,6 +1098,9 @@ Different aspects of memory_graph can be configured. The default configuration c
1078
1098
  - ***mg.config.max_string_length*** : int
1079
1099
  - The maximum length of strings shown in the graph. Longer strings will be truncated.
1080
1100
 
1101
+ - ***mg.config.precision*** : int
1102
+ - Round floats to this number of decimals, default None (no rouding).
1103
+
1081
1104
  - ***mg.config.embedded_types*** : set[type]
1082
1105
  - Holds all types for which no separate node is drawn but that are embedded in their parent Node.
1083
1106
 
@@ -1122,15 +1145,21 @@ Different aspects of memory_graph can be configured. The default configuration c
1122
1145
 
1123
1146
  ## Functions ##
1124
1147
 
1125
- - **mg.layout(horizontal: bool = None)**
1126
- - Set graph layout to 'True' for horizontal, 'False' for vertical, or 'None' to toggle.
1127
-
1128
1148
  - **mg.dark_mode(b: bool = None)**
1129
1149
  - Set dark mode to 'True' or 'False', or 'None' to toggle.
1130
1150
 
1151
+ - **mg.layout(horizontal: bool = None)**
1152
+ - Set graph layout to 'True' for horizontal, 'False' for vertical, or 'None' to toggle.
1153
+
1131
1154
  - **mg.transparent_background(b: bool = None)**
1132
1155
  - Set transparent background to 'True' or 'False', or 'None' to toggle.
1133
1156
 
1157
+ - **mg.splines(splines: str = None)**
1158
+ - Set the graphviz [splines attribute](https://graphviz.org/docs/attrs/splines/) (e.g. 'polyline', 'ortho', 'curved', 'line', 'spline'), 'None' restores the default.
1159
+
1160
+ - **mg.ranksep(ranksep: str = None)**
1161
+ - Set the graphviz [ranksep attribute](https://graphviz.org/docs/attrs/ranksep/) (separation between ranks, say "2.0"), 'None' restores the default.
1162
+
1134
1163
  ## Simplified Graph ##
1135
1164
  Memory_graph simplifies the visualization (and the viewer's mental model) by **not** showing separate nodes for immutable types like `bool`, `int`, `float`, `complex`, and `str` by default. This simplification can sometimes be slightly misleading. As in the example below, after a shallow copy, lists `a` and `b` technically share their `int` values, but the graph makes it appear as though `a` and `b` each have their own copies. However, since `int` is immutable, this simplification will never lead to unexpected changes (changing `a`'s ints won’t affect `b`) so will never result in bugs.
1136
1165
 
@@ -1401,7 +1430,7 @@ mg.show(locals())
1401
1430
 
1402
1431
  ### Images
1403
1432
 
1404
- Including the `<IMG>` tag that allows for showing local image files only, but that currently doesn't work in the Memory Graph Web Debugger, that uses 'Viz.js' for graph rendering, unfortunately.
1433
+ Including the `<IMG>` tag that allows showing local image files only.
1405
1434
 
1406
1435
  ```python
1407
1436
  import memory_graph as mg
@@ -1423,6 +1452,10 @@ mg.show(locals())
1423
1452
  ```
1424
1453
  ![html_str_image.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/html_str_image.png)
1425
1454
 
1455
+ Or see it in the [Memory Graph Web Debugger](https://memory-graph.com/#micropip=matplotlib&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/matplotlib.py&timestep=0.1&play).
1456
+
1457
+ As Matplotlib can be slow, consider [creating your own SVG file](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/plot_svg.py&timestep=0.001&play&play_button=step_over) for speed, or [use Pillow to create images](https://memory-graph.com/#micropip=pillow&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/bounce_circles.py&breakpoints=26&timestep=0&play&play_button=continue), or use many other ways.
1458
+
1426
1459
  ## Collapse Type ##
1427
1460
 
1428
1461
  Sometimes a type has too many attributes or too many child nodes in the graph for it to stay readable. We use type 'MyClass' as an example here:
@@ -1544,6 +1577,7 @@ import memory_graph as mg
1544
1577
  import numpy as np
1545
1578
  mg.extend_numpy()
1546
1579
  np.random.seed(0) # use same random numbers each run
1580
+ mg.config.precision = 3 # round floats to just 3 decimals
1547
1581
 
1548
1582
  matrix = np.matrix([[i*5+j for j in range(4)] for i in range(5)])
1549
1583
  ndarray_1d = np.array([1.1, 2, 3, 4, 5])
@@ -1,6 +1,7 @@
1
1
  LICENSE.txt
2
2
  README.md
3
3
  pyproject.toml
4
+ setup.py
4
5
  memory_graph/__init__.py
5
6
  memory_graph/call_stack.py
6
7
  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.93"
7
+ version = "0.3.95"
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"}
@@ -0,0 +1,7 @@
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