[Kimchi-devel] [PATCH V2] Organize python imports

Sheldon shaohef at linux.vnet.ibm.com
Fri Dec 27 09:16:31 UTC 2013


On 12/21/2013 05:07 AM, Rodrigo Trujillo wrote:
> Follow this rule:
> 1) Import common modules
> import ...
> import ...
> from ... import ...
> from ... import ...
>
> 2) Import kimchi modules
> import kimchi.<mod>
> import kimchi.<mod>
> from kimchi import ...
> from kimchi import ...
>
> Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
> ---
>   plugins/sample/__init__.py |  8 ++++++--
>   plugins/sample/model.py    |  2 +-
>   src/kimchi/model.py        |  4 ++--
>   src/kimchi/server.py       |  2 +-
>   src/kimchi/sslcert.py      |  2 +-
>   tests/test_exception.py    |  8 +++++---
>   tests/test_mockmodel.py    |  6 ++++--
>   tests/test_model.py        | 19 +++++++++++--------
>   tests/test_networkxml.py   |  4 +++-
>   tests/test_osinfo.py       |  5 ++++-
>   tests/test_plugin.py       |  6 +++++-
>   tests/test_rest.py         | 12 +++++++++---
>   tests/test_server.py       |  4 ++--
>   tests/test_vmtemplate.py   |  4 +++-
>   tests/utils.py             | 15 +++++++++------
>   15 files changed, 66 insertions(+), 35 deletions(-)
>
> diff --git a/plugins/sample/__init__.py b/plugins/sample/__init__.py
> index a20f5e6..7064904 100644
> --- a/plugins/sample/__init__.py
> +++ b/plugins/sample/__init__.py
> @@ -22,12 +22,16 @@
>
>   import json
>   import os
> +
> +
>   from cherrypy import expose
> -from kimchi.controller import Resource, Collection
> +
> +
> +from kimchi.controller import Collection, Resource
>   from model import Model
>
> -model = Model()
>
> +model = Model()
>
>   class Drawings(Resource):
>       def __init__(self):
> diff --git a/plugins/sample/model.py b/plugins/sample/model.py
> index f6da5d0..9a2f22f 100644
> --- a/plugins/sample/model.py
> +++ b/plugins/sample/model.py
> @@ -20,7 +20,7 @@
>   # License along with this library; if not, write to the Free Software
>   # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
>
> -from kimchi.exception import NotFoundError, InvalidOperation
> +from kimchi.exception import InvalidOperation, NotFoundError
>
>
>   class Model(object):
> diff --git a/src/kimchi/model.py b/src/kimchi/model.py
> index 3bc5d6d..d5d0dd8 100644
> --- a/src/kimchi/model.py
> +++ b/src/kimchi/model.py
> @@ -42,9 +42,9 @@ import time
>   import uuid
>
>
> -from collections import defaultdict
>   from cherrypy.process.plugins import BackgroundTask
>   from cherrypy.process.plugins import SimplePlugin
> +from collections import defaultdict
>   from xml.etree import ElementTree
>
>
> @@ -69,7 +69,7 @@ from kimchi.networkxml import to_network_xml
>   from kimchi.objectstore import ObjectStore
>   from kimchi.scan import Scanner
>   from kimchi.screenshot import VMScreenshot
> -from kimchi.utils import kimchi_log, is_digit, get_enabled_plugins
> +from kimchi.utils import get_enabled_plugins, is_digit, kimchi_log
>   from kimchi.vmtemplate import VMTemplate
>
>
> diff --git a/src/kimchi/server.py b/src/kimchi/server.py
> index 6ff6fa0..114a3a0 100644
> --- a/src/kimchi/server.py
> +++ b/src/kimchi/server.py
> @@ -33,7 +33,7 @@ from kimchi import config
>   from kimchi import model
>   from kimchi import mockmodel
>   from kimchi.root import Root
> -from kimchi.utils import import_class, get_enabled_plugins
> +from kimchi.utils import get_enabled_plugins, import_class
>
>
>   LOGGING_LEVEL = {"debug": logging.DEBUG,
> diff --git a/src/kimchi/sslcert.py b/src/kimchi/sslcert.py
> index 70441f2..529699d 100644
> --- a/src/kimchi/sslcert.py
> +++ b/src/kimchi/sslcert.py
> @@ -28,7 +28,7 @@
>   import time
>
>
> -from M2Crypto import X509, EVP, RSA, ASN1
> +from M2Crypto import ASN1, EVP, RSA, X509
>
>
>   class SSLCert(object):
> diff --git a/tests/test_exception.py b/tests/test_exception.py
> index 9b5355a..df1f507 100644
> --- a/tests/test_exception.py
> +++ b/tests/test_exception.py
> @@ -20,13 +20,15 @@
>   # 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 unittest
> -import os
>   import json
> +import os
> +import unittest
> +
>
>   import kimchi.mockmodel
>   import kimchi.server
> -from utils import *
> +from utils import get_free_port, patch_auth, request, run_server
> +
>
>   test_server = None
>   model = None
> diff --git a/tests/test_mockmodel.py b/tests/test_mockmodel.py
> index b819172..5a3c73e 100644
> --- a/tests/test_mockmodel.py
> +++ b/tests/test_mockmodel.py
> @@ -20,15 +20,17 @@
>   # 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 unittest
>   import cherrypy
>   import json
>   import os
> +import time
> +import unittest
> +
>
>   import kimchi.mockmodel
>   import kimchi.controller
> +from utils import get_free_port, patch_auth, request, run_server
Today I pull the repository, I find a whitespace after run_server

whitespace is not easy to find by eye.
You can use git-fix-whitespace to fix whitespace.
Automatically fix whitespace errors 
https://github.com/RichardBronosky/git-fix-whitespace
>
> -from utils import *
>
>   #utils.silence_server()
>   test_server = None
> diff --git a/tests/test_model.py b/tests/test_model.py
> index fb7d6dd..e19364f 100644
> --- a/tests/test_model.py
> +++ b/tests/test_model.py
> @@ -21,21 +21,24 @@
>   # 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 unittest
> -import threading
>   import os
> -import time
> -import tempfile
> -import psutil
>   import platform
> +import psutil
> +import tempfile
> +import threading
> +import time
> +import unittest
>   import uuid
>
> +
> +import iso_gen
>   import kimchi.model
>   import kimchi.objectstore
> -from kimchi.exception import *
> -from kimchi import netinfo
>   import utils
> -import iso_gen
> +from kimchi import netinfo
> +from kimchi.exception import InvalidOperation, InvalidParameter
> +from kimchi.exception import NotFoundError, OperationFailed
> +
>
>   class ModelTests(unittest.TestCase):
>       def setUp(self):
> diff --git a/tests/test_networkxml.py b/tests/test_networkxml.py
> index 4eeeaa2..3073bce 100644
> --- a/tests/test_networkxml.py
> +++ b/tests/test_networkxml.py
> @@ -20,10 +20,12 @@
>   # 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 ipaddr
>   import unittest
> +
> +
>   import kimchi.networkxml as nxml
>   from kimchi.xmlutils import xpath_get_text
> -import ipaddr
>
>
>   class NetworkXmlTests(unittest.TestCase):
> diff --git a/tests/test_osinfo.py b/tests/test_osinfo.py
> index f92567d..fda8ada 100644
> --- a/tests/test_osinfo.py
> +++ b/tests/test_osinfo.py
> @@ -21,7 +21,10 @@
>   # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
>
>   import unittest
> -from kimchi.osinfo import *
> +
> +
> +from kimchi.osinfo import lookup
> +
>
>   class OSInfoTests(unittest.TestCase):
>       def test_default_lookup(self):
> diff --git a/tests/test_plugin.py b/tests/test_plugin.py
> index 20cc598..42c87a9 100644
> --- a/tests/test_plugin.py
> +++ b/tests/test_plugin.py
> @@ -20,17 +20,21 @@
>   # 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 unittest
>   import json
>   import os
>   import sys
> +import unittest
> +
> +
>   from functools import partial
>
> +
>   import kimchi.mockmodel
>   import kimchi.server
>   import utils
>   from kimchi import config
>
> +
>   test_server = None
>   model = None
>   host = None
> diff --git a/tests/test_rest.py b/tests/test_rest.py
> index f597796..73946c0 100644
> --- a/tests/test_rest.py
> +++ b/tests/test_rest.py
> @@ -20,16 +20,22 @@
>   # 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 unittest
> +import base64
>   import json
> -import time
>   import os
> +import time
> +import unittest
> +
> +
>   from functools import partial
>
> +
>   import kimchi.mockmodel
>   import kimchi.server
> -from utils import *
>   from kimchi.asynctask import AsyncTask
> +from utils import fake_user, get_free_port, https_request, patch_auth, request
> +from utils import RollbackContext, run_server
> +
>
>   test_server = None
>   model = None
> diff --git a/tests/test_server.py b/tests/test_server.py
> index 9bb0034..734a618 100644
> --- a/tests/test_server.py
> +++ b/tests/test_server.py
> @@ -20,12 +20,12 @@
>   # 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 unittest
>   import json
>   import os
> +import unittest
>
> -import utils
>
> +import utils
>   import kimchi.mockmodel
>
>   #utils.silence_server()
> diff --git a/tests/test_vmtemplate.py b/tests/test_vmtemplate.py
> index 81382c7..7f032e7 100644
> --- a/tests/test_vmtemplate.py
> +++ b/tests/test_vmtemplate.py
> @@ -23,9 +23,11 @@
>   import unittest
>   import uuid
>
> -from kimchi.vmtemplate import *
> +
> +from kimchi.vmtemplate import VMTemplate
>   from kimchi.xmlutils import xpath_get_text
>
> +
>   class VMTemplateTests(unittest.TestCase):
>       def test_minimal_construct(self):
>           fields = (('name', 'test'), ('os_distro', 'unknown'),
> diff --git a/tests/utils.py b/tests/utils.py
> index c114813..a7596e8 100644
> --- a/tests/utils.py
> +++ b/tests/utils.py
> @@ -21,16 +21,19 @@
>   # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
>   #
>
> -import httplib
> +import base64
>   import cherrypy
> -import threading
> -import time
> +import httplib
>   import os
> -import sys
>   import socket
> -from contextlib import closing
> +import sys
> +import threading
> +import time
>   import unittest
> -import base64
> +
> +
> +from contextlib import closing
> +
>
>   import kimchi.server
>   import kimchi.model


-- 
Sheldon Feng(???)<shaohef at linux.vnet.ibm.com>
IBM Linux Technology Center

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/kimchi-devel/attachments/20131227/4e17dfe7/attachment.html>


More information about the Kimchi-devel mailing list