From 0d46805979646ce3a6f0225e804a73f552cd5296 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Wed, 2 Nov 2016 14:47:42 -0700 Subject: [PATCH] Clean up shebangs for various files. - Remove shebangs from: - ini files - unit tests - module_utils - plugins - module_docs_fragments - non-executable Makefiles - Change non-modules from '/usr/bin/python' to '/usr/bin/env python'. - Change '/bin/env' to '/usr/bin/env'. Also removed main functions from unit tests (since they no longer have a shebang) and fixed a python 3 compatibility issue with update_bundled.py so it does not need to specify a python 2 shebang. A script was added to check for unexpected shebangs in files. This script is run during CI on Shippable. --- Makefile | 1 - contrib/inventory/brook.ini | 1 - contrib/inventory/cloudforms.py | 2 +- contrib/inventory/gce.ini | 1 - contrib/inventory/nsot.py | 2 +- contrib/inventory/rackhd.py | 2 +- contrib/inventory/spacewalk.py | 2 +- docsite/Makefile | 1 - examples/scripts/uptime.py | 2 +- hacking/update_bundled.py | 4 ++-- hacking/yamlcheck.py | 2 +- lib/ansible/module_utils/f5.py | 1 - lib/ansible/module_utils/lxd.py | 1 - lib/ansible/module_utils/ovirt.py | 1 - lib/ansible/plugins/action/synchronize.py | 1 - .../utils/module_docs_fragments/azure.py | 2 -- .../utils/module_docs_fragments/azure_tags.py | 2 -- .../utils/module_docs_fragments/ovirt.py | 1 - test/sanity/code-smell/shebang.sh | 17 +++++++++++++++++ .../cloud/amazon/test_ec2_vpc_nat_gateway.py | 8 -------- .../extras/cloud/amazon/test_kinesis_stream.py | 9 --------- test/units/parsing/utils/test_jsonify.py | 1 - test/units/plugins/action/test_action.py | 1 - test/utils/shippable/code-smell.sh | 1 + 24 files changed, 26 insertions(+), 40 deletions(-) create mode 100755 test/sanity/code-smell/shebang.sh diff --git a/Makefile b/Makefile index 6465b8bf530..78bdd341142 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,3 @@ -#!/usr/bin/make # WARN: gmake syntax ######################################################## # Makefile for Ansible diff --git a/contrib/inventory/brook.ini b/contrib/inventory/brook.ini index 68f0bb11371..e88c363150f 100644 --- a/contrib/inventory/brook.ini +++ b/contrib/inventory/brook.ini @@ -1,4 +1,3 @@ -#!/usr/bin/python # Copyright 2016 Doalitic. # # This file is part of Ansible diff --git a/contrib/inventory/cloudforms.py b/contrib/inventory/cloudforms.py index c463f857f02..69c149bfc53 100755 --- a/contrib/inventory/cloudforms.py +++ b/contrib/inventory/cloudforms.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # vim: set fileencoding=utf-8 : # # Copyright (C) 2016 Guido Günther diff --git a/contrib/inventory/gce.ini b/contrib/inventory/gce.ini index 4a378b3d543..488e838a22d 100644 --- a/contrib/inventory/gce.ini +++ b/contrib/inventory/gce.ini @@ -1,4 +1,3 @@ -#!/usr/bin/python # Copyright 2013 Google Inc. # # This file is part of Ansible diff --git a/contrib/inventory/nsot.py b/contrib/inventory/nsot.py index 50c33ea40f2..0fe1b27e149 100644 --- a/contrib/inventory/nsot.py +++ b/contrib/inventory/nsot.py @@ -1,4 +1,4 @@ -#!/bin/env python +#!/usr/bin/env python ''' nsot diff --git a/contrib/inventory/rackhd.py b/contrib/inventory/rackhd.py index 92abc4d6a67..f838677f3b6 100755 --- a/contrib/inventory/rackhd.py +++ b/contrib/inventory/rackhd.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python import json import requests diff --git a/contrib/inventory/spacewalk.py b/contrib/inventory/spacewalk.py index 5d3a1821972..260241d807d 100755 --- a/contrib/inventory/spacewalk.py +++ b/contrib/inventory/spacewalk.py @@ -1,4 +1,4 @@ -#!/bin/env python +#!/usr/bin/env python """ Spacewalk external inventory script diff --git a/docsite/Makefile b/docsite/Makefile index f7f5e533271..7d2d41ba533 100644 --- a/docsite/Makefile +++ b/docsite/Makefile @@ -1,4 +1,3 @@ -#!/usr/bin/make SITELIB = $(shell python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()") FORMATTER=../hacking/module_formatter.py DUMPER=../hacking/dump_playbook_attributes.py diff --git a/examples/scripts/uptime.py b/examples/scripts/uptime.py index cad16d8df48..3ea6725b754 100755 --- a/examples/scripts/uptime.py +++ b/examples/scripts/uptime.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python from collections import namedtuple from ansible.parsing.dataloader import DataLoader from ansible.vars import VariableManager diff --git a/hacking/update_bundled.py b/hacking/update_bundled.py index 53b7a73a90c..714c2a3d8b5 100755 --- a/hacking/update_bundled.py +++ b/hacking/update_bundled.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2 -tt +#!/usr/bin/env python import glob import json @@ -25,7 +25,7 @@ for filename in glob.glob(os.path.join(basedir, '../lib/ansible/compat/*/__init_ continue metadata = json.loads(data) pypi_fh = open_url('https://pypi.python.org/pypi/{0}/json'.format(metadata['pypi_name'])) - pypi_data = json.loads(pypi_fh.read()) + pypi_data = json.loads(pypi_fh.read().decode('utf-8')) if LooseVersion(metadata['version']) < LooseVersion(pypi_data['info']['version']): print('UPDATE: {0} from {1} to {2} {3}'.format( metadata['pypi_name'], diff --git a/hacking/yamlcheck.py b/hacking/yamlcheck.py index c66d70db134..68d796cb1a5 100755 --- a/hacking/yamlcheck.py +++ b/hacking/yamlcheck.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # long version of this one liner: python -c 'import yaml,sys;yaml.safe_load(sys.stdin)' < yamltest.txt import yaml import sys diff --git a/lib/ansible/module_utils/f5.py b/lib/ansible/module_utils/f5.py index 6339d878a80..6dbb167c019 100644 --- a/lib/ansible/module_utils/f5.py +++ b/lib/ansible/module_utils/f5.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # -*- coding: utf-8 -*- # This code is part of Ansible, but is an independent component. diff --git a/lib/ansible/module_utils/lxd.py b/lib/ansible/module_utils/lxd.py index 1b869e20ad6..f3464c10e18 100644 --- a/lib/ansible/module_utils/lxd.py +++ b/lib/ansible/module_utils/lxd.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # -*- coding: utf-8 -*- # (c) 2016, Hiroaki Nakamura diff --git a/lib/ansible/module_utils/ovirt.py b/lib/ansible/module_utils/ovirt.py index 3b6c11eb0a2..adf928b6e3e 100644 --- a/lib/ansible/module_utils/ovirt.py +++ b/lib/ansible/module_utils/ovirt.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # -*- coding: utf-8 -*- # # Copyright (c) 2016 Red Hat, Inc. diff --git a/lib/ansible/plugins/action/synchronize.py b/lib/ansible/plugins/action/synchronize.py index b59b8e12e76..0087b588576 100644 --- a/lib/ansible/plugins/action/synchronize.py +++ b/lib/ansible/plugins/action/synchronize.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # -*- coding: utf-8 -*- # (c) 2012-2013, Timothy Appnel diff --git a/lib/ansible/utils/module_docs_fragments/azure.py b/lib/ansible/utils/module_docs_fragments/azure.py index 8a2e0c5396f..e4c58a9698a 100644 --- a/lib/ansible/utils/module_docs_fragments/azure.py +++ b/lib/ansible/utils/module_docs_fragments/azure.py @@ -1,5 +1,3 @@ -#!/usr/bin/python -# # Copyright (c) 2016 Matt Davis, # Chris Houseknecht, # diff --git a/lib/ansible/utils/module_docs_fragments/azure_tags.py b/lib/ansible/utils/module_docs_fragments/azure_tags.py index 7a22fc84218..3a9c6cbfed0 100644 --- a/lib/ansible/utils/module_docs_fragments/azure_tags.py +++ b/lib/ansible/utils/module_docs_fragments/azure_tags.py @@ -1,5 +1,3 @@ -#!/usr/bin/python -# # Copyright (c) 2016 Matt Davis, # Chris Houseknecht, # diff --git a/lib/ansible/utils/module_docs_fragments/ovirt.py b/lib/ansible/utils/module_docs_fragments/ovirt.py index 1d03830365f..68f97a04eb2 100644 --- a/lib/ansible/utils/module_docs_fragments/ovirt.py +++ b/lib/ansible/utils/module_docs_fragments/ovirt.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # -*- coding: utf-8 -*- # # Copyright (c) 2016 Red Hat, Inc. diff --git a/test/sanity/code-smell/shebang.sh b/test/sanity/code-smell/shebang.sh new file mode 100755 index 00000000000..15c0c317812 --- /dev/null +++ b/test/sanity/code-smell/shebang.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +grep '^#!' -RIn . 2>/dev/null | grep ':1:' | sed 's/:1:/:/' | grep -v -E \ + -e '^\./lib/ansible/modules/' \ + -e '^\./test/integration/targets/[^/]*/library/[^/]*:#!powershell$' \ + -e ':#!/bin/sh$' \ + -e ':#!/bin/bash( -[eux]|$)' \ + -e ':#!/usr/bin/make -f$' \ + -e ':#!/usr/bin/env python$' \ + -e ':#!/usr/bin/env bash$' \ + -e ':#!/usr/bin/env fish$' + +if [ $? -ne 1 ]; then + echo "One or more file(s) listed above have an unexpected shebang." + echo "See $0 for the list of acceptable values." + exit 1 +fi diff --git a/test/units/modules/extras/cloud/amazon/test_ec2_vpc_nat_gateway.py b/test/units/modules/extras/cloud/amazon/test_ec2_vpc_nat_gateway.py index 573fa377787..104dbab5fae 100644 --- a/test/units/modules/extras/cloud/amazon/test_ec2_vpc_nat_gateway.py +++ b/test/units/modules/extras/cloud/amazon/test_ec2_vpc_nat_gateway.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - from nose.plugins.skip import SkipTest try: @@ -489,9 +487,3 @@ class AnsibleEc2VpcNatGatewayFunctions(unittest.TestCase): ) self.assertFalse(success) self.assertFalse(changed) - -def main(): - unittest.main() - -if __name__ == '__main__': - main() diff --git a/test/units/modules/extras/cloud/amazon/test_kinesis_stream.py b/test/units/modules/extras/cloud/amazon/test_kinesis_stream.py index 7b5dcff67c4..c06c0b54621 100644 --- a/test/units/modules/extras/cloud/amazon/test_kinesis_stream.py +++ b/test/units/modules/extras/cloud/amazon/test_kinesis_stream.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - from nose.plugins.skip import SkipTest try: @@ -287,10 +285,3 @@ class AnsibleKinesisStreamFunctions(unittest.TestCase): self.assertTrue(changed) self.assertEqual(results, should_return) self.assertEqual(err_msg, 'Kinesis Stream test updated successfully.') - - -def main(): - unittest.main() - -if __name__ == '__main__': - main() diff --git a/test/units/parsing/utils/test_jsonify.py b/test/units/parsing/utils/test_jsonify.py index 4de92b8bad1..02c87f591fa 100644 --- a/test/units/parsing/utils/test_jsonify.py +++ b/test/units/parsing/utils/test_jsonify.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # -*- coding: utf-8 -*- # (c) 2016, James Cammarata # diff --git a/test/units/plugins/action/test_action.py b/test/units/plugins/action/test_action.py index 091b50fb88c..52083257a7a 100644 --- a/test/units/plugins/action/test_action.py +++ b/test/units/plugins/action/test_action.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- # (c) 2015, Florian Apolloner # diff --git a/test/utils/shippable/code-smell.sh b/test/utils/shippable/code-smell.sh index c544b1015cb..2ad834c3222 100755 --- a/test/utils/shippable/code-smell.sh +++ b/test/utils/shippable/code-smell.sh @@ -20,6 +20,7 @@ test/sanity/code-smell/replace-urlopen.sh . test/sanity/code-smell/use-compat-six.sh lib test/sanity/code-smell/boilerplate.sh test/sanity/code-smell/required-and-default-attributes.sh +test/sanity/code-smell/shebang.sh shellcheck \ test/integration/targets/*/*.sh \