-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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(python): add license support for requirement.txt
files
#6782
feat(python): add license support for requirement.txt
files
#6782
Conversation
requirement.txt
filesrequirement.txt
files
sort.Slice(pythonDirs, func(i, j int) bool { | ||
majorVer1, minorVer1, found1 := strings.Cut(pythonDirs[i], ".") | ||
majorVer2, minorVer2, found2 := strings.Cut(pythonDirs[j], ".") | ||
|
||
// if one of dir doesn't contain minor version => sort as strings | ||
if !found1 || !found2 { | ||
return pythonDirs[i] < pythonDirs[j] | ||
} | ||
|
||
// Sort major versions as strings | ||
// e.g. `python2.7` and `python3.10` | ||
if majorVer1 != majorVer2 { | ||
return majorVer1 < majorVer2 | ||
} | ||
|
||
// Convert minor versions | ||
ver1, err1 := strconv.Atoi(minorVer1) | ||
ver2, err2 := strconv.Atoi(minorVer2) | ||
|
||
// If we can't convert minor versions => sort as strings | ||
if err1 != nil || err2 != nil { | ||
return pythonDirs[i] < pythonDirs[j] | ||
} | ||
|
||
return ver1 < ver2 | ||
}) |
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.
I believe go-version helps.
https://go.dev/play/p/Ytgevsntqr7
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.
hm... i didn't think about this 👍
Updated in 226b3da
var pythonDirs []string | ||
for _, entry := range entries { | ||
if entry.IsDir() && strings.HasPrefix(entry.Name(), "python") { | ||
pythonDirs = append(pythonDirs, entry.Name()) | ||
} | ||
} |
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.
var pythonDirs []string | |
for _, entry := range entries { | |
if entry.IsDir() && strings.HasPrefix(entry.Name(), "python") { | |
pythonDirs = append(pythonDirs, entry.Name()) | |
} | |
} | |
var pythonVers []version.Version | |
for _, entry := range entries { | |
if entry.IsDir() && strings.HasPrefix(entry.Name(), "python") { | |
ver := strings.TrimPrefix(entry.Name(), "python") | |
v, err := version.Parse(ver) | |
if err != nil { | |
log.Debug("...", log.Err(err)) | |
continue | |
} | |
pythonVers = append(pythonVers, v) | |
} |
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.
Signed-off-by: knqyf263 <knqyf263@gmail.com>
Signed-off-by: knqyf263 <knqyf263@gmail.com>
Signed-off-by: knqyf263 <knqyf263@gmail.com>
Signed-off-by: knqyf263 <knqyf263@gmail.com>
Signed-off-by: knqyf263 <knqyf263@gmail.com>
Signed-off-by: knqyf263 <knqyf263@gmail.com>
Signed-off-by: knqyf263 <knqyf263@gmail.com> Co-authored-by: knqyf263 <knqyf263@gmail.com>
Description
Add license support for
requirement.txt
files.Related issues
Checklist