From a1b5e554da2d18ddf47a9096d0caefa5b892ee09 Mon Sep 17 00:00:00 2001 From: xucong053 Date: Tue, 31 May 2022 20:11:27 +0800 Subject: [PATCH] fix: failed to regenerate .debugtalk_gen.py correctly --- hrp/build.go | 16 +++------------- hrp/plugin.go | 21 +++++++++++++-------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/hrp/build.go b/hrp/build.go index beeafd90..4c5cb940 100644 --- a/hrp/build.go +++ b/hrp/build.go @@ -155,7 +155,7 @@ func (t *TemplateContent) parsePyContent(path string) error { } func (t *TemplateContent) genDebugTalk(path string, templ string) error { - file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0o666) + file, err := os.Create(path) if err != nil { log.Error().Err(err).Msg("open file failed") return err @@ -262,7 +262,7 @@ func buildPy(path string, output string) error { return err } - // generate debugtalk.py + // generate .debugtalk_gen.py if output == "" { dir, _ := os.Getwd() output = filepath.Join(dir, PluginPySourceGenFile) @@ -270,17 +270,7 @@ func buildPy(path string, output string) error { output = filepath.Join(output, PluginPySourceGenFile) } err = templateContent.genDebugTalk(output, pyTemplate) - if err != nil { - return err - } - - // ensure funppy in .env - _, err = builtin.EnsurePython3Venv("funppy") - if err != nil { - return err - } - - return nil + return err } func BuildPlugin(path string, output string) (err error) { diff --git a/hrp/plugin.go b/hrp/plugin.go index facb09ef..5053b2e5 100644 --- a/hrp/plugin.go +++ b/hrp/plugin.go @@ -5,6 +5,7 @@ import ( "os" "os/signal" "path/filepath" + "strings" "syscall" "github.com/httprunner/funplugin" @@ -34,6 +35,17 @@ func initPlugin(path string, logOn bool) (plugin funplugin.IPlugin, err error) { return nil, nil } + if strings.HasSuffix(pluginPath, ".py") { + // register funppy plugin + genPyPluginPath := filepath.Join(filepath.Dir(pluginPath), PluginPySourceGenFile) + err = BuildPlugin(pluginPath, genPyPluginPath) + if err != nil { + log.Error().Err(err).Str("path", pluginPath).Msg("build plugin failed") + return nil, nil + } + pluginPath = genPyPluginPath + } + // found plugin file plugin, err = funplugin.Init(pluginPath, funplugin.WithLogOn(logOn)) if err != nil { @@ -73,14 +85,7 @@ func locatePlugin(path string) (pluginPath string, err error) { pluginPath, err = locateFile(path, PluginPySourceFile) if err == nil { - // register funppy plugin - genPyPluginPath := filepath.Join(filepath.Dir(pluginPath), PluginPySourceGenFile) - err = BuildPlugin(pluginPath, genPyPluginPath) - if err != nil { - log.Error().Err(err).Str("path", pluginPath).Msg("build plugin failed") - return - } - return genPyPluginPath, nil + return } pluginPath, err = locateFile(path, PluginGoBuiltFile)