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

Function ParseSetup

opensca/sca/python/setup.go:13–47  ·  view source on GitHub ↗

ParseSetup 解析setup.py

(file *model.File)

Source from the content-addressed store, hash-verified

11
12// ParseSetup 解析setup.py
13func ParseSetup(file *model.File) *model.DepGraph {
14
15 root := &model.DepGraph{Path: file.Relpath()}
16
17 // 静态解析
18 file.OpenReader(func(reader io.Reader) {
19 data, err := io.ReadAll(reader)
20 if err != nil {
21 return
22 }
23 reg := regexp.MustCompile(`install_requires\s*=\s*\[([^\]]+)\]`)
24 requires := reg.FindStringSubmatch(string(data))
25 if len(requires) < 2 {
26 return
27 }
28 model.ReadLineNoComment(strings.NewReader(requires[1]), model.PythonTypeComment, func(line string) {
29 line = strings.Trim(strings.TrimSpace(line), `'",`)
30 words := strings.Fields(line)
31 if len(words) == 0 {
32 return
33 }
34 name := words[0]
35 var version string
36 if len(words) > 1 {
37 version = strings.Join(words[1:], "")
38 }
39 root.AppendChild(&model.DepGraph{
40 Name: name,
41 Version: version,
42 })
43 })
44 })
45
46 return root
47}

Callers 1

ScaMethod · 0.85

Calls 4

AppendChildMethod · 0.95
ReadLineNoCommentFunction · 0.92
RelpathMethod · 0.80
OpenReaderMethod · 0.80

Tested by

no test coverage detected