Caster
Caster copied to clipboard
Reloading imported files and dependencies without rebooting engine
Is your feature request related to a problem? Please describe. The rewrite by Synkarius implements reloading of grammars without rebooting the engine. However, it is still necessary to review the engine in order to reload files that are imported by grammar files. We want to be able to reload those to reload those too without rebooting the engine.
Describe the solution you'd like From Synkarius:
I have a thought about dependency reloading which I do not have time to implement, but which I would happily guide someone else through. The difficult part about deep dependency reloading is, in my opinion, figuring out what the dependency tree looks like. That goes both ways. So, if I modify a dependency, how should I know which rules use it, or which other dependencies use it, which are then in turn used by other dependencies or by rules, etc. Likewise, if I modify a rule and just look at its import statements and start reloading them and their dependencies, I may very well end up reloading things I didn't want to, like the Caster nexus, or other things in Natlink or Dragonfly which have state.
However, one simple way to do it might be to include a list of modules in the RuleDetails object which should get reloaded when a rule gets reloaded. So for example, you could specify that if firefox.py reloads, browser_shared.py should reload before it.
That would not be difficult to implement, especially with the new structure. It's not as slick as true deep dependency reloading would be, but I think it'd get us 95% of the way there in terms of usability benefit. You would have to change a dependency and then, for example, add a comment somewhere in the rule the dependency was for. The rule change would then kick off and when it came time to reload it, the list of dependent modules would get reloaded first -- even though changing the dependency itself still wouldn't kick off this process, it would be a non-terrible way of achieving almost the same thing, for fairly little engineering effort.
Describe alternatives you've considered For "true deep dependency reloading" (as opposed to the particular solution Synkarius describes above), some links of interest are here. ipython deepreload link1 ipython deepreload link2 recursive version of reload Synkarius on the options linked above:
So I tried them both. They are not drop-in solutions as I had hoped, but they both error out in the same place, which is actually a pretty good sign that the solution might (big grain of salt here) be simple to making one of them work (I'd opt for the iPython one since it's better established). If you're interested, the section of code which I dropped both of them into was _get_reload_fn in content_loader.py.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
Related: https://github.com/dictation-toolbox/Caster/issues/646