Skip to content

Commit f56b08a

Browse files
committed
update to support packages
1 parent 8d0c84d commit f56b08a

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

__init__.py

+29-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import importlib,pdb,sys,traceback
1+
import importlib,pdb,sys,traceback,inspect
22

33
class LiveObject:
44
instances=[]
@@ -27,35 +27,55 @@ def live_classes(self):
2727

2828
def store_old_live_classes(self):
2929
live_classes = {}
30+
print("start storing old live classes............")
3031
for module in self.live_modules:
31-
live_module_name_list = [mod for mod in sys.modules.keys() if module in mod]
32+
live_module_name_list = [mod for mod in sys.modules.keys() if mod.endswith(module)]
3233
live_module_name = live_module_name_list[0]
3334
live_classes[module] = []
34-
if hasattr(sys.modules[live_module_name],"live_environment"):
35-
sys.modules[live_module_name].live_environment.update()
35+
print("\nchecking module: ", live_module_name)
36+
for mod in live_module_name_list:
37+
38+
if hasattr(sys.modules[mod],"live_environment"):
39+
#print("updating module",mod)
40+
sys.modules[mod].live_environment.update()
3641
for old_obj in sys.modules[live_module_name].__dict__.values():
37-
if old_obj.__class__.__name__ == 'type' and hasattr(old_obj.__class__,"instances"):
42+
#print("checking {} for class definitions using value ".format(live_module_name,old_obj))
43+
if inspect.isclass(old_obj) and hasattr(old_obj,"instances"):
3844
live_classes[module].append(old_obj)
45+
print("appended {} to the list with type {}".format(old_obj, type(old_obj)))
3946
self._live_classes = live_classes
47+
print("\n live_classes : {} \n".format(self._live_classes))
4048
return live_classes
4149

4250
def update(self):
51+
print("\n***** START CODE RELOAD ******\n")
4352
self.store_old_live_classes()
4453
for live_module in self.live_classes: #the name of the module is used as a key for the dict that stores all
54+
print("iterating through ",live_module)
4555
# live classes
46-
live_module_name_list = [mod for mod in sys.modules.keys() if live_module in mod]
56+
57+
live_module_name_list = [mod for mod in sys.modules.keys() if mod.endswith(live_module)]
4758
live_module_name = live_module_name_list[0]
48-
#pdb.set_trace()
49-
new_live_class = 0
59+
#print("code reload for module: ", live_module_name)
60+
5061
live_classes_ids = [id(cl) for cl in self.live_classes[live_module]]
62+
#print("code reload for module: ", live_module_name)
63+
5164
importlib.reload(sys.modules[live_module_name])
5265
live_classes_ids = [id(cl) for cl in self.live_classes[live_module]]
5366

67+
#if live_module == "cyclops.morpheas":
68+
#pdb.set_trace()
5469
for live_class in self.live_classes[live_module]:
70+
print("iterate class : {} with instances: {}".format(live_class,live_class.instances))
5571
new_live_class = eval("sys.modules[live_module_name]." + live_class.__name__)
5672

5773
for live_instance in live_class.instances:
74+
print("iterate instance :",live_instance)
5875
backup_instances = live_instance.__class__.instances
5976
live_instance.__class__ = new_live_class
77+
print("reloading instance \n instance : {} id: {} \n old class: {} id: {} \n new class : {} id: {"
78+
"} \n"
79+
"".format(live_instance,id(live_instance),live_class,id(live_class),new_live_class,id(new_live_class)))
6080
live_instance.__class__.instances = backup_instances
61-
live_instance = 0
81+
print("\n**********END CODE RELOAD************\n")

0 commit comments

Comments
 (0)