From 02f8d000ff57a48dc1ccde253eb8b3ae5938a654 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Sun, 4 Aug 2013 22:51:55 -0700 Subject: [PATCH] Fix flake8 compliants in tools python programs. Change-Id: I59feb2824fce16d23d56833fd51e4814a0e641cf --- tools/git-changelog | 2 +- tools/multipip | 14 +++----------- tools/pip-download | 3 ++- tools/py2rpm | 11 ++++++----- tools/yumfind | 2 -- 5 files changed, 12 insertions(+), 20 deletions(-) diff --git a/tools/git-changelog b/tools/git-changelog index 2a6b032c..4c3bb6dd 100755 --- a/tools/git-changelog +++ b/tools/git-changelog @@ -14,9 +14,9 @@ import argparse import collections import iso8601 import logging -import re import os import os.path +import re import subprocess import sys import textwrap diff --git a/tools/multipip b/tools/multipip index 81d82dc9..0a18acad 100755 --- a/tools/multipip +++ b/tools/multipip @@ -3,14 +3,12 @@ import argparse import distutils.spawn import logging -import os import re import subprocess import sys import pip.index import pip.req -from pip.vcs import git, mercurial, subversion, bazaar import pkg_resources @@ -201,19 +199,16 @@ def join_one_requirement(req_list): """ if len(req_list) == 1: return req_list[0] - req_strict = None lower_bound_str = None lower_bound_version = None - lower_bound_req = None upper_bound_str = None upper_bound_version = None - upper_bound_req = None conflicts = [] for req in req_list: for spec in req.req.specs: if spec[0] == "==": return req - spec_str = "%s%s" % spec + spec_str = "%s%s" % spec if spec[0] == "!=": conflicts.append(spec_str) continue @@ -225,15 +220,13 @@ def join_one_requirement(req_list): (strict_check and version == lower_bound_version)): lower_bound_version = version lower_bound_str = spec_str - lower_bound_req = req else: if (not upper_bound_version or (version < upper_bound_version) or (strict_check and version == upper_bound_version)): upper_bound_version = version upper_bound_str = spec_str - upper_bound_req = req + req_key = req_list[0].req.key if lower_bound_version and upper_bound_version: - bad_bounds = False if lower_bound_version > upper_bound_version: upper_bound_str = None if lower_bound_version == upper_bound_version: @@ -244,7 +237,6 @@ def join_one_requirement(req_list): else: upper_bound_str = None req_specs = [] - req_key = req_list[0].req.key if lower_bound_str: req_specs.append(lower_bound_str) if upper_bound_str: @@ -304,7 +296,7 @@ def join_requirements(options): conflicts.append(parsed) if exact_version: for req in req_list: - if not exact_version in req.req: + if exact_version not in req.req: incompatible_requirement(joined_req, req) else: for req in req_list: diff --git a/tools/pip-download b/tools/pip-download index cfb4f8d6..02667e78 100755 --- a/tools/pip-download +++ b/tools/pip-download @@ -16,7 +16,8 @@ # License for the specific language governing permissions and limitations # under the License. -from distutils.version import (StrictVersion, LooseVersion) +from distutils.version import LooseVersion +from distutils.version import StrictVersion import collections import distutils diff --git a/tools/py2rpm b/tools/py2rpm index 2c325943..7981f26f 100755 --- a/tools/py2rpm +++ b/tools/py2rpm @@ -4,9 +4,9 @@ import argparse import distutils.spawn import email.parser import logging -import re import os import os.path +import re import shutil import subprocess import sys @@ -58,6 +58,7 @@ mv -f INSTALLED_FILES{.tmp,}""", """rm -rf $RPM_BUILD_ROOT""", } + class InstallationError(Exception): pass @@ -70,7 +71,7 @@ def python_key_to_rpm(python_name): python_name = python_name.lower() try: return package_map[python_name] - except: + except KeyError: pass python_name = python_name.replace("_", "-").replace(".", "-") if python_name.startswith("python-"): @@ -329,7 +330,7 @@ def requires_and_conflicts(req_list): for line in req_list: try: req = pkg_resources.Requirement.parse(line) - except: + except Exception: continue rpm_name = python_key_to_rpm(req.key) if not req.specs: @@ -407,7 +408,7 @@ def build_rpm(options, filename): # flake8 v2 that we don't go ahead and build a v2.0 version. # # Note(harlowja): Not sure why rpm seems to not understand these are the same... - cleaned_version = trim_zeroes(version.replace('-','_')) + cleaned_version = trim_zeroes(version.replace('-', '_')) with open(spec_name, "w") as spec_file: print >> spec_file, "%define pkg_name", pkg_name print >> spec_file, "%define rpm_name", rpm_name @@ -440,7 +441,7 @@ def build_rpm(options, filename): max_name_len = max(len(tag[0]) for tag in tags) for tag in tags: print >> spec_file, "%s:" % tag[0], " " * ( - max_name_len - len(tag[0]) + 1), one_line(tag[1], max_len=-1) + max_name_len - len(tag[0]) + 1), one_line(tag[1], max_len=-1) if rpm_requires: print >> spec_file, rpm_requires if rpm_conflicts: diff --git a/tools/yumfind b/tools/yumfind index 17efa6cb..68009d1d 100755 --- a/tools/yumfind +++ b/tools/yumfind @@ -23,9 +23,7 @@ from optparse import OptionParser import collections import json -import os import pkg_resources -import sys from yum import YumBase