respell symetric into symmetric, providing bw compat in schema *definition* (closes #20073)

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changesetc604aaa65f9d
branchdefault
phasepublic
hiddenno
parent revision#6344fc332f99 backport stable
child revision#7d0247b8b710 hop
files modified by this revision
buildobjs.py
schema.py
schema2dot.py
test/data/schema/schema.py
test/data/schema2/schema.py
test/unittest_reader.py
test/unittest_schema.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1265358743 -3600
# Fri Feb 05 09:32:23 2010 +0100
# Node ID c604aaa65f9daaa615efb8eb0ebbe004b9a1f4f1
# Parent 6344fc332f99dd2fed70b8e04a4086c9e7943136
respell symetric into symmetric, providing bw compat in schema *definition* (closes #20073)

diff --git a/buildobjs.py b/buildobjs.py
@@ -23,11 +23,11 @@
1             'RichString', ) + tuple(BASE_TYPES)
2 
3  ETYPE_PROPERTIES = ('description', '__permissions__',
4                      'meta') # XXX meta is deprecated
5  # don't put description inside, handled "manualy"
6 -RTYPE_PROPERTIES = ('symetric', 'inlined', 'fulltext_container',
7 +RTYPE_PROPERTIES = ('symmetric', 'inlined', 'fulltext_container',
8                      'meta') # XXX meta is deprecated
9  RDEF_PROPERTIES = ('cardinality', 'constraints', 'composite',
10                     'order',  'default', 'uid', 'indexed', 'uid',
11                     'fulltextindexed', 'internationalizable',
12                     '__permissions__',)
@@ -156,11 +156,15 @@
13  class XXX_backward_permissions_compat(type):
14      stacklevel = 2
15      def __new__(mcs, name, bases, classdict):
16          if 'permissions' in classdict:
17              classdict['__permissions__'] = classdict.pop('permissions')
18 -            warn('[0.26.0] permissions is deprecated, use __permissions__ instead (class %s)' % name,
19 +            warn('[yams 0.27.0] permissions is deprecated, use __permissions__ instead (class %s)' % name,
20 +                 DeprecationWarning, stacklevel=mcs.stacklevel)
21 +        if 'symetric' in classdict:
22 +            classdict['symmetric'] = classdict.pop('symetric')
23 +            warn('[yams 0.27.0] symetric has been respelled symmetric (class %s)' % name,
24                   DeprecationWarning, stacklevel=mcs.stacklevel)
25          return super(XXX_backward_permissions_compat, mcs).__new__(mcs, name, bases, classdict)
26 
27      # XXX backward compatiblity
28      def get_permissions(cls):
@@ -355,11 +359,11 @@
29 
30 
31  class RelationType(Definition):
32      __metaclass__ = XXX_backward_permissions_compat
33 
34 -    symetric = MARKER
35 +    symmetric = MARKER
36      inlined = MARKER
37      fulltext_container = MARKER
38 
39      def __init__(self, name=None, **kwargs):
40          """kwargs must have values in RTYPE_PROPERTIES"""
@@ -406,18 +410,18 @@
41 
42  class RelationDefinition(Definition):
43      # FIXME reader magic forbids to define a docstring...
44      #"""a relation is defined by a name, the entity types that can be
45      #subject or object the relation, the cardinality, the constraints
46 -    #and the symetric property.
47 +    #and the symmetric property.
48      #"""
49 
50      subject = MARKER
51      object = MARKER
52      cardinality = MARKER
53      constraints = MARKER
54 -    symetric = MARKER
55 +    symmetric = MARKER
56      inlined = MARKER
57 
58      def __init__(self, subject=None, name=None, object=None, **kwargs):
59          """kwargs keys must have values in RDEF_PROPERTIES"""
60          if subject:
@@ -429,10 +433,14 @@
61          else:
62              self.object = self.__class__.object
63          super(RelationDefinition, self).__init__(name)
64          if kwargs.pop('meta', None):
65              warn('meta is deprecated', DeprecationWarning)
66 +        if 'symetric' in kwargs:
67 +            warn('[yams 0.27.0] symetric has been respelled symmetric',
68 +                 DeprecationWarning, stacklevel=2)
69 +            kwargs['symmetric'] = kwargs.pop('symetric')
70          _check_kwargs(kwargs, RDEF_PROPERTIES + ('description',))
71          _copy_attributes(attrdict(**kwargs), self, RDEF_PROPERTIES + ('description',))
72          if self.constraints:
73              self.constraints = list(self.constraints)
74 
@@ -445,10 +453,15 @@
75 
76          register definition objects by adding them to the `defined` dictionnary
77          """
78          name = getattr(cls, 'name', cls.__name__)
79          rtype = RelationType(name)
80 +        if hasattr(cls, 'symetric'):
81 +            cls.symmetric = cls.symetric
82 +            del cls.symetric
83 +            warn('[yams 0.27.0] symetric has been respelled symmetric (class %s)' % name,
84 +                 DeprecationWarning)
85          _copy_attributes(cls, rtype, RTYPE_PROPERTIES)
86          if name in defined:
87              _copy_attributes(rtype, defined[name], RTYPE_PROPERTIES)
88          else:
89              defined[name] = rtype
@@ -533,10 +546,14 @@
90          self.name = '<undefined>'
91          self.etype = etype
92          if self.constraints:
93              self.constraints = list(self.constraints)
94          self.override = kwargs.pop('override', False)
95 +        if 'symetric' in kwargs:
96 +            kwargs['symmetric'] = kwargs.pop('symetric')
97 +            warn('[yams 0.27.0] symetric has been respelled symmetric',
98 +                 DeprecationWarning, stacklevel=2)
99          try:
100              _check_kwargs(kwargs, REL_PROPERTIES)
101          except BadSchemaDefinition, bad:
102              # XXX (auc) bad field name + required attribute can lead there instead of schema.py ~ 920
103              bsd_ex = BadSchemaDefinition(('%s in relation to entity %r (also is %r defined ? (check two '
diff --git a/schema.py b/schema.py
@@ -632,12 +632,12 @@
104 
105      __implements__ = IRelationSchema
106 
107      def __init__(self, schema=None, rdef=None, **kwargs):
108          if rdef is not None:
109 -            # if this relation is symetric/inlined
110 -            self.symetric = rdef.symetric or False
111 +            # if this relation is symmetric/inlined
112 +            self.symmetric = rdef.symmetric or False
113              self.inlined = rdef.inlined or False
114              # if full text content of subject/object entity should be added
115              # to other side entity (the container)
116              self.fulltext_container = rdef.fulltext_container or None
117              # if this relation is an attribute relation
@@ -683,11 +683,11 @@
118                  raise BadSchemaDefinition(msg)
119          constraints = getattr(rdef, 'constraints', None)
120          if constraints:
121              for cstr in constraints:
122                  cstr.check_consistency(subjschema, objschema, rdef)
123 -        if (subjschema, objschema) in self.rdefs and self.symetric:
124 +        if (subjschema, objschema) in self.rdefs and self.symmetric:
125              return
126          # update our internal struct
127          self.final = final
128          rdefs = self.init_rproperties(subjschema, objschema, rdef)
129          self._add_rdef(rdefs)
@@ -695,21 +695,21 @@
130 
131      def _add_rdef(self, rdef):
132          # update our internal struct
133          self.rdefs[(rdef.subject, rdef.object)] = rdef
134          self._update(rdef.subject, rdef.object)
135 -        if self.symetric:
136 +        if self.symmetric:
137              self._update(rdef.object, rdef.subject)
138              if rdef.object != rdef.subject:
139                  self.rdefs[(rdef.object, rdef.subject)] = rdef
140          if self.inlined and rdef.cardinality[0] in '*+':
141              raise BadSchemaDefinition(
142                  'inlined relation %s can\'t have multiple cardinality for its '
143                  'subject' % rdef)
144          # update entity types schema
145          rdef.subject.add_subject_relation(self)
146 -        if self.symetric:
147 +        if self.symmetric:
148              rdef.object.add_subject_relation(self)
149          else:
150              rdef.object.add_object_relation(self)
151 
152      def _update(self, subjectschema, objectschema):
@@ -738,11 +738,11 @@
153          try:
154              del self.rdefs[(subjschema, objschema)]
155          except KeyError:
156              pass
157          try:
158 -            if self.symetric and subjschema != objschema and not _recursing:
159 +            if self.symmetric and subjschema != objschema and not _recursing:
160                  self.del_relation_def(objschema, subjschema, True)
161          except KeyError:
162              pass
163          if not self._obj_schemas or not self._subj_schemas:
164              assert not self._obj_schemas and not self._subj_schemas
diff --git a/schema2dot.py b/schema2dot.py
@@ -34,12 +34,12 @@
165          return {'label' : ''.join(label), 'shape' : "record",
166                  'fontname' : "Courier", 'style' : "filled"}
167 
168      def edge_properties(self, rschema, subjnode, objnode):
169          """return default DOT drawing options for a relation schema"""
170 -        # symetric rels are handled differently, let yams decide what's best
171 -        if rschema.symetric:
172 +        # symmetric rels are handled differently, let yams decide what's best
173 +        if rschema.symmetric:
174              kwargs = {'label': rschema.type,
175                        'color': '#887788', 'style': 'dashed',
176                        'dir': 'both', 'arrowhead': 'normal', 'arrowtail': 'normal'}
177          else:
178              kwargs = {'label': rschema.type,
@@ -84,11 +84,11 @@
179 
180      def display_rel(self, rschema, setype, tetype):
181          if (rschema, setype, tetype) in self._done:
182              return False
183          self._done.add((rschema, setype, tetype))
184 -        if rschema.symetric:
185 +        if rschema.symmetric:
186              self._done.add((rschema, tetype, setype))
187          return True
188 
189      def nodes(self):
190          return self._nodes
diff --git a/test/data/schema/schema.py b/test/data/schema/schema.py
@@ -6,11 +6,11 @@
191      sujet = String(maxsize=128)
192      ref = String(maxsize=12)
193 
194      concerne = SubjectRelation('Societe')
195      obj_wildcard = SubjectRelation('*')
196 -    sym_rel = SubjectRelation('Person', symetric=True)
197 +    sym_rel = SubjectRelation('Person', symmetric=True)
198      inline_rel = SubjectRelation('Person', inlined=True, cardinality='?*')
199      subj_wildcard = ObjectRelation('*')
200 
201 
202  class Person(EntityType):
diff --git a/test/data/schema2/schema.py b/test/data/schema2/schema.py
@@ -8,10 +8,10 @@
203 
204 
205  class rel(RelationType):
206      composite = 'subject'
207      cardinality = '1*'
208 -    symetric = True
209 +    symmetric = True
210 
211  class __rel(RelationType):
212      name = 'rel'
213      composite = 'subject'
diff --git a/test/unittest_reader.py b/test/unittest_reader.py
@@ -145,32 +145,32 @@
214 
215      # test relation type properties ###########################################
216 
217      def test_rschema(self):
218          rschema = schema.rschema('evaluee')
219 -        self.assertEquals(rschema.symetric, False)
220 +        self.assertEquals(rschema.symmetric, False)
221          self.assertEquals(rschema.description, '')
222          self.assertEquals(rschema.final, False)
223          self.assertListEquals(sorted(rschema.subjects()), ['Person', 'Societe'])
224          self.assertListEquals(sorted(rschema.objects()), ['Note'])
225 
226          rschema = schema.rschema('sym_rel')
227 -        self.assertEquals(rschema.symetric, True)
228 +        self.assertEquals(rschema.symmetric, True)
229          self.assertEquals(rschema.description, '')
230          self.assertEquals(rschema.final, False)
231          self.assertListEquals(sorted(rschema.subjects()), ['Affaire', 'Person'])
232          self.assertListEquals(sorted(rschema.objects()), ['Affaire', 'Person'])
233 
234          rschema = schema.rschema('initial_state')
235 -        self.assertEquals(rschema.symetric, False)
236 +        self.assertEquals(rschema.symmetric, False)
237          self.assertEquals(rschema.description, 'indicate which state should be used by default when an entity using states is created')
238          self.assertEquals(rschema.final, False)
239          self.assertListEquals(sorted(rschema.subjects()), ['Eetype'])
240          self.assertListEquals(sorted(rschema.objects()), ['State'])
241 
242          rschema = schema.rschema('name')
243 -        self.assertEquals(rschema.symetric, False)
244 +        self.assertEquals(rschema.symmetric, False)
245          self.assertEquals(rschema.description, '')
246          self.assertEquals(rschema.final, True)
247          self.assertListEquals(sorted(rschema.subjects()), ['Company', 'Division', 'EPermission', 'Eetype', 'State', 'Subcompany', 'Subdivision'])
248          self.assertListEquals(sorted(rschema.objects()), ['String'])
249 
@@ -288,11 +288,11 @@
250                             'delete': ('managers', 'owners',),
251                             'update': ('managers', 'owners',)})
252 
253  ##     def test_nonregr_using_tuple_as_relation_target(self):
254  ##         rschema = schema.rschema('see_also')
255 -##         self.assertEquals(rschema.symetric, False)
256 +##         self.assertEquals(rschema.symmetric, False)
257  ##         self.assertEquals(rschema.description, '')
258  ##         self.assertEquals(rschema.final, False)
259  ##         self.assertListEquals(sorted(rschema.subjects()), ['Employee'])
260  ##         self.assertListEquals(sorted(rschema.objects()), ['Company', 'Division'])
261  ##
@@ -464,11 +464,11 @@
262                            'subject')
263          self.assertEquals(rel.rdef('Anentity', 'Anentity').cardinality,
264                            '1*')
265          self.assertEquals(rel.rdef('Anotherentity', 'Anentity').cardinality,
266                            '1*')
267 -        self.assertEquals(rel.symetric, True)
268 +        self.assertEquals(rel.symmetric, True)
269          self.assertEquals(rel.inlined, True)
270 
271      def test_imports(self):
272          SchemaLoader.main_schema_directory = 'schema'
273          schema = SchemaLoader().load([DATADIR, DATADIR+'2'], 'Test')
diff --git a/test/unittest_schema.py b/test/unittest_schema.py
@@ -359,12 +359,12 @@
274 
275      def test_raise_relation_def(self):
276          self.assertRaisesMsg(BadSchemaDefinition, "using unknown type 'Afire' in relation evaluee"  ,
277                               schema.add_relation_def, RelationDefinition('Afire', 'evaluee', 'Note'))
278  ## XXX what is this ?
279 -##        self.assertRaisesMsg(BadSchemaDefinition, 'the "symetric" property should appear on every definition of relation evaluee' ,
280 -##                             schema.add_relation_def, RelationDefinition('Affaire', 'evaluee', 'Note', symetric=True))
281 +##        self.assertRaisesMsg(BadSchemaDefinition, 'the "symmetric" property should appear on every definition of relation evaluee' ,
282 +##                             schema.add_relation_def, RelationDefinition('Affaire', 'evaluee', 'Note', symmetric=True))
283 
284      def test_schema_relations(self):
285          all_relations = ['TEST', 'concerne', 'travaille', 'evaluee',
286                           'date', 'type', 'sujet', 'ref', 'nom', 'prenom',
287                           'starton', 'sexe', 'promo', 'promo_enlarged',
@@ -442,11 +442,11 @@
288          global schema
289          schema = Schema('Test Schema')
290          ebug = schema.add_entity_type(EntityType('Bug'))
291          estory = schema.add_entity_type(EntityType('Story'))
292          eproject = schema.add_entity_type(EntityType('Project'))
293 -        schema.add_relation_type(RelationType('see_also', symetric=True))
294 +        schema.add_relation_type(RelationType('see_also', symmetric=True))
295 
296      def test_association_types(self):
297          schema.add_relation_def(RelationDefinition('Bug', 'see_also', 'Bug'))
298          schema.add_relation_def(RelationDefinition('Bug', 'see_also', 'Story'))
299          schema.add_relation_def(RelationDefinition('Bug', 'see_also', 'Project'))