From 26f12c14518a61f7c0200b0aeb7f7b56c3e8d80f Mon Sep 17 00:00:00 2001 From: Daniel Wu Date: Sat, 16 Sep 2023 19:50:28 -0400 Subject: [PATCH 1/5] modify install cmd to setup conda and poetry, modify exec bash cmds to return outputs --- cmd/backend/install/install.go | 45 +++++++++++++++--- cmd/root.go | 1 + ...h_cmd_unix.go => exec_bash_cmd_unix_os.go} | 10 +++- pkg/exec_bash_cmd_windows.go | 46 ------------------- pkg/exec_bash_cmd_windows_os.go | 31 +++++++++++++ 5 files changed, 78 insertions(+), 55 deletions(-) rename pkg/{exec_bash_cmd_unix.go => exec_bash_cmd_unix_os.go} (85%) delete mode 100644 pkg/exec_bash_cmd_windows.go create mode 100644 pkg/exec_bash_cmd_windows_os.go diff --git a/cmd/backend/install/install.go b/cmd/backend/install/install.go index b7e6c51..d72f742 100644 --- a/cmd/backend/install/install.go +++ b/cmd/backend/install/install.go @@ -4,6 +4,10 @@ Copyright © 2023 NAME HERE package install import ( + "fmt" + "strconv" + "strings" + "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/backend" "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" "github.com/spf13/cobra" @@ -16,17 +20,44 @@ var InstallCmd = &cobra.Command{ Long: `Installs training backend packages from pyproject.toml from /training in .venv`, Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { - if cmd.Flag("force").Value.String() == "true" { - pkg.ExecBashCmd(backend.BackendDir, "poetry", "env", "remove", "--all") + force, _ := strconv.ParseBool(cmd.Flag("force").Value.String()) + name := cmd.Flag("name").Value.String() + py_version := cmd.Flag("python-version").Value.String() + if cmd.Flag("reference").Value.String() == "true" { + fmt.Println("Check if " + name + " conda environment is created:") + fmt.Println("\tconda info --envs") + fmt.Println("If not created, create conda environment:") + fmt.Println("\tconda create --name " + name + " python=3.9") + fmt.Println("Activate conda env if not already activated:") + fmt.Println("\tconda activate dlp") + fmt.Println("If poetry not installed in conda env, install poetry:") + fmt.Println("\tconda install -c conda-forge poetry") + fmt.Println("Install python packages from pyproject.toml with poetry:") + fmt.Println("\tpoetry install") + return + } + res := pkg.ExecBashCmd(backend.BackendDir, "conda", "info", "--envs") + activated := strings.Contains(strings.ReplaceAll(res, " ", ""), name+"*") + if strings.Contains(res, name) && force { + pkg.ExecBashCmd(backend.BackendDir, "conda", "remove", "-n", name, "-y", "--all") + } + if !strings.Contains(res, name) || force { + pkg.ExecBashCmd(backend.BackendDir, "conda", "create", "--name", name, "-y", "python="+py_version) } - pkg.ExecBashCmd(backend.BackendDir, "pyenv", "local", "3.9") - pkg.ExecBashCmd(backend.BackendDir, "poetry", "install") - pkg.ExecBashCmd(backend.BackendDir, "poetry", "run", "ggshield", "auth", "login") - pkg.ExecBashCmd(backend.BackendDir, "poetry", "run", "pre-commit", "install") + cmd.Println(activated) + pkg.ExecBashCmd(backend.BackendDir, "conda", "run", "-n", name, "conda", "install", "-c", "conda-forge", "poetry") + pkg.ExecBashCmd(backend.BackendDir, "conda", "run", "-n", name, "poetry", "install") + //pkg.ExecBashCmd(backend.BackendDir, "bash", "-c", "eval \"$(conda shell.bash hook)\" && conda activate "+name+" && poetry install") + /* + pkg.ExecBashCmd(backend.BackendDir, "conda", "create", "--name", name, "--file", "requirements.txt") + pkg.ExecBashCmd(backend.BackendDir, "pyenv", "local", "3.9") + pkg.ExecBashCmd(backend.BackendDir, "poetry", "install")*/ }, } func init() { backend.BackendCmd.AddCommand(InstallCmd) - InstallCmd.Flags().BoolP("force", "f", false, "Force a reinstall of the backend") + InstallCmd.Flags().BoolP("force", "f", false, "Force a reinstall of backend packages") + InstallCmd.Flags().String("name", "dlp", "Name of the conda environment you want to create") + InstallCmd.Flags().String("python-version", "3.9", "Python version to specify when creating the conda environment") } diff --git a/cmd/root.go b/cmd/root.go index 4088c12..dee66b1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -40,5 +40,6 @@ func Execute() { func init() { RootCmd.PersistentFlags().String("project-dir", ".", "The directory of the project relative to the cli directory (cli-config.yaml project-dir overrides default value)") + RootCmd.PersistentFlags().BoolP("reference", "r", false, "Displays the equivalent shell commands for manual usage") viper.BindPFlag("project-dir", RootCmd.PersistentFlags().Lookup("project-dir")) } diff --git a/pkg/exec_bash_cmd_unix.go b/pkg/exec_bash_cmd_unix_os.go similarity index 85% rename from pkg/exec_bash_cmd_unix.go rename to pkg/exec_bash_cmd_unix_os.go index a12c4c9..28f1350 100644 --- a/pkg/exec_bash_cmd_unix.go +++ b/pkg/exec_bash_cmd_unix_os.go @@ -3,6 +3,7 @@ package pkg import ( + "bytes" "fmt" "io" "log" @@ -16,7 +17,7 @@ import ( "golang.org/x/term" ) -func ExecBashCmd(dir string, name string, arg ...string) { +func ExecBashCmd(dir string, name string, arg ...string) string { // Code below found in pty examples: https://github.com/creack/pty bash_cmd := exec.Command(name, arg...) bash_cmd.Dir = dir @@ -52,5 +53,10 @@ func ExecBashCmd(dir string, name string, arg ...string) { // Copy stdin to the pty and the pty to stdout. // NOTE: The goroutine will keep reading until the next keystroke before returning. go func() { io.Copy(ptmx, os.Stdin) }() - io.Copy(os.Stdout, ptmx) + var buffer bytes.Buffer + _, err = io.Copy(io.MultiWriter(os.Stdout, &buffer), ptmx) + if err != nil { + panic(err) + } + return buffer.String() } diff --git a/pkg/exec_bash_cmd_windows.go b/pkg/exec_bash_cmd_windows.go deleted file mode 100644 index d31a70e..0000000 --- a/pkg/exec_bash_cmd_windows.go +++ /dev/null @@ -1,46 +0,0 @@ -//go:build windows - -package pkg - -import ( - "fmt" - "io" - "os" - "os/exec" - "strings" - "sync" -) - -func ExecBashCmd(dir string, name string, arg ...string) { - // Use this if the pty one doesn't work - bash_cmd := exec.Command(name, arg...) - bash_cmd.Dir = dir - fmt.Println(strings.Join(bash_cmd.Args, " ")) - - stdoutPipe, _ := bash_cmd.StdoutPipe() - stderrPipe, _ := bash_cmd.StderrPipe() - err := bash_cmd.Start() - if err != nil { - fmt.Println("Error starting cmd: ", err) - return - } - var wg sync.WaitGroup - wg.Add(2) - - go func() { - defer wg.Done() - io.Copy(os.Stdout, stdoutPipe) - }() - - go func() { - defer wg.Done() - io.Copy(os.Stderr, stderrPipe) - }() - - wg.Wait() - err = bash_cmd.Wait() - if err != nil { - fmt.Println("Error waiting for cmd: ", err) - return - } -} diff --git a/pkg/exec_bash_cmd_windows_os.go b/pkg/exec_bash_cmd_windows_os.go new file mode 100644 index 0000000..ffd4d93 --- /dev/null +++ b/pkg/exec_bash_cmd_windows_os.go @@ -0,0 +1,31 @@ +//go:build windows + +package pkg + +import ( + "bytes" + "fmt" + "io" + "os" + "os/exec" + "strings" +) + +func ExecBashCmd(dir string, name string, arg ...string) string { + // Use this if the pty one doesn't work + bash_cmd := exec.Command(name, arg...) + bash_cmd.Dir = dir + fmt.Println(strings.Join(bash_cmd.Args, " ")) + + var stdoutBuf, stderrBuf bytes.Buffer + bash_cmd.Stdout = io.MultiWriter(os.Stdout, &stdoutBuf) + bash_cmd.Stderr = io.MultiWriter(os.Stderr, &stderrBuf) + err := bash_cmd.Run() + if err != nil { + fmt.Println("Error starting cmd: ", err) + return fmt.Sprint(err) + } + + outStr, errStr := string(stdoutBuf.String()), string(stderrBuf.String()) + return fmt.Sprint(outStr, errStr) +} From 8de299055259ddd4f5db0ed3fcf67a7b85a2f10a Mon Sep 17 00:00:00 2001 From: Daniel Wu Date: Sat, 16 Sep 2023 22:25:17 -0400 Subject: [PATCH 2/5] add uninstall cmd --- cmd/backend/backend.go | 1 + cmd/backend/install/install.go | 32 ++++++++++------------------- cmd/backend/uninstall/uninstall.go | 33 ++++++++++++++++++++++++++++++ main.go | 1 + 4 files changed, 46 insertions(+), 21 deletions(-) create mode 100644 cmd/backend/uninstall/uninstall.go diff --git a/cmd/backend/backend.go b/cmd/backend/backend.go index 69979f7..e5688b8 100644 --- a/cmd/backend/backend.go +++ b/cmd/backend/backend.go @@ -20,4 +20,5 @@ var BackendCmd = &cobra.Command{ func init() { cmd.RootCmd.AddCommand(BackendCmd) + BackendCmd.PersistentFlags().String("env-name", "dlp", "Name of the conda environment you want to create") } diff --git a/cmd/backend/install/install.go b/cmd/backend/install/install.go index d72f742..3331631 100644 --- a/cmd/backend/install/install.go +++ b/cmd/backend/install/install.go @@ -16,18 +16,17 @@ import ( // InstallCmd represents the backend install command var InstallCmd = &cobra.Command{ Use: "install", - Short: "Installs training backend packages from pyproject.toml", - Long: `Installs training backend packages from pyproject.toml from /training in .venv`, + Short: "Installs training backend packages from pyproject.toml using poetry and environment.yml using conda in a conda environment for dlp, creates conda environment if it doesn't exist", + Long: "Installs training backend packages from pyproject.toml using poetry and environment.yml using conda in a conda environment for dlp, creates conda environment if it doesn't exist", Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { force, _ := strconv.ParseBool(cmd.Flag("force").Value.String()) - name := cmd.Flag("name").Value.String() - py_version := cmd.Flag("python-version").Value.String() + env_name := cmd.Flag("env-name").Value.String() if cmd.Flag("reference").Value.String() == "true" { - fmt.Println("Check if " + name + " conda environment is created:") + fmt.Println("Check if " + env_name + " conda environment is created:") fmt.Println("\tconda info --envs") fmt.Println("If not created, create conda environment:") - fmt.Println("\tconda create --name " + name + " python=3.9") + fmt.Println("\tconda create --name " + env_name + " python=3.9") fmt.Println("Activate conda env if not already activated:") fmt.Println("\tconda activate dlp") fmt.Println("If poetry not installed in conda env, install poetry:") @@ -37,27 +36,18 @@ var InstallCmd = &cobra.Command{ return } res := pkg.ExecBashCmd(backend.BackendDir, "conda", "info", "--envs") - activated := strings.Contains(strings.ReplaceAll(res, " ", ""), name+"*") - if strings.Contains(res, name) && force { - pkg.ExecBashCmd(backend.BackendDir, "conda", "remove", "-n", name, "-y", "--all") + if strings.Contains(res, env_name) && force { + pkg.ExecBashCmd(backend.BackendDir, "conda", "remove", "-n", env_name, "-y", "--all") } - if !strings.Contains(res, name) || force { - pkg.ExecBashCmd(backend.BackendDir, "conda", "create", "--name", name, "-y", "python="+py_version) + if !strings.Contains(res, env_name) || force { + pkg.ExecBashCmd(backend.BackendDir, "conda", "create", "--name", env_name, "-y") } - cmd.Println(activated) - pkg.ExecBashCmd(backend.BackendDir, "conda", "run", "-n", name, "conda", "install", "-c", "conda-forge", "poetry") - pkg.ExecBashCmd(backend.BackendDir, "conda", "run", "-n", name, "poetry", "install") - //pkg.ExecBashCmd(backend.BackendDir, "bash", "-c", "eval \"$(conda shell.bash hook)\" && conda activate "+name+" && poetry install") - /* - pkg.ExecBashCmd(backend.BackendDir, "conda", "create", "--name", name, "--file", "requirements.txt") - pkg.ExecBashCmd(backend.BackendDir, "pyenv", "local", "3.9") - pkg.ExecBashCmd(backend.BackendDir, "poetry", "install")*/ + pkg.ExecBashCmd(backend.BackendDir, "conda", "run", "--live-stream", "-n", env_name, "conda", "env", "update", "--file", "environment.yml", "--prune") + pkg.ExecBashCmd(backend.BackendDir, "conda", "run", "--live-stream", "-n", env_name, "poetry", "install") }, } func init() { backend.BackendCmd.AddCommand(InstallCmd) InstallCmd.Flags().BoolP("force", "f", false, "Force a reinstall of backend packages") - InstallCmd.Flags().String("name", "dlp", "Name of the conda environment you want to create") - InstallCmd.Flags().String("python-version", "3.9", "Python version to specify when creating the conda environment") } diff --git a/cmd/backend/uninstall/uninstall.go b/cmd/backend/uninstall/uninstall.go new file mode 100644 index 0000000..1d95c14 --- /dev/null +++ b/cmd/backend/uninstall/uninstall.go @@ -0,0 +1,33 @@ +/* +Copyright © 2023 NAME HERE +*/ +package install + +import ( + "fmt" + + "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/backend" + "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" + "github.com/spf13/cobra" +) + +// InstallCmd represents the backend install command +var InstallCmd = &cobra.Command{ + Use: "uninstall", + Short: "Uninstalls all training backend packages and removes conda environment for dlp", + Long: `Uninstalls all training backend packages and removes conda environment for dlp`, + Args: cobra.ExactArgs(0), + Run: func(cmd *cobra.Command, args []string) { + env_name := cmd.Flag("env-name").Value.String() + if cmd.Flag("reference").Value.String() == "true" { + fmt.Println("Remove " + env_name + " conda environment:") + fmt.Println("\tconda remove -n " + env_name + " -y --all") + return + } + pkg.ExecBashCmd(backend.BackendDir, "conda", "remove", "-n", env_name, "-y", "--all") + }, +} + +func init() { + backend.BackendCmd.AddCommand(InstallCmd) +} diff --git a/main.go b/main.go index f56a6ca..078cbb5 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( _ "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/backend/remove" _ "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/backend/start" _ "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/backend/uid" + _ "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/backend/uninstall" _ "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/frontend" _ "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/frontend/add" _ "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/frontend/install" From 261ba28f26083772589777b9b0c84dcacec66277 Mon Sep 17 00:00:00 2001 From: Daniel Wu Date: Sun, 17 Sep 2023 01:25:55 -0400 Subject: [PATCH 3/5] use mamba cmds, modify add, remove, uninstall cmds --- cmd/backend/add/add.go | 28 +++++++++--- cmd/backend/install/install.go | 20 ++++----- cmd/backend/remove/remove.go | 28 +++++++++--- cmd/backend/uninstall/uninstall.go | 4 +- go.mod | 13 ++++++ go.sum | 71 ++++++++++++++++++++++++++++++ 6 files changed, 139 insertions(+), 25 deletions(-) diff --git a/cmd/backend/add/add.go b/cmd/backend/add/add.go index 2c85ca2..e0109c1 100644 --- a/cmd/backend/add/add.go +++ b/cmd/backend/add/add.go @@ -4,27 +4,43 @@ Copyright © 2023 NAME HERE package add import ( + "strconv" + "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/backend" "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" + "github.com/pterm/pterm" "github.com/spf13/cobra" ) // AddCmd represents the backend add command var AddCmd = &cobra.Command{ Use: "add {package}", - Short: "Add package to pyproject.toml", - Long: `Add package to pyproject.toml from /training`, + Short: "Add package to conda environment, defaults to installation via poetry unless otherwise specified", + Long: `Add package to conda environment from /training, defaults to installation via poetry unless otherwise specified`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { - bash_args := []string{"add", args[0]} - if cmd.Flag("dev").Value.String() == "true" { - bash_args = append(bash_args, "--group", "dev") + conda, _ := strconv.ParseBool(cmd.Flag("conda").Value.String()) + conda_channel := cmd.Flag("conda-channel").Value.String() + env_name := cmd.Flag("env-name").Value.String() + dev, _ := strconv.ParseBool(cmd.Flag("dev").Value.String()) + if conda { + pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "mamba", "install", "-c", conda_channel, args[0]) + pterm.DefaultSection.Println("IMPORTANT") + pterm.Info.Println("Add the following line in dependencies section in environment.yml:\n" + " - " + conda_channel + "::" + args[0]) + pterm.Info.Println("Add the following line at the bottom of the channels section in environment.yml above defaults:\n" + " - " + conda_channel) + pterm.Info.Println("Anaconda docs also recommend reinstalling the conda environment to reduce conflicts between conda-forge and PyPI dependencies, so after adding the above line, run:\ndlp-cli backend install --force") + } else if dev { + pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "poetry", "add", args[0], "--group", "dev") + } else { + pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "poetry", "add", args[0]) } - pkg.ExecBashCmd(backend.BackendDir, "poetry", bash_args...) }, } func init() { backend.BackendCmd.AddCommand(AddCmd) AddCmd.Flags().BoolP("dev", "d", false, "Add package as dev dependency") + AddCmd.Flags().BoolP("conda", "c", false, "Add package via conda (used mainly if cross-platform compatibility is needed)") + AddCmd.Flags().StringP("conda-channel", "o", "conda-forge", "Specify conda channel to install from (only used if --conda flag is set)") + AddCmd.MarkFlagsMutuallyExclusive("dev", "conda") } diff --git a/cmd/backend/install/install.go b/cmd/backend/install/install.go index 3331631..b8f2e7f 100644 --- a/cmd/backend/install/install.go +++ b/cmd/backend/install/install.go @@ -24,26 +24,26 @@ var InstallCmd = &cobra.Command{ env_name := cmd.Flag("env-name").Value.String() if cmd.Flag("reference").Value.String() == "true" { fmt.Println("Check if " + env_name + " conda environment is created:") - fmt.Println("\tconda info --envs") + fmt.Println("\tmamba info --envs") fmt.Println("If not created, create conda environment:") - fmt.Println("\tconda create --name " + env_name + " python=3.9") + fmt.Println("\tmamba create --name " + env_name + " python=3.9") fmt.Println("Activate conda env if not already activated:") - fmt.Println("\tconda activate dlp") - fmt.Println("If poetry not installed in conda env, install poetry:") - fmt.Println("\tconda install -c conda-forge poetry") + fmt.Println("\tmamba activate dlp") + fmt.Println("Install packages from environment.yml:") + fmt.Println("\tmamba env update --file environment.yml --prune") fmt.Println("Install python packages from pyproject.toml with poetry:") fmt.Println("\tpoetry install") return } - res := pkg.ExecBashCmd(backend.BackendDir, "conda", "info", "--envs") + res := pkg.ExecBashCmd(backend.BackendDir, "mamba", "info", "--envs") if strings.Contains(res, env_name) && force { - pkg.ExecBashCmd(backend.BackendDir, "conda", "remove", "-n", env_name, "-y", "--all") + pkg.ExecBashCmd(backend.BackendDir, "mamba", "remove", "-n", env_name, "-y", "--all") } if !strings.Contains(res, env_name) || force { - pkg.ExecBashCmd(backend.BackendDir, "conda", "create", "--name", env_name, "-y") + pkg.ExecBashCmd(backend.BackendDir, "mamba", "create", "--name", env_name, "-y") } - pkg.ExecBashCmd(backend.BackendDir, "conda", "run", "--live-stream", "-n", env_name, "conda", "env", "update", "--file", "environment.yml", "--prune") - pkg.ExecBashCmd(backend.BackendDir, "conda", "run", "--live-stream", "-n", env_name, "poetry", "install") + pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "mamba", "env", "update", "--file", "environment.yml", "--prune") + pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "poetry", "install") }, } diff --git a/cmd/backend/remove/remove.go b/cmd/backend/remove/remove.go index 76e3dc7..a47b638 100644 --- a/cmd/backend/remove/remove.go +++ b/cmd/backend/remove/remove.go @@ -4,27 +4,41 @@ Copyright © 2023 NAME HERE package remove import ( + "strconv" + "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/backend" "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" + "github.com/pterm/pterm" "github.com/spf13/cobra" ) -// AddCmd represents the backend add command +// RemoveCmd represents the backend remove command var RemoveCmd = &cobra.Command{ Use: "remove {package}", - Short: "Remove package from pyproject.toml", - Long: `Remove package from pyproject.toml from /training`, + Short: "Remove package from conda environment, defaults to removal via poetry unless otherwise specified", + Long: `Remove package from conda environment from /training, defaults to removal via poetry unless otherwise specified`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { - bash_args := []string{"remove", args[0]} - if cmd.Flag("dev").Value.String() == "true" { - bash_args = append(bash_args, "--group", "dev") + conda, _ := strconv.ParseBool(cmd.Flag("conda").Value.String()) + conda_channel := cmd.Flag("conda-channel").Value.String() + env_name := cmd.Flag("env-name").Value.String() + dev, _ := strconv.ParseBool(cmd.Flag("dev").Value.String()) + if conda { + pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "mamba", "remove", "-c", conda_channel, args[0]) + pterm.DefaultSection.Println("IMPORTANT") + pterm.Info.Println("Remove the following line in dependencies section in environment.yml:\n" + " - " + conda_channel + "::" + args[0]) + } else if dev { + pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "poetry", "remove", args[0], "--group", "dev") + } else { + pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "poetry", "remove", args[0]) } - pkg.ExecBashCmd(backend.BackendDir, "poetry", bash_args...) }, } func init() { backend.BackendCmd.AddCommand(RemoveCmd) RemoveCmd.Flags().BoolP("dev", "d", false, "Remove package from dev dependencies") + RemoveCmd.Flags().BoolP("conda", "c", false, "Remove package via conda (used mainly if cross-platform compatibility is needed)") + RemoveCmd.Flags().StringP("conda-channel", "o", "conda-forge", "Specify conda channel to install from (only used if --conda flag is set)") + RemoveCmd.MarkFlagsMutuallyExclusive("dev", "conda") } diff --git a/cmd/backend/uninstall/uninstall.go b/cmd/backend/uninstall/uninstall.go index 1d95c14..b8dbbdf 100644 --- a/cmd/backend/uninstall/uninstall.go +++ b/cmd/backend/uninstall/uninstall.go @@ -21,10 +21,10 @@ var InstallCmd = &cobra.Command{ env_name := cmd.Flag("env-name").Value.String() if cmd.Flag("reference").Value.String() == "true" { fmt.Println("Remove " + env_name + " conda environment:") - fmt.Println("\tconda remove -n " + env_name + " -y --all") + fmt.Println("\tmamba remove -n " + env_name + " --all") return } - pkg.ExecBashCmd(backend.BackendDir, "conda", "remove", "-n", env_name, "-y", "--all") + pkg.ExecBashCmd(backend.BackendDir, "mamba", "remove", "-n", env_name, "--all") }, } diff --git a/go.mod b/go.mod index c217750..7d18049 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,19 @@ require ( github.com/spf13/viper v1.16.0 ) +require ( + atomicgo.dev/cursor v0.2.0 // indirect + atomicgo.dev/keyboard v0.2.9 // indirect + atomicgo.dev/schedule v0.1.0 // indirect + github.com/containerd/console v1.0.3 // indirect + github.com/gookit/color v1.5.4 // indirect + github.com/lithammer/fuzzysearch v1.1.8 // indirect + github.com/mattn/go-runewidth v0.0.15 // indirect + github.com/pterm/pterm v0.12.69 // indirect + github.com/rivo/uniseg v0.4.4 // indirect + github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect +) + require ( github.com/creack/pty v1.1.18 github.com/fsnotify/fsnotify v1.6.0 // indirect diff --git a/go.sum b/go.sum index 553c7ce..6c9a1b1 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,9 @@ +atomicgo.dev/cursor v0.2.0 h1:H6XN5alUJ52FZZUkI7AlJbUc1aW38GWZalpYRPpoPOw= +atomicgo.dev/cursor v0.2.0/go.mod h1:Lr4ZJB3U7DfPPOkbH7/6TOtJ4vFGHlgj1nc+n900IpU= +atomicgo.dev/keyboard v0.2.9 h1:tOsIid3nlPLZ3lwgG8KZMp/SFmr7P0ssEN5JUsm78K8= +atomicgo.dev/keyboard v0.2.9/go.mod h1:BC4w9g00XkxH/f1HXhW2sXmJFOCWbKn9xrOunSFtExQ= +atomicgo.dev/schedule v0.1.0 h1:nTthAbhZS5YZmgYbb2+DH8uQIZcTlIrd4eYr3UQxEjs= +atomicgo.dev/schedule v0.1.0/go.mod h1:xeUa3oAkiuHYh8bKiQBRojqAMq3PXXbJujjb0hw8pEU= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= @@ -38,6 +44,14 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/MarvinJWendt/testza v0.1.0/go.mod h1:7AxNvlfeHP7Z/hDQ5JtE3OKYT3XFUeLCDE2DQninSqs= +github.com/MarvinJWendt/testza v0.2.1/go.mod h1:God7bhG8n6uQxwdScay+gjm9/LnO4D3kkcZX4hv9Rp8= +github.com/MarvinJWendt/testza v0.2.8/go.mod h1:nwIcjmr0Zz+Rcwfh3/4UhBp7ePKVhuBExvZqnKYWlII= +github.com/MarvinJWendt/testza v0.2.10/go.mod h1:pd+VWsoGUiFtq+hRKSU1Bktnn+DMCSrDrXDpX2bG66k= +github.com/MarvinJWendt/testza v0.2.12/go.mod h1:JOIegYyV7rX+7VZ9r77L/eH6CfJHHzXjB69adAhzZkI= +github.com/MarvinJWendt/testza v0.3.0/go.mod h1:eFcL4I0idjtIx8P9C6KkAuLgATNKpX4/2oUqKc6bF2c= +github.com/MarvinJWendt/testza v0.4.2/go.mod h1:mSdhXiKH8sg/gQehJ63bINcCKp7RtYewEjXsvsVUPbE= +github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= @@ -46,6 +60,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= +github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= @@ -121,6 +137,10 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= +github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ= +github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo= +github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0= +github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= @@ -132,6 +152,9 @@ github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLf github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.0.10/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= +github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= @@ -140,8 +163,13 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4= +github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= +github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0= @@ -151,10 +179,23 @@ github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qR github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/pterm/pterm v0.12.27/go.mod h1:PhQ89w4i95rhgE+xedAoqous6K9X+r6aSOI2eFF7DZI= +github.com/pterm/pterm v0.12.29/go.mod h1:WI3qxgvoQFFGKGjGnJR849gU0TsEOvKn5Q8LlY1U7lg= +github.com/pterm/pterm v0.12.30/go.mod h1:MOqLIyMOgmTDz9yorcYbcw+HsgoZo3BQfg2wtl3HEFE= +github.com/pterm/pterm v0.12.31/go.mod h1:32ZAWZVXD7ZfG0s8qqHXePte42kdz8ECtRyEejaWgXU= +github.com/pterm/pterm v0.12.33/go.mod h1:x+h2uL+n7CP/rel9+bImHD5lF3nM9vJj80k9ybiiTTE= +github.com/pterm/pterm v0.12.36/go.mod h1:NjiL09hFhT/vWjQHSj1athJpx6H8cjpHXNAK5bUw8T8= +github.com/pterm/pterm v0.12.40/go.mod h1:ffwPLwlbXxP+rxT0GsgDTzS3y3rmpAO1NMjUkGTYf8s= +github.com/pterm/pterm v0.12.69 h1:fBCKnB8dSLAl8FlYRQAWYGp2WTI/Xm/tKJ21Hyo9USw= +github.com/pterm/pterm v0.12.69/go.mod h1:wl06ko9MHnqxz4oDV++IORDpjCzw6+mfrvf0MPj6fdk= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= +github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= @@ -173,6 +214,7 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= @@ -180,10 +222,14 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -196,6 +242,7 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -230,6 +277,8 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -262,6 +311,8 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -281,6 +332,8 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -312,14 +365,25 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0= golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -330,6 +394,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -382,6 +448,8 @@ golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -477,11 +545,14 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From ac534bab5e929e275f10db33778100a00b0c7cae Mon Sep 17 00:00:00 2001 From: Daniel Wu Date: Sun, 17 Sep 2023 01:52:03 -0400 Subject: [PATCH 4/5] update flags names for mamba --- cmd/backend/add/add.go | 18 +++++++++--------- cmd/backend/remove/remove.go | 16 ++++++++-------- cmd/backend/start/start.go | 3 ++- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/cmd/backend/add/add.go b/cmd/backend/add/add.go index e0109c1..3378ae7 100644 --- a/cmd/backend/add/add.go +++ b/cmd/backend/add/add.go @@ -19,15 +19,15 @@ var AddCmd = &cobra.Command{ Long: `Add package to conda environment from /training, defaults to installation via poetry unless otherwise specified`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { - conda, _ := strconv.ParseBool(cmd.Flag("conda").Value.String()) - conda_channel := cmd.Flag("conda-channel").Value.String() + mamba, _ := strconv.ParseBool(cmd.Flag("mamba").Value.String()) + channel := cmd.Flag("channel").Value.String() env_name := cmd.Flag("env-name").Value.String() dev, _ := strconv.ParseBool(cmd.Flag("dev").Value.String()) - if conda { - pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "mamba", "install", "-c", conda_channel, args[0]) + if mamba { + pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "mamba", "install", "-c", channel, args[0]) pterm.DefaultSection.Println("IMPORTANT") - pterm.Info.Println("Add the following line in dependencies section in environment.yml:\n" + " - " + conda_channel + "::" + args[0]) - pterm.Info.Println("Add the following line at the bottom of the channels section in environment.yml above defaults:\n" + " - " + conda_channel) + pterm.Info.Println("Add the following line in dependencies section in environment.yml:\n" + " - " + channel + "::" + args[0]) + pterm.Info.Println("Add the following line at the bottom of the channels section in environment.yml above defaults:\n" + " - " + channel) pterm.Info.Println("Anaconda docs also recommend reinstalling the conda environment to reduce conflicts between conda-forge and PyPI dependencies, so after adding the above line, run:\ndlp-cli backend install --force") } else if dev { pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "poetry", "add", args[0], "--group", "dev") @@ -40,7 +40,7 @@ var AddCmd = &cobra.Command{ func init() { backend.BackendCmd.AddCommand(AddCmd) AddCmd.Flags().BoolP("dev", "d", false, "Add package as dev dependency") - AddCmd.Flags().BoolP("conda", "c", false, "Add package via conda (used mainly if cross-platform compatibility is needed)") - AddCmd.Flags().StringP("conda-channel", "o", "conda-forge", "Specify conda channel to install from (only used if --conda flag is set)") - AddCmd.MarkFlagsMutuallyExclusive("dev", "conda") + AddCmd.Flags().BoolP("mamba", "m", false, "Add package via mamba (used mainly if cross-platform compatibility is needed)") + AddCmd.Flags().StringP("channel", "c", "conda-forge", "Specify conda channel to install from (only used if --mamba flag is set)") + AddCmd.MarkFlagsMutuallyExclusive("dev", "mamba") } diff --git a/cmd/backend/remove/remove.go b/cmd/backend/remove/remove.go index a47b638..2e6a0a3 100644 --- a/cmd/backend/remove/remove.go +++ b/cmd/backend/remove/remove.go @@ -19,14 +19,14 @@ var RemoveCmd = &cobra.Command{ Long: `Remove package from conda environment from /training, defaults to removal via poetry unless otherwise specified`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { - conda, _ := strconv.ParseBool(cmd.Flag("conda").Value.String()) - conda_channel := cmd.Flag("conda-channel").Value.String() + mamba, _ := strconv.ParseBool(cmd.Flag("mamba").Value.String()) + channel := cmd.Flag("channel").Value.String() env_name := cmd.Flag("env-name").Value.String() dev, _ := strconv.ParseBool(cmd.Flag("dev").Value.String()) - if conda { - pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "mamba", "remove", "-c", conda_channel, args[0]) + if mamba { + pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "mamba", "remove", "-c", channel, args[0]) pterm.DefaultSection.Println("IMPORTANT") - pterm.Info.Println("Remove the following line in dependencies section in environment.yml:\n" + " - " + conda_channel + "::" + args[0]) + pterm.Info.Println("Remove the following line in dependencies section in environment.yml:\n" + " - " + channel + "::" + args[0]) } else if dev { pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "poetry", "remove", args[0], "--group", "dev") } else { @@ -38,7 +38,7 @@ var RemoveCmd = &cobra.Command{ func init() { backend.BackendCmd.AddCommand(RemoveCmd) RemoveCmd.Flags().BoolP("dev", "d", false, "Remove package from dev dependencies") - RemoveCmd.Flags().BoolP("conda", "c", false, "Remove package via conda (used mainly if cross-platform compatibility is needed)") - RemoveCmd.Flags().StringP("conda-channel", "o", "conda-forge", "Specify conda channel to install from (only used if --conda flag is set)") - RemoveCmd.MarkFlagsMutuallyExclusive("dev", "conda") + RemoveCmd.Flags().BoolP("mamba", "m", false, "Remove package via conda (used mainly if cross-platform compatibility is needed)") + RemoveCmd.Flags().StringP("channel", "c", "conda-forge", "Specify conda channel to install from (only used if --mamba flag is set)") + RemoveCmd.MarkFlagsMutuallyExclusive("dev", "mamba") } diff --git a/cmd/backend/start/start.go b/cmd/backend/start/start.go index 78dc347..d99bc22 100644 --- a/cmd/backend/start/start.go +++ b/cmd/backend/start/start.go @@ -18,7 +18,8 @@ var StartCmd = &cobra.Command{ Long: `Starts an instance of the training backend Django app in /training in the terminal`, Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { - pkg.ExecBashCmd(backend.BackendDir, "poetry", "run", "python", "manage.py", "runserver", fmt.Sprintf("%v", cmd.Flag("port").Value)) + env_name := cmd.Flag("env-name").Value.String() + pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "poetry", "run", "python", "manage.py", "runserver", fmt.Sprintf("%v", cmd.Flag("port").Value)) }, } From 5119f20c8e7c096335fb68f03eee959d43c90495 Mon Sep 17 00:00:00 2001 From: Daniel Wu Date: Sun, 17 Sep 2023 17:18:22 -0400 Subject: [PATCH 5/5] add support for non-unix machines running in unix terminals + better prints for bash cmds --- cmd/backend/add/add.go | 7 ++--- cmd/backend/backend.go | 4 +++ cmd/backend/id_token/id_token.go | 4 +-- cmd/backend/install/install.go | 11 +++---- cmd/backend/remove/remove.go | 7 ++--- cmd/backend/start/start.go | 3 +- cmd/backend/uid/uid.go | 3 +- cmd/backend/uninstall/uninstall.go | 3 +- cmd/frontend/add/add.go | 3 +- cmd/frontend/frontend.go | 4 +++ cmd/frontend/install/install.go | 3 +- cmd/frontend/remove/remove.go | 3 +- cmd/frontend/start/start.go | 3 +- cmd/root.go | 11 +++++++ cmd/serverless/core/add/add.go | 3 +- cmd/serverless/core/core.go | 5 +++ cmd/serverless/core/remove/remove.go | 3 +- cmd/serverless/functions/add/add.go | 3 +- cmd/serverless/functions/functions.go | 5 +++ cmd/serverless/functions/remove/remove.go | 3 +- cmd/serverless/install/install.go | 3 +- cmd/serverless/serverless.go | 4 +++ cmd/serverless/start/start.go | 3 +- ...c_bash_cmd_unix_os.go => exec_bash_cmd.go} | 28 +++++++++++++---- pkg/exec_bash_cmd_windows_os.go | 31 ------------------- 25 files changed, 80 insertions(+), 80 deletions(-) rename pkg/{exec_bash_cmd_unix_os.go => exec_bash_cmd.go} (60%) delete mode 100644 pkg/exec_bash_cmd_windows_os.go diff --git a/cmd/backend/add/add.go b/cmd/backend/add/add.go index 3378ae7..75c71c7 100644 --- a/cmd/backend/add/add.go +++ b/cmd/backend/add/add.go @@ -7,7 +7,6 @@ import ( "strconv" "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/backend" - "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" "github.com/pterm/pterm" "github.com/spf13/cobra" ) @@ -24,15 +23,15 @@ var AddCmd = &cobra.Command{ env_name := cmd.Flag("env-name").Value.String() dev, _ := strconv.ParseBool(cmd.Flag("dev").Value.String()) if mamba { - pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "mamba", "install", "-c", channel, args[0]) + backend.ExecBashCmd("mamba", "run", "--live-stream", "-n", env_name, "mamba", "install", "-c", channel, args[0]) pterm.DefaultSection.Println("IMPORTANT") pterm.Info.Println("Add the following line in dependencies section in environment.yml:\n" + " - " + channel + "::" + args[0]) pterm.Info.Println("Add the following line at the bottom of the channels section in environment.yml above defaults:\n" + " - " + channel) pterm.Info.Println("Anaconda docs also recommend reinstalling the conda environment to reduce conflicts between conda-forge and PyPI dependencies, so after adding the above line, run:\ndlp-cli backend install --force") } else if dev { - pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "poetry", "add", args[0], "--group", "dev") + backend.ExecBashCmd("mamba", "run", "--live-stream", "-n", env_name, "poetry", "add", args[0], "--group", "dev") } else { - pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "poetry", "add", args[0]) + backend.ExecBashCmd("mamba", "run", "--live-stream", "-n", env_name, "poetry", "add", args[0]) } }, } diff --git a/cmd/backend/backend.go b/cmd/backend/backend.go index e5688b8..6cae3e9 100644 --- a/cmd/backend/backend.go +++ b/cmd/backend/backend.go @@ -22,3 +22,7 @@ func init() { cmd.RootCmd.AddCommand(BackendCmd) BackendCmd.PersistentFlags().String("env-name", "dlp", "Name of the conda environment you want to create") } + +func ExecBashCmd(name string, args ...string) string { + return cmd.ExecBashCmd(BackendDir, name, args...) +} diff --git a/cmd/backend/id_token/id_token.go b/cmd/backend/id_token/id_token.go index 58ea9a6..0f3a9f1 100644 --- a/cmd/backend/id_token/id_token.go +++ b/cmd/backend/id_token/id_token.go @@ -6,7 +6,6 @@ Copyright © 2023 NAME HERE import ( "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/backend" - "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" "github.com/spf13/cobra" ) @@ -17,11 +16,10 @@ var IdTokenCmd = &cobra.Command{ Long: `gets a user's id token by email from the backend`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { - pkg.ExecBashCmd(backend.BackendDir, "poetry", "run", "python", "cli.py", "get-id-token", args[0]) + backend.ExecBashCmd("poetry", "run", "python", "cli.py", "get-id-token", args[0]) }, } func init() { backend.BackendCmd.AddCommand(IdTokenCmd) - //IdTokenCmd.Flags().StringP("email", "") } diff --git a/cmd/backend/install/install.go b/cmd/backend/install/install.go index b8f2e7f..8a34776 100644 --- a/cmd/backend/install/install.go +++ b/cmd/backend/install/install.go @@ -9,7 +9,6 @@ import ( "strings" "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/backend" - "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" "github.com/spf13/cobra" ) @@ -35,15 +34,15 @@ var InstallCmd = &cobra.Command{ fmt.Println("\tpoetry install") return } - res := pkg.ExecBashCmd(backend.BackendDir, "mamba", "info", "--envs") + res := backend.ExecBashCmd("mamba", "info", "--envs") if strings.Contains(res, env_name) && force { - pkg.ExecBashCmd(backend.BackendDir, "mamba", "remove", "-n", env_name, "-y", "--all") + backend.ExecBashCmd("mamba", "remove", "-n", env_name, "-y", "--all") } if !strings.Contains(res, env_name) || force { - pkg.ExecBashCmd(backend.BackendDir, "mamba", "create", "--name", env_name, "-y") + backend.ExecBashCmd("mamba", "create", "--name", env_name, "-y") } - pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "mamba", "env", "update", "--file", "environment.yml", "--prune") - pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "poetry", "install") + backend.ExecBashCmd("mamba", "run", "--live-stream", "-n", env_name, "mamba", "env", "update", "--file", "environment.yml", "--prune") + backend.ExecBashCmd("mamba", "run", "--live-stream", "-n", env_name, "poetry", "install") }, } diff --git a/cmd/backend/remove/remove.go b/cmd/backend/remove/remove.go index 2e6a0a3..2d5abff 100644 --- a/cmd/backend/remove/remove.go +++ b/cmd/backend/remove/remove.go @@ -7,7 +7,6 @@ import ( "strconv" "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/backend" - "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" "github.com/pterm/pterm" "github.com/spf13/cobra" ) @@ -24,13 +23,13 @@ var RemoveCmd = &cobra.Command{ env_name := cmd.Flag("env-name").Value.String() dev, _ := strconv.ParseBool(cmd.Flag("dev").Value.String()) if mamba { - pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "mamba", "remove", "-c", channel, args[0]) + backend.ExecBashCmd("mamba", "run", "--live-stream", "-n", env_name, "mamba", "remove", "-c", channel, args[0]) pterm.DefaultSection.Println("IMPORTANT") pterm.Info.Println("Remove the following line in dependencies section in environment.yml:\n" + " - " + channel + "::" + args[0]) } else if dev { - pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "poetry", "remove", args[0], "--group", "dev") + backend.ExecBashCmd("mamba", "run", "--live-stream", "-n", env_name, "poetry", "remove", args[0], "--group", "dev") } else { - pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "poetry", "remove", args[0]) + backend.ExecBashCmd("mamba", "run", "--live-stream", "-n", env_name, "poetry", "remove", args[0]) } }, } diff --git a/cmd/backend/start/start.go b/cmd/backend/start/start.go index d99bc22..07772d0 100644 --- a/cmd/backend/start/start.go +++ b/cmd/backend/start/start.go @@ -7,7 +7,6 @@ import ( "fmt" "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/backend" - "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" "github.com/spf13/cobra" ) @@ -19,7 +18,7 @@ var StartCmd = &cobra.Command{ Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { env_name := cmd.Flag("env-name").Value.String() - pkg.ExecBashCmd(backend.BackendDir, "mamba", "run", "--live-stream", "-n", env_name, "poetry", "run", "python", "manage.py", "runserver", fmt.Sprintf("%v", cmd.Flag("port").Value)) + backend.ExecBashCmd("mamba", "run", "--live-stream", "-n", env_name, "poetry", "run", "python", "manage.py", "runserver", fmt.Sprintf("%v", cmd.Flag("port").Value)) }, } diff --git a/cmd/backend/uid/uid.go b/cmd/backend/uid/uid.go index 6053c2e..0fd0620 100644 --- a/cmd/backend/uid/uid.go +++ b/cmd/backend/uid/uid.go @@ -6,7 +6,6 @@ Copyright © 2023 NAME HERE import ( "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/backend" - "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" "github.com/spf13/cobra" ) @@ -17,7 +16,7 @@ var UidCmd = &cobra.Command{ Long: `gets a user's uid by email from the backend`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { - pkg.ExecBashCmd(backend.BackendDir, "poetry", "run", "python", "cli.py", "get-uid", args[0]) + backend.ExecBashCmd("poetry", "run", "python", "cli.py", "get-uid", args[0]) }, } diff --git a/cmd/backend/uninstall/uninstall.go b/cmd/backend/uninstall/uninstall.go index b8dbbdf..ba908b9 100644 --- a/cmd/backend/uninstall/uninstall.go +++ b/cmd/backend/uninstall/uninstall.go @@ -7,7 +7,6 @@ import ( "fmt" "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/backend" - "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" "github.com/spf13/cobra" ) @@ -24,7 +23,7 @@ var InstallCmd = &cobra.Command{ fmt.Println("\tmamba remove -n " + env_name + " --all") return } - pkg.ExecBashCmd(backend.BackendDir, "mamba", "remove", "-n", env_name, "--all") + backend.ExecBashCmd("mamba", "remove", "-n", env_name, "--all") }, } diff --git a/cmd/frontend/add/add.go b/cmd/frontend/add/add.go index cc50697..59e4b62 100644 --- a/cmd/frontend/add/add.go +++ b/cmd/frontend/add/add.go @@ -5,7 +5,6 @@ package add import ( "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/frontend" - "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" "github.com/spf13/cobra" ) @@ -20,7 +19,7 @@ var AddCmd = &cobra.Command{ if cmd.Flag("dev").Value.String() == "true" { bash_args = append(bash_args, "--dev") } - pkg.ExecBashCmd(frontend.FrontendDir, "yarn", bash_args...) + frontend.ExecBashCmd("yarn", bash_args...) }, } diff --git a/cmd/frontend/frontend.go b/cmd/frontend/frontend.go index 2275d03..10cebfd 100644 --- a/cmd/frontend/frontend.go +++ b/cmd/frontend/frontend.go @@ -21,3 +21,7 @@ var FrontendCmd = &cobra.Command{ func init() { cmd.RootCmd.AddCommand(FrontendCmd) } + +func ExecBashCmd(name string, args ...string) string { + return cmd.ExecBashCmd(FrontendDir, name, args...) +} diff --git a/cmd/frontend/install/install.go b/cmd/frontend/install/install.go index 687bab0..d2ce2cb 100644 --- a/cmd/frontend/install/install.go +++ b/cmd/frontend/install/install.go @@ -5,7 +5,6 @@ package install import ( "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/frontend" - "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" "github.com/spf13/cobra" ) @@ -20,7 +19,7 @@ var InstallCmd = &cobra.Command{ if cmd.Flag("force").Value.String() == "true" { bash_args = append(bash_args, "--force") } - pkg.ExecBashCmd(frontend.FrontendDir, "yarn", bash_args...) + frontend.ExecBashCmd("yarn", bash_args...) }, } diff --git a/cmd/frontend/remove/remove.go b/cmd/frontend/remove/remove.go index b2da576..1b6cd9a 100644 --- a/cmd/frontend/remove/remove.go +++ b/cmd/frontend/remove/remove.go @@ -5,7 +5,6 @@ package remove import ( "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/frontend" - "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" "github.com/spf13/cobra" ) @@ -20,7 +19,7 @@ var RemoveCmd = &cobra.Command{ if cmd.Flag("dev").Value.String() == "true" { bash_args = append(bash_args, "--dev") } - pkg.ExecBashCmd(frontend.FrontendDir, "yarn", bash_args...) + frontend.ExecBashCmd("yarn", bash_args...) }, } diff --git a/cmd/frontend/start/start.go b/cmd/frontend/start/start.go index 632b774..a5f4632 100644 --- a/cmd/frontend/start/start.go +++ b/cmd/frontend/start/start.go @@ -7,7 +7,6 @@ import ( "fmt" "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/frontend" - "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" "github.com/spf13/cobra" ) @@ -18,7 +17,7 @@ var StartCmd = &cobra.Command{ Long: `Starts an instance of the nextjs frontend in the terminal`, Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { - pkg.ExecBashCmd(frontend.FrontendDir, "yarn", "next", "dev", "-p", fmt.Sprintf("%v", cmd.Flag("port").Value)) + frontend.ExecBashCmd("yarn", "next", "dev", "-p", fmt.Sprintf("%v", cmd.Flag("port").Value)) }, } diff --git a/cmd/root.go b/cmd/root.go index dee66b1..df6b730 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -6,7 +6,9 @@ package cmd import ( "os" "path/filepath" + "runtime" + "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -40,6 +42,15 @@ func Execute() { func init() { RootCmd.PersistentFlags().String("project-dir", ".", "The directory of the project relative to the cli directory (cli-config.yaml project-dir overrides default value)") + RootCmd.PersistentFlags().BoolP("no-unix", "w", false, "Execute bash commands as if on Windows (use if your os doesn't support Unix PTYs)") RootCmd.PersistentFlags().BoolP("reference", "r", false, "Displays the equivalent shell commands for manual usage") viper.BindPFlag("project-dir", RootCmd.PersistentFlags().Lookup("project-dir")) } + +func ExecBashCmd(dir string, name string, args ...string) string { + runtime_os := runtime.GOOS + if RootCmd.Flag("no-unix").Value.String() == "true" { + runtime_os = "windows" + } + return pkg.ExecBashCmd(runtime_os, dir, name, args...) +} diff --git a/cmd/serverless/core/add/add.go b/cmd/serverless/core/add/add.go index 785bc25..953ce33 100644 --- a/cmd/serverless/core/add/add.go +++ b/cmd/serverless/core/add/add.go @@ -5,7 +5,6 @@ package add import ( "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/serverless/core" - "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" "github.com/spf13/cobra" ) @@ -20,7 +19,7 @@ var AddCmd = &cobra.Command{ if cmd.Flag("dev").Value.String() == "true" { bash_args = append(bash_args, "--dev") } - pkg.ExecBashCmd(core.CoreDir, "yarn", bash_args...) + core.ExecBashCmd("yarn", bash_args...) }, } diff --git a/cmd/serverless/core/core.go b/cmd/serverless/core/core.go index 921b4a5..0bf7d18 100644 --- a/cmd/serverless/core/core.go +++ b/cmd/serverless/core/core.go @@ -4,6 +4,7 @@ Copyright © 2023 NAME HERE package core import ( + "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd" "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/serverless" "github.com/spf13/cobra" ) @@ -21,3 +22,7 @@ var CoreCmd = &cobra.Command{ func init() { serverless.ServerlessCmd.AddCommand(CoreCmd) } + +func ExecBashCmd(name string, args ...string) string { + return cmd.ExecBashCmd(CoreDir, name, args...) +} diff --git a/cmd/serverless/core/remove/remove.go b/cmd/serverless/core/remove/remove.go index 98e7cab..e4c45d8 100644 --- a/cmd/serverless/core/remove/remove.go +++ b/cmd/serverless/core/remove/remove.go @@ -5,7 +5,6 @@ package remove import ( "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/serverless/core" - "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" "github.com/spf13/cobra" ) @@ -20,7 +19,7 @@ var RemoveCmd = &cobra.Command{ if cmd.Flag("dev").Value.String() == "true" { bash_args = append(bash_args, "--dev") } - pkg.ExecBashCmd(core.CoreDir, "yarn", bash_args...) + core.ExecBashCmd("yarn", bash_args...) }, } diff --git a/cmd/serverless/functions/add/add.go b/cmd/serverless/functions/add/add.go index 67f333e..653368e 100644 --- a/cmd/serverless/functions/add/add.go +++ b/cmd/serverless/functions/add/add.go @@ -5,7 +5,6 @@ package add import ( "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/serverless/functions" - "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" "github.com/spf13/cobra" ) @@ -20,7 +19,7 @@ var AddCmd = &cobra.Command{ if cmd.Flag("dev").Value.String() == "true" { bash_args = append(bash_args, "--dev") } - pkg.ExecBashCmd(functions.FunctionsDir, "yarn", bash_args...) + functions.ExecBashCmd("yarn", bash_args...) }, } diff --git a/cmd/serverless/functions/functions.go b/cmd/serverless/functions/functions.go index c5c2813..31928b7 100644 --- a/cmd/serverless/functions/functions.go +++ b/cmd/serverless/functions/functions.go @@ -4,6 +4,7 @@ Copyright © 2023 NAME HERE package functions import ( + "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd" "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/serverless" "github.com/spf13/cobra" ) @@ -21,3 +22,7 @@ var FunctionsCmd = &cobra.Command{ func init() { serverless.ServerlessCmd.AddCommand(FunctionsCmd) } + +func ExecBashCmd(name string, args ...string) string { + return cmd.ExecBashCmd(FunctionsDir, name, args...) +} diff --git a/cmd/serverless/functions/remove/remove.go b/cmd/serverless/functions/remove/remove.go index 8bc0227..e20ad26 100644 --- a/cmd/serverless/functions/remove/remove.go +++ b/cmd/serverless/functions/remove/remove.go @@ -5,7 +5,6 @@ package remove import ( "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/serverless/functions" - "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" "github.com/spf13/cobra" ) @@ -20,7 +19,7 @@ var RemoveCmd = &cobra.Command{ if cmd.Flag("dev").Value.String() == "true" { bash_args = append(bash_args, "--dev") } - pkg.ExecBashCmd(functions.FunctionsDir, "yarn", bash_args...) + functions.ExecBashCmd("yarn", bash_args...) }, } diff --git a/cmd/serverless/install/install.go b/cmd/serverless/install/install.go index d3b00f9..994c87f 100644 --- a/cmd/serverless/install/install.go +++ b/cmd/serverless/install/install.go @@ -5,7 +5,6 @@ package install import ( "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/serverless" - "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" "github.com/spf13/cobra" ) @@ -20,7 +19,7 @@ var InstallCmd = &cobra.Command{ if cmd.Flag("force").Value.String() == "true" { bash_args = append(bash_args, "--force") } - pkg.ExecBashCmd(serverless.ServerlessDir, "yarn", bash_args...) + serverless.ExecBashCmd("yarn", bash_args...) }, } diff --git a/cmd/serverless/serverless.go b/cmd/serverless/serverless.go index 86cbee4..c1bd309 100644 --- a/cmd/serverless/serverless.go +++ b/cmd/serverless/serverless.go @@ -21,3 +21,7 @@ var ServerlessCmd = &cobra.Command{ func init() { cmd.RootCmd.AddCommand(ServerlessCmd) } + +func ExecBashCmd(name string, args ...string) string { + return cmd.ExecBashCmd(ServerlessDir, name, args...) +} diff --git a/cmd/serverless/start/start.go b/cmd/serverless/start/start.go index b78e109..71f8a65 100644 --- a/cmd/serverless/start/start.go +++ b/cmd/serverless/start/start.go @@ -5,7 +5,6 @@ package serverless import ( "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/serverless" - "github.com/DSGT-DLP/Deep-Learning-Playground/cli/pkg" "github.com/spf13/cobra" ) @@ -16,7 +15,7 @@ var StartCmd = &cobra.Command{ Long: `Starts SST's Live Lambda Development environment in the terminal`, Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { - pkg.ExecBashCmd(serverless.ServerlessDir, "yarn", "sst", "dev") + serverless.ExecBashCmd("yarn", "sst", "dev") }, } diff --git a/pkg/exec_bash_cmd_unix_os.go b/pkg/exec_bash_cmd.go similarity index 60% rename from pkg/exec_bash_cmd_unix_os.go rename to pkg/exec_bash_cmd.go index 28f1350..412b320 100644 --- a/pkg/exec_bash_cmd_unix_os.go +++ b/pkg/exec_bash_cmd.go @@ -1,12 +1,9 @@ -//go:build !windows - package pkg import ( "bytes" "fmt" "io" - "log" "os" "os/exec" "os/signal" @@ -14,14 +11,33 @@ import ( "syscall" "github.com/creack/pty" + "github.com/pterm/pterm" "golang.org/x/term" ) -func ExecBashCmd(dir string, name string, arg ...string) string { +func ExecBashCmd(runtime_os string, dir string, name string, arg ...string) string { + if runtime_os == "windows" { + // Use this if the pty one doesn't work + bash_cmd := exec.Command(name, arg...) + bash_cmd.Dir = dir + pterm.DefaultHeader.WithFullWidth().Println(strings.Join(bash_cmd.Args, " ")) + + var stdoutBuf, stderrBuf bytes.Buffer + bash_cmd.Stdout = io.MultiWriter(os.Stdout, &stdoutBuf) + bash_cmd.Stderr = io.MultiWriter(os.Stderr, &stderrBuf) + err := bash_cmd.Run() + if err != nil { + pterm.Error.Println("Error starting cmd: ", err) + return fmt.Sprint(err) + } + + outStr, errStr := string(stdoutBuf.String()), string(stderrBuf.String()) + return fmt.Sprint(outStr, errStr) + } // Code below found in pty examples: https://github.com/creack/pty bash_cmd := exec.Command(name, arg...) bash_cmd.Dir = dir - fmt.Println(strings.Join(bash_cmd.Args, " ")) + pterm.DefaultHeader.WithFullWidth().Println(strings.Join(bash_cmd.Args, " ")) ptmx, err := pty.Start(bash_cmd) if err != nil { panic(err) @@ -35,7 +51,7 @@ func ExecBashCmd(dir string, name string, arg ...string) string { go func() { for range ch { if err := pty.InheritSize(os.Stdin, ptmx); err != nil { - log.Printf("error resizing pty: %s", err) + pterm.Error.Printf("error resizing pty: %s", err) } } }() diff --git a/pkg/exec_bash_cmd_windows_os.go b/pkg/exec_bash_cmd_windows_os.go deleted file mode 100644 index ffd4d93..0000000 --- a/pkg/exec_bash_cmd_windows_os.go +++ /dev/null @@ -1,31 +0,0 @@ -//go:build windows - -package pkg - -import ( - "bytes" - "fmt" - "io" - "os" - "os/exec" - "strings" -) - -func ExecBashCmd(dir string, name string, arg ...string) string { - // Use this if the pty one doesn't work - bash_cmd := exec.Command(name, arg...) - bash_cmd.Dir = dir - fmt.Println(strings.Join(bash_cmd.Args, " ")) - - var stdoutBuf, stderrBuf bytes.Buffer - bash_cmd.Stdout = io.MultiWriter(os.Stdout, &stdoutBuf) - bash_cmd.Stderr = io.MultiWriter(os.Stderr, &stderrBuf) - err := bash_cmd.Run() - if err != nil { - fmt.Println("Error starting cmd: ", err) - return fmt.Sprint(err) - } - - outStr, errStr := string(stdoutBuf.String()), string(stderrBuf.String()) - return fmt.Sprint(outStr, errStr) -}