feat #1342: support specify custom python3 venv

This commit is contained in:
debugtalk
2022-06-13 21:31:05 +08:00
parent abd31a8d88
commit fac6dc4955
35 changed files with 381 additions and 123 deletions
+4 -4
View File
@@ -6,25 +6,25 @@ import (
func TestGenDemoExamples(t *testing.T) {
dir := "../../../examples/demo-with-go-plugin"
err := CreateScaffold(dir, Go, true)
err := CreateScaffold(dir, Go, "", true)
if err != nil {
t.Fatal()
}
dir = "../../../examples/demo-with-py-plugin"
err = CreateScaffold(dir, Py, true)
err = CreateScaffold(dir, Py, "", true)
if err != nil {
t.Fatal()
}
dir = "../../../examples/demo-without-plugin"
err = CreateScaffold(dir, Ignore, true)
err = CreateScaffold(dir, Ignore, "", true)
if err != nil {
t.Fatal()
}
dir = "../../../examples/demo-empty-project"
err = CreateScaffold(dir, Empty, true)
err = CreateScaffold(dir, Empty, "", true)
if err != nil {
t.Fatal()
}
+12 -4
View File
@@ -8,6 +8,7 @@ import (
"path/filepath"
"time"
"github.com/httprunner/funplugin/fungo"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
@@ -51,7 +52,7 @@ func CopyFile(templateFile, targetFile string) error {
return nil
}
func CreateScaffold(projectName string, pluginType PluginType, force bool) error {
func CreateScaffold(projectName string, pluginType PluginType, venv string, force bool) error {
// report event
sdk.SendEvent(sdk.EventTracking{
Category: "Scaffold",
@@ -165,7 +166,7 @@ func CreateScaffold(projectName string, pluginType PluginType, force bool) error
// create debugtalk function plugin
switch pluginType {
case Py:
return createPythonPlugin(projectName)
return createPythonPlugin(projectName, venv)
case Go:
return createGoPlugin(projectName)
}
@@ -194,7 +195,7 @@ func createGoPlugin(projectName string) error {
return nil
}
func createPythonPlugin(projectName string) error {
func createPythonPlugin(projectName, venv string) error {
log.Info().Msg("start to create hashicorp python plugin")
// create debugtalk.py
@@ -204,7 +205,14 @@ func createPythonPlugin(projectName string) error {
return errors.Wrap(err, "copy file failed")
}
_, err = builtin.EnsurePython3Venv("funppy")
if venv == "" {
venv = filepath.Join(projectName, ".venv")
}
packages := []string{
fmt.Sprintf("funppy==%s", fungo.Version),
fmt.Sprintf("httprunner==%s", version.VERSION),
}
_, err = builtin.EnsurePython3Venv(venv, packages...)
if err != nil {
return err
}
@@ -2,12 +2,12 @@
package main
import (
"github.com/httprunner/funplugin/fungo"
"github.com/httprunner/funplugin/fungo"
)
func main() {
{{- range $functionName := .FunctionNames }}
fungo.Register("{{ $functionName }}", {{ $functionName }})
fungo.Register("{{ $functionName }}", {{ $functionName }})
{{- end }}
fungo.Serve()
}
@@ -12,6 +12,7 @@
{{ end }}
if __name__ == "__main__":
import funppy
{{- range $functionName := .FunctionNames }}
funppy.register("{{ $functionName }}", {{ $functionName }})
{{- end }}
@@ -1,4 +1,4 @@
// NOTE: Generated By hrp v4.1.2, DO NOT EDIT!
// NOTE: Generated By hrp v4.1.3, DO NOT EDIT!
package main
import (