-
Notifications
You must be signed in to change notification settings - Fork 350
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
VSCode debugger support: 'debug cell' #1325
Comments
Can you use |
Yes. But this breaks into the Within the notebook itself using pdb isn't too bad, but my use case is one where the notebook calls other code - like my model implementation - and it's in that implementation where I want to set breakpoints (visually, ideally). |
Got it, yea, the vscode debugger is much better than basic It's not super trivial, but I think we would need to be able to run marimo with a I'm not sure when we will get to i - maybe a contributor can pick it up, or if there are enough 👍 we can try to prioritize it sooner. |
Cool, thanks for considering! |
By the way: I tried what I thought might be the alternative approach, which was to directly launch the script (notebook) from VSCode. But it seems that marimo creates a copy of the script somehwere in |
Are you running it as a script ( |
I'm running as a script, using VSCode's |
Got it:
|
Using |
Hmm, maybe it's not being copied after all. It's just that when I hit an error (e.g. if I imported something that can't be found), the exception says that it's in a file called e.g. Regardless, I can't seem to get normal VSCode breakpoints to get hit when running the script. I thought marimo was copying the file to By the way, this script comes from a Jupyter Notebook which I then converted to a script using |
Oh interesting, thanks for that context. Each cell is compiled and given a unique filename (which happens to be under tmp). Maybe that confuses vscode, or maybe it's the exec like you say. It's surprising because this works at the command line (insert a breakpoint in your file with |
+1 for interactive debugging support (not just pdb text interface). This is the main feature that's blocking me from moving our team from jupyter to marimo. |
Here's an approach for debugging inside VSCode I've found. The gist of the strategy is to separate the decoration of cells with import marimo
__generated_with = "0.4.12"
app = marimo.App()
def defines_x():
x = 2
return x
def defines_y(x):
y = x + 1
y
return y
def computes_z(x, y):
z = x + y + 1
z
return z
def test_computes_z():
assert computes_z(5, 3) == 9
app.cell(computes_z)
app.cell(defines_y)
app.cell(defines_x)
if __name__ == "__main__":
test_computes_z()
app.run() Since you still call But at the same time, with this design, functions like You can even treat the notebook as a module, importing specific functions like you'd import Python functions normally OR using the recipe described in the docs's Cell API reference, which seems to take advantage of the DAG specified in your notebook in a way that the base function could not. Downsides:
I think this approach would work a lot more smoothly if marimo already separated calls to With these changes, uers would be defining ordinary and pure Pythons functions as a side effect of notebook development inside marimo. They could then re-use these functions anywhere they'd like as if they weren't even specified inside notebooks in the first place. And at the same time, they'd still maintain access to the Cell instantiation of these functions -- either inside or outside the notebook. Still, being able to debug within the DAG context would be better, and not be addressed by these changes. |
Same here - this is the main thing stopping me from switching to marimo. |
Thanks everyone for the thoughtful feedback. I believe if we just ran the cells as functions, instead of But We don't have a solution yet ... but just wanted to acknowledge that we hear you and hope to find one. |
Am I mistaken that a possible solution would be to return a tuple of the last expression and the return value, discarding the last expression when used as a notebook (via marimo module machinery) and using it as usual. Or am I missing something here? Edit: I naively assumed you produce a python file anyway and instead of execing the code for a cell we could call the function (dynamically, per the DAG), but it seems that does not happen. |
https://code.visualstudio.com/docs/python/debugging#_local-script-debugging Seems to provide some clue for getting this to work. You add a remote attach configuration to your
Then this is the gist of the pattern you use to start a debugging session: import debugpy
# 5678 is the default attach port in the VS Code debug configurations. Unless a host and port are specified, host defaults to 127.0.0.1
debugpy.listen(5678)
print("Waiting for debugger attach")
debugpy.wait_for_client()
breakpoint()
print('break on this line') I've found that if I put the debugging setup in its own cell (everything before Maybe significantly, this works even if one is primarily developing with marimo's native UI, since it works over a (local) network connection. Full example of a script with a breakpoint in it: import marimo
__generated_with = "0.7.0"
app = marimo.App()
@app.cell
def __():
import debugpy; debugpy.listen(5678); debugpy.wait_for_client()
return debugpy,
@app.cell
def computes_z(x, y):
z = x + y + 1
z
return z,
@app.cell
def defines_y(x):
y = x + 1
breakpoint()
y
return y,
@app.cell
def defines_x():
x = 2
return x,
if __name__ == "__main__":
app.run() Would be nice to find some way to smooth this workflow out further. |
@githubpsyche - I really appreciate the detailed write-up. It would be great to get this workflow smoother. are there any obvious things we could do? for example:
I am not too familiar with debugpy or the vscode's debugpy integration so would appreciate any help |
Description
I am using marimo in VSCode using the extension. With Jupyter Notebooks, I have an option to 'debug' a cell rather than just run it. This will hit VSCode breakpoints in the called code. I like this a lot since lets me fluidly mix between notebook-style execution and IDE-style debugging.
Does that way of working fit the marimo model at all? Or is the idea that if I want to debug I run the whole file directly from the VSCode debugger (without marimo)? If it's the former, it would be nice to have a 'debug cell' option.
Suggested solution
Implement a 'debug cell' option
Alternative
Document the inteded approach to interactive debugging when one needs to examine code called by a marimo notebook. Searching the docs for 'debug' didn't come up with anything.
Additional context
No response
The text was updated successfully, but these errors were encountered: