Add interpreter check. Fixes #1

reviewable/pr18001/r3
Matt Martz 10 years ago committed by John Barker
parent f0413bfd45
commit 46670598aa

@ -72,10 +72,10 @@ class ModuleValidator(Validator):
self.name, _ = os.path.splitext(self.basename) self.name, _ = os.path.splitext(self.basename)
with open(path) as f: with open(path) as f:
text = f.read() self.text = f.read()
self.length = len(text.splitlines()) self.length = len(self.text.splitlines())
try: try:
self.ast = ast.parse(text) self.ast = ast.parse(self.text)
except: except:
self.ast = None self.ast = None
@ -99,6 +99,10 @@ class ModuleValidator(Validator):
return False return False
return True return True
def _check_interpreter(self):
if not self.text.startswith('#!/usr/bin/python'):
self.errors.append('Interpreter line is not "#!/usr/bin/python"')
def _find_module_utils(self): def _find_module_utils(self):
linenos = [] linenos = []
for child in self.ast.body: for child in self.ast.body:
@ -208,6 +212,7 @@ class ModuleValidator(Validator):
self.warnings.append('No RETURN provided') self.warnings.append('No RETURN provided')
if not self._just_docs(): if not self._just_docs():
self._check_interpreter()
module_utils = self._find_module_utils() module_utils = self._find_module_utils()
main = self._find_main_call() main = self._find_main_call()
for mu in module_utils: for mu in module_utils:

Loading…
Cancel
Save