| 1 |
#!/usr/bin/env python |
| 2 |
# |
| 3 |
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation) |
| 4 |
# Copyright (c) 2008-2016 California Institute of Technology. |
| 5 |
# Copyright (c) 2016-2026 The Uncertainty Quantification Foundation. |
| 6 |
# License: 3-clause BSD. The full license text is available at: |
| 7 |
# - https://github.com/uqfoundation/dill/blob/master/LICENSE |
| 8 |
""" |
| 9 |
display the reference paths for objects in ``dill.types`` or a .pkl file |
| 10 |
|
| 11 |
Notes: |
| 12 |
the generated image is useful in showing the pointer references in |
| 13 |
objects that are or can be pickled. Any object in ``dill.objects`` |
| 14 |
listed in ``dill.load_types(picklable=True, unpicklable=True)`` works. |
| 15 |
|
| 16 |
Examples:: |
| 17 |
|
| 18 |
$ get_objgraph ArrayType |
| 19 |
Image generated as ArrayType.png |
| 20 |
""" |
| 21 |
|
| 22 |
import dill as pickle |
| 23 |
#pickle.debug.trace(True) |
| 24 |
#import pickle |
| 25 |
|
| 26 |
# get all objects for testing |
| 27 |
from dill import load_types |
| 28 |
load_types(pickleable=True,unpickleable=True) |
| 29 |
from dill import objects |
| 30 |
|
| 31 |
if __name__ == "__main__": |
| 32 |
import sys |
| 33 |
if len(sys.argv) != 2: |
| 34 |
print ("Please provide exactly one file or type name (e.g. 'IntType')") |
| 35 |
msg = "\n" |
| 36 |
for objtype in list(objects.keys())[:40]: |
| 37 |
msg += objtype + ', ' |
| 38 |
print (msg + "...") |
| 39 |
else: |
| 40 |
objtype = str(sys.argv[-1]) |
| 41 |
try: |
| 42 |
obj = objects[objtype] |
| 43 |
except KeyError: |
| 44 |
obj = pickle.load(open(objtype,'rb')) |
| 45 |
import os |
| 46 |
objtype = os.path.splitext(objtype)[0] |
| 47 |
try: |
| 48 |
import objgraph |
| 49 |
objgraph.show_refs(obj, filename=objtype+'.png') |
| 50 |
except ImportError: |
| 51 |
print ("Please install 'objgraph' to view object graphs") |
| 52 |
|
| 53 |
|
| 54 |
# EOF |