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

feat: add a api for unifying the KCL cli #369

Closed
wants to merge 1 commit into from

Conversation

zong-zhe
Copy link
Contributor

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

  • N
  • Y

re #289

2. What is the scope of this PR (e.g. component or file name):

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Other

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other

@zong-zhe zong-zhe added the enhancement New feature or request label Jun 26, 2024
@zong-zhe zong-zhe requested a review from Peefy June 26, 2024 04:00
@zong-zhe zong-zhe self-assigned this Jun 26, 2024
}
}

func (c *KpmClient) Add(options ...AddOption) (*pkg.KclPkg, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can split this to some small functions.

return "", fmt.Errorf("no kcl module root path found")
}

func (source *Source) ToFilePath() (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use some abstract interfaces or factory methods to implement redundant if else code, improving the level of abstraction while avoiding bugs.

pkg/client/client.go Show resolved Hide resolved
pkg/client/client.go Show resolved Hide resolved

type AddOption func(*AddOptions) error

func WithNewPkgName(name string) AddOption {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add more docs and examples for public APIs.

}
}

if runtime.GOOS != "windows" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest use a new function for this judgment, e.g.,

func moveTmpDirToLocal


type PullOption func(*PullOptions) error

func WithPullSource(source *downloader.Source) PullOption {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add more docs and examples here.

pkg/client/run.go Show resolved Hide resolved
pkg/client/run.go Show resolved Hide resolved
pkg/client/run.go Show resolved Hide resolved
@zong-zhe zong-zhe changed the title [WIP] feat: add a api for unifying the KCL cli feat: add a api for unifying the KCL cli Jul 3, 2024
@coveralls
Copy link

coveralls commented Jul 3, 2024

Pull Request Test Coverage Report for Build 9778724044

Details

  • 307 of 1386 (22.15%) changed or added relevant lines in 16 files are covered.
  • 42 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-5.6%) to 38.592%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/cmd/cmd_push.go 0 1 0.0%
pkg/oci/oci.go 3 8 37.5%
pkg/downloader/downloader.go 25 34 73.53%
pkg/package/package.go 0 11 0.0%
pkg/cmd/cmd_run.go 0 12 0.0%
pkg/opt/opt.go 0 23 0.0%
pkg/client/visitor.go 85 113 75.22%
pkg/utils/utils.go 0 28 0.0%
pkg/client/pull.go 0 56 0.0%
pkg/client/client.go 46 103 44.66%
Files with Coverage Reduction New Missed Lines %
pkg/oci/oci.go 1 23.56%
pkg/cmd/cmd_run.go 2 0.0%
pkg/client/client.go 39 51.67%
Totals Coverage Status
Change from base Build 9576048206: -5.6%
Covered Lines: 2647
Relevant Lines: 6859

💛 - Coveralls

@zong-zhe zong-zhe marked this pull request as ready for review July 3, 2024 13:27
// MoveFile will move the file from 'src' to 'dest'.
// On windows, it will copy the file from 'src' to 'dest', and then delete the file under 'src'.
// On unix-like systems, it will rename the file from 'src' to 'dest'.
func MoveFile(src, dest string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this issue: #370

@@ -23,6 +23,11 @@ import (
type EntryKind string

// Entry is the entry of 'kpm run'.
// 一个编译入口,主要包括
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use English doc comments.

@@ -245,6 +245,6 @@ func TestGenSource(t *testing.T) {
src, err = GenSource("oci", "oci://ghcr.io/kcl-lang/k8s", "1.24")
assert.Equal(t, err, nil)
assert.Equal(t, src.Oci.Reg, "ghcr.io")
assert.Equal(t, src.Oci.Repo, "kcl-lang/k8s")
assert.Equal(t, src.Oci.Repo, "/kcl-lang/k8s")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add a / for oci.Repo and what's the spec of OCI reg and repo.

type RunOptions struct {
// CompileOptions is the options for kcl compiler.
hasSettingsYaml bool
SettingYamls []string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Settings

ro.Option = kcl.NewOption()
}
ro.hasSettingsYaml = true
ro.SettingYamls = settingFiles
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SettingYamls or SettingFiles?

}

// WithStrictRange sets the strict range flag for the kcl package.
func WithStrictRange(strictRange bool) RunOption {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WithStrictRangeCheck

}

// NoCompileEntries returns true if there is no compile entries.
func (o *RunOptions) NoCompileEntries() bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HasCompileEntries

}

// Merge merges the options from kcl.yaml which is located in the work directory or inputed by the cli.
func (o *RunOptions) loadYamlSettingsFromLocalAndCli(rootPath string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to know why you new so many names? SettingsYamls, YamlSettings, Settings, SettingFiles...

func (o *RunOptions) loadCliSettings(rootPath string, rootPkgSource *downloader.Source) error {
// If user input is empty, return error.
if o.NoCompileEntries() {
return ErrNoCliSettings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why no entris returns no cli settings err message...

}

// acquire the lock of the package cache.
err := c.AcquirePackageCacheLock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why lock here if we do not load deps from remote sources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Enhancement: kpm add command displaying optimization
3 participants