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

refactor: add loader to load kcl package #486

Closed
wants to merge 3 commits into from
Closed

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 #478

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 Sep 19, 2024
@zong-zhe zong-zhe self-assigned this Sep 19, 2024
@coveralls
Copy link

coveralls commented Sep 19, 2024

Pull Request Test Coverage Report for Build 10938239849

Details

  • 91 of 147 (61.9%) changed or added relevant lines in 3 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.4%) to 42.365%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/downloader/source.go 0 3 0.0%
pkg/client/client.go 36 49 73.47%
pkg/loader/loader.go 55 95 57.89%
Files with Coverage Reduction New Missed Lines %
pkg/client/client.go 1 59.34%
Totals Coverage Status
Change from base Build 10888425126: 0.4%
Covered Lines: 3532
Relevant Lines: 8337

💛 - Coveralls

@zong-zhe zong-zhe changed the title feat: add loader to load kcl package refactor: add loader to load kcl package Sep 19, 2024
Load(pkgPath string) (*pkg.KclPkg, error)
}

// PkgLoader is a struct that contains the settings.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove Loader, there is no need for additional complex structures, a function is enough.

)

var features = map[string]bool{
SupportMVS: false,
SupportMVS: false,
SupportPackageLoader: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use branch 'dev' to replace features gate

@@ -76,6 +79,7 @@ func NewKpmClient() (*KpmClient, error) {
logWriter: os.Stdout,
settings: *settings,
homePath: homePath,
PkgLoader: loader.NewFileLoader(settings),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove Pkgloader from client.


// Get dependencies from kcl.mod.lock.
deps, err := c.LoadLockDeps(pkgPath)
if ok, err := features.Enabled(features.SupportPackageLoader); err != nil && ok {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove feature gates, refactor is not feature

@@ -34,3 +34,7 @@ jobs:
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage.out
- name: Send coverage
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove un-used code.

HomePath: pkgPath,
Dependencies: *deps,
}, nil
return loader.Load(
Copy link
Contributor

Choose a reason for hiding this comment

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

Use Load.. functions in the package package.

@@ -0,0 +1,153 @@
package loader

import (
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use LoadModFile function instead of using a new LoadModFile function in the loader package.

@@ -58,6 +58,7 @@ func NewKclPkg(opts *opt.InitOptions) KclPkg {
}
}

// Deprecated: Use `KpmClient.LoadPkgFromPath()` instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the deprecated comment information.

@@ -1832,7 +1793,22 @@ func (c *KpmClient) DownloadDeps(deps *pkg.Dependencies, lockDeps *pkg.Dependenc

existDep, err := c.dependencyExistsLocal(pkghome, &d)
if existDep != nil && err == nil {

if d.GetPackage() != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

The start comment of the function should be DownloadDeps instead of downloadDeps

@zong-zhe zong-zhe closed this Sep 20, 2024
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