mirror of
https://github.com/anchore/syft.git
synced 2026-11-05 00:46:38 +01:00
clean package names in python parsers (#1417)
Signed-off-by: Alex Goodman <alex.goodman@anchore.com> Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
@@ -43,8 +43,13 @@ func parseSetup(_ source.FileResolver, _ *generic.Environment, reader source.Loc
|
||||
version := strings.TrimSpace(parts[len(parts)-1])
|
||||
version = strings.Trim(version, "'\"")
|
||||
|
||||
if hasTemplateDirective(name) || hasTemplateDirective(version) {
|
||||
// this can happen in more dynamic setup.py where there is templating
|
||||
continue
|
||||
}
|
||||
|
||||
if name == "" || version == "" {
|
||||
log.WithFields("path", reader.RealPath).Warnf("unable to parse package in setup.py line: %q", line)
|
||||
log.WithFields("path", reader.RealPath).Debugf("unable to parse package in setup.py line: %q", line)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -54,3 +59,7 @@ func parseSetup(_ source.FileResolver, _ *generic.Environment, reader source.Loc
|
||||
|
||||
return packages, nil, nil
|
||||
}
|
||||
|
||||
func hasTemplateDirective(s string) bool {
|
||||
return strings.Contains(s, `%s`) || strings.Contains(s, `{`) || strings.Contains(s, `}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user