[Checkins] SVN: z3c.relationfield/trunk/ Move schema2xml and lxml dependencies to an exta. The functionalty will be enabled and the adapters registered if those packages are available for import, so even if you don't use the extra and you have them in your build, it'll work

Martin Aspeli optilude at gmx.net
Tue Jun 30 11:21:20 EDT 2009


Log message for revision 101341:
  Move schema2xml and lxml dependencies to an exta. The functionalty will be enabled and the adapters registered if those packages are available for import, so even if you don't use the extra and you have them in your build, it'll work

Changed:
  U   z3c.relationfield/trunk/CHANGES.txt
  U   z3c.relationfield/trunk/setup.py
  U   z3c.relationfield/trunk/src/z3c/relationfield/schema.py
  A   z3c.relationfield/trunk/src/z3c/relationfield/xml.py

-=-
Modified: z3c.relationfield/trunk/CHANGES.txt
===================================================================
--- z3c.relationfield/trunk/CHANGES.txt	2009-06-30 15:18:42 UTC (rev 101340)
+++ z3c.relationfield/trunk/CHANGES.txt	2009-06-30 15:21:20 UTC (rev 101341)
@@ -4,6 +4,11 @@
 0.5 (unreleased)
 ==================
 
+* Move lxml and schema2xml dependencies to an [xml] extra so that people can
+  use this package without having to install lxml, which still causes issues
+  on some platforms. If z3c.schema2xml and lxml are not importable, the
+  relevant adapters will not be defined, but everything else will still work.
+
 * Subscribe to IIntIdAddedEvent instead of IObjectAddedEvent to prevent
   errors due to subscriber ordering.
 

Modified: z3c.relationfield/trunk/setup.py
===================================================================
--- z3c.relationfield/trunk/setup.py	2009-06-30 15:18:42 UTC (rev 101340)
+++ z3c.relationfield/trunk/setup.py	2009-06-30 15:21:20 UTC (rev 101341)
@@ -34,13 +34,15 @@
         'grokcore.component',
         'zope.app.intid',
         'zope.app.container',
-        'z3c.schema2xml >= 1.0',
         'z3c.objpath',
         'zc.relation >= 1.0',
-        'lxml',
         # for tests
         'zope.app.zcmlfiles',
         'zope.securitypolicy',
         ],
+    extras_require = {
+        'xml':  ['z3c.schema2xml >= 1.0',
+                 'lxml'],
+      },
     entry_points={},
     )

Modified: z3c.relationfield/trunk/src/z3c/relationfield/schema.py
===================================================================
--- z3c.relationfield/trunk/src/z3c/relationfield/schema.py	2009-06-30 15:18:42 UTC (rev 101340)
+++ z3c.relationfield/trunk/src/z3c/relationfield/schema.py	2009-06-30 15:21:20 UTC (rev 101341)
@@ -1,59 +1,15 @@
-import grokcore.component as grok
-
-from lxml import etree
-
 from zope.interface import implements
 from zope.schema import Field, List, Choice
 
-from z3c.schema2xml import IXMLGenerator
-
 from z3c.relationfield.interfaces import IRelation, IRelationChoice, IRelationList
-from z3c.relationfield.relation import TemporaryRelationValue
 
 class Relation(Field):
     implements(IRelation)
 
-class RelationGenerator(grok.Adapter):
-    """Eport a relation to XML.
-    """
-    grok.context(IRelation)
-    grok.implements(IXMLGenerator)
-
-    def output(self, container, value):
-        element = etree.SubElement(container, self.context.__name__)
-        if value is not None:
-            element.text = value.to_path
-
-    def input(self, element):
-        if element.text is None:
-            return None
-        path = element.text
-        return TemporaryRelationValue(path)
-
 class RelationList(List):
     implements(IRelationList)
 
     value_type = Relation()
 
 class RelationChoice(Choice):
-    implements(IRelationChoice)
-
-class RelationListGenerator(grok.Adapter):
-    """Export a relation list to XML.
-    """
-    grok.context(IRelationList)
-    grok.implements(IXMLGenerator)
-
-    def output(self, container, value):
-        element = etree.SubElement(container, self.context.__name__)
-        field = self.context.value_type
-        if value is not None:
-            for v in value:
-                IXMLGenerator(field).output(element, v)
-
-    def input(self, element):
-        field = self.context.value_type
-        return [
-            IXMLGenerator(field).input(sub_element)
-            for sub_element in element]
-
+    implements(IRelationChoice)
\ No newline at end of file

Added: z3c.relationfield/trunk/src/z3c/relationfield/xml.py
===================================================================
--- z3c.relationfield/trunk/src/z3c/relationfield/xml.py	                        (rev 0)
+++ z3c.relationfield/trunk/src/z3c/relationfield/xml.py	2009-06-30 15:21:20 UTC (rev 101341)
@@ -0,0 +1,49 @@
+import grokcore.component as grok
+
+try:
+    from lxml import etree
+    from z3c.schema2xml import IXMLGenerator
+    XML_GENERATORS = True
+except ImportError:
+    XML_GENERATORS = False
+
+from z3c.relationfield.relation import TemporaryRelationValue
+from z3c.relationfield.interfaces import IRelationList, IRelation
+    
+if XML_GENERATORS:
+    
+    class RelationListGenerator(grok.Adapter):
+        """Export a relation list to XML.
+        """
+        grok.context(IRelationList)
+        grok.implements(IXMLGenerator)
+
+        def output(self, container, value):
+            element = etree.SubElement(container, self.context.__name__)
+            field = self.context.value_type
+            if value is not None:
+                for v in value:
+                    IXMLGenerator(field).output(element, v)
+
+        def input(self, element):
+            field = self.context.value_type
+            return [
+                IXMLGenerator(field).input(sub_element)
+                for sub_element in element]
+
+    class RelationGenerator(grok.Adapter):
+        """Eport a relation to XML.
+        """
+        grok.context(IRelation)
+        grok.implements(IXMLGenerator)
+
+        def output(self, container, value):
+            element = etree.SubElement(container, self.context.__name__)
+            if value is not None:
+                element.text = value.to_path
+
+        def input(self, element):
+            if element.text is None:
+                return None
+            path = element.text
+            return TemporaryRelationValue(path)



More information about the Checkins mailing list