-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathfix_annotate_command.py
34 lines (26 loc) · 1.13 KB
/
fix_annotate_command.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
32
33
34
from __future__ import absolute_import, print_function
import json
import shlex
import subprocess
from .fix_annotate_json import BaseFixAnnotateFromSignature, FixAnnotateJson as _FixAnnotateJson
class FixAnnotateCommand(BaseFixAnnotateFromSignature):
# run after FixAnnotateJson
run_order = _FixAnnotateJson.run_order + 1
command = None
@classmethod
def set_command(cls, command):
cls.command = command
def get_command(self, filename, lineno):
return shlex.split(self.command.format(filename=filename, lineno=lineno))
def get_types(self, node, results, funcname):
cmd = self.get_command(self.filename, node.get_lineno())
try:
out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as err:
self.log_message("Line %d: Failed calling `%s`: %s" %
(node.get_lineno(), self.command,
err.output.rstrip()))
return None
data = json.loads(out)
signature = data[0]['signature']
return signature['arg_types'], signature['return_type']