From: Chris Lumens clumens@redhat.com
--- Makefile | 3 +++ python-meh.spec | 1 + tests/pylint/runpylint.py | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100755 tests/pylint/runpylint.py
diff --git a/Makefile b/Makefile index 910d850..fce34a8 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,9 @@ test: @echo "*** Running unittests with Python 3 ***" PYTHONPATH=. $(PYTHON3) $(TESTSUITE) -v
+check: + PYTHONPATH=. tests/pylint/runpylint.py + install: $(PYTHON) setup.py install --root=$(DESTDIR) $(MAKE) -C po install diff --git a/python-meh.spec b/python-meh.spec index 578ab35..1da4cd8 100644 --- a/python-meh.spec +++ b/python-meh.spec @@ -36,6 +36,7 @@ BuildRequires: python3-setuptools BuildRequires: python3-dbus BuildRequires: libreport-python3 >= %{libreportver} BuildRequires: python3-six +BuildRequires: python3-pocketlint %endif
Requires: python diff --git a/tests/pylint/runpylint.py b/tests/pylint/runpylint.py new file mode 100755 index 0000000..2fbdb5c --- /dev/null +++ b/tests/pylint/runpylint.py @@ -0,0 +1,20 @@ +#!/usr/bin/python3 + +import os + +from pocketlint import PocketLintConfig, PocketLinter + +class MehLintConfig(PocketLintConfig): + @property + def pylintPlugins(self): + retval = super(MehLintConfig, self).pylintPlugins + retval.remove("pocketlint.checkers.eintr") + retval.remove("pocketlint.checkers.markup") + return retval + +if __name__ == "__main__": + conf = MehLintConfig() + linter = PocketLinter(conf) + rc = linter.run() + os._exit(rc) +
From: Chris Lumens clumens@redhat.com
--- meh/dump.py | 1 - meh/handler.py | 4 +--- meh/ui/gui.py | 4 ++-- meh/ui/text.py | 4 ++-- tests/attrSkipList.py | 6 ++---- tests/baseclass.py | 3 +-- tests/handle_unicode.py | 1 - 7 files changed, 8 insertions(+), 15 deletions(-)
diff --git a/meh/dump.py b/meh/dump.py index a018324..bf983b2 100644 --- a/meh/dump.py +++ b/meh/dump.py @@ -25,7 +25,6 @@ import inspect import os import traceback -import types import sys import codecs import six diff --git a/meh/handler.py b/meh/handler.py index 9363304..e143006 100644 --- a/meh/handler.py +++ b/meh/handler.py @@ -16,11 +16,9 @@ # # Author(s): Chris Lumens clumens@redhat.com # -from meh import * +from meh import MAIN_RESPONSE_DEBUG, MAIN_RESPONSE_SAVE, MAIN_RESPONSE_SHELL, MAIN_RESPONSE_QUIT, DumpInfo, ExceptionInfo import bdb import os -from .network import hasActiveNetDev -import signal import sys import report import traceback diff --git a/meh/ui/gui.py b/meh/ui/gui.py index a7f3602..4941898 100644 --- a/meh/ui/gui.py +++ b/meh/ui/gui.py @@ -16,8 +16,8 @@ # # Author(s): Chris Lumens clumens@redhat.com # -from meh import * -from meh.ui import * +from meh import MAIN_RESPONSE_DEBUG, MAIN_RESPONSE_NONE, MAIN_RESPONSE_QUIT, MAIN_RESPONSE_SAVE +from meh.ui import AbstractIntf, AbstractSaveExceptionWindow, AbstractMainExceptionWindow, AbstractMessageWindow import os import sys import report diff --git a/meh/ui/text.py b/meh/ui/text.py index 274b802..4d99190 100644 --- a/meh/ui/text.py +++ b/meh/ui/text.py @@ -19,8 +19,8 @@ # from __future__ import print_function
-from meh import * -from meh.ui import * +from meh import MAIN_RESPONSE_DEBUG, MAIN_RESPONSE_SAVE, MAIN_RESPONSE_SHELL, MAIN_RESPONSE_QUIT +from meh.ui import AbstractIntf, AbstractSaveExceptionWindow, AbstractMainExceptionWindow, AbstractMessageWindow import report import report.io.TextIO from report import LIBREPORT_WAIT, LIBREPORT_RUN_CLI diff --git a/tests/attrSkipList.py b/tests/attrSkipList.py index d9fe567..b21c6d1 100644 --- a/tests/attrSkipList.py +++ b/tests/attrSkipList.py @@ -1,9 +1,7 @@ -import os import unittest -from tests.baseclass import * +from tests.baseclass import BaseTestCase
-from meh.handler import * -from meh.dump import * +from meh import Config
class Example: def __init__(self): diff --git a/tests/baseclass.py b/tests/baseclass.py index ced4518..25be349 100644 --- a/tests/baseclass.py +++ b/tests/baseclass.py @@ -7,8 +7,7 @@ import six
from meh import ExceptionInfo -from meh.handler import * -from meh.dump import * +from meh.dump import ExceptionDump
class BaseTestCase(unittest.TestCase): def dump(self, conf, obj): diff --git a/tests/handle_unicode.py b/tests/handle_unicode.py index 3ff4ca9..a4e88d0 100644 --- a/tests/handle_unicode.py +++ b/tests/handle_unicode.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -import tempfile import six
from tests.baseclass import BaseTestCase
From: Chris Lumens clumens@redhat.com
--- meh/dump.py | 11 +++++------ tests/baseclass.py | 3 +-- 2 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/meh/dump.py b/meh/dump.py index bf983b2..c45741d 100644 --- a/meh/dump.py +++ b/meh/dump.py @@ -166,7 +166,7 @@ def get_package_and_component(file_=sys.argv[0]): try: name_end = srpm_name.rindex('-') name_end = srpm_name[:name_end].rindex('-') - except ValueError as e: + except ValueError: # expected exception pass
@@ -194,7 +194,7 @@ def get_other_packages(self): if not self.stack: return packages
- for (frame, fn, lineno, func, ctx, idx) in self.stack: + for (_frame, fn, _lineno, _func, _ctx, _idx) in self.stack: try: pkg_info = get_package_and_component(fn)[0] package = "{0.name}-{0.version}-{0.release}.{0.arch}".format( @@ -233,11 +233,10 @@ def get_environment_variables(): #--begining of the method _get_environment_info-- try: pkg_info, component = get_package_and_component() - except RPMinfoError as rpmierr: + except RPMinfoError: pkg_info = None component = None
- release_ver = get_release_version() other_packages = ", ".join(get_other_packages(self))
ret = dict() @@ -278,7 +277,7 @@ def _format_stack(self): return []
frames = [] - for (frame, fn, lineno, func, ctx, idx) in self.stack: + for (_frame, fn, lineno, func, ctx, _idx) in self.stack: if type(ctx) == type([]): code = "".join(ctx) else: @@ -505,7 +504,7 @@ def hash(self): s = ""
if self.stack: - for (file, lineno, func, text) in [f[1:5] for f in self.stack]: + for (file, _lineno, func, text) in [f[1:5] for f in self.stack]: if type(text) == type([]): text = "".join(text) s += "%s %s %s\n" % (os.path.basename(file), func, text) diff --git a/tests/baseclass.py b/tests/baseclass.py index 25be349..78ca1e2 100644 --- a/tests/baseclass.py +++ b/tests/baseclass.py @@ -56,7 +56,6 @@ def loadModules(moduleDir, cls_pattern="_TestCase", skip_list=["__init__", "base sys.path.insert(0, moduleDir)
# Get a list of all *.py files in moduleDir - moduleList = [] lst = map(lambda x: os.path.splitext(os.path.basename(x))[0], glob.glob(moduleDir + "/*.py"))
@@ -68,7 +67,7 @@ def loadModules(moduleDir, cls_pattern="_TestCase", skip_list=["__init__", "base # Attempt to load the found module. try: loaded = importlib.import_module(module) - except ImportError as e: + except ImportError: print("Error loading module %s." % module) continue
From: Chris Lumens clumens@redhat.com
--- meh/dump.py | 2 ++ meh/handler.py | 5 +++-- meh/network.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/meh/dump.py b/meh/dump.py index c45741d..4c9af70 100644 --- a/meh/dump.py +++ b/meh/dump.py @@ -21,6 +21,8 @@ # Erik Troan ewt@redhat.com # Chris Lumens clumens@redhat.com # +# pylint: disable=bare-except,broad-except + import copy import inspect import os diff --git a/meh/handler.py b/meh/handler.py index e143006..939731c 100644 --- a/meh/handler.py +++ b/meh/handler.py @@ -29,6 +29,7 @@
class NoNetwork(Exception): def __init__(self, msg=""): + Exception.__init__(self) self.msg = msg
def __str__(self): @@ -267,7 +268,7 @@ def runSave(self, exc_info): ret = callback() if ret: params[item_name] = ret - except Exception as exc: + except Exception as exc: # pylint: disable=broad-except params[item_name] = "Caused error: %s" % exc
for fpath in self.conf.fileList: @@ -280,7 +281,7 @@ def runSave(self, exc_info): params[filename] = fobj.read() else: params[filename+"_file"] = fobj.read() - except: + except: # pylint: disable=bare-except #skip files we cannot read continue
diff --git a/meh/network.py b/meh/network.py index e6aa331..ede2b8a 100644 --- a/meh/network.py +++ b/meh/network.py @@ -41,5 +41,5 @@ def hasActiveNetDev(): return True else: return False - except: + except dbus.DBusException: return False
From: Chris Lumens clumens@redhat.com
--- meh/dump.py | 5 ++++- tests/baseclass.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/meh/dump.py b/meh/dump.py index 4c9af70..cac3878 100644 --- a/meh/dump.py +++ b/meh/dump.py @@ -291,7 +291,7 @@ def _format_stack(self):
# Create a string representation of a class. This method will recursively # handle all attributes of the base given class. - def _dumpClass(self, instance, level=0, parentkey="", skipList=[]): + def _dumpClass(self, instance, level=0, parentkey="", skipList=None): # This is horribly cheesy, and bound to require maintainence in the # future. The problem is that anything subclassed from object fails # the types.InstanceType test we used to have which means those @@ -315,6 +315,9 @@ def __isSimpleType(instance):
ret = SafeStr()
+ if not skipList: + skipList = [] + # protect from loops try: # Store the id(), not the instance name to protect against diff --git a/tests/baseclass.py b/tests/baseclass.py index 78ca1e2..007a372 100644 --- a/tests/baseclass.py +++ b/tests/baseclass.py @@ -42,9 +42,12 @@ def tracebackContains(self, path, str): f.close() return False
-def loadModules(moduleDir, cls_pattern="_TestCase", skip_list=["__init__", "baseclass"]): +def loadModules(moduleDir, cls_pattern="_TestCase", skip_list=None): '''taken from firstboot/loader.py'''
+ if not skip_list: + skip_list = ["__init__", "baseclass"] + # Guaruntee that __init__ is skipped if skip_list.count("__init__") == 0: skip_list.append("__init__")
From: Chris Lumens clumens@redhat.com
--- tests/baseclass.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/tests/baseclass.py b/tests/baseclass.py index 007a372..d242ce3 100644 --- a/tests/baseclass.py +++ b/tests/baseclass.py @@ -27,7 +27,7 @@ def openFile(self, mode="w"):
return (fo, path)
- def tracebackContains(self, path, str): + def tracebackContains(self, path, s): f = open(path) while True: l = f.readline() @@ -35,7 +35,7 @@ def tracebackContains(self, path, str): f.close() return False
- if l.find(str) != -1: + if l.find(s) != -1: f.close() return True
@@ -52,7 +52,7 @@ def loadModules(moduleDir, cls_pattern="_TestCase", skip_list=None): if skip_list.count("__init__") == 0: skip_list.append("__init__")
- tstList = list() + tests = list()
# Make sure moduleDir is in the system path so imputil works. if not moduleDir in sys.path: @@ -75,18 +75,18 @@ def loadModules(moduleDir, cls_pattern="_TestCase", skip_list=None): continue
# Find class names that match the supplied pattern (default: "_TestCase") - beforeCount = len(tstList) + beforeCount = len(tests) for obj in loaded.__dict__.keys(): if obj.endswith(cls_pattern): - tstList.append(loaded.__dict__[obj]) - afterCount = len(tstList) + tests.append(loaded.__dict__[obj]) + afterCount = len(tests)
# Warn if no tests found if beforeCount == afterCount: print("Module %s does not contain any test cases; skipping." % module) continue
- return tstList + return tests
# Run the tests if __name__ == "__main__":
From: Chris Lumens clumens@redhat.com
--- meh/dump.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/meh/dump.py b/meh/dump.py index cac3878..9a9db09 100644 --- a/meh/dump.py +++ b/meh/dump.py @@ -280,7 +280,7 @@ def _format_stack(self):
frames = [] for (_frame, fn, lineno, func, ctx, _idx) in self.stack: - if type(ctx) == type([]): + if isinstance(ctx, list): code = "".join(ctx) else: code = ctx @@ -510,7 +510,7 @@ def hash(self):
if self.stack: for (file, _lineno, func, text) in [f[1:5] for f in self.stack]: - if type(text) == type([]): + if isinstance(text, list): text = "".join(text) s += "%s %s %s\n" % (os.path.basename(file), func, text) else:
From: Chris Lumens clumens@redhat.com
Most of these can be gotten rid of by disabling the error messages. This is okay because a lot of the errors only turn up under python3 (like when pocketlint is running), but the code in question is only reachable under python2. --- examples/meh_test.py | 2 +- meh/dump.py | 4 ++-- meh/handler.py | 1 + meh/safe_string.py | 4 ++-- meh/ui/gui.py | 5 ++++- meh/ui/text.py | 4 ++-- 6 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/examples/meh_test.py b/examples/meh_test.py index 16e81cb..5725b7d 100755 --- a/examples/meh_test.py +++ b/examples/meh_test.py @@ -17,7 +17,7 @@ def __init__(self): self.binary_data = '\xff\xff\xfe'
if __name__ == "__main__": - print "***Running python-meh test***" + print("***Running python-meh test***")
config = meh.Config(programName="myMehTest", programVersion="1.0-1", programArch="noarch", diff --git a/meh/dump.py b/meh/dump.py index 9a9db09..c746e57 100644 --- a/meh/dump.py +++ b/meh/dump.py @@ -35,12 +35,12 @@
# Python 2/3 compatibilty try: - longtype = long + longtype = long # pylint: disable=undefined-variable except NameError: longtype = int
try: - unitype = unicode + unitype = unicode # pylint: disable=undefined-variable except NameError: unitype = str
diff --git a/meh/handler.py b/meh/handler.py index 939731c..6ae0a5d 100644 --- a/meh/handler.py +++ b/meh/handler.py @@ -55,6 +55,7 @@ def __init__(self, confObj, intfClass, exnClass):
self._exitcode = 10 self._exn = None + self.exnFile = None self.exnText = ""
def _setExitCode(self, code): diff --git a/meh/safe_string.py b/meh/safe_string.py index 7fd0c56..714ce37 100644 --- a/meh/safe_string.py +++ b/meh/safe_string.py @@ -42,13 +42,13 @@ def __add__(self, other): if PY > 2: return SafeStr(str.__add__(self, str(other)))
- if not (isinstance(other, str) or isinstance(other, unicode)): + if not (isinstance(other, str) or isinstance(other, unicode)): # pylint: disable=undefined-variable if hasattr(other, "__str__"): other = other.__str__() else: other = "OMITTED OBJECT WITHOUT __str__ METHOD"
- if isinstance(other, unicode): + if isinstance(other, unicode): # pylint: disable=undefined-variable ret = SafeStr(str.__add__(self, other.encode("utf-8"))) else: try: diff --git a/meh/ui/gui.py b/meh/ui/gui.py index 4941898..d512f6f 100644 --- a/meh/ui/gui.py +++ b/meh/ui/gui.py @@ -67,6 +67,7 @@ def saveExceptionWindow(self, signature, *args, **kwargs):
class SaveExceptionWindow(AbstractSaveExceptionWindow): def __init__(self, signature, *args, **kwargs): + AbstractSaveExceptionWindow.__init__(self, signature, *args, **kwargs) self.signature = signature
def run(self, *args, **kwargs): @@ -139,6 +140,8 @@ def on_main_window_deleted(self, *args): class MessageWindow(AbstractMessageWindow): def __init__(self, title, text, *args, **kwargs): AbstractMessageWindow.__init__(self, title, text, *args, **kwargs) + self.rc = 0 + self.dialog = Gtk.MessageDialog(buttons=Gtk.ButtonsType.OK, type=Gtk.MessageType.INFO, message_format=text) @@ -154,7 +157,7 @@ def run(self, *args, **kwargs): self.dialog.destroy()
class ExitWindow(MessageWindow): - def __init__(self, title, text, *args, **kwargs): + def __init__(self, title, text, *args, **kwargs): # pylint: disable=super-init-not-called self.dialog = Gtk.MessageDialog(buttons=Gtk.ButtonsType.NONE, type=Gtk.MessageType.INFO, message_format=text) diff --git a/meh/ui/text.py b/meh/ui/text.py index 4d99190..e4d99f2 100644 --- a/meh/ui/text.py +++ b/meh/ui/text.py @@ -30,7 +30,7 @@ if sys.version_info.major == 3: raw_input_fn = input else: - raw_input_fn = raw_input + raw_input_fn = raw_input # pylint: disable=undefined-variable
import gettext _ = lambda x: gettext.ldgettext("python-meh", x) @@ -43,7 +43,7 @@ class IOHandler(object):
"""
- def __init__(self, in_func=raw_input_fn, out_func=print): + def __init__(self, in_func=raw_input_fn, out_func=print): # pylint: disable=used-before-assignment """ Constructor for the IOhandler class. Arguments can be used to override default I/O functions with the custom ones.
anaconda-patches@lists.fedorahosted.org