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

How can you add a dependency with hyphens to a kcl package #141

Closed
ma-ble opened this issue Jun 15, 2024 · 8 comments
Closed

How can you add a dependency with hyphens to a kcl package #141

ma-ble opened this issue Jun 15, 2024 · 8 comments

Comments

@ma-ble
Copy link

ma-ble commented Jun 15, 2024

General Question

I would like to add the model "crossplane-provider-aws" to my package as a dependency so that I can get validation in my IDE.

kcl mod init my-package && cd my-package
kcl mod add crossplane-provider-aws

When I try to import the package,

import crossplane-provider-aws.v1beta1

I get an error saying that hyphens are not allowed in imports.

If I manually rename the folder in the download directory (/User/xxx/.kcl/kpm) - with underscores instead of hyphens - the import works as expected.

However, that certainly won't be the normal way, right?

@Peefy
Copy link
Contributor

Peefy commented Jun 17, 2024

cc @zong-zhe

@zong-zhe
Copy link
Collaborator

Hi @ma-ble 😄

Thanks for your feedback and help us find the omissions in the documentation work. I have explained this problem through PR kcl-lang/kcl-lang.io#389. I hope it will be helpful

@ma-ble
Copy link
Author

ma-ble commented Jun 18, 2024

Thank you very much for the answer and the adjustment of the documentation.
I'm currently having the problem that the customization doesn't work immediately after downloading the modules.

$ kcl mod init test && cd test
$ kcl mod add crossplane-provider-aws
  add dependency 'crossplane-provider-aws' successfully
$ kcl mod add crossplane-provider-azure
   add dependency 'crossplane-provider-azure' successfully
$ kcl mod add crossplane-provider-helm
  add dependency 'crossplane-provider-helm' successfully
import crossplane_provider_helm.v1alpha1 as helm
import crossplane_provider_aws.v1beta1 as aws
import crossplane_provider_azure.v1alpha1 as azure

pkgpath crossplane_provider_helm.v1alpha1 not found in the program(CannotFindModule). Cannot find the module crossplane_provider_helm.v1alpha1 from /Users/USERNAME/test/kcl/examples/test/crossplane_provider_helm/v1alpha1 not found in the program.

For AWS and Azure it also took a little longer until the error messages disappeared.

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

[dependencies]
crossplane-provider-kubernetes = { oci = "oci://ghcr.io/kcl-lang/crossplane-provider-kubernetes", tag = "0.9.0" }
crossplane-provider-aws = { oci = "oci://ghcr.io/kcl-lang/crossplane-provider-aws", tag = "0.36.2" }
crossplane-provider-azure = { oci = "oci://ghcr.io/kcl-lang/crossplane-provider-azure", tag = "0.20.0" }
crossplane-provider-helm = { oci = "oci://ghcr.io/kcl-lang/crossplane-provider-helm", tag = "0.13.0" }
kcl version
0.8.9-darwin-arm64

I use vscode as an IDE and I have the extension installed.

Can you force the conversion of the modules (hyphens to underscores)?

@zong-zhe
Copy link
Collaborator

Hi @ma-ble 😄

You can try to upgrade the KCL version to the 0.9.0 prefix using command go install kcl-lang.io/cli/cmd/kcl@main or manually download from here https://github.com/kcl-lang/cli?tab=readme-ov-file#download-from-github-release-page

@ma-ble
Copy link
Author

ma-ble commented Jun 18, 2024

I think I know the problem. Its because of the module dependencies. All three modules "crossplane-provider-aws, crossplane-provider-azure, crossplane-provider-helm" need the module k8s. Modul dependencies are not installed automatically and there is no automatic reuse if the module already exists on the computer.

@zong-zhe
Copy link
Collaborator

zong-zhe commented Jun 18, 2024

@ma-ble Thanks very much for your feedback, which helped us find some problems and will be very helpful for the future of KCL.

Let me provide you with some more detailed information. 😄

It is known that in version 0.8.9-darwin-arm64, the IDE cannot find the dependencies. This issue is fixed in PR kcl-lang/kpm#338.

Suppose you also encounter an error in the IDE that you cannot find the dependencies. In that case, you can try to compile using the command kcl run; if the command compiles properly, you have encountered the known problem I mentioned above.

You can try the two ways I mentioned above to upgrade kcl version in your local.

You can try to upgrade the KCL version to the 0.9.0 prefix using command go install kcl-lang.io/cli/cmd/kcl@main or manually download from here https://github.com/kcl-lang/cli?tab=readme-ov-file#download-from-github-release-page

or use the scripts here: https://www.kcl-lang.io/docs/user_docs/getting-started/install#using-script-to-install-the-latest-release

When downloading KCL's dependencies, KCL will give priority to checking whether a dependency already exists locally each time. If it does exist, it will recursively look for indirect dependencies. If it does not exist, it will re-download and reload indirect dependencies.

@ma-ble
Copy link
Author

ma-ble commented Jun 18, 2024

kcl run works as expected. No errors.

$ kcl --version
kcl version 0.9.0-beta.1

After updating to the 0.9.0 , 'kcl run' works as expected, and the dependencies are working.

When you install further dependencies without a specific version, the first kcl run does not find the dependency because it looks for "/Users/USERNAME/.kcl/kpm/crossplane-provider-kubernetes_latest".

$ ls /Users/USERNAME/.kcl/kpm/
crossplane-provider-kubernetes
crossplane-provider-kubernetes_
crossplane-provider-kubernetes_0.9.0

When you run the command kcl mod add crossplane-provider-kubernetes again, kcl run works.

@Peefy
Copy link
Contributor

Peefy commented Jul 3, 2024

Closed by kcl-lang/kcl-lang.io#389

@Peefy Peefy closed this as completed Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants