diff options
author | Matt Clay <mclay@redhat.com> | 2021-08-12 15:07:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-12 15:07:06 -0700 |
commit | 99a79e1969472ab4ba5c0bd0cab61927b9aa93d9 (patch) | |
tree | eff0efdf8d721c836a4081191039d2dfcfde68fd /test/lib/ansible_test/_util/controller/sanity/code-smell/metaclass-boilerplate.py | |
parent | 394860560a553e85e1934699bbab1ba615922c85 (diff) | |
download | ansible-99a79e1969472ab4ba5c0bd0cab61927b9aa93d9.tar.gz |
ansible-test - Move code from _data to _util. (#75495)
* Update paths to match relocated files.
* Update ansible-test symlink paths.
* Update path classification.
* Update MANIFEST.in
* Update sanity test context paths.
* Update sanity ignores.
* Update shebang sanity test.
* Update configure-remoting-ps1 sanity test.
* Update BOTMETA.yml to reflect new paths.
* Update paths in collection loader comments.
* Update Makefile for ansible-test.
* Update docs.
* Add changelog fragment.
Diffstat (limited to 'test/lib/ansible_test/_util/controller/sanity/code-smell/metaclass-boilerplate.py')
-rwxr-xr-x | test/lib/ansible_test/_util/controller/sanity/code-smell/metaclass-boilerplate.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/metaclass-boilerplate.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/metaclass-boilerplate.py new file mode 100755 index 0000000000..28d06f363b --- /dev/null +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/metaclass-boilerplate.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import ast +import sys + + +def main(): + for path in sys.argv[1:] or sys.stdin.read().splitlines(): + with open(path, 'rb') as path_fd: + lines = path_fd.read().splitlines() + + missing = True + if not lines: + # Files are allowed to be empty of everything including boilerplate + missing = False + + for text in lines: + if text == b'__metaclass__ = type': + missing = False + break + + if missing: + with open(path) as file: + contents = file.read() + + # noinspection PyBroadException + try: + node = ast.parse(contents) + + # files consisting of only assignments have no need for metaclass boilerplate + # the most likely case is that of a documentation only python file + if all(isinstance(statement, ast.Assign) for statement in node.body): + missing = False + except Exception: # pylint: disable=broad-except + pass # the compile sanity test will report this error + + if missing: + print('%s: missing: __metaclass__ = type' % path) + + +if __name__ == '__main__': + main() |