pkg/terminal: remove deprecated starlark global options (#3722)

This commit is contained in:
Oleksandr Redko 2024-05-20 18:35:30 +03:00 committed by GitHub
parent 7c7265f4e6
commit 468727c34d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 15 deletions

@ -1,8 +1,9 @@
package starbind
import (
"go.starlark.net/starlark"
"testing"
"go.starlark.net/starlark"
)
func TestConv(t *testing.T) {
@ -10,7 +11,7 @@ func TestConv(t *testing.T) {
# A list global that we'll unmarshal into a slice.
x = [1,2]
`
globals, err := starlark.ExecFile(&starlark.Thread{}, "test.star", script, nil)
globals, err := execFileOptions(nil, &starlark.Thread{}, "test.star", script, nil)
starlarkVal, ok := globals["x"]
if !ok {
t.Fatal("missing global 'x'")

@ -116,7 +116,7 @@ func rep(rl *liner.State, thread *starlark.Thread, globals starlark.StringDict,
if expr := soleExpr(f); expr != nil {
//TODO: check for 'exit'
// eval
v, err := starlark.EvalExpr(thread, expr, globals)
v, err := evalExprOptions(nil, thread, expr, globals)
if err != nil {
printError(err)
return nil
@ -194,7 +194,7 @@ func MakeLoad() func(thread *starlark.Thread, module string) (starlark.StringDic
// Load it.
thread := &starlark.Thread{Name: "exec " + module, Load: thread.Load}
globals, err := starlark.ExecFile(thread, module, nil, nil)
globals, err := execFileOptions(nil, thread, module, nil, nil)
e = &entry{globals, err}
// Update the cache.

@ -11,8 +11,8 @@ import (
"sync"
startime "go.starlark.net/lib/time"
"go.starlark.net/resolve"
"go.starlark.net/starlark"
"go.starlark.net/syntax"
"github.com/go-delve/delve/service"
"github.com/go-delve/delve/service/api"
@ -32,14 +32,12 @@ const (
helpBuiltinName = "help"
)
func init() {
resolve.AllowNestedDef = true
resolve.AllowLambda = true
resolve.AllowFloat = true
resolve.AllowSet = true
resolve.AllowBitwise = true
resolve.AllowRecursion = true
resolve.AllowGlobalReassign = true
var defaultSyntaxFileOpts = &syntax.FileOptions{
Set: true,
While: true,
TopLevelControl: true,
GlobalReassign: true,
Recursion: true,
}
// Context is the context in which starlark scripts are evaluated.
@ -220,7 +218,7 @@ func (env *Env) Execute(path string, source interface{}, mainFnName string, args
}()
thread := env.newThread()
globals, err := starlark.ExecFile(thread, path, source, env.env)
globals, err := execFileOptions(nil, thread, path, source, env.env)
if err != nil {
return starlark.None, err
}
@ -305,7 +303,7 @@ func (env *Env) createCommand(name string, val starlark.Value) error {
env.ctx.RegisterCommand(name, helpMsg, func(args string) error {
thread := env.newThread()
argval, err := starlark.Eval(thread, "<input>", "("+args+")", env.env)
argval, err := evalOptions(nil, thread, "<input>", "("+args+")", env.env)
if err != nil {
return err
}
@ -369,3 +367,30 @@ type EchoWriter interface {
Echo(string)
Flush()
}
// execFileOptions is a wrapper around starlark.ExecFileOptions.
// If no options are provided, it uses default options.
func execFileOptions(opts *syntax.FileOptions, thread *starlark.Thread, path string, source any, env starlark.StringDict) (starlark.StringDict, error) {
if opts == nil {
opts = defaultSyntaxFileOpts
}
return starlark.ExecFileOptions(opts, thread, path, source, env)
}
// evalOptions is a wrapper around starlark.EvalOptions.
// If no options are provided, it uses default options.
func evalOptions(opts *syntax.FileOptions, thread *starlark.Thread, path string, source any, env starlark.StringDict) (starlark.Value, error) {
if opts == nil {
opts = defaultSyntaxFileOpts
}
return starlark.EvalOptions(opts, thread, path, source, env)
}
// evalExprOptions is a wrapper around starlark.EvalExprOptions.
// If no options are provided, it uses default options.
func evalExprOptions(opts *syntax.FileOptions, thread *starlark.Thread, expr syntax.Expr, globals starlark.StringDict) (starlark.Value, error) {
if opts == nil {
opts = defaultSyntaxFileOpts
}
return starlark.EvalExprOptions(opts, thread, expr, globals)
}