By that I mean reducing the time between you saving the changes on a python file, and actually running those changes within FreeCAD.
My current strategy is to use:
Code: Select all
importlib.reload(module.i.just.changed)
Code: Select all
importlib.reload(module.i.just.changed)
That's about how you do it. I'm not even that efficient... You could probably write a lambda function in the console to do that, I guess.. ?
I was also considering that. I noticed that (perhaps due to a screwup on my module organisation) I need to run the method on each of the submodules, individually if I want to have the entire module be updated, so I thought it might be worthwhile to have some simple function to run it recursively.Joel_graff wrote: ↑Tue Mar 05, 2019 3:27 am That's about how you do it. I'm not even that efficient... You could probably write a lambda function in the console to do that, I guess.. ?
Someone's probably got that all figured out. I'm too lazy to care, tbh. But yes, you need to reload each module that gets changed.David_D wrote: ↑Tue Mar 05, 2019 3:35 am I was also considering that. I noticed that (perhaps due to a screwup on my module organisation) I need to run the method on each of the submodules, individually if I want to have the entire module be updated, so I thought it might be worthwhile to have some simple function to run it recursively.
Code: Select all
my_modules = ['moduleA', 'moduleB', 'moduleC']
my_reload = lambda mod_list: [reload(mod) for mod in mod_list]
That's a clever way of doing it. It's a shame about the not reloading the deps, though.furti wrote: ↑Tue Mar 05, 2019 10:42 am https://github.com/furti/FreeCAD-Lithop ... e_image.py this is a example if setting up the object as i need for testing.
I adapted some code on stack exchange to work for FreeCAD, and added this function to one of my modules, to do what you're recommending. In my case, the module "Detailing" is the one I'm working on and want to reload.Joel_graff wrote: ↑Tue Mar 05, 2019 3:48 am Someone's probably got that all figured out. I'm too lazy to care, tbh. But yes, you need to reload each module that gets changed.
Code: Select all
import os
import types
import importlib
import Detailing
def reload_code():
reload_module = Detailing
fn = reload_module.__file__
fn_dir = os.path.dirname(fn) + os.sep
module_visit = {fn}
del fn
def reload_recursive_ex(module):
importlib.reload(module)
for module_child in vars(module).values():
if isinstance(module_child, types.ModuleType):
fn_child = getattr(module_child, "__file__", None)
if (fn_child is not None) and fn_child.startswith(fn_dir):
if fn_child not in module_visit:
FreeCAD.Console.PrintMessage("Reloading: {}, from: {}\n".format(
fn_child, module
))
module_visit.add(fn_child)
reload_recursive_ex(module_child)
return reload_recursive_ex(reload_module)