-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtypecheck.go
49 lines (44 loc) · 1.04 KB
/
typecheck.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"os/exec"
"strings"
)
// checkMypyInstalled returns true if mypy is installed.
func checkMypyInstalled(_ string) bool {
cmd := exec.Command(pip3, "list")
data, err := cmd.Output()
if err != nil {
return false
}
return strings.Contains(string(data), "mypy")
}
// installMypy installs mypy.
func installMypy(path string) error {
if checkMypyInstalled(path) {
return nil
}
_, err := exec.Command(pip3, "install", "mypy==0.910").Output()
return err
}
// checkTypeFile checks type of given file.
func checkTypeFile(_, file string) ([]string, error) {
cmd := exec.Command(vpython, "-m", "mypy", file)
rs, _ := cmd.Output()
return strings.Split(string(rs), "\n"), nil
}
// checkTypeFiles checks type of given files.
func checkTypeFiles(path string) (map[string][]string, error) {
fs, err := getFileListRecursive(path)
if err != nil {
return nil, err
}
rs := make(map[string][]string)
for _, f := range fs {
el, err := checkTypeFile(path, f)
if err != nil {
return nil, err
}
rs[f] = el
}
return rs, nil
}