Skip to content

Commit 315b062

Browse files
committed
FIX: module refresher
1 parent 4adf78f commit 315b062

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

GH/PyGH/components/scriptsynccpy/code.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,12 @@ def init_script_path(self, btn : bool = False):
278278
if not os.path.exists(self.path):
279279
raise Exception("script-sync::File does not exist")
280280

281-
def reload_all_modules(directory):
281+
def reload_all_modules(self, directory):
282282
for filename in os.listdir(directory):
283-
if filename.endswith('.py') and filename != '__init__.py':
284-
module_name = filename[:-3] # remove '.py' from filename
285-
if module_name in sys.modules:
286-
importlib.reload(sys.modules[module_name])
283+
if filename.endswith('.py') and filename != '__init__.py':
284+
module_name = filename[:-3] # remove '.py' from filename
285+
if module_name in sys.modules:
286+
importlib.reload(sys.modules[module_name])
287287

288288
def safe_exec(self, path, globals, locals):
289289
"""
@@ -300,8 +300,6 @@ def safe_exec(self, path, globals, locals):
300300
# add the path of the file to use the modules
301301
path_dir = os.path.dirname(path)
302302
sys.path.insert(0, path_dir)
303-
reload_all_modules(path_dir)
304-
305303
self.reload_all_modules(path_dir)
306304

307305
# parse the code

GH/PyGH/test/my_module.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
def print_from_my_module():
3+
print("script-sync::Hello from my_module.py")

GH/PyGH/test/test_module.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#! python3
2+
3+
import my_module
4+
5+
def main() -> None:
6+
print("script-sync::running main()")
7+
my_module.print_from_my_module()
8+
9+
if __name__ == "__main__":
10+
main()

0 commit comments

Comments
 (0)