[PATCH 2 of 4 seda] [code gen] Record XSD tag name and documentation on RdefMapping objects

Sylvain Thenault sylvain.thenault at logilab.fr
Wed Oct 11 11:01:47 CEST 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1507561232 -7200
#      Mon Oct 09 17:00:32 2017 +0200
# Node ID 0e0ef58c8e1466f6dccfa54193d4145add52a0a9
# Parent  38e82974a48fbecb11545fcd08249f9b9d4642bf
# Available At https://hg.logilab.org/review/cubes/seda
#              hg pull https://hg.logilab.org/review/cubes/seda -r 0e0ef58c8e14
[code gen] Record XSD tag name and documentation on RdefMapping objects

so that they may be used later to generate tooltips in the UI.

This requires using yet unreleased pyxst to get support for documentation
elements.

Related to #17106808

diff --git a/cubicweb_seda/xsd2yams.py b/cubicweb_seda/xsd2yams.py
--- a/cubicweb_seda/xsd2yams.py
+++ b/cubicweb_seda/xsd2yams.py
@@ -300,19 +300,24 @@ class ETypeMapping(object):
         return '<{0}>'.format(self.etype)
 
 
 class RdefMapping(object):
     """Map a relation to a simple relation definition."""
-    def __init__(self, subjtype, rtype, objtypes, card, composite=None, inlined=False, alias=None):
+
+    def __init__(self, subjtype, rtype, objtypes, card,
+                 composite=None, inlined=False, alias=None,
+                 desc=(), element_name=None):
         assert len(card) == 2, card
         self.subjtype = subjtype
         self.rtype = rtype
         self.objtypes = objtypes
         self.card = card
         self.composite = composite
         self.inlined = inlined
         self.alias = alias
+        self.desc = desc  # list of text collected under xsd:documentation
+        self.element_name = element_name  # XML tag name
 
     @property
     def final(self):
         return next(iter(self.objtypes)) in BASE_TYPES
 
@@ -359,10 +364,12 @@ class XSYMapping(object):
                         continue
                     # we want seda_uri for SEDAAltBinaryDataObjectAttachment but not for Attachment
                     # (it should be systematically added in XSD for the later)
                     if rtype == 'seda_uri' and emapping.etype == 'SEDAAttachment':
                         continue
+                    rdef_options['desc'] = getattr(occ.target, 'desc', ())
+                    rdef_options['element_name'] = getattr(occ.target, 'local_name', None)
                     if role == 'subject':
                         subjtype = current_emapping.etype
                         objtype = target_etype
                         rdef_options['alias'] = _alias(subjtype, rtype)
                     else:
@@ -419,15 +426,18 @@ class XSYMapping(object):
         else:
             self.etypes[emapping.etype] = emapping
             self.ordered.append(emapping)
         return emapping
 
-    def map_rdef(self, subjtype, rtype, objtypes, card, composite=None, inlined=False, alias=None):
+    def map_rdef(self, subjtype, rtype, objtypes, card,
+                 composite=None, inlined=False, alias=None,
+                 desc=(), element_name=None):
         """Register a relation definition."""
         objtypes = _ensure_set(objtypes)
         mapping = RdefMapping(subjtype, rtype, objtypes,
-                              card=card, composite=composite, inlined=inlined, alias=alias)
+                              card=card, composite=composite, inlined=inlined, alias=alias,
+                              desc=desc, element_name=element_name)
         self.ordered.append(mapping)
         return mapping
 
 
 def _ensure_set(value):
diff --git a/dev-requirements.txt b/dev-requirements.txt
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -1,1 +1,2 @@
 pytest
+http://hg.logilab.org/review/pyxst/archive/tip.tar.bz2#egg=pyxst


More information about the saem-devel mailing list