Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Support Jupyter notebooks and IPython #16

Closed
zhouyanasd opened this issue Apr 23, 2019 · 8 comments
Closed

Feature request: Support Jupyter notebooks and IPython #16

zhouyanasd opened this issue Apr 23, 2019 · 8 comments
Assignees

Comments

@zhouyanasd
Copy link

I think it can not support jupyter right now, but I hope it could be done lately.

NotImplementedError                       Traceback (most recent call last)
<ipython-input-6-48087d91d6cf> in <module>()
      5     return number
      6 
----> 7 number_to_bits(6)

<decorator-gen-164> in number_to_bits(number)

C:\ProgramData\Anaconda3\lib\site-packages\pysnooper\pysnooper.py in decorate(function, *args, **kwargs)
     70                     write=write, variables=variables,
     71                     depth=depth, prefix=prefix):
---> 72             return function(*args, **kwargs)
     73 
     74     return decorate

<ipython-input-6-48087d91d6cf> in number_to_bits(number)
      1 import pysnooper
      2 
----> 3 @pysnooper.snoop('file.log')
      4 def number_to_bits(number):
      5     return number

C:\ProgramData\Anaconda3\lib\site-packages\pysnooper\tracer.py in trace(self, frame, event, arg)
    180 
    181         now_string = datetime_module.datetime.now().time().isoformat()
--> 182         source_line = get_source_from_frame(frame)[frame.f_lineno - 1]
    183         self.write('{indent}{now_string} {event:9} '
    184                    '{frame.f_lineno:4} {source_line}'.format(**locals()))

C:\ProgramData\Anaconda3\lib\site-packages\pysnooper\tracer.py in get_source_from_frame(frame)
     73             pass
     74     if source is None:
---> 75         raise NotImplementedError
     76 
     77     # If we just read the source from a file, or if the loader did not

NotImplementedError: 
@chaoyue729
Copy link

same issue

@cool-RR cool-RR changed the title Some error rise when used in Jupyter notebook. Feature request: Support Jupyter notebooks. Apr 23, 2019
@cool-RR
Copy link
Owner

cool-RR commented Apr 23, 2019

If someone were to write a test case for this and add it to the test suite, I might be tempted to try implementing a solution.

@cool-RR cool-RR changed the title Feature request: Support Jupyter notebooks. Feature request: Support Jupyter notebooks and IPython Apr 24, 2019
@cool-RR
Copy link
Owner

cool-RR commented Apr 24, 2019

Everyone: If you want this to be fixed, I need you to find how to get the code from an iPython shell or a Jupyter notebook. If it's possible, send me the code and I could add that it to PySnooper.

Also, adding a test case to the test suite would be helpful.

@YubinXie
Copy link

I'd like to help but I do not really understand what do you mean by the code from iPython shell? The input code for PySnooper is same as the example you provided. As for what is actually going on in iPython, any suggestion to get it out?

@cool-RR
Copy link
Owner

cool-RR commented Apr 24, 2019

@YubinXie The function get_source_from_frame attempts to extract the source from the frame object. This is easy with source that resides in files, but more difficult with interactive shells such as IPython and Jupyter because the frame wouldn't have a file name. You need to talk to the IPython and Jupyter and ask whether the source can be extracted from the shell.

@cool-RR
Copy link
Owner

cool-RR commented Apr 24, 2019

I just pushed a fix that'll at least make PySnooper fail gracefully when it can't show the source. Now the task remains to get the code out of IPython or Jupyter.

@cool-RR cool-RR self-assigned this Apr 24, 2019
@cool-RR
Copy link
Owner

cool-RR commented Apr 24, 2019

I implemented IPython support! Now just Jupyter support left.

@cool-RR
Copy link
Owner

cool-RR commented Apr 24, 2019

Oh awesome, looks like that fixed Jupyter as well :)

I made a separate task #43 to add testing for this feature. Any takers?

@cool-RR cool-RR closed this as completed Apr 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants