ionelmc / python-hunter

Hunter is a flexible code tracing toolkit.
https://python-hunter.readthedocs.io/
BSD 2-Clause "Simplified" License
796 stars 46 forks source link

Jupyter Notebook - Trace missing code source #63

Closed tigrus closed 5 years ago

tigrus commented 5 years ago

We have following code:

import hunter

hunter.trace(module=__name__, function='good_tracing_example', actions=[hunter.CallPrinter, hunter.VarsPrinter("a", "b", "result")])

class A(object): 
    def good_tracing_example(self, a, b):
        a += 3 
        a += 7
        a += 20
        result = a + b
        return result

class B(A):
    def good_tracing_example(self, a, b):
        b += 20
        a += 30 
        result = super().good_tracing_example(a, b)
        return result

b = B()
b.good_tracing_example(1, 2)

When we run it in jupyter cell - we have following result:

TracingNotebookCell

When we run it as bash command - we have much better result:

TracingBashCell

How to make hunter work well in jupyter notebook?

ionelmc commented 5 years ago

Looks like hunter has made some bad assumptions about __file__. Will be fixed in next release.

tigrus commented 5 years ago

Thanks, looking forward for fix :)

ionelmc commented 5 years ago

Well feel free to try the master or wheel from a recent dev build: https://test.pypi.org/project/hunter/2.2.2.dev62/

ionelmc commented 5 years ago

Hunter 3.0 is released.