This is how many of Blender's official add-ons do it, including the FBX exporter, the glTF exporter and the OBJ exporter.
The idea is as follows:
if "bpy" in locals():
import importlib
if "module_name" in locals():
importlib.reload("module_name")
import bpy
A reload is triggered for every module that we maintain ourselves since it may have changes made to its code, even while Blender is running.
When the module is first imported, its name is not in locals yet. On subsequent reloads this is the case and so this can be used as the condition to determine whether a reload is needed (this of course doesn't mean that a file's contents have been changed!).
This is how many of Blender's official add-ons do it, including the FBX exporter, the glTF exporter and the OBJ exporter.
The idea is as follows:
A reload is triggered for every module that we maintain ourselves since it may have changes made to its code, even while Blender is running.
When the module is first imported, its name is not in locals yet. On subsequent reloads this is the case and so this can be used as the condition to determine whether a reload is needed (this of course doesn't mean that a file's contents have been changed!).