Skip to content

fix(python): debugpy requires -m module #115

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

Merged
merged 3 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/integration-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- name: Install required tools
run: |
set -e
set -ex
mkdir -p $HOME/bin
curl -Lo $HOME/bin/skaffold https://storage.googleapis.com/skaffold/builds/latest/skaffold-linux-amd64
curl -Lo $HOME/bin/container-structure-test https://storage.googleapis.com/container-structure-test/latest/container-structure-test-linux-amd64
Expand All @@ -46,17 +46,17 @@ jobs:

- name: Run nodejs helper tests
run: |
set -e
set -ex
(cd nodejs/helper-image; go test .)

- name: Run python helper tests
run: |
set -e
set -ex
(cd python/helper-image/launcher; go test .)

- name: Run image build
run: |
set -e
set -ex
# Create a kind configuration to use the docker daemon's configured registry-mirrors.
docker system info --format '{{printf "apiVersion: kind.x-k8s.io/v1alpha4\nkind: Cluster\ncontainerdConfigPatches:\n"}}{{range $reg, $config := .RegistryConfig.IndexConfigs}}{{if $config.Mirrors}}{{printf "- |-\n [plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors.\"%s\"]\n endpoint = %q\n" $reg $config.Mirrors}}{{end}}{{end}}' > /tmp/kind.config

Expand Down
10 changes: 9 additions & 1 deletion python/helper-image/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ func (pc *pythonContext) updateEnv(ctx context.Context) error {
}

func (pc *pythonContext) updateCommandLine(ctx context.Context) error {
// TODO(#76): we're assuming the `-m module` argument comes first
var cmdline []string
switch pc.debugMode {
case ModePtvsd:
Expand All @@ -367,7 +368,14 @@ func (pc *pythonContext) updateCommandLine(ctx context.Context) error {
if pc.wait {
cmdline = append(cmdline, "--wait-for-client")
}
cmdline = append(cmdline, pc.args[1:]...)
// debugpy expects the `-m` module argument to be separate
for i, arg := range pc.args[1:] {
if i == 0 && arg != "-m" && strings.HasPrefix(arg, "-m") {
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't remember why I thought i == 0 was significant but it seems fragile. And some flags, like -u for unbuffered output, seems reasonable to allow.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, it's because arguments after -m are no longer python arguments and are instead handed off to the program or module.

Copy link
Member Author

Choose a reason for hiding this comment

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

This situation is #76. I'll add a comment here and punt on it for now.

cmdline = append(cmdline, "-m", strings.TrimPrefix(arg, "-m"))
} else {
cmdline = append(cmdline, arg)
}
}
pc.args = cmdline

case ModePydevd, ModePydevdPycharm:
Expand Down
14 changes: 14 additions & 0 deletions python/helper-image/launcher/launcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,20 @@ func TestPrepare(t *testing.T) {
AndRunCmd([]string{"python", "-m", "debugpy", "--listen", "2345", "app.py"}),
expected: pythonContext{debugMode: "debugpy", port: 2345, wait: false, major: 3, minor: 7, args: []string{"python", "-m", "debugpy", "--listen", "2345", "app.py"}, env: env{"PYTHONPATH": dbgRoot + "/python/lib/python3.7/site-packages"}},
},
{
description: "debugpy with module",
pc: pythonContext{debugMode: "debugpy", port: 2345, wait: false, args: []string{"python", "-m", "gunicorn", "app:app"}, env: nil},
commands: RunCmdOut([]string{"python", "-V"}, "Python 3.7.4\n").
AndRunCmd([]string{"python", "-m", "debugpy", "--listen", "2345", "app.py"}),
expected: pythonContext{debugMode: "debugpy", port: 2345, wait: false, major: 3, minor: 7, args: []string{"python", "-m", "debugpy", "--listen", "2345", "-m", "gunicorn", "app:app"}, env: env{"PYTHONPATH": dbgRoot + "/python/lib/python3.7/site-packages"}},
},
{
description: "debugpy with module (no space)",
pc: pythonContext{debugMode: "debugpy", port: 2345, wait: false, args: []string{"python", "-mgunicorn", "app:app"}, env: nil},
commands: RunCmdOut([]string{"python", "-V"}, "Python 3.7.4\n").
AndRunCmd([]string{"python", "-m", "debugpy", "--listen", "2345", "app.py"}),
expected: pythonContext{debugMode: "debugpy", port: 2345, wait: false, major: 3, minor: 7, args: []string{"python", "-m", "debugpy", "--listen", "2345", "-m", "gunicorn", "app:app"}, env: env{"PYTHONPATH": dbgRoot + "/python/lib/python3.7/site-packages"}},
},
{
description: "debugpy with wait",
pc: pythonContext{debugMode: "debugpy", port: 2345, wait: true, args: []string{"python", "app.py"}, env: nil},
Expand Down