Skip to content

Commit 9ee8082

Browse files
committedMay 16, 2020
grc: fixup: dynamically update namespaces from blocks (gnuradio#3317)
1 parent 57ec125 commit 9ee8082

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
 

‎grc/core/blocks/block.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def __init__(self, parent):
7676
self.active_sinks = [] # on rewrite
7777

7878
self.states = {'state': True, 'bus_source': False, 'bus_sink': False, 'bus_structure': None}
79+
self.block_namespace = {}
7980

8081
if Flags.HAS_CPP in self.flags and self.enabled and not (self.is_virtual_source() or self.is_virtual_sink()):
8182
# This is a workaround to allow embedded python blocks/modules to load as there is
@@ -131,17 +132,18 @@ def rekey(ports):
131132
self.active_sinks = [p for p in self.sinks if not p.hidden]
132133

133134
# namespaces may have changed, update them
134-
self.block_namespace = {}
135+
self.block_namespace.clear()
136+
imports = ""
135137
try:
136-
exec(self.templates.render('imports'), self.block_namespace)
138+
imports = self.templates.render('imports')
139+
exec(imports, self.block_namespace)
137140
except ImportError:
138141
# We do not have a good way right now to determine if an import is for a
139142
# hier block, these imports will fail as they are not in the search path
140143
# this is ok behavior, unfortunately we could be hiding other import bugs
141144
pass
142145
except Exception:
143-
log.exception('Failed to evaluate import expression "{0}"'.format(expr), exc_info=True)
144-
pass
146+
self.add_error_message(f'Failed to evaluate import expression {imports!r}')
145147

146148
def update_bus_logic(self):
147149
###############################

0 commit comments

Comments
 (0)
Please sign in to comment.