#!/usr/bin/python import sys import os # TODO: parse parameters to allow checking more than one file at a time, and # propagating parameters to pylint. assert len(sys.argv) == 2, 'One and only one parameter expected.' source_file_name = sys.argv[1] source_file = open(source_file_name, 'r') line = source_file.readline() assert line.startswith('## Script (Python)'), repr(line) builtin_list = [] append = builtin_list.append while line.startswith('##'): line = line.lstrip('#').strip() if line.startswith('bind'): assert '=' in line, repr(line) value = line.split('=', 1)[1] if value: append(value) elif line.startswith('parameters'): assert '=' in line, repr(line) for param in line.split('=', 1)[1].split(','): if '=' in param: param = param.split('=', 1)[0] append(param.strip(' *')) line = source_file.readline() # Call pylint with given Python Script file. # - add script parameters as additional built-ins # - disable E0104 (return outside of function), as top-level block behaves just # as a function. # - disable persistence of results os.system('pylint --additional-builtins=%(builtins)s --disable-msg=E0104 ' \ '--persistent=n %(file)s' % { 'file': source_file_name, 'builtins': ','.join(builtin_list) })