Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: add '-E/--external' to api. #567

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions internal/spec/gpyrpc/gpyrpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import "google/protobuf/descriptor.proto";

// ----------------------------------------------------------------------------

// kcl main.k -E pkg_name=pkg_path
message CmdExternalPkgSpec {
string pkg_name = 1;
string pkg_path = 2;
}

// kcl main.k -D name=value
message CmdArgSpec {
string name = 1;
Expand Down Expand Up @@ -140,6 +146,9 @@ message ExecProgram_Args {
bool sort_keys = 12;
// include schema type path in JSON/YAML result
bool include_schema_type_path = 13;

// -E --external : external packages path
repeated CmdExternalPkgSpec external_pkgs = 14;
}
message ExecProgram_Result {
string json_result = 1;
Expand Down
10 changes: 10 additions & 0 deletions kclvm/api/src/capi_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ fn test_c_api_call_exec_program() {
);
}

#[test]
fn test_c_api_call_exec_program_with_external_pkg() {
test_c_api::<ExecProgramArgs, ExecProgramResult, _>(
"KclvmService.ExecProgram",
"exec-program-with-external-pkg.json",
"exec-program-with-external-pkg.response.json",
|res| res.escaped_time = "0".to_owned(),
);
}

#[test]
fn test_c_api_call_override_file() {
test_c_api_without_wrapper::<OverrideFileArgs, OverrideFileResult>(
Expand Down
12 changes: 12 additions & 0 deletions kclvm/api/src/testdata/exec-program-with-external-pkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"work_dir" : "./src/testdata",
"k_filename_list":[
"hello_import.k"
],
"external_pkgs": [
{
"pkg_name": "external",
"pkg_path": "./src/testdata/external"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"json_result": "[{\"a\": \"Hello External World!\"}]",
"yaml_result": "a: Hello External World!",
"escaped_time": "0.002061128616333008"
}
6 changes: 6 additions & 0 deletions kclvm/api/src/testdata/external/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "external"
edition = "0.0.1"
version = "0.0.1"

[dependencies]
1 change: 1 addition & 0 deletions kclvm/api/src/testdata/external/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a = 'Hello External World!'
2 changes: 2 additions & 0 deletions kclvm/api/src/testdata/hello_import.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import external as ext
a = ext.a