kcl-lang / kcl

KCL Programming Language (CNCF Sandbox Project). https://kcl-lang.io
https://kcl-lang.io
Apache License 2.0
1.7k stars 119 forks source link

[Bug] Import of modules containing "-" fails #1261

Closed dennybaa closed 6 months ago

dennybaa commented 6 months ago

Hi there, I've bumped into inability to use hosted modules from artifactshub in case if they contain dash "-" character.

1. Minimal reproduce step (Required)

Let's suppose the following directory structure:

├── appsops
│   └── rules
│       ├── dev
│       │   ├── kcl.yaml
│       │   ├── main.k
│       └── iaas-prod
├── kcl.mod
├── kcl.mod.lock
├── pkg
│   ├── rules.k

Namely the import statement is located in the rule.k file which is in turn imported from main.k triggered by kcl.yaml.

Sample rules.k contents:

# import victoria_metrics_operator.v1beta1.operator_victoriametrics_com_v1beta1_vm_rule as vmrule
import k8s.apimachinery.pkg.apis.meta.v1

# k = vmrule.OperatorVictoriametricsComV1beta1VMRuleSpecGroupsItems0RulesItems0 {alert = "hello"}
v = v1.ObjectMeta {name = "hello"}

In case a module doesn't have any dashes such as k8s everything works smooth whereas importing victoria_metrics_operator doesn't work. Error message:

8 | k = vmrule.OperatorVictoriametricsComV1beta1VMRuleSpecGroupsItems0RulesItems0 {alert = "hello"}
  |     ^ Invalid schema type 'any'

It's odd, but if we place the same dashed import on the level with kcl.mod into say it a.k file, and simply invoke kcl a.k this scenario is operable.

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

"0.8.6"

Peefy commented 6 months ago

Hello. Thanks for the feedback. Could you please show me the content of kcl.mod? I will double check it.

dennybaa commented 6 months ago

Yep, sure @Peefy

[package]
name = "some-test"
edition = "v0.8.0"
version = "0.0.1"

[dependencies]
k8s = { oci = "oci://ghcr.io/kcl-lang/k8s", tag = "1.28" }
victoria-metrics-operator = { oci = "oci://ghcr.io/kcl-lang/victoria-metrics-operator", tag = "0.0.1" }

And for the whole picture kcl.yaml which is:

kcl_cli_configs:
  files:
    - main.k
Peefy commented 6 months ago

Thank you! I will fix it and release a new version today.

dennybaa commented 6 months ago

Also just an idea which seems pretty much as another issue... To brush up modules import behavior. By this I mean, even if there's no dependency in kcl.mod, the module if available in cache (~/.kcl/kpm) is silently imported which seems not unambiguous.

dennybaa commented 6 months ago

Thank you too! It's a pleasure to work with KCL language.

Peefy commented 6 months ago

Also just an idea which seems pretty much as another issue... To brush up modules import behavior. By this I mean, even if there's no dependency in kcl.mod, the module if available in cache (~/.kcl/kpm) is silently imported which seems not unambiguous.

Thank you, I will fix it together.

Peefy commented 6 months ago

Closed by https://github.com/kcl-lang/cli/pull/73 and https://github.com/kcl-lang/kpm/pull/309