-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgo.py
31 lines (28 loc) · 1.06 KB
/
go.py
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
import os
from lint import Linter
def find_files(root, ext):
root = root.rstrip(os.sep) + os.sep
ret = []
for base, dirs, names in os.walk(root):
for name in names:
if name.endswith(ext):
base = base.replace(root, '', 1)
ret.append(os.path.join(base, name))
return ret
class Golang(Linter):
language = 'go'
cmd = ('go', 'build', '-gcflags', '-e -N')
regex = r'.+?:(?P<line>\d+): (?P<error>.+)'
def run(self, cmd, code):
code = code.encode('utf8')
path = os.path.split(self.filename)[0]
if not self.filename or not path:
tools = self.popen(('go', 'tool')).communicate()[0].decode('utf8').split('\n')
for compiler in ('compile', '6g', '8g'):
if compiler in tools:
return self.tmpfile(('go', 'tool', compiler, '-e', '-o', os.devnull), code, suffix='.go')
else:
os.chdir(path)
files = find_files(path, '.go')
answer = self.tmpdir(cmd, files, code)
return answer