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

docs: Add debugging section to contributing docs #10576

Merged
merged 4 commits into from
Feb 9, 2024

Conversation

mcrumiller
Copy link
Contributor

@mcrumiller mcrumiller commented Aug 17, 2023

This is the followup to #9962, which ended up more of a research project. Thanks to @SeanTroyUWO for figuring out how to attach the Rust debugger to a Python process, which was the most important step to all of this.

This PR introduces a really nice and easy way to set up debugging in VS Code. It allows you to F5 a python script and halt on breakpoints in both your Python and Rust code. The setup is just 2 (maybe 3) steps, which are:

  1. Install the LLDB extension in VS Code, and:
  2. Add some configuration to your launch.json file.
  3. (if necessary) Disable ptrace protection

I added documentation in CONTRIBUTING.md that explains how to set it up (which is easy). There's also a new README.md in the /debug folder that I added, which contains the script used by the debugging config.

I've been using this all the time since I set it up and I would encourage others to do so too and try it out.

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels Aug 17, 2023
@reswqa
Copy link
Collaborator

reswqa commented Aug 18, 2023

That's great and exactly what I'm looking forward to. Before seeing this, I used to rewrite Python code into equivalent Rust code to debug.(´I`)

@alexander-beedie
Copy link
Collaborator

alexander-beedie commented Aug 18, 2023

Nice one! Looks incredibly useful :)

Wondering if anybody could add similar guidance for PyCharm/CLion IDEs? (@ritchie46, I recall you use these?) I haven't gone much past dbg! when I'm playing down in the Rust layer, so actually attaching a debugger and walking through the code would feel quite luxurious, heh.

@c-peters
Copy link
Collaborator

c-peters commented Aug 18, 2023

Love this!

For me the code ran, but lldb gave an error at the end. In order for it to work I had to disable ptrace protection like was mentioned in #9962

echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope

@mcrumiller
Copy link
Contributor Author

mcrumiller commented Aug 18, 2023

@c-peters what OS/system are you running on? I'll add a note in there if I can figure out why some people seem to need to run that.

Edit: I added an optional step for disabling ptrace using your command. I don't have a /yama folder in my WSL, so it's probably only enabled on certain distributions I guess? I wonder if I should document more and/or there are other commands required for people on other distributions.

@c-peters
Copy link
Collaborator

I'm on Ubuntu 22.04

@mcrumiller
Copy link
Contributor Author

Wondering if anybody could add similar guidance for PyCharm/CLion IDEs?

@alexander-beedie it's possible, I'm not familiar with PyCharm or Clion at all. The key element here was that VSCode has a way for debug configurations to "detect" patterns in the debug console and trigger a configuration launch when that pattern appears. The mechanism here is that when the "debug my file" configuration is run, it runs the launch.py script which prints the current pID to the debug console, which then triggers the rust LLDB debugger to attach to the current process using that pID.

@c-peters
Copy link
Collaborator

I also got it to work on CLion following this guide: https://www.jetbrains.com/help/clion/debugging-python-extensions.html#debug-custom-py. You can either go for option 1, but that will get annoying fast. If you follow option 2 setting the following custom build target does the trick for me.

Screenshot from 2023-08-21 18-34-05

@mcrumiller
Copy link
Contributor Author

mcrumiller commented Aug 21, 2023

Thanks @c-peters. I'll install CLion after work and see if I can get this running and see if I can get into this PR.

Edit: I don't have a license and don't want to pay for it just to make this PR. Perhaps in the future someone else can figure out how to make this work in other IDEs.

@stinodego or @ritchie46 do you want any other improvements for this PR, or are we good to go?

@ritchie46
Copy link
Member

@stinodego you are VS-code user right. I leave this one to you.

@reswqa
Copy link
Collaborator

reswqa commented Aug 22, 2023

@mcrumiller I'm a jetBrains user, I can help verify it, but I suggest not blocking this PR. :)

@stinodego
Copy link
Member

I think this is great stuff we should have in our contributing guide somewhere. I'll give this a try sometime this week.

But I am right now in the process of restructuring our docs, including contributing information. So I'd prefer to wait a moment with merging this.

Give it a week or two, and this information will be nicely incorporated in our shiny new Polars docs 👌

@stinodego stinodego changed the title feat(rust, python): debug rust & python in VS Code via python script chore: debug rust & python in VS Code via python script Sep 5, 2023
@stinodego stinodego removed the enhancement New feature or an improvement of an existing feature label Sep 5, 2023
@github-actions github-actions bot added the internal An internal refactor or improvement label Sep 5, 2023
@mcrumiller mcrumiller requested a review from c-peters as a code owner November 25, 2023 20:22
@mcrumiller
Copy link
Contributor Author

Hey @stinodego, I just rebased on main and moved the docs to the new contributing section. Let me know if this is what you had in mind, or if you have any suggested to the documentation. I saw someone on Discord asking about this so I think it's a useful section/feature.

@Kai-Striega
Copy link

Thanks @c-peters. I'll install CLion after work and see if I can get this running and see if I can get into this PR.

Edit: I don't have a license and don't want to pay for it just to make this PR. Perhaps in the future someone else can figure out how to make this work in other IDEs.

@mcrumiller JetBrains offers free all products pack for free and open source development. Maybe you could make the argument that it's worth giving you a copy to try it out?

https://www.jetbrains.com/community/opensource/#support

They have also released Rust Rover their version of a rust IDE for free, maybe it's worth trying on that?

@mcrumiller
Copy link
Contributor Author

@mcrumiller JetBrains offers free all products pack for free and open source development. Maybe you could make the argument that it's worth giving you a copy to try it out?

Thanks @Kai-Striega, I did not know that. I may reach out to them.

Copy link
Member

@stinodego stinodego left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took me a long time to get back to this one, but it's ready to be merged!

@stinodego stinodego changed the title chore: debug rust & python in VS Code via python script docs: Add debugging section to contributing docs Feb 9, 2024
@stinodego stinodego removed the internal An internal refactor or improvement label Feb 9, 2024
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Feb 9, 2024
@mcrumiller
Copy link
Contributor Author

Thanks @stinodego! I think this one will really be helpful to people. I use it all the time.

I think it might be worth adding a quick example with a walk-through, but I'm not sure if I want to make it any longer than it is. What do you think?

@stinodego
Copy link
Member

stinodego commented Feb 9, 2024

I think it might be worth adding a quick example with a walk-through, but I'm not sure if I want to make it any longer than it is. What do you think?

What did you have in mind exactly? The section already reads like a step-by-step walkthrough of how to set it up and then how to run the debugger. I followed it and it was completely clear to me. I don't think it needs anything else. We don't have to explain the basics of debugging in VSCode, that's best left for the official VSCode docs, in my opinion.

EDIT: I went ahead and merged it as-is, possible adjustments can be made in a separate PR!

@stinodego stinodego merged commit 41b33c5 into pola-rs:main Feb 9, 2024
14 checks passed
@mcrumiller
Copy link
Contributor Author

Ok great. I was imagining showing an actual sample script and saying "set a breakpoint here in the code", but you're right, that's too much hand-holding and it also be difficult to keep up with code changes.

@mcrumiller mcrumiller deleted the debug-setup branch February 9, 2024 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants