kcl-lang / cli

The KCL Command Line Interface (CLI).
https://kcl-lang.io
Apache License 2.0
19 stars 14 forks source link

kcl run command fails to resolve relative paths listed in a settings file #118

Closed Fdall closed 3 months ago

Fdall commented 3 months ago

Bug Report

1. Minimal reproduce step (Required)

Use the documentation example in https://www.kcl-lang.io/docs/user_docs/support/faq-cli#2-how-to-input-dynamic-options-how-to-get-dynamic-options-in-code

kcl_bug/file1.k

env = option("env-type")
deploy_topology = option("deploy-topology")

kcl_bug/settings.yaml

kcl_cli_configs:
  files:
    - file1.k
kcl_options:
  - key: env-type
    value: TEST
  - key: deploy-topology
    value:
      - cluster: my-cluster
        idc: my-idc
        replicas: 2
        workspace: my-workspace
        zone: my-zone

While inside the directory kcl_bug, the following command succeeds:

kcl run -Y settings.yaml

But if run using the absolute path of the settings file, from a directory that is not kcl_bug the command fails with:

Cannot find the kcl file, please check the file path file1.k

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

The same setup works with any KCL release prior to the 0.9.X. The relative path of files listed in the settings file should be resolved from the settings file and not from the user shell workdir.

3. What did you see instead (Required)

But if run using the absolute path of the settings file, from a directory that is not kcl_bug the command fails with:

Cannot find the kcl file, please check the file path file1.k

It seems that the files listed in the settings file are resolved from the workdir of the shell and not from the the settings file itself. I could not find any CLI option to configure the 'root' folder from which the paths are resolved.

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

kcl version 0.9.1 -> not working kcl version 0.8.9 -> working

Peefy commented 3 months ago

cc @zong-zhe Could you help check this break?

zong-zhe commented 3 months ago

Hi @Fdall πŸ˜ƒ

This issue was a bug that incorrectly set the current working directory to the location of the settings.yaml file, which we fixed in https://github.com/kcl-lang/kcl-go/pull/314.

more details: https://github.com/kcl-lang/kpm/issues/320#issuecomment-2125362110

Fdall commented 3 months ago

Hi @zong-zhe,

Thank you for the quick answer :+1:

We are currently only using the kcl CLI component, is there a way to make the compilation process "workdir independant" at the moment using some options or other kcl related components?

We have different internal config repositories managed by kcl and each can be generated in different "flavors" based on settings file. To illustrate, the structure looks like this:

β”œβ”€β”€ kcl
β”‚Β Β  β”œβ”€β”€ moduleA
β”‚Β Β  β”œβ”€β”€ moduleB
β”‚Β Β  └── moduleC
└── targets
    β”œβ”€β”€ settings1.yaml # refering to several files in the kcl folder + CLI options
    └── settings2.yaml

Having to strictly ensure the shell workdir from which the run command is executed is manageable but a bit bothersome.

Peefy commented 3 months ago

Closed by https://github.com/kcl-lang/kpm/pull/440 and released in KCL CLI v0.9.7

Fdall commented 3 months ago

Awesome :+1: Just tested it, it works as I expected it to in my initial post. You can close the issue