Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
  • Loading branch information
AkashKumar7902 committed Feb 18, 2024
1 parent 72b51bc commit 4ff8af0
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 20 deletions.
5 changes: 0 additions & 5 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,6 @@ func (c *KpmClient) Compile(kclPkg *pkg.KclPkg, kclvmCompiler *runner.Compiler)
kclvmCompiler.AddDepPath(dName, dPath)
}

kclPkg.UpdatePkgEdition(kclvmCompiler.GetKclVersion())
if err := kclPkg.ModFile.StoreModFile(); err != nil {
return nil, err
}

return kclvmCompiler.Run()
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestInitEmptyPkg(t *testing.T) {
assert.Equal(t, err, nil)
assert.Equal(t, testKclPkg.ModFile.Pkg.Name, "test_name")
assert.Equal(t, testKclPkg.ModFile.Pkg.Version, "0.0.1")
assert.Equal(t, testKclPkg.ModFile.Pkg.Edition, "0.0.1")
assert.Equal(t, testKclPkg.ModFile.Pkg.Edition, runner.GetKclVersion())
}

func TestUpdateKclModAndLock(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/test_data/expected/kcl.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "test_add_deps"
edition = "0.0.1"
edition = "v0.7.0"
version = "0.0.1"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/test_data/expected/kcl.reverse.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "test_add_deps"
edition = "0.0.1"
edition = "v0.7.0"
version = "0.0.1"

[dependencies]
Expand Down
3 changes: 2 additions & 1 deletion pkg/package/modfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"kcl-lang.io/kcl-go/pkg/kcl"
"kcl-lang.io/kpm/pkg/opt"
"kcl-lang.io/kpm/pkg/reporter"
"kcl-lang.io/kpm/pkg/runner"
"kcl-lang.io/kpm/pkg/settings"
"kcl-lang.io/kpm/pkg/utils"
)
Expand Down Expand Up @@ -315,7 +316,7 @@ func (mfile *ModFile) GetModLockFilePath() string {
}

const defaultVerion = "0.0.1"
const defaultEdition = "0.0.1"
var defaultEdition = runner.GetKclVersion()

func NewModFile(opts *opt.InitOptions) *ModFile {
return &ModFile{
Expand Down
3 changes: 2 additions & 1 deletion pkg/package/modfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/stretchr/testify/assert"
"kcl-lang.io/kpm/pkg/opt"
"kcl-lang.io/kpm/pkg/runner"
"kcl-lang.io/kpm/pkg/utils"
)

Expand Down Expand Up @@ -81,7 +82,7 @@ func TestModFileExists(t *testing.T) {
}

NewModFile, err := LoadModFile(testDir)
if err != nil || NewModFile.Pkg.Name != "test_kcl_pkg" || NewModFile.Pkg.Version != "0.0.1" || NewModFile.Pkg.Edition != "0.0.1" {
if err != nil || NewModFile.Pkg.Name != "test_kcl_pkg" || NewModFile.Pkg.Version != "0.0.1" || NewModFile.Pkg.Edition != runner.GetKclVersion() {
t.Errorf("test 'LoadModFile' failed.")
}
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/package/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ func (kclPkg *KclPkg) UpdateModAndLockFile() error {
return nil
}

// update compile edition of package
func (kclPkg *KclPkg) UpdatePkgEdition(newEdition string) {
kclPkg.ModFile.Pkg.Edition = newEdition
}

// LockDepsVersion locks the dependencies of the current kcl package into kcl.mod.lock.
func (kclPkg *KclPkg) LockDepsVersion() error {
fullPath := filepath.Join(kclPkg.HomePath, MOD_LOCK_FILE)
Expand Down
3 changes: 2 additions & 1 deletion pkg/package/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"kcl-lang.io/kpm/pkg/env"
"kcl-lang.io/kpm/pkg/opt"
"kcl-lang.io/kpm/pkg/reporter"
"kcl-lang.io/kpm/pkg/runner"
"kcl-lang.io/kpm/pkg/utils"
)

Expand Down Expand Up @@ -47,7 +48,7 @@ func TestLoadKclPkg(t *testing.T) {
}
assert.Equal(t, kclPkg.ModFile.Pkg.Name, "test_name")
assert.Equal(t, kclPkg.ModFile.Pkg.Version, "0.0.1")
assert.Equal(t, kclPkg.ModFile.Pkg.Edition, "0.0.1")
assert.Equal(t, kclPkg.ModFile.Pkg.Edition, runner.GetKclVersion())
assert.Equal(t, len(kclPkg.ModFile.Dependencies.Deps), 0)
assert.Equal(t, len(kclPkg.Dependencies.Deps), 0)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ func (compiler *Compiler) AddDepPath(depName string, depPath string) *Compiler {
return compiler
}

func (compiler *Compiler) GetKclVersion() string {
return string(scripts.KclvmVersionType_latest)
}

// Call KCL Compiler and return the result.
func (compiler *Compiler) Run() (*kcl.KCLResultList, error) {
return kcl.RunWithOpts(*compiler.opts.Option)
}

func GetKclVersion() string {
return string(scripts.KclvmVersionType_latest)
}

0 comments on commit 4ff8af0

Please sign in to comment.