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

feat: add ability to pass user flags to python interpreter #442

Merged

Conversation

muravev-vasilii
Copy link
Contributor

@muravev-vasilii muravev-vasilii commented Nov 20, 2024

This change is meant to demonstrate the proposed update for the following feature request: #436


Changes are visible to end-users: yes

Users can influence behaviour of interpreter by passing additional flags via interpreter_args attribute

Test plan

  • Manual testing;

Modified py_binary with new attribute

py_binary(
    name = "foo",
    srcs = [...],
    deps = [...],
    interpreter_options = ["-m", "debugpy", "--listen", "12345", "--wait-for-client"],
)

Ran bazel target

bazel run //path/to/rules_py/py_binary/target:foo

From VSCode side:

  • installed Python Debugger extension
  • updated launch.json with
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python Debugger: Attach",
            "type": "debugpy",
            "request": "attach",
            "connect": {
              "host": "localhost",
              "port": 12345
            }
          }
    ]
}

Used Run&Debug tab in VSCode to set breakpoints, connect to program and debug.

I also tried to do proposed here (#436) way with select and -c dbg, it works, but less minimalistic to show proposed change

@CLAassistant
Copy link

CLAassistant commented Nov 20, 2024

CLA assistant check
All committers have signed the CLA.

@mnoah1
Copy link

mnoah1 commented Nov 20, 2024

Also, one other change for the debug use case is that the run template should set the PYDEVD_RESOLVE_SYMLINKS environment variable to true before starting debugpy. This resolves symlinks when sending paths to the client. Without this set, VS Code will open any paths within the Bazel cache as their own tab instead of showing the breakpoint in the original source file. More info: microsoft/debugpy#743

@muravev-vasilii muravev-vasilii force-pushed the add-interpreter-user-flags branch from 81d4469 to 9e882de Compare November 26, 2024 13:22
py/private/py_binary.bzl Outdated Show resolved Hide resolved
@thesayyn thesayyn self-requested a review December 5, 2024 16:43
py/private/py_binary.bzl Outdated Show resolved Hide resolved
Copy link
Member

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

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

optional: maybe we should document a bit more about the --compilation_mode dbg use case you'll use this for

@muravev-vasilii muravev-vasilii force-pushed the add-interpreter-user-flags branch from 9e882de to 4aa0f58 Compare December 10, 2024 10:54
@muravev-vasilii muravev-vasilii force-pushed the add-interpreter-user-flags branch from 4aa0f58 to 9ba3f47 Compare December 10, 2024 11:01
@muravev-vasilii
Copy link
Contributor Author

optional: maybe we should document a bit more about the --compilation_mode dbg use case you'll use this for

This one I would prefer to add in a separate example, as I need to create minimalistic example not applied to our monorepo first

@alexeagle alexeagle enabled auto-merge (squash) December 10, 2024 15:10
@alexeagle alexeagle merged commit e4f87b0 into aspect-build:main Dec 10, 2024
12 checks passed
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

Successfully merging this pull request may close these issues.

4 participants