Skip to content

Commit 298e5e5

Browse files
authored
fix(python): debugpy requires -m module (#115)
added todo for handling python interpreter flags
1 parent 7d56e5d commit 298e5e5

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

.github/workflows/integration-linux.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
3636
- name: Install required tools
3737
run: |
38-
set -e
38+
set -ex
3939
mkdir -p $HOME/bin
4040
curl -Lo $HOME/bin/skaffold https://storage.googleapis.com/skaffold/builds/latest/skaffold-linux-amd64
4141
curl -Lo $HOME/bin/container-structure-test https://storage.googleapis.com/container-structure-test/latest/container-structure-test-linux-amd64
@@ -46,17 +46,17 @@ jobs:
4646
4747
- name: Run nodejs helper tests
4848
run: |
49-
set -e
49+
set -ex
5050
(cd nodejs/helper-image; go test .)
5151
5252
- name: Run python helper tests
5353
run: |
54-
set -e
54+
set -ex
5555
(cd python/helper-image/launcher; go test .)
5656
5757
- name: Run image build
5858
run: |
59-
set -e
59+
set -ex
6060
# Create a kind configuration to use the docker daemon's configured registry-mirrors.
6161
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
6262

python/helper-image/launcher/launcher.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ func (pc *pythonContext) updateEnv(ctx context.Context) error {
350350
}
351351

352352
func (pc *pythonContext) updateCommandLine(ctx context.Context) error {
353+
// TODO(#76): we're assuming the `-m module` argument comes first
353354
var cmdline []string
354355
switch pc.debugMode {
355356
case ModePtvsd:
@@ -367,7 +368,14 @@ func (pc *pythonContext) updateCommandLine(ctx context.Context) error {
367368
if pc.wait {
368369
cmdline = append(cmdline, "--wait-for-client")
369370
}
370-
cmdline = append(cmdline, pc.args[1:]...)
371+
// debugpy expects the `-m` module argument to be separate
372+
for i, arg := range pc.args[1:] {
373+
if i == 0 && arg != "-m" && strings.HasPrefix(arg, "-m") {
374+
cmdline = append(cmdline, "-m", strings.TrimPrefix(arg, "-m"))
375+
} else {
376+
cmdline = append(cmdline, arg)
377+
}
378+
}
371379
pc.args = cmdline
372380

373381
case ModePydevd, ModePydevdPycharm:

python/helper-image/launcher/launcher_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,20 @@ func TestPrepare(t *testing.T) {
252252
AndRunCmd([]string{"python", "-m", "debugpy", "--listen", "2345", "app.py"}),
253253
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"}},
254254
},
255+
{
256+
description: "debugpy with module",
257+
pc: pythonContext{debugMode: "debugpy", port: 2345, wait: false, args: []string{"python", "-m", "gunicorn", "app:app"}, env: nil},
258+
commands: RunCmdOut([]string{"python", "-V"}, "Python 3.7.4\n").
259+
AndRunCmd([]string{"python", "-m", "debugpy", "--listen", "2345", "app.py"}),
260+
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"}},
261+
},
262+
{
263+
description: "debugpy with module (no space)",
264+
pc: pythonContext{debugMode: "debugpy", port: 2345, wait: false, args: []string{"python", "-mgunicorn", "app:app"}, env: nil},
265+
commands: RunCmdOut([]string{"python", "-V"}, "Python 3.7.4\n").
266+
AndRunCmd([]string{"python", "-m", "debugpy", "--listen", "2345", "app.py"}),
267+
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"}},
268+
},
255269
{
256270
description: "debugpy with wait",
257271
pc: pythonContext{debugMode: "debugpy", port: 2345, wait: true, args: []string{"python", "app.py"}, env: nil},

0 commit comments

Comments
 (0)