Skip to content

Unable to execute with just k_code_list #217

@maxstepanov

Description

@maxstepanov

I'm trying to execute KCL code that i have in a string using Python by passing it in k_code_list
KCL refuses with "No input KCL files or paths"
If empty file is specified using k_filename_list it works.
It doesn't look like k_filename_list should be required.

import kcl_lib.api as kcl
import sys
import traceback

try:
    args = kcl.ExecProgram_Args(k_code_list=['name = "hello"'])
#     args = kcl.ExecProgram_Args(k_filename_list=['base.k'], k_code_list=['name = "hello"'])

    result = kcl.API().exec_program(args)

    if result.err_message:
        print(f"KCL execution error: {result.err_message}")
    else:
        print("--- KCL SUCCESS ---")
        print(result.yaml_result)

except Exception as e:
    print(f"A Python exception occurred: {e}")
    traceback.print_exc(file=sys.stdout)

requirements.txt:

kcl-lib==0.11.0
    # via -r requirements.in
protobuf==6.31.1
    # via kcl-lib

Output:

A Python exception occurred: No input KCL files or paths
Traceback (most recent call last):
  File "/Users/user/src/kcl/some1.py", line 9, in <module>
    result = kcl.API().exec_program(args)
  File "/Users/user/src/kcl/.venv/lib/python3.9/site-packages/kcl_lib/api/service.py", line 140, in exec_program
    return self.call("KclvmService.ExecProgram", args)
  File "/Users/user/src/kcl/.venv/lib/python3.9/site-packages/kcl_lib/api/service.py", line 667, in call
    raise Exception(result.decode(encoding="utf-8").removeprefix("ERROR:"))
Exception: No input KCL files or paths

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions