mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-10 23:12:41 +08:00
fix: ensure all dependencies in debugtalk.go are installed
This commit is contained in:
21
hrp/build.go
21
hrp/build.go
@@ -44,6 +44,7 @@ type TemplateContent struct {
|
|||||||
FromImports []string // python from...import...
|
FromImports []string // python from...import...
|
||||||
Functions []string // python/go function
|
Functions []string // python/go function
|
||||||
FunctionNames []string // function name set by user
|
FunctionNames []string // function name set by user
|
||||||
|
Packages []string // python packages
|
||||||
}
|
}
|
||||||
|
|
||||||
type Regexps struct {
|
type Regexps struct {
|
||||||
@@ -127,8 +128,15 @@ func (t *TemplateContent) parsePyContent(path string) error {
|
|||||||
|
|
||||||
if strings.HasPrefix(line, "import") {
|
if strings.HasPrefix(line, "import") {
|
||||||
t.Imports = append(t.Imports, strings.Trim(line, " "))
|
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") {
|
} else if strings.HasPrefix(line, "from") {
|
||||||
t.FromImports = append(t.FromImports, strings.Trim(line, " "))
|
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 {
|
} else {
|
||||||
// no parse content at under of `if __name__ == "__main__"`
|
// no parse content at under of `if __name__ == "__main__"`
|
||||||
if strings.HasPrefix(line, "if __name__") {
|
if strings.HasPrefix(line, "if __name__") {
|
||||||
@@ -257,11 +265,24 @@ func buildPy(path string, output string) error {
|
|||||||
FunctionName: regexp.MustCompile(regexPythonFunctionName),
|
FunctionName: regexp.MustCompile(regexPythonFunctionName),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
err := templateContent.parsePyContent(path)
|
err := templateContent.parsePyContent(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
// generate .debugtalk_gen.py
|
||||||
if output == "" {
|
if output == "" {
|
||||||
dir, _ := os.Getwd()
|
dir, _ := os.Getwd()
|
||||||
|
|||||||
@@ -103,6 +103,11 @@ func EnsurePython3Venv(packages ...string) (string, error) {
|
|||||||
return python3, nil
|
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 {
|
func ExecCommandInDir(cmd *exec.Cmd, dir string) error {
|
||||||
log.Info().Str("cmd", cmd.String()).Str("dir", dir).Msg("exec command")
|
log.Info().Str("cmd", cmd.String()).Str("dir", dir).Msg("exec command")
|
||||||
cmd.Dir = dir
|
cmd.Dir = dir
|
||||||
|
|||||||
Reference in New Issue
Block a user