[Kimchi-devel] [WIP PATCH 2/5] Register Kimchi's namespace when updating XML

Crístian Viana vianac at linux.vnet.ibm.com
Tue Oct 21 19:17:20 UTC 2014


On 21-10-2014 16:58, Aline Manera wrote:
>> +import kimchi.model
>> +
>
> Instead of importing the whole module, import only the constants you 
> need here.

If I import anything longer than kimchi.model.* (e.g. 
kimchi.model.utils), I get a cyclic import error. And in order to 
actually solve that, we'd have to do a big refactoring on the code. 
Importing kimchi.model seemed much simpler for now.

Here's the error I get when I import only the constants instead of the 
whole module:

$ git diff
diff --git a/src/kimchi/xmlutils/utils.py b/src/kimchi/xmlutils/utils.py
index fcb6b14..d40664e 100644
--- a/src/kimchi/xmlutils/utils.py
+++ b/src/kimchi/xmlutils/utils.py
@@ -22,7 +22,7 @@ from lxml import objectify

  from xml.etree import ElementTree

-import kimchi.model
+from kimchi.model.utils import KIMCHI_NAMESPACE, KIMCHI_META_URL


  def xpath_get_text(xml, expr):
@@ -35,8 +35,7 @@ def xpath_get_text(xml, expr):


  def xml_item_update(xml, xpath, value, attr=None):
- ElementTree.register_namespace(kimchi.model.utils.KIMCHI_NAMESPACE,
- kimchi.model.utils.KIMCHI_META_URL)
+    ElementTree.register_namespace(KIMCHI_NAMESPACE, KIMCHI_META_URL)

      root = ElementTree.fromstring(xml)
      item = root.find(xpath)

$ sudo src/kimchid
Traceback (most recent call last):
   File "src/kimchid", line 28, in <module>
     import kimchi.server
   File "/home/vianac/LTC/kimchi/src/kimchi/server.py", line 26, in <module>
     from kimchi import auth
   File "/home/vianac/LTC/kimchi/src/kimchi/auth.py", line 33, in <module>
     from kimchi import template
   File "/home/vianac/LTC/kimchi/src/kimchi/template.py", line 25, in 
<module>
     from kimchi.config import paths
   File "/home/vianac/LTC/kimchi/src/kimchi/config.py", line 30, in <module>
     from kimchi.xmlutils.utils import xpath_get_text
   File "/home/vianac/LTC/kimchi/src/kimchi/xmlutils/utils.py", line 25, 
in <module>
     from kimchi.model.utils import KIMCHI_NAMESPACE, KIMCHI_META_URL
   File "/home/vianac/LTC/kimchi/src/kimchi/model/utils.py", line 21, in 
<module>
     from kimchi.exception import OperationFailed
   File "/home/vianac/LTC/kimchi/src/kimchi/exception.py", line 25, in 
<module>
     from kimchi.template import get_lang, validate_language
ImportError: cannot import name get_lang

I had to do this on patch 5/5 as well, for the same reason.

If you have a better suggestion (which does not require refactoring most 
classes), please let me know.




More information about the Kimchi-devel mailing list