-
Notifications
You must be signed in to change notification settings - Fork 47
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
sparse checkout feature - Load the package after downloading the entire repository #452
Closed
officialasishkumar
wants to merge
4
commits into
kcl-lang:main
from
officialasishkumar:sparse-checkout-repo
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
32ddefb
sparse checkout feature
officialasishkumar 88ba144
define subpackage internally
officialasishkumar aaa4610
search for package name inside kcl.mod file
officialasishkumar f4bb91a
add comments on functions and use constant variables
officialasishkumar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import ( | |
"runtime" | ||
"strings" | ||
|
||
"github.com/BurntSushi/toml" | ||
"github.com/distribution/reference" | ||
"github.com/moby/term" | ||
"github.com/otiai10/copy" | ||
|
@@ -599,3 +600,50 @@ func AbsTarPath(tarPath string) (string, error) { | |
|
||
return absTarPath, nil | ||
} | ||
|
||
// FindPackage finds the package with the package name 'targetPackage' under the 'root' directory kcl.mod file. | ||
func FindPackage(root, targetPackage string) (string, error) { | ||
var result string | ||
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if info.IsDir() { | ||
kclModPath := filepath.Join(path, constants.KCL_MOD) | ||
if _, err := os.Stat(kclModPath); err == nil { | ||
if matchesPackageName(kclModPath, targetPackage) { | ||
result = path | ||
return filepath.SkipAll | ||
} | ||
} | ||
} | ||
return nil | ||
}) | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
if result == "" { | ||
return "", fmt.Errorf("kcl.mod with package '%s' not found", targetPackage) | ||
} | ||
return result, nil | ||
} | ||
|
||
// MatchesPackageName checks whether the package name in the kcl.mod file under 'kclModPath' is equal to 'targetPackage'. | ||
func matchesPackageName(kclModPath, targetPackage string) bool { | ||
type Package struct { | ||
Name string `toml:"name"` | ||
} | ||
type ModFile struct { | ||
Package Package `toml:"package"` | ||
} | ||
|
||
var modFile ModFile | ||
_, err := toml.DecodeFile(kclModPath, &modFile) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is it? Can you share the link of the code or the docs? |
||
if err != nil { | ||
fmt.Printf("Error parsing kcl.mod file: %v\n", err) | ||
return false | ||
} | ||
|
||
return modFile.Package.Name == targetPackage | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add more documents and unit tests?