From be8f55e6bc6ded3c9997c0bf54524b86bb5fc3a5 Mon Sep 17 00:00:00 2001 From: Piyush Kaushik Date: Wed, 30 Mar 2022 07:34:01 +0000 Subject: [PATCH 1/4] DXE-705 updating and installing packages does not work with linux yes command --- pkg/terminal/terminal.go | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/pkg/terminal/terminal.go b/pkg/terminal/terminal.go index bbae6c7..13a3567 100644 --- a/pkg/terminal/terminal.go +++ b/pkg/terminal/terminal.go @@ -15,11 +15,13 @@ package terminal import ( + "bufio" "context" "errors" "fmt" "io" "os" + "regexp" "strings" "time" @@ -87,7 +89,13 @@ type ( contextType string ) -var terminalContext contextType = "terminal" +var ( + terminalContext contextType = "terminal" + + // the regex for reading from pipe + yesRx = regexp.MustCompile("^(?i:y(?:es)?)$") + noRx = regexp.MustCompile("^(?i:n(?:o)?)$") +) // Color returns a colorable terminal func Color() *DefaultTerminal { @@ -180,7 +188,33 @@ func (t *DefaultTerminal) Confirm(p string, def bool) (bool, error) { Default: def, } - err := survey.AskOne(q, &rval, survey.WithStdio(t.in, t.out, t.err)) + // there is a known issue https://github.com/AlecAivazis/survey/issues/394 with survey.AskOne(...) not able to handle + // piped input data. eg: `yes n | akamai update` + // workaround: check if input data is from pipe or from terminal before calling survey.AskOne(...) + fi, err := os.Stdin.Stat() + if err != nil { + return def, err + } + if (fi.Mode() & os.ModeCharDevice) == 0 { + // data is from pipe + reader := bufio.NewReader(os.Stdin) + fmt.Println(q.Message) + val, _, err := reader.ReadLine() + if err != nil { + return def, err + } + switch { + case yesRx.Match(val): + rval = true + case noRx.Match(val): + rval = false + case string(val) == "": + rval = def + } + } else { + // data is from terminal + err = survey.AskOne(q, &rval, survey.WithStdio(t.in, t.out, t.err)) + } return rval, err } From f59e0698236806d1622bc7c4c2ca09a3781b2d0a Mon Sep 17 00:00:00 2001 From: Roberto Lopez Lopez Date: Tue, 5 Apr 2022 13:00:41 +0000 Subject: [PATCH 2/4] DXE-885 adjust pip pattern to match recent python versions --- CHANGELOG.md | 6 ++++ pkg/packages/python.go | 4 +-- pkg/packages/python_test.go | 55 +++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86c9a03..976a544 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 1.4.2 (April XX, 2022) + +## Fixes + +* Handle recent Python versions ([GH#148](https://github.com/akamai/cli/issues/148)). + # 1.4.1 (March 24, 2022) ## Fixes diff --git a/pkg/packages/python.go b/pkg/packages/python.go index d098f24..efc7a06 100644 --- a/pkg/packages/python.go +++ b/pkg/packages/python.go @@ -32,9 +32,9 @@ import ( ) var ( - pythonVersionPattern = `Python (\d+\.\d+\.\d+).*` + pythonVersionPattern = `Python ([2,3]\.\d+\.\d+).*` pythonVersionRegex = regexp.MustCompile(pythonVersionPattern) - pipVersionPattern = `^pip \d{1,2}\..+ \(python \d\.\d\)` + pipVersionPattern = `^pip \d{1,2}\..+ \(python [2,3]\.\d+\)` venvHelpPattern = `usage: venv ` pipVersionRegex = regexp.MustCompile(pipVersionPattern) venvHelpRegex = regexp.MustCompile(venvHelpPattern) diff --git a/pkg/packages/python_test.go b/pkg/packages/python_test.go index 98cfe0d..3a89949 100644 --- a/pkg/packages/python_test.go +++ b/pkg/packages/python_test.go @@ -128,8 +128,10 @@ venv: error: the following arguments are required: ENV_DIR py3WindowsPipVersion := "pip 20.1.3 from c:\\Program Files\\WindowsApps\\" + "PythonSoftwareFoundation.Python.3.9_3.9.1264.0_x64__qbz5n2kfra8p0\\" + "lib\\site-packages\\pip (python 3.4)" + py310WindowsPipVersion := "pip 22.0.4 from c:\\Python\\lib\\site-packages\\pip (python 3.10)" py2Version := "Python 2.7.16" py34Version := "Python 3.4.0" + py310Version := "Python 3.10.0" ver2 := "2.0.0" ver3 := "3.0.0" ver355 := "3.5.5" @@ -273,6 +275,59 @@ venv: error: the following arguments are required: ENV_DIR }, true).Return(nil, nil).Once() }, }, + "with py 3.10 (windows) and pip, python 3 required": { + givenDir: srcDir, + veDir: veDir, + requiredPy: ver3, + goos: "windows", + init: func(m *mocked) { + m.On("LookPath", "python3").Return("", errors.New("")).Once() + m.On("LookPath", "python3.exe").Return(py3BinWindows, nil).Once() + m.On("ExecCommand", &exec.Cmd{ + Path: py3BinWindows, + Args: []string{py3BinWindows, "-m", "pip", "--version"}, + }, true).Return([]byte(py310WindowsPipVersion), nil).Once() + m.On("ExecCommand", &exec.Cmd{ + Path: py3BinWindows, + Args: []string{py3BinWindows, "--version"}, + }, true).Return([]byte(py310Version), nil).Twice() + m.On("ExecCommand", &exec.Cmd{ + Path: py3BinWindows, + Args: []string{py3BinWindows, "-m", "venv", "--version"}, + }, true).Return([]byte(py3VenvHelp), nil).Once() + m.On("ExecCommand", &exec.Cmd{ + Path: py3BinWindows, + Args: []string{py3BinWindows, "-m", "ensurepip", "--upgrade"}, + }, true).Return(nil, nil).Once() + m.On("ExecCommand", &exec.Cmd{ + Path: py3BinWindows, + Args: []string{py3BinWindows, "-m", "pip", "install", "--no-cache", "--upgrade", "pip", "setuptools"}, + }, true).Return(nil, nil).Once() + m.On("ExecCommand", &exec.Cmd{ + Path: py3BinWindows, + Args: []string{py3BinWindows, "-m", "venv", "veDir"}, + Dir: "", + }, true).Return(nil, nil).Once() + m.On("FileExists", veDir).Return(true, nil).Once() + m.On("ExecCommand", &exec.Cmd{ + Path: "veDir/Scripts/activate.bat", + Args: []string{}, + Dir: "", + }, true).Return(nil, nil).Once() + m.On("GetOS").Return("windows").Times(4) + m.On("FileExists", "testDir/requirements.txt").Return(true, nil).Once() + m.On("FileExists", ".").Return(true, nil).Once() + m.On("ExecCommand", &exec.Cmd{ + Path: winVePipPath, + Args: []string{winVePipPath, "install", "--upgrade", "--ignore-installed", "-r", requirementsFile}, + Dir: "", + }, true).Return(nil, nil).Once() + m.On("ExecCommand", &exec.Cmd{ + Path: winDeactivatePath, + Args: []string{winDeactivatePath}, + }, true).Return(nil, nil).Once() + }, + }, "with python 2, 3.9 and pip, python 2 required": { givenDir: srcDir, requiredPy: ver2, From 740c12dd19801c7a63829303bde07458cdee9036 Mon Sep 17 00:00:00 2001 From: Roberto Lopez Lopez Date: Wed, 4 May 2022 15:16:16 +0000 Subject: [PATCH 3/4] DXE-990 release 1.4.2 --- CHANGELOG.md | 4 +++- Makefile | 2 +- README.md | 6 ------ pkg/version/version.go | 2 +- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 976a544..62d101a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ -# 1.4.2 (April XX, 2022) +# 1.4.2 (May 10, 2022) ## Fixes * Handle recent Python versions ([GH#148](https://github.com/akamai/cli/issues/148)). +* Handle `yes` command input ([GH#136](https://github.com/akamai/cli/issues/136)). +* Purge directories on unit test error. # 1.4.1 (March 24, 2022) diff --git a/Makefile b/Makefile index 4942902..b85e174 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,7 @@ coverage: ; $(info $(M) Running tests with coverage...) @ ## Run tests and gener .PHONY: create-junit-report create-junit-report: | $(GOJUNITREPORT) ; $(info $(M) Creating juint xml report) @ ## Generate junit-style coverage report @cat $(CURDIR)/test/tests.output | $(GOJUNITREPORT) > $(CURDIR)/test/tests.xml - @sed -i -e 's/skip=/skipped=/g;s/ failures=/ errors="0" failures=/g' $(CURDIR)/test/tests.xml + @sed -i -e 's/\( -
- Akamai CLI usage -
- - # Akamai CLI [![Go Report Card](https://goreportcard.com/badge/github.com/akamai/cli)](https://goreportcard.com/report/github.com/akamai/cli) [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fakamai%2Fcli.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fakamai%2Fcli?ref=badge_shield) diff --git a/pkg/version/version.go b/pkg/version/version.go index 212f1a2..53207e5 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -4,7 +4,7 @@ import "github.com/Masterminds/semver" const ( // Version Application Version - Version = "1.4.1" + Version = "1.4.2" // Equals p1==p2 in version.Compare(p1, p2) Equals = 0 // Error failure parsing one of the parameters in version.Compare(p1, p2) From 2060c7564beeb602f0dafb898273a2099fd0e5d6 Mon Sep 17 00:00:00 2001 From: Roberto Lopez Lopez Date: Wed, 11 May 2022 07:17:20 +0000 Subject: [PATCH 4/4] DXE-990 update release date --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62d101a..90508c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 1.4.2 (May 10, 2022) +# 1.4.2 (May 11, 2022) ## Fixes