mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 05:10:22 -07:00
Add interpreter check. Fixes #1
This commit is contained in:
parent
f0413bfd45
commit
46670598aa
1 changed files with 8 additions and 3 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue