mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 08:59:44 +08:00
Merge pull request #1346 from xucong053/bugfix
fix: ensure all dependencies in debugtalk.go are installed
This commit is contained in:
2
go.mod
2
go.mod
@@ -10,7 +10,7 @@ require (
|
||||
github.com/go-openapi/spec v0.20.6
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/gorilla/websocket v1.4.1
|
||||
github.com/httprunner/funplugin v0.4.8
|
||||
github.com/httprunner/funplugin v0.4.9
|
||||
github.com/jinzhu/copier v0.3.2
|
||||
github.com/jmespath/go-jmespath v0.4.0
|
||||
github.com/json-iterator/go v1.1.12
|
||||
|
||||
2
go.sum
2
go.sum
@@ -255,6 +255,8 @@ github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS
|
||||
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
|
||||
github.com/httprunner/funplugin v0.4.8 h1:G785jrEn6EAEg2nwuPcCQUHBTgwgoaSz5qdQU4X3JpI=
|
||||
github.com/httprunner/funplugin v0.4.8/go.mod h1:vPyeJIfbpGe0epZZtAV0wCn16gLY9+imSw/zfxq0Lcc=
|
||||
github.com/httprunner/funplugin v0.4.9 h1:gmF1sP5D4/nvdocqgOAyT3GpVDz3fL4ErZ17WHo8x9U=
|
||||
github.com/httprunner/funplugin v0.4.9/go.mod h1:vPyeJIfbpGe0epZZtAV0wCn16gLY9+imSw/zfxq0Lcc=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA=
|
||||
|
||||
21
hrp/build.go
21
hrp/build.go
@@ -44,6 +44,7 @@ type TemplateContent struct {
|
||||
FromImports []string // python from...import...
|
||||
Functions []string // python/go function
|
||||
FunctionNames []string // function name set by user
|
||||
Packages []string // python packages
|
||||
}
|
||||
|
||||
type Regexps struct {
|
||||
@@ -127,8 +128,15 @@ func (t *TemplateContent) parsePyContent(path string) error {
|
||||
|
||||
if strings.HasPrefix(line, "import") {
|
||||
t.Imports = append(t.Imports, strings.Trim(line, " "))
|
||||
// e.g. import module as md
|
||||
// import package.module
|
||||
t.Packages = append(t.Packages, strings.Split(strings.Split(line, " ")[1], ".")[0])
|
||||
} else if strings.HasPrefix(line, "from") {
|
||||
t.FromImports = append(t.FromImports, strings.Trim(line, " "))
|
||||
// e.g. from package.module import function
|
||||
// from module import function
|
||||
// from package import module
|
||||
t.Packages = append(t.Packages, strings.Split(strings.Split(line, " ")[1], ".")[0])
|
||||
} else {
|
||||
// no parse content at under of `if __name__ == "__main__"`
|
||||
if strings.HasPrefix(line, "if __name__") {
|
||||
@@ -257,11 +265,24 @@ func buildPy(path string, output string) error {
|
||||
FunctionName: regexp.MustCompile(regexPythonFunctionName),
|
||||
},
|
||||
}
|
||||
|
||||
err := templateContent.parsePyContent(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// ensure installation of packages
|
||||
_, err = builtin.EnsurePython3Venv(templateContent.Packages...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// check the syntax of debugtalk.py
|
||||
err = builtin.CheckPythonScriptSyntax(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// generate .debugtalk_gen.py
|
||||
if output == "" {
|
||||
dir, _ := os.Getwd()
|
||||
|
||||
@@ -103,6 +103,11 @@ func EnsurePython3Venv(packages ...string) (string, error) {
|
||||
return python3, nil
|
||||
}
|
||||
|
||||
func CheckPythonScriptSyntax(path string) error {
|
||||
err := ExecCommand("python3", "-m", "py_compile", path)
|
||||
return err
|
||||
}
|
||||
|
||||
func ExecCommandInDir(cmd *exec.Cmd, dir string) error {
|
||||
log.Info().Str("cmd", cmd.String()).Str("dir", dir).Msg("exec command")
|
||||
cmd.Dir = dir
|
||||
|
||||
@@ -163,7 +163,7 @@ func (iter *ParametersIterator) Next() map[string]interface{} {
|
||||
|
||||
// merge with random parameters
|
||||
for _, paramName := range iter.randomParameterNames {
|
||||
randSource := rand.New(rand.NewSource(time.Now().Unix()))
|
||||
randSource := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
randIndex := randSource.Intn(len(iter.data[paramName]))
|
||||
for k, v := range iter.data[paramName][randIndex] {
|
||||
selectedParameters[k] = v
|
||||
|
||||
Reference in New Issue
Block a user