xeus-python icon indicating copy to clipboard operation
xeus-python copied to clipboard

Get file source through python, not from disk

Open timkpaine opened this issue 5 years ago • 2 comments

If I'm looking correctly, this line of code makes the assumption that the file's source is on disk: https://github.com/jupyter-xeus/xeus-python/blob/master/src/xdebugger.cpp#L216

However, it is quite easy to configure Python to allow files to be imported from e.g. network/remote. So maybe it would make sense to failover, if the file does not exist on disk then instead attempt to read source from the python object e.g. inspect.getsource.

timkpaine avatar Aug 14 '20 22:08 timkpaine

Makes sense, although I am not sure we can rely on Python in this part of the code, there is no Python interpreter running here. What do you think @JohanMabille?

martinRenou avatar Aug 24 '20 05:08 martinRenou

There are two ways to get Python code executed from xdebugger.cpp:

  • either send the code to the shell through the control_messenger object, as done here. The problem here is that the source is usually asked after the execution flow hits a breakpoint, therefore you cannot get the Python interpreter execute any code before you resume the execution.

  • send an Evaluate request to PTVSD. However, I'm pretty sure this requires the interpreter to be stopped on a breakpoint. Even if I don't see any use case that asks for a source while the code is executing, we should hande this case too.

So the solution would be to use one of this solution depending on the interpreter state.

JohanMabille avatar Aug 24 '20 06:08 JohanMabille