Skip to content
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

Release/v1.4.2 #153

Merged
merged 4 commits into from
May 11, 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: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 1.4.2 (May 11, 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)

## Fixes
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/\(<testsuites .*\) skipped="[0-9]*"\(.*\)/\1 \2/g' $(CURDIR)/test/tests.xml

.PHONY: create-coverage-files
create-coverage-files: | $(GOCOV) $(GOCOVXML); $(info $(M) Creating coverage files...) @ ## Generate coverage report files
Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<h1 style="text-align: center">
<br>
<img alt="Akamai CLI usage" src="assets/screen-1.png">
<br>
</h1>

# 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)

Expand Down
4 changes: 2 additions & 2 deletions pkg/packages/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
55 changes: 55 additions & 0 deletions pkg/packages/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
38 changes: 36 additions & 2 deletions pkg/terminal/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
package terminal

import (
"bufio"
"context"
"errors"
"fmt"
"io"
"os"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down