diff options
author | Sebastian Koslowski <sebastian.koslowski@gmail.com> | 2020-05-16 22:00:03 +0200 |
---|---|---|
committer | Sebastian Koslowski <sebastian.koslowski@gmail.com> | 2020-05-16 22:01:51 +0200 |
commit | 9ee8082f1e2a704d524d25cbd9e3234ae3560d99 (patch) | |
tree | d8dcf5f0e92deeec38724e84cef2e0e99f0cb5d6 | |
parent | 57ec125023b3e125a7073dfede765435859c91ca (diff) |
grc: fixup: dynamically update namespaces from blocks (#3317)
-rw-r--r-- | grc/core/blocks/block.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/grc/core/blocks/block.py b/grc/core/blocks/block.py index 3fc238f42f..3dbdfbef1a 100644 --- a/grc/core/blocks/block.py +++ b/grc/core/blocks/block.py @@ -76,6 +76,7 @@ class Block(Element): self.active_sinks = [] # on rewrite self.states = {'state': True, 'bus_source': False, 'bus_sink': False, 'bus_structure': None} + self.block_namespace = {} if Flags.HAS_CPP in self.flags and self.enabled and not (self.is_virtual_source() or self.is_virtual_sink()): # This is a workaround to allow embedded python blocks/modules to load as there is @@ -131,17 +132,18 @@ class Block(Element): self.active_sinks = [p for p in self.sinks if not p.hidden] # namespaces may have changed, update them - self.block_namespace = {} + self.block_namespace.clear() + imports = "" try: - exec(self.templates.render('imports'), self.block_namespace) + imports = self.templates.render('imports') + exec(imports, self.block_namespace) except ImportError: # We do not have a good way right now to determine if an import is for a # hier block, these imports will fail as they are not in the search path # this is ok behavior, unfortunately we could be hiding other import bugs pass except Exception: - log.exception('Failed to evaluate import expression "{0}"'.format(expr), exc_info=True) - pass + self.add_error_message(f'Failed to evaluate import expression {imports!r}') def update_bus_logic(self): ############################### |