Git Product home page Git Product logo

kcl-go's People

Contributors

amyxia1994 avatar bozaro avatar chai2010 avatar dependabot[bot] avatar ekkoful avatar fossabot avatar jakezhu9 avatar ldxdl avatar neverrar avatar peefy avatar reckless-huang avatar shruti2522 avatar xiaok29 avatar zong-zhe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

kcl-go's Issues

feat: provides restful client

Feature Request

Is your feature request related to a problem? Please describe:

local kclvm-sdk api same as restful api, the sdk unit test can also be used for restful api

Describe the feature you'd like:

provides same client for local kclvm-sdk and restful api

Describe alternatives you've considered:

client := pkg.NewLocalClient()
client = pkg.NewRestClient("http://host/apibase")

reply, err := clietn.Ping(&pkg.PingArgs{})

use protoc-gen or kcl-gen tool to generate sub code.

Teachability, Documentation, Adoption, Migration Strategy:

Shorter install commands, for Go users

Feature Request

Is your feature request related to a problem? Please describe:

In v0.4.6 it can be installed via go install:

go install kusionstack.io/kclvm-go/cmds/kcl-go@main

https://kcl-lang.io/docs/user_docs/getting-started/install/#from-go

Describe the feature you'd like:

The install command line is a bit too long, it can be changed to be shorter.

Describe alternatives you've considered:

For example: go install kcl-lang.io/kcl-go@main

Teachability, Documentation, Adoption, Migration Strategy:

kcl test tool produces reflect error when schema parameter has type hint

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

a. create a test file: <dir>/main_test.k with the following content

schema Person:
    name: str

schema GetName[p: Person]:
    result: str = p.name

b. run: kcl-test <dir>/...

2. What did you expect to see? (Required)

test pass

3. What did you see instead (Required)

err occurred: FAIL <dir> err: reflect.Set: value of type *ast.Identifier is not assignable to type ast.TypeInterface%

4. What is your KusionStack components version? (Required)

releaseVersion: v0.3.20-debug-73-test
gitInfo:
    latestTag: v0.3.20-debug-73-test
    commit: 87ea0e74d8001e05e2049baf08e2990bdcf768b0
    treeState: dirty
buildInfo:
    goVersion: go1.17.9
    GOOS: linux
    GOARCH: amd64
    numCPU: 80
    compiler: gc
    buildTime: "2022-08-05 04:24:34"
dependency:
    kclvmVersion: v0.4.2-alpha.9
    kclPluginVersion: v0.2.20

Inconsistent native and service KCL api `ParseFile` behaviour

Bug Report

Native KCL api ParseFile method returns rust panicked error.

1. Minimal reproduce step (Required)

Test for reproduce: https://github.com/bozaro/kcl-parse-file-issue/blob/master/kcl_parse_file_issue_test.go

  1. Clone repository:
git clone https://github.com/bozaro/kcl-parse-file-issue.git .
  1. Run test:
go test -v .

2. What did you expect to see? (Required)

I expect to see same result for native and service tests.

3. What did you see instead (Required)

Native client returns rust panicked error with kcl parse non-empty errors case:

=== RUN   Test
=== RUN   Test/pygrpc
=== RUN   Test/pygrpc/simple
=== RUN   Test/pygrpc/pkgpath_not_found
=== RUN   Test/native
=== RUN   Test/native/simple
=== RUN   Test/native/pkgpath_not_found
thread '<unnamed>' panicked at api/src/service/capi.rs:154:5:
called `Result::unwrap()` on an `Err` value: NulError(7238, [10, 139, 55,..., 111, 39, 18, 0])
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    kcl_parse_file_issue_test.go:64: 
        	Error Trace:	/home/bozaro/xxx/xxa/kcl_parse_file_issue_test.go:64
        	Error:      	ParseFile returns error: %s
        	Test:       	Test/native/pkgpath_not_found
        	Messages:   	called `Result::unwrap()` on an `Err` value: NulError(7238, [10, 139, 55, 123, 34, 102, 105, 108, 10
--- FAIL: Test (0.01s)
    --- PASS: Test/pygrpc (0.00s)
        --- PASS: Test/pygrpc/simple (0.00s)
        --- PASS: Test/pygrpc/pkgpath_not_found (0.00s)
    --- FAIL: Test/native (0.00s)
        --- PASS: Test/native/simple (0.00s)
        --- FAIL: Test/native/pkgpath_not_found (0.00s)
FAIL
FAIL	github.com/bozaro/kcl-parse-file-issue	0.014s
FAIL

4. What is your KCL components version? (Required)

kcl-lang.io/kcl-go v0.8.1

Bug: Error Json schema import output for Github workflow.

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

The input json schema config: https://github.com/kcl-lang/modules/blob/main/github-workflow/jsonschema/github-workflow.json

2. What did you expect to see? (Required)

The right union type annotation instead of wrong type annotation. Besides, this issue can be aligned with the implementation in the kcl-lang/kcl-openapi repo.

image

3. What did you see instead (Required)

The wrong type annotations

image

image

image

It should be noted that the errors encountered may go far beyond those mentioned in the issue, and the input and output results should be carefully checked.

4. What is your KCL components version? (Required)

kcl-go v0.7.1

bug: ListDepFiles `-use-fast-parser` command option not found

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

restfull method ListDepFiles use -use-fast-parser to speed up for single app

https://github.com/KusionStack/KCLVM/blob/v0.4.2-alpha.4/internal/kclvm_py/program/rpc-server/__main__.py#L368

but the kcl-Go list-app do not support -use-fast-parser command options

2. What did you expect to see? (Required)

kcl-Go list-app should support -use-fast-parser

3. What did you see instead (Required)

go run ./cmds/kcl-go/ list-app -h
NAME:
   kcl-go list-app - list app files/packages 

USAGE:
   kcl-go list-app [command options] [pkgpath]

OPTIONS:
   --info                     show root and pkgpath (default: true)
   --file                     list files (default: true)
   --pkg                      list packages (default: false)
   --changed-files value      set changed files  (accepts multiple inputs)
   --show-abs                 use abs path (default: false)
   --show-index               show index (default: true)
   --include-all              include all elems (default: false)
   --kcl-yaml-file value      set custom kcl.yaml file (default: "kcl.yaml")
   --project-yaml-file value  set custom project.yaml file (default: "project.yaml")
   --help, -h                 show help (default: false)

--use-fast-parser not found

4. What is your KusionStack components version? (Required)

https://github.com/KusionStack/kclvm-go/releases/tag/v0.4.2-alpha.8

[Question] [API] How can i get all params (option function call) from the kcl code

for example,i have a kclfile

apiVersion = "apps/v1"
kind = "Deployment"
metadata = {
    name = "nginx"
    labels.app = "nginx"
}
spec = {
    replicas = 3
    selector.matchLabels = metadata.labels
    template.metadata.labels = metadata.labels
    template.spec.containers = [
        {
            name = metadata.name
            image = "${metadata.name}:1.14.2" if option("env") == "prod" else "${metadata.name}:latest"
            ports = [{ containerPort = 80 }]
        }
    ]
}

how to get a params list :
env str default is "prod"

[Enhancement] kclvm-go needs to be able to be installed through go install command

Enhancement

To enable kusionctl to be installed through go install, kclvm go needs to be installed and used through go install, which can be done through go embedded, such as the go binding method of wasmer and wasmtime:

Goals

The following commands can be used directly

  • a.k
a = 1
$ go install kusionstack.io/kclvm-go@latest
$ kcl-go run a.k
a: 1

[Enhancement]support an option to display schema attributes in a flatten way

Enhancement

Background

KCL focuses on model abstraction and configuration, and it's important to provide a clear overview of the attribute list and attribute details in the model documentation to both model maintainers and developers writing configurations based on the model.

The goal is to achieve that: With all information readily available in the doc, developers can write usable configurations without the need to navigate to other pages -- that requires all the configurable fields, along with their structures, constraints, and descriptions, can be obtained on a single page for the concerned model.

Design

Currently, the documentation generated by the KCL Doc tool only supports nested display of models, see konfig model docs on kusionstack.io.

flat(the way terraform registry adopted, example) and the nested representation, pros and cons:

  • flat representation: more complete information within a concentrated view. No need to navigate between pages.
  • nested representation: more concise schema structure, more independent schemas, less duplicate infos.

Solution

provide an option on whether to display schema attributes in a flattened or nested way.

NAME:
   kcl-go doc generate - generates documents from code and examples

USAGE:
   # Generate Markdown document for current package
   kcl-go doc generate

   # Generate Markdown document for specific package to a <target directory>
   kcl-go doc generate --file-path <package path> --target <target directory>

   # Generate Markdown document for specific package to a <target directory>. Display the schema attribute type in a flattened way
   kcl-go doc generate --file-path <package path> --target <target directory> --flatten


OPTIONS:
   --flatten                  Whether to display the schema attribute type in a flattened way. (default: false)

KclvmService.ValidateCode failed with kcl-go rest-server

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  1. go install kcl-lang.io/kcl-go/cmds/kcl-go@main
  2. kcl-go rest-server
  3. cat > vet-hello.json << EOF
    {
        "code": "\nschema Person:\n    key: str\n\n    check:\n        \"value\" in key  # 'key' is required and 'key' must contain \"value\"\n",
        "data": "{\"key\": \"value\"}"
    }
    EOF
    
  4.  curl -X POST \
     http://127.0.0.1:2021/api:protorpc/KclvmService.ValidateCode \
     -H  "accept: application/json" \
     --data @./vet-hello.json
    

2. What did you expect to see? (Required)

{
    "error": "",
    "result": {
        "success": true
    }
}

3. What did you see instead (Required)

{
	"error": "run cc failed: stdout , stderr: ld: warning: ignoring file /var/folders/bz/9gzt5_xn37ng7km3wmtqbfzh0000gp/T/.tmpJg3CnQ/libkclvm_cli_cdylib.dylib, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x23 0x21 0x2F 0x62 0x69 0x6E 0x2F 0x62 0x61 0x73 0x68 0x0A 0x4B 0x43 0x4C 0x5F )\nUndefined symbols for architecture arm64:\n  \"_kclvm_builtin_abs\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_abs)\n  \"_kclvm_builtin_all_true\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_all_true)\n  \"_kclvm_builtin_any_true\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_any_true)\n  \"_kclvm_builtin_bin\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_bin)\n  \"_kclvm_builtin_bool\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_bool)\n  \"_kclvm_builtin_dict\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_dict)\n  \"_kclvm_builtin_float\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_float)\n  \"_kclvm_builtin_hex\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_hex)\n  \"_kclvm_builtin_int\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_int)\n  \"_kclvm_builtin_isunique\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_isunique)\n  \"_kclvm_builtin_len\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_len)\n  \"_kclvm_builtin_list\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_list)\n  \"_kclvm_builtin_max\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_max)\n  \"_kclvm_builtin_min\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_min)\n  \"_kclvm_builtin_multiplyof\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_multiplyof)\n  \"_kclvm_builtin_oct\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_oct)\n  \"_kclvm_builtin_option\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_option)\n  \"_kclvm_builtin_ord\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_ord)\n  \"_kclvm_builtin_pow\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_pow)\n  \"_kclvm_builtin_print\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_print)\n  \"_kclvm_builtin_range\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_range)\n  \"_kclvm_builtin_round\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_round)\n  \"_kclvm_builtin_sorted\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_sorted)\n  \"_kclvm_builtin_str\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_str)\n  \"_kclvm_builtin_sum\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_sum)\n  \"_kclvm_builtin_typeof\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_typeof)\n  \"_kclvm_builtin_zip\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n     (maybe you meant: _$builtin___main___kclvm_builtin_zip)\n  \"_kclvm_config_attr_map\", referenced from:\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key.18 in 88891_1690257051736332000.o\n  \"_kclvm_context_current\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n  \"_kclvm_context_set_kcl_filename\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_check_block.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n      _$kclvm_schema_check_block.__main__.Person.17 in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key.18 in 88891_1690257051736332000.o\n      ...\n  \"_kclvm_context_set_kcl_line_col\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_check_block.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n      _$kclvm_schema_check_block.__main__.Person.17 in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key.18 in 88891_1690257051736332000.o\n      ...\n  \"_kclvm_context_set_kcl_pkgpath\", referenced from:\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n  \"_kclvm_default_collection_insert_int_pointer\", referenced from:\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n  \"_kclvm_default_collection_insert_value\", referenced from:\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n  \"_kclvm_dict_get_entry\", referenced from:\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key.18 in 88891_1690257051736332000.o\n  \"_kclvm_dict_has_value\", referenced from:\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_check_block.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n      _$kclvm_schema_check_block.__main__.Person.17 in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key.18 in 88891_1690257051736332000.o\n  \"_kclvm_dict_insert\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n  \"_kclvm_dict_insert_value\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n  \"_kclvm_dict_merge\", referenced from:\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n  \"_kclvm_dict_safe_insert\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n  \"_kclvm_list_append\", referenced from:\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n  \"_kclvm_list_len\", referenced from:\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_check_block.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n      _$kclvm_schema_check_block.__main__.Person.17 in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key.18 in 88891_1690257051736332000.o\n  \"_kclvm_list_pop\", referenced from:\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_check_block.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n      _$kclvm_schema_check_block.__main__.Person.17 in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key.18 in 88891_1690257051736332000.o\n  \"_kclvm_schema_assert\", referenced from:\n      _$kclvm_schema_check_block.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_check_block.__main__.Person.17 in 88891_1690257051736332000.o\n  \"_kclvm_schema_backtrack_cache\", referenced from:\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key.18 in 88891_1690257051736332000.o\n  \"_kclvm_schema_default_settings\", referenced from:\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n  \"_kclvm_schema_get_value\", referenced from:\n      _$kclvm_schema_check_block.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_check_block.__main__.Person.17 in 88891_1690257051736332000.o\n  \"_kclvm_schema_optional_check\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n  \"_kclvm_schema_value_check\", referenced from:\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n  \"_kclvm_schema_value_new\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n  \"_kclvm_value_Bool\", referenced from:\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n  \"_kclvm_value_Dict\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n  \"_kclvm_value_Function_using_ptr\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n  \"_kclvm_value_Int\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n  \"_kclvm_value_List\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n  \"_kclvm_value_None\", referenced from:\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n  \"_kclvm_value_Str\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_check_block.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n      _$kclvm_schema_check_block.__main__.Person.17 in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key.18 in 88891_1690257051736332000.o\n      ...\n  \"_kclvm_value_Undefined\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_check_block.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n      _$kclvm_schema_check_block.__main__.Person.17 in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key.18 in 88891_1690257051736332000.o\n      ...\n  \"_kclvm_value_deep_copy\", referenced from:\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n  \"_kclvm_value_in\", referenced from:\n      _$kclvm_schema_check_block.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_check_block.__main__.Person.17 in 88891_1690257051736332000.o\n  \"_kclvm_value_is_truthy\", referenced from:\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n  \"_kclvm_value_plan_to_json\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n  \"_kclvm_value_schema_function\", referenced from:\n      _kclvm_main in 88891_1690257051736332000.o\n  \"_kclvm_value_schema_with_config\", referenced from:\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n  \"_kclvm_value_union\", referenced from:\n      _$kclvm_schema.__main__.Person in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key in 88891_1690257051736332000.o\n      _$kclvm_schema.__main__.Person.16 in 88891_1690257051736332000.o\n      _$kclvm_schema_attr.__main__.Person.key.18 in 88891_1690257051736332000.o\nld: symbol(s) not found for architecture arm64\nclang: error: linker command failed with exit code 1 (use -v to see invocation)\n",
	"result": null
}

4. What is your KCL components version? (Required)

➜  kcl-go -v
kcl-go version v0.5.0

➜ kcl -V
Version: 0.5.0-20ab3eb4b9179219d6837a57f5d35286
Platform: aarch64-apple-darwin
GitCommit: 64401faf2d588260d23d1f06b8209a00472e3298

bug: memory leak

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

hello.go

// Copyright 2022 The KCL Authors. All rights reserved.

package main

import (
	"fmt"
	"os"
	"path/filepath"
	"time"

	"kusionstack.io/kclvm-go"
)

func main() {
	os.Setenv("KCLVM_TARGET", "native")

	wd, _ := os.Getwd()

	filename := filepath.Join(wd, "hello-temp.k")
	os.WriteFile(filename, []byte{}, 0666)
	defer os.Remove(filename)

	for i := 0; i < 10000; i++ {
		fmt.Println(i, "-------------")

		yaml := kclvm.MustRun(filename, kclvm.WithCode(k_code1+fmt.Sprintf("\n#%d", i))).First().YAMLString()
		fmt.Println(yaml)

		yaml = kclvm.MustRun(filename, kclvm.WithCode(k_code2+fmt.Sprintf("\n#%d", i))).First().YAMLString()
		fmt.Println(yaml)

		time.Sleep(time.Second / 10)
	}
}

const k_code1 = `
import kcl_plugin.hello

name = "kcl"
age = 1
two = hello.add(1, 1)

schema Person:
    name: str = "kcl"
    age: int = 1

x0 = Person {}
x1 = Person {
    age = 101
}
`

const k_code2 = `
schema Fib:
    n1: int = n - 1
    n2: int = n1 - 1
    n: int
    value: int = 1 if n <= 2 else Fib {n = n1}.value + Fib {n = n2}.value

fib = Fib {n = 20}.value
`

run code:

go run hello.go
....

2. What did you expect to see? (Required)

Small changes in memory usage

3. What did you see instead (Required)

memory leak

image

4. What is your KusionStack components version? (Required)

https://github.com/KusionStack/kclvm-go/releases/tag/v0.4.2-alpha.8

bug: Failed to compile a single kcl file using the API of kclvm-go.

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Use version 'v0.5.0-alpha.3' of the kclvm-go api.

go get kusionstack.io/[email protected]

Write a kcl program in main.k.

The_first_kcl_program = 'Hello World!'

Write the go program as shown below and execute it.

package main

import (
	"fmt"

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

func main() {

	workDiroptb := kcl.WithKFilenames("/Users/main.k")
	fmt.Println(kcl.Run("", workDiroptb))
}

2. What did you expect to see? (Required)

The_first_kcl_program: Hello World!

3. What did you see instead (Required)

error[E1001]: ImmutableError
 --> /Users/main.k:1:1
  |
1 | The_first_kcl_program = 'Hello World!'
  | ^ Can not change the value of 'The_first_kcl_program', because it was declared immutable
  |

 --> /Users/main.k:1:1
  |
1 | The_first_kcl_program = 'Hello World!'
  | ^ The variable 'The_first_kcl_program' is declared here
  |
note: change the variable name to '_The_first_kcl_program' to make it mutable

4. What is your KusionStack components version? (Required)

kusionstack.io/kclvm-go v0.5.0-alpha.3

[Bug] Error JsonSchema import output

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

The json schema file a.schema.json

{
    "$id": "https://example.com/monaco.manifest.schema.json",
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "title": "Dynatrace Monitoring as Code Manifest File",
    "type": "object",
    "properties": {
        "manifestVersion": {
            "type": "string",
            "description": "The schema version this manifest conforms to - e.g. 1.0"
        },
        "projects": {
            "type": "array",
            "description": "The projects grouped by this manifest",
            "items": {
                "type": "object",
                "properties": {
                    "name": {
                        "type": "string",
                        "description": "The name of this project"
                    },
                    "type": {
                        "type": "string",
                        "description": "Optional Type of this project. Default: Simple",
                        "oneOf": [
                            {
                                "const": "simple",
                                "description": "A simple project, directly containing configuration. Default."
                            },
                            {
                                "const": "grouping",
                                "description": "A grouping project, containing several sub-projects."
                            }
                        ]
                    },
                    "path": {
                        "type": "string",
                        "description": "Optional filepath of the project relative to the manifest.yaml location. Defaults to name"
                    }
                },
                "required": [
                    "name"
                ]
            }
        },
        "environmentGroups": {
            "description": "The Environment groups to which projects in this manifest are deployed",
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "name": {
                        "type": "string",
                        "description": "The name of this environment group"
                    },
                    "environments": {
                        "description": "The environments in this group",
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "name": {
                                    "type": "string",
                                    "description": "The name of this environment"
                                },
                                "url": {
                                    "description": "The URL of this environment",
                                    "type": "object",
                                    "properties": {
                                        "type": {
                                            "description": "Optional Type of URL definition.",
                                            "type": "string",
                                            "oneOf": [
                                                {
                                                    "const": "value",
                                                    "description": "URL directly defined in the 'value'. Default."
                                                },
                                                {
                                                    "const": "environment",
                                                    "description": "URL defined by an environment variable name in 'value' to read from."
                                                }
                                            ]
                                        },
                                        "value": {
                                            "type": "string",
                                            "description": "The value of the URL, based on type either an URL or environment variable name"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "required": [
        "manifestVersion",
        "projects",
        "environmentGroups"
    ]
}

2. What did you expect to see? (Required)

The right KCL schema output

3. What did you see instead (Required)

"""
This file was generated by the KCL auto-gen tool. DO NOT EDIT.
Editing this file might prove futile when you re-run the KCL auto-gen generate command.
"""

schema MonacoManifestSchema:
    """
    MonacoManifestSchema

    Attributes
    ----------
    manifest_version : str, required
        The schema version this manifest conforms to - e.g. 1.0
    projects : [items], required
        The projects grouped by this manifest
    environment_groups : [items], required
        The Environment groups to which projects in this manifest are deployed
    """

    manifest_version: str
    projects: [items]
    environment_groups: [items] # items is not defined.

schema Url:
    """
    The URL of this environment

    Attributes
    ----------
    type : str, optional
        Optional Type of URL definition.
    value : str, optional
        The value of the URL, based on type either an URL or environment variable name
    """

    type?: str
    value?: str

4. What is your KCL components version? (Required)

KCL v0.7.0 version

new client api, support call restfull method

Feature Request

Is your feature request related to a problem? Please describe:

Describe the feature you'd like:

the local kclvm api and the remote restfull api is same, we shouild add a new client api to support call local and remote method.

Describe alternatives you've considered:

client := kclvm.New() // default local kclvm
client := kclvm.New(kclvm.WithKclvm("path/to/kclvm/root"))
client := kclvm.New(kclvm.WithService("http://127.0.0.1:2021"))

reply, err := client.ExecProgram(&gpyrpc.ExecProgram_Result{})

Teachability, Documentation, Adoption, Migration Strategy:

Bug: `package manifests: no kcl file` when `kcl-go list-app`.

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  1. git clone the konfig.
git clone https://github.com/KusionStack/konfig.git
  1. cd the wordpress/dev
cd konfig/appops/wordpress/dev
  1. kcl-go list-app
kcl-go list-app --include-all --show-index=false --info=false

2. What did you expect to see? (Required)

Output all import files

appops/wordpress/base/base.k
appops/wordpress/dev/main.k
appops/wordpress/dev/platform.k
base/pkg/kusion_clouds/alicloud/alicloud_db_connection.k
base/pkg/kusion_clouds/alicloud/alicloud_db_instance.k
base/pkg/kusion_clouds/alicloud/alicloud_instance.k
base/pkg/kusion_clouds/alicloud/alicloud_oss_bucket.k
base/pkg/kusion_clouds/alicloud/alicloud_rds_account.k
base/pkg/kusion_clouds/alicloud/alicloud_security_group.k
base/pkg/kusion_clouds/alicloud/alicloud_slb.k
base/pkg/kusion_clouds/alicloud/alicloud_vpc.k
.......

3. What did you see instead (Required)

package manifests: no kcl file

4. What is your KusionStack components version? (Required)

[Document] KCL doc Spec

Doc Representation And Generation Spec

  1. This is the specification of the document format of KCL package and restricts the best practice of KCL package and schema design. It requires the package owners and the schema developers to provide key information to their users: package introduction, schema description and examples, etc.
  2. This defines the way kpm and doc tools read and parse the KCL packages and generate documentation.

A typical KCL package has the following directory structure:

packageRoot
├── subPackage
│   ├── fileA.k
│   └── ...
├── fileB.k
├── ...
├── kcl.mod
└── README.md

package doc spec

Define the package's meta information in the kcl.mod file: name, version, short description, dependencies, etc. :

[package]
name = "hello_world" # the name of the package
version = "0.1.0"    # the current version, obeying semver
edition = "0.5.0"    # the KCL compiler version
description = "A KCL hello world project" # the brief description of the package

Define detailed description of the package in the README.md file, which can include richer media such as badges and images.

docstring spec

"""
model_description: 不包含三引号的字符串,可使用 markdown

Attributes
---------
<attribute_name>: <attribute_description>

Examples
--------
A brief description of the example code

<code_example>


See Also
--------
<http_link>
<sample_directory_path>
"""

example spec

In addition to schema docstring, the example usages can be defined in the examples(_name).k file in the same directory as the schema file.

import a.b.c

"""
A description of the example: when to use it, what it solves
"""
example_<schema_name>_XXX = c.<schema_name>{
    # ...
}

output spec

From KCL schema source code, extract and generate readable documents in various formats, mainly including Markdown and Html. Take Markdown as an example:

package.md
├── Schemas
│   ├── SchemaA.md
│   └── SchemaB.md
├── Rules
│   ├── RuleC.md
│   └── RuleD.md
└── Protocols
    ├── ProtocolE.md
    └── ProtocolF.md

the generated package document

The package document is the home page of the package, which contains three chapters: README, Documentation and Source Files.

  • The README section comes from readme.md in the package root
  • Documentation section:
    • Overview package description in the package doc spec
    • Index serves as the package index page, pointing to subpackages and schema/rules/protocol
  • Source Files section
  • Indicates the source code of the current package
## README

Rendered as the homepage of the package.

## Documentation

### Overview

A brief overview of the package

### Index

Indexes to all the schemas/protocols/rules in this package

## Source Files

- [package](source file link to the package)

the generated schema document

## Documentation

### Overview

A description of the schema

### Parent Schema(optional) 

[parent_schema_name](link to the parent schema doc)

### Parameters(optional) 

**`parameter_name`** type

## Attributes

**`attr_name`** *deprecated* *required* *readonly*
`basic_type` or [schema_type](link to schema type)
A description of the attribute
Default: `value` or ```multiple lines value```

## Examples

**`example_name`**
A brief description of the example code

\`\`\`
<code_example>
\`\`\`

## Source Files

- [schema definition](source file link to schema)
- [schema examples](source file to schema examples)

[Bug] Unexpected Import data format for YAML

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Import the following YAML to KCL

# This is an example .goreleaser.yml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
before:
  hooks:
    # You may remove this if you don't use go modules.
    - go mod tidy

# .goreleaser.yml
builds:
  - id: "kcl"
    main: ./kcl.go
    goos:
      - darwin
      - linux
      - windows
    goarch:
      - amd64
      - arm64
    env:
      - CGO_ENABLED=0
    ldflags:
      - "-X kcl-lang.io/cli/pkg/version.version={{.Version}}"

2. What did you expect to see? (Required)

"""
This file was generated by the KCL auto-gen tool. DO NOT EDIT.
Editing this file might prove futile when you re-run the KCL auto-gen generate command.
"""

before = {
    hooks = [
        "go mod tidy"
    ]
}
builds = [
    {
        id = "kcl"
        main = "./kcl.go"
        goos = [
            "darwin"
            "linux"
            "windows"
        ]
        goarch = [
            "amd64"
            "arm64"
        ]
        env = [
            "CGO_ENABLED=0"
        ]
        ldflags = [
            "-X kcl-lang.io/cli/pkg/version.version={{.Version}}"
        ]
    }
]

3. What did you see instead (Required)

"""
This file was generated by the KCL auto-gen tool. DO NOT EDIT.
Editing this file might prove futile when you re-run the KCL auto-gen generate command.
"""

before = {
    hooks = [
        "go mod tidy"]
}
builds = [
    {
        id = "kcl"
        main = "./kcl.go"
        goos = [
            "darwin"    "linux"    "windows"]
        goarch = [
            "amd64"    "arm64"]
        env = [
            "CGO_ENABLED=0"]
        ldflags = [
            "-X kcl-lang.io/cli/pkg/version.version={{.Version}}"]
    }
]

4. What is your KCL components version? (Required)

kcl-go v0.6.1

[Enhancement] Stable KCL Go calling KCL Rust Core lib through dllopen or CGO

Enhancement

Just like wasmtime (written by Rust) and wasmtime-go, it needs to break away from the KCLVM Rust binary dependency and python server from KCLVM Go SDK (Call KCL core capabilities directly through KCL rust CAPIs) and support senseless installation. This is one of task

  • Stable KCLVM Go calling KCL Rust Core lib through dllopen or CGO

TestFormatPath Failed

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

OS: ubuntu:20.04
python version: 3.9.10
run command : go test -run ^TestFormatPath$ kusionstack.io/kclvm-go/pkg/tools/format

2. What did you expect to see? (Required)

Go test succeeded

3. What did you see instead (Required)

format_test.go:69: format path exec failed. KCL Compile Error[E2L23] : A complie error occurs during compiling
        ---> File /home/runner/work/kclvm-go/kclvm-go/pkg/tools/format/testdata/success/hello.k -> Failure
        [Errno 32] Broken pipe: stderr = KCL format done and 2 files were formatted:

4. What is your KusionStack components version? (Required)

v0.4.4-alpha.2

version miss match

error log

(base) reckless@recklessdeMacBook-Pro myk8s % kcl main.k        
Init kcl runtime failed, path:  /usr/local
Tip: Have you used a binary version of KCL in your PATH that is not consistent with the KCL Go SDK? You can upgrade or reduce the KCL version or delete the KCL in your PATH
If not, you can run `rm -r /usr/local/bin` to fix this issue
panic: unexpected EOF: stderr = dyld[94858]: Library not loaded: @rpath/libkclvm_cli_cdylib.dylib
  Referenced from: <2CA48E8D-8E5A-31AA-9008-B3D2A90BB609> /usr/local/bin/kclvm_cli
  Reason: tried: '/usr/local/bin/../../../../../../../.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libkclvm_cli_cdylib.dylib' (no such file), '/usr/local/bin/libkclvm_cli_cdylib.dylib' (no such file), '/usr/local/bin/../../../../../../../.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libkclvm_cli_cdylib.dylib' (no such file), '/usr/local/bin/libkclvm_cli_cdylib.dylib' (no such file), '/usr/local/lib/libkclvm_cli_cdylib.dylib' (no such file), '/usr/lib/libkclvm_cli_cdylib.dylib' (no such file, not in dyld cache)


goroutine 1 [running]:
kcl-lang.io/kcl-go/pkg/runtime.initRuntime(0x0?)
        /home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/runtime/init.go:72 +0x5d8
kcl-lang.io/kcl-go/pkg/runtime.GetRuntime.func1()
        /home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/runtime/init.go:29 +0x20
sync.(*Once).doSlow(0x30?, 0x10a931420?)
        /opt/hostedtoolcache/go/1.21.8/x64/src/sync/once.go:74 +0x100
sync.(*Once).Do(...)
        /opt/hostedtoolcache/go/1.21.8/x64/src/sync/once.go:65
kcl-lang.io/kcl-go/pkg/runtime.GetRuntime()
        /home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/runtime/init.go:29 +0x40
kcl-lang.io/kcl-go/pkg/service.NewKclvmServiceClient()
        /home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/service/client_kclvm_service.go:21 +0x1c
kcl-lang.io/kcl-go/pkg/kcl.runWithHooks({0x14000f11578, 0x0, 0x0}, {0x10a8ebf90, 0x1, 0x1}, {0x14000f115e8, 0x1, 0x1})
        /home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/kcl/api.go:378 +0xf4
kcl-lang.io/kcl-go/pkg/kcl.run(...)
        /home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/kcl/api.go:387
kcl-lang.io/kcl-go/pkg/kcl.RunWithOpts({0x14000f115e8?, 0x1400089fe30?, 0x0?})
        /home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/kcl/api.go:274 +0x50
kcl-lang.io/kpm/pkg/runner.(*Compiler).Run(...)
        /home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/runner/runner.go:52
kcl-lang.io/kpm/pkg/client.(*KpmClient).Compile(0x140001c7c00, 0x14000a49858?, 0x14000f11750)
        /home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/client/client.go:331 +0x158
kcl-lang.io/kpm/pkg/client.(*KpmClient).CompileWithOpts(0x140001c7c00, 0x140005281c0)
        /home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/client/client.go:380 +0x4a4
kcl-lang.io/cli/pkg/options.(*RunOptions).Run(0x14000280700)
        /home/runner/work/cli/cli/pkg/options/run.go:155 +0x880
kcl-lang.io/cli/cmd/kcl/commands.NewRunCmd.func1(0x140009c0400?, {0x14000b0cf80?, 0x4?, 0x103ec60c5?})
        /home/runner/work/cli/cli/cmd/kcl/commands/run.go:49 +0x6c
github.com/spf13/cobra.(*Command).execute(0x1400086af00, {0x1400004c0b0, 0x1, 0x1})
        /home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:983 +0x840
github.com/spf13/cobra.(*Command).ExecuteC(0x1400086af00)
        /home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1115 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
        /home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1039
kcl-lang.io/cli/cmd/kcl/commands.executeRunCmd({0x1400004c0b0, 0x1, 0x1})
        /home/runner/work/cli/cli/cmd/kcl/commands/plugin.go:17 +0x6c
kcl-lang.io/cli/cmd/kcl/commands.bootstrapCmdPlugin(0x14000804000?, {0x104baaa30, 0x1400088d428})
        /home/runner/work/cli/cli/cmd/kcl/commands/plugin.go:67 +0x3e8
kcl-lang.io/cli/cmd/kcl/commands.New()
        /home/runner/work/cli/cli/cmd/kcl/commands/root.go:126 +0x3d8
main.main()
        /home/runner/work/cli/cli/cmd/kcl/main.go:14 +0x1c

Request: allow disabling shared lib download behavior at build time

Feature Request

Is your feature request related to a problem? Please describe:

I want to package KCL programs (the Go CLI and the Rust shared lib + LSP server) for the Linux distributions I use, namely AlpineLinux and NixOS. For a proper packaging workflow, I need the Go CLI not to arbitrarily download the pre-built Rust shared object, and instead rely on the one built by the distro at the defined location. The downloaded artifact doesn't work on AlpineLinux anyway, due to the usage of musl libc. To ensure a consistent user experience, stopping this behavior at build time is desired.

Looking through the code, the artifact download behavior and the lookup location can be configured at runtime via some environment variables: KCL_GO_DISABLE_ARTIFACT, KCL_LIB_HOME and KCL_GO_USE_PLUGIN. The common lib https://github.com/kcl-lang/lib/blob/main/install.go then puts the shared object at hardcoded subdirectory bin inside that home directory.

Describe the feature you'd like:

  • Turn UseKCLPluginEnvVar, LibHomeEnvVar and DisableArtifactEnvVar into actual bool values to be set at build time, instead of variable names intended for runtime usage.
  • Allow more flexible fine-tuning of the shared lib location. It should be {configurable_prefix}/{configurable_path}/<shared_lib_file> (usually /usr/lib) instead of {libHome}/bin/<shared_lib_file>

[Bug] In go image, kcl-go run command failed.

# kcl-go doc generate --file-path demo --escape-html
Init kcl runtime failed, path:  /go
Tip: Have you used a binary version of KCL in your PATH that is not consistent with the KCL Go SDK? You can upgrade or reduce the KCL version or delete the KCL in your PATH
panic: unexpected EOF: stderr = qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory

CI failed in build-and-test-windows

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

run github workflow build-and-test-windows

2. What did you expect to see? (Required)

all tests should pass

3. What did you see instead (Required)

build-and-test-windows always failed since 16ee99b. It seems that there is some problem with cgo

# kcl-lang.io/kcl-go/pkg/kcl_plugin/hello_plugin.test
C:\hostedtoolcache\windows\go\1.19.13\x64\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\RUNNER~1\AppData\Local\Temp\go-link-425057140\000006.o: in function `_cgo_preinit_init':
\\_\_\runtime\cgo/gcc_libinit_windows.c:40: undefined reference to `__imp___iob_func'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\RUNNER~1\AppData\Local\Temp\go-link-425057140\000006.o: in function `x_cgo_notify_runtime_init_done':
\\_\_\runtime\cgo/gcc_libinit_windows.c:[105](https://github.com/kcl-lang/kcl-go/actions/runs/6609481621/job/17950015784#step:4:106): undefined reference to `__imp___iob_func'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\RUNNER~1\AppData\Local\Temp\go-link-425057140\000006.o: in function `_cgo_beginthread':
\\_\_\runtime\cgo/gcc_libinit_windows.c:149: undefined reference to `__imp___iob_func'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\RUNNER~1\AppData\Local\Temp\go-link-425057140\000007.o: in function `x_cgo_thread_start':
\\_\_\runtime\cgo/gcc_util.c:18: undefined reference to `__imp___iob_func'
collect2.exe: error: ld returned 1 exit status

# kcl-lang.io/kcl-go/pkg/kcl_plugin.test
FAIL	kcl-lang.io/kcl-go/pkg/kcl_plugin [build failed]
C:\hostedtoolcache\windows\go\1.19.13\x64\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
FAIL	kcl-lang.io/kcl-go/pkg/kcl_plugin/hello_plugin [build failed]
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\RUNNER~1\AppData\Local\Temp\go-link-1519708659\000006.o: in function `_cgo_preinit_init':
\\_\_\runtime\cgo/gcc_libinit_windows.c:40: undefined reference to `__imp___iob_func'
?   	kcl-lang.io/kcl-go/pkg/kclvm_runtime	[no test files]
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\RUNNER~1\AppData\Local\Temp\go-link-1519708659\000006.o: in function `x_cgo_notify_runtime_init_done':
\\_\_\runtime\cgo/gcc_libinit_windows.c:105: undefined reference to `__imp___iob_func'
ok  	kcl-lang.io/kcl-go/pkg/logger	0.030s [no tests to run]
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\RUNNER~1\AppData\Local\Temp\go-link-1519708659\000006.o: in function `_cgo_beginthread':
?   	kcl-lang.io/kcl-go/pkg/path	[no test files]
\\_\_\runtime\cgo/gcc_libinit_windows.c:149: undefined reference to `__imp___iob_func'
ok  	kcl-lang.io/kcl-go/pkg/service	1.047s
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\RUNNER~1\AppData\Local\Temp\go-link-1519708659\000007.o: in function `x_cgo_thread_start':
ok  	kcl-lang.io/kcl-go/pkg/settings	0.047s
\\_\_\runtime\cgo/gcc_util.c:18: undefined reference to `__imp___iob_func'
?   	kcl-lang.io/kcl-go/pkg/spec/gpyrpc	[no test files]
collect2.exe: error: ld returned 1 exit status
ok  	kcl-lang.io/kcl-go/pkg/tools/format	0.062s

WithSettings should merge options instead of overwriting

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

kcl --help 的输出的信息中提到 -Y 应该接受一个列表
image
但是 sdk 中,kcl.WithSettings 的逻辑是覆盖,并不是合并,两者逻辑不一致

2. What did you expect to see? (Required)

3. What did you see instead (Required)

4. What is your KCL components version? (Required)

kclvm version is 0.4.4; checksum: c5339e572207211e46477825e8aca903

support Go API for GetSchemaTypeMapping

Feature Request

Is your feature request related to a problem? Please describe:

We have rest API rpc GetSchemaTypeMapping(GetSchemaTypeMapping_Args) returns(GetSchemaTypeMapping_Result); on kcl-py but the corresponding Go API is missing.

The GetSchemaTypeMapping((file: string, code:string) is required to export HIR of KCL schema, which could be used to integrate other tools, like kcl-doc, vscode-kcl low code create from schema, etc.

Describe the feature you'd like:

add GetSchemaTypeMapping((file: string, code:string) Go API

Describe alternatives you've considered:

Teachability, Documentation, Adoption, Migration Strategy:

[Bug] KCL Run API Options are not consistent with the KCL command line.

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Write the Go code (main.go) and run:

package main

import (
	"fmt"

	"kusionstack.io/kclvm-go"
)

func main() {
	v := `obj='{"spec":{"replicas":2},"status":{"replicas":2}}'`
	kclRes := kclvm.MustRun("x.k", kclvm.WithOptions(v), kclvm.WithCode(`
obj = option("obj")`))
	fmt.Println(kclRes.First().YAMLString())
}

And run the command:

go run main.go

2. What did you expect to see? (Required)

The YAML output:

obj:
    spec:
        replicas: 2
    status:
        replicas: 2

3. What did you see instead (Required)

The YAML output:

obj: '{"spec":{"replicas":2},"status":{"replicas":2}}'

4. What is your KusionStack components version? (Required)

kclvm version is 0.4.4; checksum: c5339e572207211e46477825e8aca903

ListDownStreamFiles does not support deleted files in changed files list

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

use the test data in pkg/tools/list/testdata/complicate/appops/projectD as an example:

set the ListDepsOption.ChangedPaths and contains a deleted file path in it, then call ListDownStreamFiles API, for example:

depParser, err := NewImportDepParser("pkg/tools/list/testdata/complicate/", DepOption{Files: []string{"appops/projectD/base/base.k", "appops/projectD/dev/main.k"}, ChangedPaths: []string{"base/frontend/not_exist.k"}})
affected := depParser.ListDownStreamFiles()

2. What did you expect to see? (Required)

down stream files should be:
[]string{"base/frontend/not_exist.k", "base/frontend/not_exist", "appops/projectD/base/base.k", "appops/projectD/base"}

3. What did you see instead (Required)

the program returns file not exist error

4. What is your KusionStack components version? (Required)

kusion: v0.3.22-alpha.12
kclvm-go: v0.4.2-alpha2

[Enhancement] kcl doc gen: optimize the document format and styles

Enhancement

parent issue: #139

This issue is raised according to catalog doc sync PR:

https://kusionstack.io/docs/reference/model/catalog_models/internal/container/doc_container

The model docs on the official website have been manually modified and are more more clear and human-friendly than the documents generated directly by the kcl-doc tool.

The doc gen spec and templates should be optimized accordingly.

cc @ffforest

[Enhancement] Add AllOf validations for KCL jsonschema generations

Before

  • kcl-go/pkg/tools/gen/types.go
type validation struct {
	Name             string
	Minimum          *float64
	ExclusiveMinimum bool
	Maximum          *float64
	ExclusiveMaximum bool
	MinLength        *int
	MaxLength        *int
	Regex            *regexp.Regexp
	MultiplyOf       *int
	Unique           bool
}
  • After
type validation struct {
	Name             string
	Minimum          *float64
	ExclusiveMinimum bool
	Maximum          *float64
	ExclusiveMaximum bool
	MinLength        *int
	MaxLength        *int
	Regex            *regexp.Regexp
	MultiplyOf       *int
	Unique           bool
        AllOf   []*validation
}

[Feature] KCL doc tool: extract, generate document of KCL packages

Feature Request

Users and Typical Scenarios

  • Document creation & maintenance: Platform SRE
  • Document review & consumption: Application SRE and developer

User story and Workflow

Command Line Interface

The kcl-doc command extracts and renders documentation files of KCL packages. It will provider 2 sub commands: generate, start:

kcl-doc:

# kcl-doc command
kcl-doc -h

Usage: [--version] [--help] <command> [<args>]
Available commands are:
                the generate command is run by default
    generate    generates documents from code and examples
    start       starts a document website locally

arguments:
    --version                        show version of this kcl-doc command line tool
    --help                           show this information

kcl-doc generate:

# kcl-doc generate command
kcl-doc generate -h
generates documents from code and examples
    --schema-path <ARG>              Relative or absolute file path to the KCL package root
                                     when running kcl-doc command from outside of the KCL package root directory.
                                     If not specified, docs of all the KCL models under the work directory will be generated.
    --ignore-deprecated <ARG>        Do not generate documentation for deprecated schemas                                      (default: "false")
    --format <ARG>                   The document format to generate. Supported values: markdown, html, openapi                                                 (default: "markdown")
    --target <ARG>                   The target directory to store the generated document files.                               (default: "")
                                     If not specified, the current work directory will be used.
                                     A docs/ folder will be created under the target directory

kcl-doc start:

# kcl-doc start command
kcl-doc start
starts a document website locally

Spec of KCL Package and Schema Docs

the KCL doc spec is detailed defined in: #156

Integrate with IDE

doc highlight

Attribute names, types and descriptions in docstring can be highlighted at the semantic level to improve docstring readability. Here's a good example:

image

Hover to see docs

When the cursor hovers over the schema name and Attribute name, the document is displayed:

package info
---
schema description
---
**attribute**: type
description
---
\`\`\`
Example
\`\`\`

Here's a good example:

image

Document preview

In the schema file toolbar, click the preview button to expand the preview format of the document. The preview view in Markdown format is loaded by default. Here's a good example:

image

Auto-Completion in writing docstring

When a docstring is added to the model, the scaffolding code in docstring format is automatically generated, and the <> is a placeholder to be filled by the user:

<schema_description>

Attributes
----------
attr_name: <attribute_description>

Examples
--------
<example_code>

When editing docstring, automatically complete the Attributes document in docstring format, as well as the Attributes/Examples chapter title, etc. :

  1. Auto-complete attribute names: Attributes, triggered by newlines/English characters
  2. Automatically completes Attribues & Examples Chapter title: In the first line of the chapter, it is triggered by the prefix of the newline/chapter name

Here's a demo:

docstring_completion

Diagnose and error reporting

Model/attributes for a. missing documents; b. The document contains undefined attributes; c. If the document content does not match the attribute declaration, mark the error message and provide quick repair actions.
todo: The contents and quick repair actions of each type of error prompt need to be detailed and discussed in the design of the error prompt function.

Auto-Completion in writing config

When assigning a configuration value, the assignment expression, including schema expr and value of attribute entry, completes the code snippet, and displays the snippet across multiple lines using inline completion. The snippets in samples/docstring-examples can be used as a source of completed code snippets.

Here's a demo:

example_completion

Go to definition & reference

Jump from the attribute name in the docstring to the attribute definition and vice versa.
A good example:

goto

Integrate with Github/Gitlab Pipeline

Integrated CICD pipeline in the model library

  1. Document validation: A subset of the functionality of kcl-lint action
  2. Document synchronization: Generate documents and synchronize them to github page; Synchronize data to the specified webhook

Integrate with Kpm Registry

  • kpm package doc auto sync: CICD pipeline

Bug: using the `--selector` may result in a compilation error

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

The example that triggers this bug during the use of the API is as follows:

func TestWithSelectorsAA(t *testing.T) {
	const code = `
schema Person:
    labels: {str:str}

alice = Person {
    "labels": {"skin": "yellow"}
}
`
	const testdata_main_k = "testdata/main_selector.k"
	kfile, err := os.Create(testdata_main_k)
	if err != nil {
		t.Fatal(err)
	}
	kfile.Close()

	result, err := kcl.Run(testdata_main_k,
		kcl.WithCode(code),
		kcl.WithSelectors("alice.labels.skin"),
	)
	if err != nil {
		t.Fatal(err)
	}
	if expect, got := "a1-app", result.First().Get("name"); expect != got {
		t.Fatalf("expect = %v, got = %v", expect, got)
	}
	os.Remove(testdata_main_k)
	defer os.Remove(testdata_main_k)
}

2. What did you expect to see? (Required)

yellow

3. What did you see instead (Required)

Got an error

json: cannot unmarshal string into Go value of type []map[string]interface {}

4. What is your KCL components version? (Required)

The main branch of kcl-go.

Import tool use wrong mode and generate schema with error

I want to import the following json schema:

{
	"$schema": "http://json-schema.org/draft-07/schema#",
	"$id": "https://example.com/schemas/book.json",
	"description": "This is a simple schema to validate a book in a package and you can use template variables with ${{ }}.",
	"type": "object",
	"properties": {
		"title": {
			"type": "string"
		}
	}
}

But error occurs if I don't specify mode.

expected 'package', found '{' (and 1 more errors)

So I specify the mode to import from jsonschema and I got the following result:

"""
This file was generated by the KCL auto-gen tool. DO NOT EDIT.
Editing this file might prove futile when you re-run the KCL auto-gen generate command.
"""
            	            	 
schema Book:
    """
    This is a simple schema to validate a book in a package and you can use template variables with ${{ }}.

    Attributes
    ----------
    title : str, optional
    """

    title?: str

I try to run it but get a error:

error[E1001]: InvalidSyntax
 --> /tmp/sandbox146949776/prog.k:8:105
  |
8 |     This is a simple schema to validate a book in a package and you can use template variables with ${{ }}.
  |                                                                                                         ^ expected one of ["}"] got eof
  |

feat: add version subcommand to print build info

Feature Request

Is your feature request related to a problem? Please describe:

kcl-go can not print tag version

Describe the feature you'd like:

kcl-go bulid-info print module build info

Describe alternatives you've considered:

Teachability, Documentation, Adoption, Migration Strategy:

[Bug] Import tool generates error data format.

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

main.yaml

name: Backport merged pull request
on:
  pull_request_target:
    types: [closed]
permissions:
  contents: write # so it can comment
  pull-requests: write # so it can create pull requests
jobs:
  backport:
    name: Backport pull request
    runs-on: ubuntu-latest
    # Don't run on closed unmerged pull requests
    if: github.event.pull_request.merged
    steps:
      - uses: actions/checkout@v3
      - name: Create backport pull requests
        uses: korthout/backport-action@v1

Run with the import tool

2. What did you expect to see? (Required)

The right KCL code

"""
This file was generated by the KCL auto-gen tool. DO NOT EDIT.
Editing this file might prove futile when you re-run the KCL auto-gen generate command.
"""

name = "Backport merged pull request"
on = {
    pull_request_target = {
        types = [
            "closed"
        ]
    }
}
permissions = {
    contents = "write"
    "pull-requests" = "write"
}
jobs = {
    backport = {
        name = "Backport pull request"
        "runs-on" = "ubuntu-latest"
        $if = "github.event.pull_request.merged"
        steps = [
            {
                uses = "actions/checkout@v3"
            }
            {
                name = "Create backport pull requests"
                uses = "korthout/backport-action@v1"
            }
        ]
    }
}

3. What did you see instead (Required)

The wrong KCL code

"""
This file was generated by the KCL auto-gen tool. DO NOT EDIT.
Editing this file might prove futile when you re-run the KCL auto-gen generate command.
"""

name = "Backport merged pull request"
on = {
    pull_request_target = {
        types = [
            "closed"
        ]
    }
}
permissions = {
    contents = "write"
    pull-requests = "write" # Lost ""
}
jobs = {
    backport = {
        name = "Backport pull request"
        runs-on = "ubuntu-latest"
        $if = "github.event.pull_request.merged"
        steps = [
            {
                uses = "actions/checkout@v3"
            }
            {
                name = "Create backport pull requests"
                uses = "korthout/backport-action@v1"
            }
        ]
    }
}

4. What is your KCL components version? (Required)

v0.7.0-alpha.2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.