MCPcopy Create free account
hub / github.com/XmirrorSecurity/OpenSCA-cli / ParseRequirementTxt

Function ParseRequirementTxt

opensca/sca/python/pip.go:70–98  ·  view source on GitHub ↗
(file *model.File)

Source from the content-addressed store, hash-verified

68}
69
70func ParseRequirementTxt(file *model.File) *model.DepGraph {
71
72 root := &model.DepGraph{Path: file.Relpath()}
73
74 file.ReadLine(func(line string) {
75
76 if strings.HasPrefix(line, `-r`) {
77 return
78 }
79
80 if i := strings.Index(line, "#"); i != -1 {
81 line = line[:i]
82 }
83
84 line = strings.TrimSpace(strings.Split(line, ";")[0])
85 if strings.ContainsAny(line, `#$%`) || len(line) == 0 {
86 return
87 }
88
89 if i := strings.IndexAny(line, "=!<>~"); i == -1 {
90 root.AppendChild(&model.DepGraph{Name: line})
91 } else {
92 root.AppendChild(&model.DepGraph{Name: line[:i], Version: strings.TrimPrefix(line[i:], "==")})
93 }
94
95 })
96
97 return root
98}
99
100func ParseRequirementIn(file *model.File) *model.DepGraph {
101

Callers 1

ScaMethod · 0.85

Calls 4

AppendChildMethod · 0.95
RelpathMethod · 0.80
ReadLineMethod · 0.80
IndexMethod · 0.80

Tested by

no test coverage detected