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

fix: fix the module not found when run with '--no_sum_check' #235

Merged
merged 2 commits into from
Dec 25, 2023
Merged
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
13 changes: 13 additions & 0 deletions pkg/api/kpm_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,16 @@ func TestRunPkgWithOpts(t *testing.T) {
expectedJson, _ := os.ReadFile(filepath.Join(pkgPath, "expected.json"))
assert.Equal(t, utils.RmNewline(string(result.GetRawJsonResult())), utils.RmNewline(string(expectedJson)))
}

func TestRunWithOptsAndNoSumCheck(t *testing.T) {
pkgPath := getTestDir("test_run_pkg_in_path")

res, err := RunWithOpts(
opt.WithNoSumCheck(true),
opt.WithEntries([]string{filepath.Join(pkgPath, "test_run_no_sum_check", "main.k")}),
opt.WithKclOption(kcl.WithWorkDir(filepath.Join(pkgPath, "test_run_no_sum_check"))),
)
assert.Equal(t, err, nil)
assert.Equal(t, res.GetRawYamlResult(), "a: Hello World!")
assert.Equal(t, err, nil)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "test_catalog"
edition = "0.0.1"
version = "0.0.1"

[dependencies]
helloworld = "0.1.1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import helloworld as hw

a = hw.The_first_kcl_program
7 changes: 7 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ func (c *KpmClient) ResolvePkgDepsMetadata(kclPkg *pkg.KclPkg, update bool) erro
// If under the mode of '--no_sum_check', the checksum of the package will not be checked.
// There is no kcl.mod.lock, and the dependencies in kcl.mod and kcl.mod.lock do not need to be aligned.
if !c.noSumCheck {
// If not under the mode of '--no_sum_check',
// all the dependencies in kcl.mod.lock are the dependencies of the current package.
//
// alian the dependencies between kcl.mod and kcl.mod.lock
// clean the dependencies in kcl.mod.lock which not in kcl.mod
// clean the dependencies in kcl.mod.lock and kcl.mod which have different version
Expand All @@ -204,6 +207,10 @@ func (c *KpmClient) ResolvePkgDepsMetadata(kclPkg *pkg.KclPkg, update bool) erro
kclPkg.Dependencies.Deps[name] = d
}
}
} else {
// If under the mode of '--no_sum_check', the checksum of the package will not be checked.
// All the dependencies in kcl.mod are the dependencies of the current package.
kclPkg.Dependencies.Deps = kclPkg.ModFile.Dependencies.Deps
Peefy marked this conversation as resolved.
Show resolved Hide resolved
}

for name, d := range kclPkg.Dependencies.Deps {
Expand Down
Loading