kcl-lang / kcl-go Goto Github PK
View Code? Open in Web Editor NEWKCL Go SDK
Home Page: https://pkg.go.dev/kcl-lang.io/kcl-go@main
License: Apache License 2.0
KCL Go SDK
Home Page: https://pkg.go.dev/kcl-lang.io/kcl-go@main
License: Apache License 2.0
The kcl code (test.k) is
print("hello world")
Expected:
$ kcl-go run test.k
hello world
I got:
{"code":-32603,"message":"bad response: 1"}
v0.4.7-0.20230413075310-38a48b691fe2
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:
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:
Please answer these questions before submitting your issue. Thanks!
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>/...
test pass
err occurred: FAIL <dir> err: reflect.Set: value of type *ast.Identifier is not assignable to type ast.TypeInterface%
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
current github action only include Go 1.17,
check should include Go 1.18 and Go tip version
Native KCL api ParseFile
method returns rust panicked error.
Test for reproduce: https://github.com/bozaro/kcl-parse-file-issue/blob/master/kcl_parse_file_issue_test.go
git clone https://github.com/bozaro/kcl-parse-file-issue.git .
go test -v .
I expect to see same result for native and service tests.
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
kcl-lang.io/kcl-go v0.8.1
Please answer these questions before submitting your issue. Thanks!
The input json schema config: https://github.com/kcl-lang/modules/blob/main/github-workflow/jsonschema/github-workflow.json
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.
The wrong type annotations
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.
kcl-go v0.7.1
Please answer these questions before submitting your issue. Thanks!
restfull method ListDepFiles
use -use-fast-parser
to speed up for single app
but the kcl-Go list-app do not support -use-fast-parser
command options
kcl-Go list-app should support -use-fast-parser
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
https://github.com/KusionStack/kclvm-go/releases/tag/v0.4.2-alpha.8
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"
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:
The following commands can be used directly
a = 1
$ go install kusionstack.io/kclvm-go@latest
$ kcl-go run a.k
a: 1
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.
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:
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)
clearer distinction between attributes in the generated docs:
Now the boundaries between attrs are not very clear making it difficult to distinguish and search.
Please answer these questions before submitting your issue. Thanks!
go install kcl-lang.io/kcl-go/cmds/kcl-go@main
kcl-go rest-server
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
curl -X POST \
http://127.0.0.1:2021/api:protorpc/KclvmService.ValidateCode \
-H "accept: application/json" \
--data @./vet-hello.json
{
"error": "",
"result": {
"success": true
}
}
{
"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
}
➜ kcl-go -v
kcl-go version v0.5.0
➜ kcl -V
Version: 0.5.0-20ab3eb4b9179219d6837a57f5d35286
Platform: aarch64-apple-darwin
GitCommit: 64401faf2d588260d23d1f06b8209a00472e3298
Please answer these questions before submitting your issue. Thanks!
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
....
Small changes in memory usage
memory leak
https://github.com/KusionStack/kclvm-go/releases/tag/v0.4.2-alpha.8
Please answer these questions before submitting your issue. Thanks!
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))
}
The_first_kcl_program: Hello World!
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
kusionstack.io/kclvm-go v0.5.0-alpha.3
Please answer these questions before submitting your issue. Thanks!
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"
]
}
The right KCL schema output
"""
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
KCL v0.7.0 version
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:
Please answer these questions before submitting your issue. Thanks!
git clone https://github.com/KusionStack/konfig.git
cd konfig/appops/wordpress/dev
kcl-go list-app --include-all --show-index=false --info=false
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
.......
package manifests: no kcl file
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
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.
"""
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>
"""
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>{
# ...
}
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 package document is the home page of the package, which contains three chapters: README, Documentation and Source Files.
## 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)
## 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)
Please answer these questions before submitting your issue. Thanks!
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}}"
"""
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}}"
]
}
]
"""
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}}"]
}
]
kcl-go v0.6.1
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
Please answer these questions before submitting your issue. Thanks!
OS: ubuntu:20.04
python version: 3.9.10
run command : go test -run ^TestFormatPath$ kusionstack.io/kclvm-go/pkg/tools/format
Go test succeeded
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:
v0.4.4-alpha.2
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
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:
UseKCLPluginEnvVar
, LibHomeEnvVar
and DisableArtifactEnvVar
into actual bool values to be set at build time, instead of variable names intended for runtime usage.{configurable_prefix}/{configurable_path}/<shared_lib_file>
(usually /usr/lib) instead of {libHome}/bin/<shared_lib_file>
# 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
Please answer these questions before submitting your issue. Thanks!
run github workflow build-and-test-windows
all tests should pass
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
Please answer these questions before submitting your issue. Thanks!
kcl --help
的输出的信息中提到 -Y
应该接受一个列表
但是 sdk 中,kcl.WithSettings
的逻辑是覆盖,并不是合并,两者逻辑不一致
kclvm version is 0.4.4; checksum: c5339e572207211e46477825e8aca903
For the following YAML
a-b-c: a-b-c
The import tool should generate the following code
{
"a-b-c" = "a-b-c"
}
Instead of
"a-b-c" = "a-b-c"
This is because the current version of KCL does not support the syntax mentioned in the above code.
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:
Please answer these questions before submitting your issue. Thanks!
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
The YAML output:
obj:
spec:
replicas: 2
status:
replicas: 2
The YAML output:
obj: '{"spec":{"replicas":2},"status":{"replicas":2}}'
kclvm version is 0.4.4; checksum: c5339e572207211e46477825e8aca903
That will be helpful to navigate from schema and its usages to get an overview of a schema
Please answer these questions before submitting your issue. Thanks!
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()
down stream files should be:
[]string{"base/frontend/not_exist.k", "base/frontend/not_exist", "appops/projectD/base/base.k", "appops/projectD/base"}
the program returns file not exist error
kusion: v0.3.22-alpha.12
kclvm-go: v0.4.2-alpha2
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
type validation struct {
Name string
Minimum *float64
ExclusiveMinimum bool
Maximum *float64
ExclusiveMaximum bool
MinLength *int
MaxLength *int
Regex *regexp.Regexp
MultiplyOf *int
Unique bool
}
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
}
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
the KCL doc spec is detailed defined in: #156
Attribute names, types and descriptions in docstring can be highlighted at the semantic level to improve docstring readability. Here's a good example:
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:
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:
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. :
Here's a demo:
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.
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:
Jump from the attribute name in the docstring to the attribute definition and vice versa.
A good example:
Integrated CICD pipeline in the model library
See also: kcl-lang/kcl-lang.io#256
Please answer these questions before submitting your issue. Thanks!
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)
}
yellow
Got an error
json: cannot unmarshal string into Go value of type []map[string]interface {}
The main
branch of kcl-go.
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
|
Currently the script only support read md5sum from github url,
if the github can not access, read md5sum will fail.
provide api to export openapi from kcl package
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:
program CI needs a coverage check to guarantee pass quality, for example, modified code should have a >95 coverage
Please answer these questions before submitting your issue. Thanks!
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
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"
}
]
}
}
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"
}
]
}
}
v0.7.0-alpha.2
Go SDK should support develop kcl plugin with Go
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.