From 8b0c5f2531a6bdc1075d7ac342b158b9dc3f7059 Mon Sep 17 00:00:00 2001 From: mohsenari Date: Fri, 3 Mar 2023 19:48:49 -0500 Subject: [PATCH] Fixed bug on multiple python extensions listed in devcontainer --- internal/boxcli/generate/devcontainer_util.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/boxcli/generate/devcontainer_util.go b/internal/boxcli/generate/devcontainer_util.go index 098cfd7f488..41c360a6a57 100644 --- a/internal/boxcli/generate/devcontainer_util.go +++ b/internal/boxcli/generate/devcontainer_util.go @@ -6,9 +6,11 @@ import ( "html/template" "os" "path/filepath" + "regexp" "strings" "github.com/pkg/errors" + "go.jetpack.io/devbox/internal/debug" ) type devcontainerObject struct { @@ -114,11 +116,19 @@ func getDevcontainerContent(pkgs []string) *devcontainerObject { RemoteUser: "devbox", } + // match only python3 or python3xx as package names + py3pattern, err := regexp.Compile(`(python3)$|(python3[0-9]{1,2})$`) + if err != nil { + debug.Log("Failed to compile regex") + return nil + } for _, pkg := range pkgs { - if strings.Contains(pkg, "python3") { + if py3pattern.MatchString(pkg) { + // Setup python3 interpreter path to devbox in the container devcontainerContent.Customizations.Vscode.Settings = map[string]any{ "python.defaultInterpreterPath": "/code/.devbox/nix/profile/default/bin/python3", } + // add python extension if a python3 package is installed devcontainerContent.Customizations.Vscode.Extensions = append(devcontainerContent.Customizations.Vscode.Extensions, "ms-python.python") }