kcl-lang / kpm

KCL Package Manager
https://kcl-lang.io
Apache License 2.0
27 stars 44 forks source link

Enhancement : Supports adding third-party dependencies from git repo with the `version` field #266

Open zong-zhe opened 7 months ago

zong-zhe commented 7 months ago

This issue comes from the preceding https://github.com/kcl-lang/kpm/issues/190 The content in the above issue https://github.com/kcl-lang/kpm/issues/190 is outdated, so add some more detail to this issue.

Related PR: https://github.com/kcl-lang/kpm/pull/254

Context

KPM currently supports adding third-party dependencies from git repositories as dependencies, mainly supporting through tags or commits from the git repository.

You can use command as below to add a kcl package from git repo

kcl mod add --git https://github.com/KusionStack/catalog.git --commit a29e3db

Then you will see the below content added in kcl.mod

[dependencies]
catalog = { git = "https://github.com/KusionStack/catalog.git", commit = "a29e3db" }

or

You can use command as below to add a kcl package from git repo

kcl mod add --git https://github.com/KusionStack/catalog.git --tag 0.1.0

Then you will see the below content added in kcl.mod

[dependencies]
catalog = { git = "https://github.com/KusionStack/catalog.git", tag = “0.1.0” }

Referring to the implementation of Cargo in Rust, we hope to support adding dependencies from git repositories with the version of kcl package.

Feature

  1. If you add a dependency using the following command,

    kcl mod add --git https://github.com/KusionStack/catalog.git --commit a29e3db

    Then the following content will appear in your kcl.mod file, because the version field in the kcl.mod of the KCL package corresponding to commit a29e3db is 0.1.1.

    [dependencies]
    catalog = { git = "https://github.com/KusionStack/catalog.git", commit = “a29e3db”, version = “0.1.1” }
  2. If you add a dependency using the following command,

    kcl mod add --git https://github.com/KusionStack/catalog.git --tag 0.0.2

    Then the following content will appear in your kcl.mod file, because the version field in the kcl.mod of the KCL package corresponding to tag 0.0.2 is 0.1.1.

    [dependencies]
    catalog = { git = "https://github.com/KusionStack/catalog.git", tag=“0.0.2”, version = “0.1.1” }
  3. If you manually write the kcl.mod file as follows,

    [dependencies]
    catalog = { git = "https://github.com/KusionStack/catalog.git", tag=“0.0.3”, version = “0.1.1” }

    But the version field in the kcl.mod of the KCL package corresponding to tag 0.0.3 is 0.0.1, i.e., version 0.1.1 does not exist in the KCL package with tag 0.0.3. Then, during the process of compiling or updating KCL third-party libraries that trigger the re-download of third-party libraries, an error should be thrown to notify the user that this third-party library with version 0.1.1 does not exist in the repo with tag 0.0.3.

AkashKumar7902 commented 6 months ago

@Peefy please assign me this issue

Peefy commented 6 months ago

@AkashKumar7902 Thank you for the contribution. ❤️

vinayakjaas commented 2 months ago

Hey @zong-zhe @Peefy I'd like to work on this issue, but I see there's still ongoing work. If any tasks are left to be completed, please let me know so I can move forward with this issue.

Peefy commented 2 months ago

Hello @vinayakjaas

This is an unfinished feature, I assigned it to you, good luck! ❤️

Manoramsharma commented 2 months ago

@vinayakjaas, can you please pass this issue to me? I saw that you are working on another issue, and I have already worked with Git dependencies in one of my PRs.

vinayakjaas commented 2 months ago

Hey @Manoramsharma I started planning to work on this issue , but if you want to take over and move forward with it, that's okay no problem at all.

Manoramsharma commented 2 months ago

Thanks @vinayakjaas I already have a draft PR in mind that would possibly solve this issue .

I would like get this assigned @Peefy

Manoramsharma commented 2 months ago

Hi @Gmin2 I think your changes in pkg/package/toml.go and pkg/package/modfile.go were not required as this would not have solved the parsing of version to dependencies struct from the corresponding mod files. Rather directly setting it as a a value here sourceWithoutBrace += fmt.Sprintf(, version = "%s", dep.Version) which is not an ideal approach.