breuleux / jurigged

Hot reloading for Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Workaround for Geany IDE: Detect other types of file modifications: file move, file close, file overwritten

animaone opened this issue · comments

This is related to how Geany handles files by default: It creates a temporary file copy, writes the modifications to it and them copies the modifications to the current file.
These steps are made to prevent file corruption when there is no space left in the device.
Unfortunately this is not detected as a modification by jurigged and the file is not hot-reloaded

these are the events I logged by using on_any_event inside the class JuriggedHandler(FileSystemEventHandler):

event type: created path src : app_path/test_flask_hotreloading/.goutputstream-6PJ0X1
event type: modified path src : app_path/test_flask_hotreloading
event type: modified path src : app_path/test_flask_hotreloading/.goutputstream-6PJ0X1
event type: closed path src : app_path/test_flask_hotreloading/test_flask_hello.py
event type: modified path src : app_path/test_flask_hotreloading
event type: modified path src : app_path/test_flask_hotreloading/.goutputstream-6PJ0X1
event type: moved path src : app_path/test_flask_hotreloading/.goutputstream-6PJ0X1
event type: modified path src : app_path/test_flask_hotreloading
event type: closed path src : app_path/test_flask_hotreloading/test_flask_hello.py
event type: modified path src : app_path/test_flask_hotreloading

I propose the following temporary workaround:

    on_closed = on_modified

however, the best way can be to use only an on_any_event event and them, inside it handle all possible situations:

def on_any_event(self, event):
    print(f'event type: {event.event_type}  path src : {event.src_path}', flush = True)

a more aggressive approach:

def on_any_event(self, event):
    print(f'event type: {event.event_type}  path src : {event.src_path}', flush = True)
    if ".py" in event.src_path:
        #do reload procedure

I've not made a pull request because it is open to discussion, but I'm using the temporary workaround.