Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/terminal: remove deprecated starlark global options #3722

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/terminal/starbind/conv_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package starbind

import (
"go.starlark.net/starlark"
"testing"

"go.starlark.net/starlark"
)

func TestConv(t *testing.T) {
script := `
# 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'")
Expand Down
4 changes: 2 additions & 2 deletions pkg/terminal/starbind/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
47 changes: 36 additions & 11 deletions pkg/terminal/starbind/starlark.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}