Skip to content

Commit

Permalink
Showing 16 changed files with 959 additions and 5,038 deletions.
11 changes: 1 addition & 10 deletions cmds/kcl-go/command/cmd_run.go
Original file line number Diff line number Diff line change
@@ -6,11 +6,10 @@ import (
"fmt"
"os"
"strings"
"time"

"github.com/urfave/cli/v2"

"kcl-lang.io/kcl-go"
kclvm "kcl-lang.io/kcl-go"
"kcl-lang.io/kcl-go/pkg/kcl"
)

@@ -99,7 +98,6 @@ func NewRunCmd() *cli.Command {
fmt.Println("======== args end ========")
}

start := time.Now()
result, err := kcl.RunFiles(
c.Args().Slice(),
kcl.WithOptions(c.StringSlice("argument")...),
@@ -108,13 +106,6 @@ func NewRunCmd() *cli.Command {
kcl.WithSortKeys(c.Bool("sort-keys")),
)

if c.Bool("debug") {
fmt.Println("======== EscapedTime begin ========")
fmt.Println("Python:", result.GetPyEscapedTime())
fmt.Println("Golang:", time.Since(start).Seconds())
fmt.Println("======== EscapedTime end ========")
}

if err != nil {
fmt.Print(err)
os.Exit(1)
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -20,8 +20,8 @@ require (
google.golang.org/grpc v1.56.3
google.golang.org/protobuf v1.30.0
gopkg.in/yaml.v3 v3.0.1
kcl-lang.io/kcl-artifact-go v0.7.0-alpha.2
kcl-lang.io/kpm v0.3.8-0.20231101092819-703dd7cf0a25
kcl-lang.io/kcl-artifact-go v0.7.0-beta.1
kcl-lang.io/kpm v0.4.1
)

require (
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -750,10 +750,10 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
kcl-lang.io/kcl-artifact-go v0.7.0-alpha.2 h1:ct6HPq+ssN4kNwMnyqyJAJ35YGiWPMgV4vWyyqzqpYo=
kcl-lang.io/kcl-artifact-go v0.7.0-alpha.2/go.mod h1:c07mqi9Hu2UjPW7lYfHhAAWOlZiB7lo7Vkr4jL5ov/M=
kcl-lang.io/kpm v0.3.8-0.20231101092819-703dd7cf0a25 h1:JyHQebmfJImAbpi5VvcgQ8ut76q2D8MwhAjLsKPNsag=
kcl-lang.io/kpm v0.3.8-0.20231101092819-703dd7cf0a25/go.mod h1:yT6B1imC2utPsnNtMmA18WyLVFKsymCH57orvQIAxAk=
kcl-lang.io/kcl-artifact-go v0.7.0-beta.1 h1:u1l/OXWblOiDHabN+6ApSHTZwNyOskuOCf90fXreGu4=
kcl-lang.io/kcl-artifact-go v0.7.0-beta.1/go.mod h1:c07mqi9Hu2UjPW7lYfHhAAWOlZiB7lo7Vkr4jL5ov/M=
kcl-lang.io/kpm v0.4.1 h1:72kNdmMF6UNMGwa0JOsTVWwFSHyb5TAVaj3PYMmkw4Y=
kcl-lang.io/kpm v0.4.1/go.mod h1:GM6IrXwcTZHU+JLg6b0/JXoAcfwIzJkjIbGqV15jrtI=
oras.land/oras-go v1.2.3 h1:v8PJl+gEAntI1pJ/LCrDgsuk+1PKVavVEPsYIHFE5uY=
oras.land/oras-go v1.2.3/go.mod h1:M/uaPdYklze0Vf3AakfarnpoEckvw0ESbRdN8Z1vdJg=
oras.land/oras-go/v2 v2.3.0 h1:lqX1aXdN+DAmDTKjiDyvq85cIaI4RkIKp/PghWlAGIU=
15 changes: 9 additions & 6 deletions pkg/kcl/api.go
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ package kcl

import (
"encoding/json"
"errors"
"fmt"
"strings"

@@ -22,7 +23,6 @@ type KCLResultList struct {
list []KCLResult
raw_json_result string
raw_yaml_result string
escaped_time string
}

func (p *KCLResultList) Len() int {
@@ -65,10 +65,6 @@ func (p *KCLResultList) GetRawYamlResult() string {
return p.raw_yaml_result
}

func (p *KCLResultList) GetPyEscapedTime() string {
return p.escaped_time
}

type KCLResult map[string]interface{}

func (m KCLResult) Get(key string, target ...interface{}) interface{} {
@@ -228,6 +224,14 @@ func run(pathList []string, opts ...Option) (*KCLResultList, error) {
if err != nil {
return nil, err
}
// Output log message
logger := args.GetLogger()
if logger != nil && resp.LogMessage != "" {
logger.Info(resp.LogMessage)
}
if resp.ErrMessage != "" {
return nil, errors.New(resp.ErrMessage)
}

var result KCLResultList
if strings.TrimSpace(resp.JsonResult) == "" {
@@ -250,6 +254,5 @@ func run(pathList []string, opts ...Option) (*KCLResultList, error) {

result.raw_json_result = resp.JsonResult
result.raw_yaml_result = resp.YamlResult
result.escaped_time = resp.EscapedTime
return &result, nil
}
2 changes: 0 additions & 2 deletions pkg/kcl/api_test.go
Original file line number Diff line number Diff line change
@@ -43,8 +43,6 @@ f = 1.5
tAssert(t, result.Len() > 0)
tAssert(t, result.First().Get("name") == "kcl")

_ = result.GetPyEscapedTime()

var s string
var i int
var f float64
14 changes: 13 additions & 1 deletion pkg/kcl/opt.go
Original file line number Diff line number Diff line change
@@ -9,14 +9,16 @@ import (
"path/filepath"
"strings"

"kcl-lang.io/kcl-go/pkg/logger"
"kcl-lang.io/kcl-go/pkg/settings"
"kcl-lang.io/kcl-go/pkg/spec/gpyrpc"
"kcl-lang.io/kcl-go/pkg/tools/override"
)

type Option struct {
*gpyrpc.ExecProgram_Args
Err error
logger logger.Logger
Err error
}

// NewOption returns a new Option.
@@ -34,6 +36,10 @@ func (p *Option) JSONString() string {
return string(x)
}

func (p *Option) GetLogger() logger.Logger {
return p.logger
}

func ParseArgs(pathList []string, opts ...Option) (Option, error) {
var tmpOptList []Option
for _, s := range pathList {
@@ -73,6 +79,12 @@ func ParseArgs(pathList []string, opts ...Option) (Option, error) {
return *args, nil
}

func WithLogger(l logger.Logger) Option {
var opt = NewOption()
opt.logger = l
return *opt
}

func WithWorkDir(s string) Option {
var opt = NewOption()
opt.WorkDir = s
16 changes: 16 additions & 0 deletions pkg/service/client_kclvm_service.go
Original file line number Diff line number Diff line change
@@ -101,6 +101,14 @@ func (p *KclvmServiceClient) GetSchemaTypeMapping(args *gpyrpc.GetSchemaTypeMapp
return
}

func (p *KclvmServiceClient) GetFullSchemaType(args *gpyrpc.GetFullSchemaType_Args) (resp *gpyrpc.GetSchemaType_Result, err error) {
p.Runtime.DoTask(func(c *rpc.Client, stderr io.Reader) {
resp, err = p.getClient(c).GetFullSchemaType(args)
err = p.wrapErr(err, stderr)
})
return
}

func (p *KclvmServiceClient) ValidateCode(args *gpyrpc.ValidateCode_Args) (resp *gpyrpc.ValidateCode_Result, err error) {
p.Runtime.DoTask(func(c *rpc.Client, stderr io.Reader) {
resp, err = p.getClient(c).ValidateCode(args)
@@ -140,3 +148,11 @@ func (p *KclvmServiceClient) RenameCode(args *gpyrpc.RenameCode_Args) (resp *gpy
})
return
}

func (p *KclvmServiceClient) Test(args *gpyrpc.Test_Args) (resp *gpyrpc.Test_Result, err error) {
p.Runtime.DoTask(func(c *rpc.Client, stderr io.Reader) {
resp, err = p.getClient(c).Test(args)
err = p.wrapErr(err, stderr)
})
return
}
6 changes: 6 additions & 0 deletions pkg/service/grpc_server.go
Original file line number Diff line number Diff line change
@@ -61,6 +61,9 @@ func (p *_KclvmServiceImpl) GetSchemaType(ctx context.Context, args *gpyrpc.GetS
func (p *_KclvmServiceImpl) GetSchemaTypeMapping(ctx context.Context, args *gpyrpc.GetSchemaTypeMapping_Args) (*gpyrpc.GetSchemaTypeMapping_Result, error) {
return p.c.GetSchemaTypeMapping(args)
}
func (p *_KclvmServiceImpl) GetFullSchemaType(ctx context.Context, args *gpyrpc.GetFullSchemaType_Args) (*gpyrpc.GetSchemaType_Result, error) {
return p.c.GetFullSchemaType(args)
}
func (p *_KclvmServiceImpl) ValidateCode(ctx context.Context, args *gpyrpc.ValidateCode_Args) (*gpyrpc.ValidateCode_Result, error) {
return p.c.ValidateCode(args)
}
@@ -76,3 +79,6 @@ func (p *_KclvmServiceImpl) Rename(ctx context.Context, args *gpyrpc.Rename_Args
func (p *_KclvmServiceImpl) RenameCode(ctx context.Context, args *gpyrpc.RenameCode_Args) (*gpyrpc.RenameCode_Result, error) {
return p.c.RenameCode(args)
}
func (p *_KclvmServiceImpl) Test(ctx context.Context, args *gpyrpc.Test_Args) (*gpyrpc.Test_Result, error) {
return p.c.Test(args)
}
2 changes: 2 additions & 0 deletions pkg/service/kclvm_service.go
Original file line number Diff line number Diff line change
@@ -11,9 +11,11 @@ type KclvmService interface {
OverrideFile(in *gpyrpc.OverrideFile_Args) (out *gpyrpc.OverrideFile_Result, err error)
GetSchemaType(in *gpyrpc.GetSchemaType_Args) (out *gpyrpc.GetSchemaType_Result, err error)
GetSchemaTypeMapping(in *gpyrpc.GetSchemaTypeMapping_Args) (out *gpyrpc.GetSchemaTypeMapping_Result, err error)
GetFullSchemaType(in *gpyrpc.GetFullSchemaType_Args) (out *gpyrpc.GetSchemaType_Result, err error)
ValidateCode(in *gpyrpc.ValidateCode_Args) (out *gpyrpc.ValidateCode_Result, err error)
ListDepFiles(in *gpyrpc.ListDepFiles_Args) (out *gpyrpc.ListDepFiles_Result, err error)
LoadSettingsFiles(in *gpyrpc.LoadSettingsFiles_Args) (out *gpyrpc.LoadSettingsFiles_Result, err error)
Rename(in *gpyrpc.Rename_Args) (out *gpyrpc.Rename_Result, err error)
RenameCode(in *gpyrpc.RenameCode_Args) (out *gpyrpc.RenameCode_Result, err error)
Test(in *gpyrpc.Test_Args) (out *gpyrpc.Test_Result, err error)
}
18 changes: 18 additions & 0 deletions pkg/service/rest_server.go
Original file line number Diff line number Diff line change
@@ -77,7 +77,11 @@ func (p *restServer) initHttpRrouter() {
p.router.POST("/api:protorpc/KclvmService.OverrideFile", p.handle_OverrideFile)
p.router.POST("/api:protorpc/KclvmService.GetSchemaType", p.handle_GetSchemaType)
p.router.POST("/api:protorpc/KclvmService.GetSchemaTypeMapping", p.handle_GetSchemaTypeMapping)
p.router.POST("/api:protorpc/KclvmService.GetFullSchemaType", p.handle_GetFullSchemaType)
p.router.POST("/api:protorpc/KclvmService.ValidateCode", p.handle_ValidateCode)
p.router.POST("/api:protorpc/KclvmService.Rename", p.handle_Rename)
p.router.POST("/api:protorpc/KclvmService.RenameCode", p.handle_RenameCode)
p.router.POST("/api:protorpc/KclvmService.Test", p.handle_Test)
}

func (p *restServer) handle(
@@ -178,6 +182,13 @@ func (p *restServer) handle_GetSchemaTypeMapping(w http.ResponseWriter, r *http.
})
}

func (p *restServer) handle_GetFullSchemaType(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
args := new(gpyrpc.GetFullSchemaType_Args)
p.handle(w, r, args, func() (proto.Message, error) {
return p.c.GetFullSchemaType(args)
})
}

func (p *restServer) handle_ValidateCode(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
args := new(gpyrpc.ValidateCode_Args)
p.handle(w, r, args, func() (proto.Message, error) {
@@ -212,3 +223,10 @@ func (p *restServer) handle_RenameCode(w http.ResponseWriter, r *http.Request, p
return p.c.RenameCode(args)
})
}

func (p *restServer) handle_Test(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
args := new(gpyrpc.Test_Args)
p.handle(w, r, args, func() (proto.Message, error) {
return p.c.Test(args)
})
}
1,117 changes: 769 additions & 348 deletions pkg/spec/gpyrpc/gpyrpc.pb.go

Large diffs are not rendered by default.

80 changes: 80 additions & 0 deletions pkg/spec/gpyrpc/gpyrpc.pb.protorpc.go
39 changes: 35 additions & 4 deletions pkg/spec/gpyrpc/gpyrpc.proto
Original file line number Diff line number Diff line change
@@ -81,6 +81,7 @@ service KclvmService {
rpc OverrideFile(OverrideFile_Args) returns (OverrideFile_Result);

rpc GetSchemaType(GetSchemaType_Args) returns(GetSchemaType_Result);
rpc GetFullSchemaType(GetFullSchemaType_Args) returns(GetSchemaType_Result);
rpc GetSchemaTypeMapping(GetSchemaTypeMapping_Args) returns(GetSchemaTypeMapping_Result);
rpc ValidateCode(ValidateCode_Args) returns(ValidateCode_Result);

@@ -89,6 +90,8 @@ service KclvmService {

rpc Rename(Rename_Args) returns(Rename_Result);
rpc RenameCode(RenameCode_Args) returns(RenameCode_Result);

rpc Test(Test_Args) returns (Test_Result);
}

message Ping_Args {
@@ -168,8 +171,8 @@ message ExecProgram_Args {
message ExecProgram_Result {
string json_result = 1;
string yaml_result = 2;

string escaped_time = 101;
string log_message = 3;
string err_message = 4;
}

message ResetPlugin_Args {
@@ -213,6 +216,11 @@ message OverrideFile_Result {
bool result = 1;
}

message GetFullSchemaType_Args {
ExecProgram_Args exec_args = 1;
string schema_name = 2;
}

message GetSchemaType_Args {
string file = 1;
string code = 2;
@@ -304,7 +312,7 @@ message KeyValuePair {
message Rename_Args {
string symbol_path = 1; // the path to the target symbol to be renamed. The symbol path should conform to format: `<pkgpath>:<field_path>` When the pkgpath is '__main__', `<pkgpath>:` can be omitted.
repeated string file_paths = 2; // the paths to the source code files
string newName = 3; // the new name of the symbol
string new_name = 3; // the new name of the symbol
}

message Rename_Result {
@@ -319,13 +327,36 @@ message Rename_Result {
message RenameCode_Args {
string symbol_path = 1; // the path to the target symbol to be renamed. The symbol path should conform to format: `<pkgpath>:<field_path>` When the pkgpath is '__main__', `<pkgpath>:` can be omitted.
map<string, string> source_codes = 2; // the source code. a <filename>:<code> map
string newName = 3; // the new name of the symbol
string new_name = 3; // the new name of the symbol
}

message RenameCode_Result {
map<string, string> changed_codes = 1; // the changed code. a <filename>:<code> map
}

// ---------------------------------------------------------------------------------
// Test API
// Test KCL packages with test arguments
// ---------------------------------------------------------------------------------

message Test_Args {
ExecProgram_Args exec_args = 1; // This field stores the execution program arguments.
repeated string pkg_list = 2; // The package path list to be tested e.g., "./...", "/path/to/package/", "/path/to/package/..."
string run_regexp = 3; // This field stores a regular expression for filtering tests to run.
bool fail_fast = 4; // This field determines whether the test run should stop on the first failure.
}

message Test_Result {
repeated TestCaseInfo info = 2;
}

message TestCaseInfo {
string name = 1; // Test case name
string error = 2;
uint64 duration = 3; // Number of whole microseconds in the duration.
string log_message = 4;
}

// ----------------------------------------------------------------------------
// KCL Type Structure
// ----------------------------------------------------------------------------
4,659 changes: 0 additions & 4,659 deletions pkg/spec/gpyrpc/kcl-lang.io/kcl-go/pkg/spec/gpyrpc/gpyrpc.pb.go

This file was deleted.

1 change: 1 addition & 0 deletions pkg/tools/override/testdata/test.k
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pkg

schema Config:
image: str

5 changes: 3 additions & 2 deletions scripts/kclvm.go
Original file line number Diff line number Diff line change
@@ -17,9 +17,10 @@ const (
)

const (
KclvmAbiVersion KclvmVersionType = KclvmVersionType_v0_7_0_alpha_2
KclvmVersionType_latest = KclvmVersionType_v0_7_0_alpha_2
KclvmAbiVersion KclvmVersionType = KclvmVersionType_v0_7_0_beta_1
KclvmVersionType_latest = KclvmVersionType_v0_7_0_beta_1

KclvmVersionType_v0_7_0_beta_1 KclvmVersionType = "v0.7.0-beta.1"
KclvmVersionType_v0_7_0_alpha_2 KclvmVersionType = "v0.7.0-alpha.2"
KclvmVersionType_v0_7_0_alpha_1 KclvmVersionType = "v0.7.0-alpha.1"
KclvmVersionType_v0_6_0 KclvmVersionType = "v0.6.0"

0 comments on commit a15c657

Please sign in to comment.