ansible/test/sanity/code-smell/boilerplate.py
Matt Clay 5b5cba5e50
Update more code-smell tests. (#36570)
* Enhance use-compat-six code-smell test.
* Enhance use-argspec-type-path code-smell test.
* Enhance replace-urlopen code-smell test.
* Enhance boilerplate code-smell test.
* Enhance no-underscore-variable code-smell test.
2018-02-22 08:08:29 -08:00

72 lines
2.1 KiB
Python
Executable file

#!/usr/bin/env python
import sys
def main():
skip = set([
'lib/ansible/compat/selectors/_selectors2.py',
'lib/ansible/module_utils/six/_six.py',
'setup.py',
])
prune = [
'contrib/inventory/',
'contrib/vault/',
'docs/',
'examples/',
'hacking/',
'lib/ansible/module_utils/',
'lib/ansible/modules/cloud/amazon/',
'lib/ansible/modules/cloud/cloudstack/',
'lib/ansible/modules/cloud/ovirt/',
'lib/ansible/modules/network/aos/',
'lib/ansible/modules/network/avi/',
'lib/ansible/modules/network/cloudengine/',
'lib/ansible/modules/network/eos/',
'lib/ansible/modules/network/ios/',
'lib/ansible/modules/network/netvisor/',
'lib/ansible/modules/network/nxos/',
'lib/ansible/modules/network/panos/',
'lib/ansible/modules/network/vyos/',
'lib/ansible/modules/windows/',
'lib/ansible/utils/module_docs_fragments/',
'test/'
]
for path in sys.argv[1:]:
if path in skip:
continue
if any(path.startswith(p) for p in prune):
continue
with open(path, 'r') as path_fd:
future_ok = None
metaclass_ok = None
lines = path_fd.read().splitlines()
if not lines:
continue
for line, text in enumerate(lines):
if text in ('from __future__ import (absolute_import, division, print_function)',
'from __future__ import absolute_import, division, print_function'):
future_ok = line
if text == '__metaclass__ = type':
metaclass_ok = line
if future_ok and metaclass_ok:
break
if future_ok is None:
print('%s: missing: from __future__ import (absolute_import, division, print_function)' % path)
if metaclass_ok is None:
print('%s: missing: __metaclass__ = type' % path)
if __name__ == '__main__':
main()