Fixes unbound import of dependency
This commit is contained in:
parent
9483b98e34
commit
f83c6d0570
1 changed files with 21 additions and 28 deletions
|
@ -1,7 +1,5 @@
|
|||
import logging
|
||||
|
||||
DEPENDENCY_INSTALLED = None
|
||||
|
||||
try:
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import (
|
||||
|
@ -10,27 +8,16 @@ try:
|
|||
FileModifiedEvent,
|
||||
)
|
||||
|
||||
DEPENDENCY_INSTALLED = True
|
||||
logging.debug("Watchdog imported successfully. Hot reloading available.")
|
||||
except ImportError:
|
||||
DEPENDENCY_INSTALLED = False
|
||||
logging.info("Watchdog is not installed. Hot reloading unavailable.")
|
||||
|
||||
|
||||
class HotReloader(FileSystemEventHandler):
|
||||
def __init__(self, path):
|
||||
if not DEPENDENCY_INSTALLED:
|
||||
return
|
||||
"""Might be unbound, if watchdog is not installed. Check if equal to None before use."""
|
||||
|
||||
def __init__(self, path):
|
||||
self.path = path
|
||||
self.observer = Observer()
|
||||
self.observer.schedule(self, path, recursive=True)
|
||||
self.observer.start()
|
||||
|
||||
def __del__(self):
|
||||
if not DEPENDENCY_INSTALLED:
|
||||
return
|
||||
|
||||
self.observer.stop()
|
||||
self.observer.join()
|
||||
|
||||
|
@ -39,3 +26,9 @@ class HotReloader(FileSystemEventHandler):
|
|||
|
||||
def on_created(self, event: FileCreatedEvent):
|
||||
logging.info("New config file created. Triggering hot reload.")
|
||||
|
||||
logging.debug("Watchdog imported successfully. Hot reloading available.")
|
||||
|
||||
|
||||
except ImportError:
|
||||
logging.info("Watchdog is not installed. Hot reloading unavailable.")
|
||||
|
|
Loading…
Reference in a new issue