Commit 6967a12b authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

#19467: have a post-read hook for the schema

--HG--
branch : stable
parent 8069cfd20eb4
ChangeLog for yams
------------------
--
* #19467 add post_build_callback support
--
2010/01/12 -- 0.25.1
* Small improvement of error message
......@@ -10,6 +11,7 @@ ChangeLog for yams
* Fix a bug when multiple reference to the same declaration exist
2009-10-21 -- 0.25.0
......
......@@ -168,6 +168,8 @@ class PyFileReader(object):
continue
warn('%s: please explicitly import %s (%s)'
% (filepath, pname, name), DeprecationWarning)
elif name == 'post_build_callback' and callable(obj):
self.loader.post_build_callbacks.append(obj)
for key in self.context:
fglobals.pop(key, None)
fglobals['__file__'] = filepath
......@@ -203,6 +205,7 @@ class SchemaLoader(object):
"""
self.defined = {}
self.loaded_files = []
self.post_build_callbacks = []
self._pyreader = PyFileReader(self)
sys.modules[__name__].context = self
# ensure we don't have an iterator
......@@ -226,6 +229,8 @@ class SchemaLoader(object):
for directory in directories]
cleanup_sys_modules(directories)
schema.loaded_files = self.loaded_files
for cb in self.post_build_callbacks:
cb(schema)
return schema
def _load_definition_files(self, directories):
......
from yams.buildobjs import EntityType
def post_build_callback(schema):
schema.add_entity_type(EntityType(name='Toto'))
......@@ -491,6 +491,10 @@ class SchemaLoaderTC2(TestCase):
relations = sorted( rel[0].type for rel in relations_def)
self.assertEquals( relations, expected_relations)
def test_post_build_callback(self):
SchemaLoader.main_schema_directory = 'post_build_callback'
schema = SchemaLoader().load([DATADIR], 'Test')
self.assertIn('Toto', schema.entities())
if __name__ == '__main__':
unittest_main()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment