Skip to content

Commit 94deae6

Browse files
committed
Removed deprecated starlark API calls
1 parent 683e2ff commit 94deae6

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

internal/app/app.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/openrundev/openrun/internal/types"
3434
"go.starlark.net/starlark"
3535
"go.starlark.net/starlarkstruct"
36+
"go.starlark.net/syntax"
3637
)
3738

3839
// App is the main object that represents a OpenRun app. It is created when the app is loaded
@@ -827,14 +828,21 @@ func (a *App) loadStarlark(thread *starlark.Thread, module string, cache map[str
827828
if err != nil {
828829
return nil, err
829830
}
830-
globals, err := starlark.ExecFile(thread, module, buf, builtin)
831+
globals, err := starlark.ExecFileOptions(AppFileOptions(), thread, module, buf, builtin)
831832
cacheEntry = &starlarkCacheEntry{globals, err}
832833
// Update the cache.
833834
cache[module] = cacheEntry
834835
}
835836
return cacheEntry.globals, cacheEntry.err
836837
}
837838

839+
func AppFileOptions() *syntax.FileOptions {
840+
return &syntax.FileOptions{
841+
While: true,
842+
Recursion: true,
843+
}
844+
}
845+
838846
// updateAppConfig updates the app defaults from the metadata
839847
// It creates a TOML intermediate string so that the TOML parsing can be used
840848
func (a *App) updateAppConfig() error {

internal/app/apptype/param_loader.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/openrundev/openrun/internal/types"
1515
"go.starlark.net/starlark"
1616
"go.starlark.net/starlarkstruct"
17+
"go.starlark.net/syntax"
1718
)
1819

1920
const (
@@ -191,7 +192,7 @@ func LoadParamInfo(fileName string, data []byte, serverConfig *types.ServerConfi
191192
Print: func(_ *starlark.Thread, msg string) { fmt.Println(msg) },
192193
}
193194

194-
_, err := starlark.ExecFile(thread, fileName, data, builtins)
195+
_, err := starlark.ExecFileOptions(&syntax.FileOptions{}, thread, fileName, data, builtins)
195196
if err != nil {
196197
if evalErr, ok := err.(*starlark.EvalError); ok {
197198
fmt.Printf("Error loading app params: %s\n", evalErr.Backtrace()) // TODO: log

internal/app/apptype/schema_loader.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/openrundev/openrun/internal/app/starlark_type"
1111
"go.starlark.net/starlark"
1212
"go.starlark.net/starlarkstruct"
13+
"go.starlark.net/syntax"
1314
)
1415

1516
const (
@@ -114,7 +115,7 @@ func LoadStoreInfo(fileName string, data []byte) (*starlark_type.StoreInfo, erro
114115
Print: func(_ *starlark.Thread, msg string) { fmt.Println(msg) },
115116
}
116117

117-
_, err := starlark.ExecFile(thread, fileName, data, builtins)
118+
_, err := starlark.ExecFileOptions(&syntax.FileOptions{}, thread, fileName, data, builtins)
118119
if err != nil {
119120
if evalErr, ok := err.(*starlark.EvalError); ok {
120121
fmt.Printf("Error loading app schema: %s\n", evalErr.Backtrace()) // TODO: log

internal/app/audit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (a *App) Audit() (*types.ApproveResult, error) {
8181
return nil, err
8282
}
8383

84-
_, prog, err := starlark.SourceProgram(a.getStarPath(apptype.APP_FILE_NAME), buf, builtin.Has)
84+
_, prog, err := starlark.SourceProgramOptions(AppFileOptions(), a.getStarPath(apptype.APP_FILE_NAME), buf, builtin.Has)
8585
if err != nil {
8686
return nil, fmt.Errorf("parsing source failed %v", err)
8787
}

internal/app/setup.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,10 @@ import (
2727
"github.com/openrundev/openrun/internal/app/dev"
2828
"github.com/openrundev/openrun/internal/app/starlark_type"
2929
"github.com/openrundev/openrun/internal/types"
30-
"go.starlark.net/resolve"
3130
"go.starlark.net/starlark"
3231
"go.starlark.net/starlarkstruct"
3332
)
3433

35-
func init() {
36-
resolve.AllowRecursion = true
37-
}
38-
3934
func (a *App) loadStarlarkConfig(dryRun types.DryRun) error {
4035
a.Info().Str("path", a.Path).Str("domain", a.Domain).Msg("Loading app")
4136

@@ -56,7 +51,7 @@ func (a *App) loadStarlarkConfig(dryRun types.DryRun) error {
5651
return err
5752
}
5853

59-
a.globals, err = starlark.ExecFile(thread, a.getStarPath(apptype.APP_FILE_NAME), buf, builtin)
54+
a.globals, err = starlark.ExecFileOptions(AppFileOptions(), thread, a.getStarPath(apptype.APP_FILE_NAME), buf, builtin)
6055
if err != nil {
6156
if evalErr, ok := err.(*starlark.EvalError); ok {
6257
a.Error().Err(err).Str("trace", evalErr.Backtrace()).Msg("Error loading app")

0 commit comments

Comments
 (0)