From fd0708286cb0455d666e3297a25ddb9d68f83baa Mon Sep 17 00:00:00 2001 From: Gregory Haynes Date: Mon, 17 Nov 2014 07:47:41 -0800 Subject: [PATCH] Check python with flake8 instead of dib-lint We check python files with dib-lint rather than flake8 which have conflicting opinions. This means weve been (forcibly) writing non pep8 python. Also fixing pep8 issues so tests pass. Change-Id: Idc9db40334f6e15738a7802c06697270df68741c --- bin/dib-lint | 11 +++++--- .../pre-install.d/00-configure-pypi-mirror | 14 +++++++++- elements/rhel/bin/map-packages | 2 -- elements/svc-map/bin/svc-map | 1 + .../extra-data.d/10-merge-svc-map-files | 26 +++++++++++++++---- 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/bin/dib-lint b/bin/dib-lint index 559393735..cf8a5b3a4 100755 --- a/bin/dib-lint +++ b/bin/dib-lint @@ -71,9 +71,14 @@ for i in $(find elements -type f); do fi # Ensure 4 spaces indent are used - if ! excluded indent; then - if grep -q "^ \{4\}* \{1,3\}[^ ]" ${i}; then - error "$i should use 4 spaces indent" + + if [ "$(file -b --mime-type $i)" = "text/x-python" ]; then + flake8 $i + else + if ! excluded indent ; then + if grep -q "^ \{4\}* \{1,3\}[^ ]" ${i}; then + error "$i should use 4 spaces indent" + fi fi fi fi diff --git a/elements/pypi/pre-install.d/00-configure-pypi-mirror b/elements/pypi/pre-install.d/00-configure-pypi-mirror index e30899ca5..a184f995d 100755 --- a/elements/pypi/pre-install.d/00-configure-pypi-mirror +++ b/elements/pypi/pre-install.d/00-configure-pypi-mirror @@ -1,7 +1,20 @@ #!/usr/bin/env python +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. import os.path + def main(): home = os.path.expanduser("~") backup_configs(home) @@ -42,4 +55,3 @@ def backup_configs(home): if __name__ == '__main__': main() - diff --git a/elements/rhel/bin/map-packages b/elements/rhel/bin/map-packages index 97e500287..814d2e47a 100755 --- a/elements/rhel/bin/map-packages +++ b/elements/rhel/bin/map-packages @@ -1,6 +1,4 @@ #!/usr/bin/env python -# dib-lint: disable=indent -# dib-lint indent requirements causes issue with pep8 # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain diff --git a/elements/svc-map/bin/svc-map b/elements/svc-map/bin/svc-map index fea710b37..034c1fca8 100755 --- a/elements/svc-map/bin/svc-map +++ b/elements/svc-map/bin/svc-map @@ -16,6 +16,7 @@ # under the License. import os import sys + import yaml diff --git a/elements/svc-map/extra-data.d/10-merge-svc-map-files b/elements/svc-map/extra-data.d/10-merge-svc-map-files index 4757771f2..32885e6c8 100755 --- a/elements/svc-map/extra-data.d/10-merge-svc-map-files +++ b/elements/svc-map/extra-data.d/10-merge-svc-map-files @@ -1,11 +1,25 @@ #!/usr/bin/env python +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + import os import sys + import yaml def os_family(distro): - """Given a distribution, returns a operating system family.""" + "Given a distribution, returns a operating system family." family = None if distro in ['centos7', 'fedora', 'rhel', 'rhel7']: family = 'redhat' @@ -17,8 +31,10 @@ def os_family(distro): def merge_data(source, destination, distro): - """Merges two dictionaries and filters on distro, family, or default - (in order).""" + """Merges two dictionaries and filters on distro. + + Merges two dictionaries and filters on distro family, or default (in order) + """ result = dict() result.update(destination) family = os_family(distro) @@ -61,8 +77,8 @@ def main(): service_names, os.environ.get("DISTRO_NAME")) except Exception as err: - print("%s. Check %s for duplicate \ - service name." % (err, element)) + print("%s. Check %s for duplicate" + " service name." % (err, element)) sys.exit(1) write_data_to_file(service_names, os.path.join("/tmp", 'svc-map-services'))