1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/test/sanity/code-smell/boilerplate.py
2018-02-27 00:36:16 -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:] or sys.stdin.read().splitlines():
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()