[PATCH V5 0/4] check the python code with pyflakes

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> V4 -> V5 We do not need pyflakes to run or build Kimchi. It is only used for developers to check code style. V3 -> V4 address Rodrigo's comment. add delete the cloned template in rollback. V2 -> V3 address zhengsheng's comment. improve the SKIP_PYFLAKES_ERR list. V1 -> V2 address Crístian'comment: remove the whole statement "info = self._get_vm(name).inf" address ming's comment: break down the patch into small patches by the pyflakes error. Pyflakes analyzes programs and detects various errors. It works by parsing the source file, not importing it, so it is safe to use on modules with side effects. It's also much faster. This is important to improve the code quality. ShaoHe Feng (4): make pyflakes happly, remove the unused import module make pyflakes happly, remove unused availables add template_delete to rollback after create a template run pyflakes when make check Makefile.am | 7 +++++++ configure.ac | 7 +++++++ src/kimchi/control/plugins.py | 2 +- src/kimchi/featuretests.py | 2 -- src/kimchi/mockmodel.py | 5 ++--- src/kimchi/model/storagepools.py | 2 +- src/kimchi/screenshot.py | 1 - src/kimchi/template.py | 1 - tests/test_model.py | 2 ++ tests/test_server.py | 1 - ui/pages/help/gen-index.py | 1 - 11 files changed, 20 insertions(+), 11 deletions(-) -- 1.8.5.3

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> remove the unused import module. make pyflakes happly before introduce pyflakes. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> --- src/kimchi/control/plugins.py | 2 +- src/kimchi/featuretests.py | 2 -- src/kimchi/mockmodel.py | 2 +- src/kimchi/screenshot.py | 1 - src/kimchi/template.py | 1 - tests/test_server.py | 1 - ui/pages/help/gen-index.py | 1 - 7 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/kimchi/control/plugins.py b/src/kimchi/control/plugins.py index 8dc2273..12c621e 100644 --- a/src/kimchi/control/plugins.py +++ b/src/kimchi/control/plugins.py @@ -18,7 +18,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import kimchi.template -from kimchi.control.base import Collection, Resource +from kimchi.control.base import Collection from kimchi.control.utils import get_class_name, model_fn from kimchi.control.utils import UrlSubNode diff --git a/src/kimchi/featuretests.py b/src/kimchi/featuretests.py index a6a28fa..07d5676 100644 --- a/src/kimchi/featuretests.py +++ b/src/kimchi/featuretests.py @@ -20,7 +20,6 @@ import cherrypy import libvirt import lxml.etree as ET -import os import socket import subprocess import threading @@ -29,7 +28,6 @@ import threading from lxml.builder import E -from kimchi import config from kimchi.utils import kimchi_log diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py index d40f61a..8ff3dbf 100644 --- a/src/kimchi/mockmodel.py +++ b/src/kimchi/mockmodel.py @@ -51,7 +51,7 @@ from kimchi.model.utils import get_vm_name from kimchi.model.vms import VM_STATIC_UPDATE_PARAMS from kimchi.objectstore import ObjectStore from kimchi.screenshot import VMScreenshot -from kimchi.utils import pool_name_from_uri, run_command +from kimchi.utils import pool_name_from_uri from kimchi.utils import template_name_from_uri from kimchi.vmtemplate import VMTemplate diff --git a/src/kimchi/screenshot.py b/src/kimchi/screenshot.py index 6c8a599..0040d7c 100644 --- a/src/kimchi/screenshot.py +++ b/src/kimchi/screenshot.py @@ -20,7 +20,6 @@ import glob import os -import random import signal import tempfile import time diff --git a/src/kimchi/template.py b/src/kimchi/template.py index 5707121..9bb2da5 100644 --- a/src/kimchi/template.py +++ b/src/kimchi/template.py @@ -20,7 +20,6 @@ import cherrypy import errno import json -import os from kimchi.config import paths diff --git a/tests/test_server.py b/tests/test_server.py index d7b93ad..d06e17a 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -17,7 +17,6 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -import json import os import unittest diff --git a/ui/pages/help/gen-index.py b/ui/pages/help/gen-index.py index 56cbf47..cf7c5d7 100755 --- a/ui/pages/help/gen-index.py +++ b/ui/pages/help/gen-index.py @@ -18,7 +18,6 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -import glob import libxml2 import sys -- 1.8.5.3

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> remove unused availables make pyflakes happly before introduce pyflakes. 1. the info is unused when start the vm, remove the statement. 2. the AsyncTask, we use it to create a task and run the task. 3. the Exception, we just catch it and do not use it. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- src/kimchi/mockmodel.py | 3 +-- src/kimchi/model/storagepools.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py index 8ff3dbf..b6f1eb8 100644 --- a/src/kimchi/mockmodel.py +++ b/src/kimchi/mockmodel.py @@ -127,7 +127,6 @@ class MockModel(object): def vm_start(self, name): self._get_vm(name).info['state'] = 'running' - info = self._get_vm(name).info def vm_stop(self, name): self._get_vm(name).info['state'] = 'shutoff' @@ -729,7 +728,7 @@ class MockModel(object): def add_task(self, target_uri, fn, opaque=None): id = self.next_taskid self.next_taskid = self.next_taskid + 1 - task = AsyncTask(id, target_uri, fn, self.objstore, opaque) + AsyncTask(id, target_uri, fn, self.objstore, opaque) return id diff --git a/src/kimchi/model/storagepools.py b/src/kimchi/model/storagepools.py index fea19f6..92b2496 100644 --- a/src/kimchi/model/storagepools.py +++ b/src/kimchi/model/storagepools.py @@ -222,7 +222,7 @@ class StoragePoolModel(object): try: poolDef.prepare(conn) return True - except Exception as e: + except Exception: return False def lookup(self, name): -- 1.8.5.3

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> We know ModelTests will tear down the template datebase. But it is better to delete the template explicitly. In this way, the test case also can test the template_delete. Also this can make pyflakes happy. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> --- tests/test_model.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_model.py b/tests/test_model.py index c8c54c0..69f9b5b 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -513,9 +513,11 @@ class ModelTests(unittest.TestCase): orig_params = {'name': 'test-template', 'memory': 1024, 'cpus': 1, 'cdrom': self.kimchi_iso} inst.templates_create(orig_params) + rollback.prependDefer(inst.template_delete, 'test-template') orig_temp = inst.template_lookup(orig_params['name']) ident = inst.template_clone('test-template') + rollback.prependDefer(inst.template_delete, ident) clone_temp = inst.template_lookup(ident) clone_temp['name'] = orig_temp['name'] -- 1.8.5.3

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Pyflakes analyzes programs and detects various errors. It works by parsing the source file, not importing it, so it is safe to use on modules with side effects. It's also much faster. This is important to improve the code quality. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> --- Makefile.am | 7 +++++++ configure.ac | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/Makefile.am b/Makefile.am index 2fdafb1..c68f050 100644 --- a/Makefile.am +++ b/Makefile.am @@ -71,7 +71,14 @@ PEP8_WHITELIST = \ tests/utils.py \ $(NULL) +SKIP_PYFLAKES_ERR = "\./src/kimchi/websocket\.py" + check-local: + find . -path './.git' -prune -type f -o \ + -name '*.py' -o -name '*.py.in' | xargs $(PYFLAKES) | \ + grep -w -v $(SKIP_PYFLAKES_ERR) | \ + while read LINE; do echo "$$LINE"; false; done + $(PEP8) --version $(PEP8) --filename '*.py,*.py.in' $(PEP8_WHITELIST) diff --git a/configure.ac b/configure.ac index 365348f..a625f35 100644 --- a/configure.ac +++ b/configure.ac @@ -42,6 +42,13 @@ AM_GNU_GETTEXT([external]) AM_GNU_GETTEXT_VERSION([0.10]) AC_PATH_PROG([CHEETAH], [cheetah], [/usr/bin/cheetah]) +# Checking for pyflakes +AC_PATH_PROG([PYFLAKES], [pyflakes]) +if test "x$PYFLAKES" = "x"; then + AC_MSG_WARN([pyflakes not found]) +fi + + AC_CONFIG_FILES([ po/Makefile.in po/gen-pot -- 1.8.5.3
participants (2)
-
Aline Manera
-
shaohef@linux.vnet.ibm.com