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

Enhancement: The feature renaming dependency is incomplete #420

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/api/test_data/store_mod_and_lock/dep1_0.0.1/kcl.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ edition = "0.0.1"
version = "0.0.1"

[dependencies]
dep1 = { oci = "oci://ghcr.io/kcl-lang/dep1", tag = "0.0.1" }
dep1 = { oci = "oci://ghcr.io/kcl-lang/dep1", tag = "0.0.1" }
1 change: 1 addition & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ func (c *KpmClient) AddDepWithOpts(kclPkg *pkg.KclPkg, opt *opt.AddOptions) (*pk
return nil, fmt.Errorf("dependency '%s' not found in 'kcl.mod'", d.Name)
}
tempDeps.Name = opt.NewPkgName
tempDeps.Package = d.Name
kclPkg.ModFile.Dependencies.Deps.Set(d.Name, tempDeps)

// update the kcl.mod.lock with NewPkgName
Expand Down
24 changes: 15 additions & 9 deletions pkg/client/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -11,7 +12,11 @@ import (
)

func TestPull(t *testing.T) {
pulledPath := getTestDir("test_pull")
tmpDir, err := ioutil.TempDir("", "test_pull")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpDir)

kpmcli, err := NewKpmClient()
assert.NilError(t, err)
Expand All @@ -20,7 +25,7 @@ func TestPull(t *testing.T) {
kpmcli.SetLogWriter(&buf)

kPkg, err := kpmcli.Pull(
WithLocalPath(pulledPath),
WithLocalPath(tmpDir),
WithPullSource(&downloader.Source{
Oci: &downloader.Oci{
Reg: "ghcr.io",
Expand All @@ -30,24 +35,25 @@ func TestPull(t *testing.T) {
}),
)

pkgPath := filepath.Join(pulledPath, "oci", "ghcr.io", "kcl-lang", "helloworld", "0.0.1")
pkgPath := filepath.Join(tmpDir, "oci", "ghcr.io", "kcl-lang", "helloworld", "0.0.1")
assert.NilError(t, err)
assert.Equal(t, kPkg.GetPkgName(), "helloworld")
assert.Equal(t, kPkg.GetPkgVersion(), "0.0.1")
assert.Equal(t, kPkg.HomePath, pkgPath)

kPkg, err = kpmcli.Pull(
WithLocalPath(pulledPath),
WithLocalPath(tmpDir),
WithPullSourceUrl("oci://ghcr.io/kcl-lang/helloworld?tag=0.1.0"),
)
pkgPath = filepath.Join(pulledPath, "oci", "ghcr.io", "kcl-lang", "helloworld", "0.1.0")
pkgPath = filepath.Join(tmpDir, "oci", "ghcr.io", "kcl-lang", "helloworld", "0.1.0")
assert.NilError(t, err)
assert.Equal(t, kPkg.GetPkgName(), "helloworld")
assert.Equal(t, kPkg.GetPkgVersion(), "0.1.0")
assert.Equal(t, kPkg.HomePath, pkgPath)

defer func() {
err = os.RemoveAll(filepath.Join(pulledPath, "oci"))
assert.NilError(t, err)
}()
// Handle cleanup within the same filesystem
err = os.RemoveAll(filepath.Join(tmpDir, "oci"))
if err != nil {
t.Errorf("Failed to remove directory: %v", err)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ edition = "0.0.1"
version = "0.0.1"

[dependencies]
flask-demo-kcl-manifests = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git", commit = "ade147b" }
flask-demo-kcl-manifests = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git", commit = "ade147b", package = "flask-demo-kcl-manifests" }
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
name = "flask-demo-kcl-manifests"
full_name = "flask_manifests_0.0.1"
version = "0.0.1"
package = "flask-demo-kcl-manifests"
url = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git"
commit = "ade147b"
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ edition = "0.0.1"
version = "0.0.1"

[dependencies]
flask-demo-kcl-manifests = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git", commit = "ade147b" }
flask-demo-kcl-manifests = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git", commit = "ade147b", package = "flask-demo-kcl-manifests" }
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
name = "flask-demo-kcl-manifests"
full_name = "flask_manifests_0.0.1"
version = "0.0.1"
package = "flask-demo-kcl-manifests"
url = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git"
commit = "ade147b"
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ version = "0.0.1"

[dependencies]
dep_pkg = { path = "../dep_pkg" }
helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.2" }
helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.2", package = "helloworld" }
4 changes: 2 additions & 2 deletions pkg/client/test_data/expected/kcl.reverse.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ edition = "v0.10.0"
version = "0.0.1"

[dependencies]
name = { git = "test_url", tag = "test_tag" }
oci_name = { oci = "oci://test_reg/test_repo", tag = "test_tag" }
name = git = "test_url", tag = "test_tag"
oci_name = oci = "oci://test_reg/test_repo", tag = "test_tag"
3 changes: 1 addition & 2 deletions pkg/client/test_data/test_data_add_deps/kcl.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ version = "0.0.1"

[dependencies]
oci_name = { oci = "oci://test_reg/test_repo", tag = "test_tag" }
name = { git = "test_url", tag = "test_tag" }

name = { git = "test_url", tag = "test_tag" }
4 changes: 2 additions & 2 deletions pkg/client/test_data/test_dep_order/expect.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ edition = "v0.10.0"
version = "0.0.1"

[dependencies]
helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.2" }
jsonpatch = { oci = "oci://ghcr.io/kcl-lang/jsonpatch", tag = "0.0.5" }
helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.2", package = "helloworld" }
jsonpatch = { oci = "oci://ghcr.io/kcl-lang/jsonpatch", tag = "0.0.5", package = "jsonpatch" }

[profile]
entries = ["./sub/main.k"]
4 changes: 2 additions & 2 deletions pkg/client/test_data/test_dep_order/kcl.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ edition = "v0.10.0"
version = "0.0.1"

[dependencies]
helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.2" }
jsonpatch = { oci = "oci://ghcr.io/kcl-lang/jsonpatch", tag = "0.0.5" }
helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.2", package = "helloworld" }
jsonpatch = { oci = "oci://ghcr.io/kcl-lang/jsonpatch", tag = "0.0.5", package = "jsonpatch" }

[profile]
entries = ["./sub/main.k"]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ edition = "v0.10.0"
version = "0.0.1"

[dependencies]
helloworld = { oci = "oci://ghcr.io/zong-zhe/helloworld", tag = "0.0.3" }
helloworld = { oci = "oci://ghcr.io/zong-zhe/helloworld", tag = "0.0.3", package = "helloworld" }
3 changes: 2 additions & 1 deletion pkg/client/test_data/test_oci_downloader/add_dep/pkg/kcl.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ edition = "v0.10.0"
version = "0.0.1"

[dependencies]
helloworld = { oci = "oci://ghcr.io/zong-zhe/helloworld", tag = "0.0.3" }
helloworld = { oci = "oci://ghcr.io/zong-zhe/helloworld", tag = "0.0.3", package = "helloworld" }

Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ edition = "v0.10.0"
version = "0.0.1"

[dependencies]
helloworld = { oci = "oci://ghcr.io/zong-zhe/helloworld", tag = "0.0.3" }
helloworld = { oci = "oci://ghcr.io/zong-zhe/helloworld", tag = "0.0.3", package = "helloworld" }
1 change: 1 addition & 0 deletions pkg/package/modfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ type Dependency struct {
FullName string `json:"-" toml:"full_name,omitempty"`
Version string `json:"-" toml:"version,omitempty"`
Sum string `json:"-" toml:"sum,omitempty"`
Package string `json:"-" toml:"package,omitempty"`
// The actual local path of the package.
// In vendor mode is "current_kcl_package/vendor"
// In non-vendor mode is "$KCL_PKG_PATH"
Expand Down
4 changes: 4 additions & 0 deletions pkg/package/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ const DEP_PATTERN = "%s = %s"
func (dep *Dependency) MarshalTOML() string {
source := dep.Source.MarshalTOML()
var sb strings.Builder
if len(dep.Package) != 0 {
Manoramsharma marked this conversation as resolved.
Show resolved Hide resolved
source = source[:len(source)-2] + fmt.Sprintf(", package = \"%s\" }", dep.Package)
}

if len(source) != 0 {
sb.WriteString(fmt.Sprintf(DEP_PATTERN, dep.Name, source))
}
Expand Down
Loading