changeset 1514:16228994ca3b

server: fix hot reloading of modules in dev mode
author Goffi <goffi@goffi.org>
date Mon, 22 May 2023 11:57:49 +0200
parents ff95501abe74
children 73c848c2f41e
files libervia/server/pages.py libervia/server/server.py
diffstat 2 files changed, 34 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/server/pages.py	Mon May 22 11:57:49 2023 +0200
+++ b/libervia/server/pages.py	Mon May 22 11:57:49 2023 +0200
@@ -17,40 +17,43 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from __future__ import annotations
-
-import uuid
-import os.path
-import urllib.request, urllib.parse, urllib.error
-import time
+import copy
+from functools import reduce
 import hashlib
-import copy
 import json
-import traceback
+import os.path
 from pathlib import Path
-from functools import reduce
-from typing import Optional, Union, List
+import time
+import traceback
+from typing import List, Optional, Union
+import urllib.error
+import urllib.parse
+import urllib.request
+import uuid
 
+from twisted.internet import defer
+from twisted.python import failure
+from twisted.python.filepath import FilePath
 from twisted.web import server
 from twisted.web import resource as web_resource
 from twisted.web import util as web_util
-from twisted.internet import defer
 from twisted.words.protocols.jabber import jid
-from twisted.python import failure
 
+from sat.core import exceptions
 from sat.core.i18n import _
-from sat.core import exceptions
-from sat.tools.utils import as_deferred
+from sat.core.log import getLogger
 from sat.tools.common import date_utils
 from sat.tools.common import utils
 from sat.tools.common import data_format
-from sat.core.log import getLogger
+from sat.tools.utils import as_deferred
 from sat_frontends.bridge.bridge_frontend import BridgeException
 
-from .constants import Const as C
 from . import session_iface
-from .utils import quote, SubPage
 from .classes import WebsocketMeta
 from .classes import Script
+from .constants import Const as C
+from .resources import LiberviaRootResource
+from .utils import SubPage, quote
 
 log = getLogger(__name__)
 
@@ -442,15 +445,22 @@
                     cls.create_browser_data(vhost_root, resource, browser_path, new_path)
 
     @classmethod
-    def on_file_change(cls, host, file_path, flags, site_root, site_path):
+    def on_file_change(
+        cls,
+        host,
+        file_path: FilePath,
+        flags: List[str],
+        site_root: LiberviaRootResource,
+        site_path: Path
+    ) -> None:
         """Method triggered by file_watcher when something is changed in files
 
         This method is used in dev mode to reload pages when needed
-        @param file_path(filepath.FilePath): path of the file which triggered the event
-        @param flags[list[unicode]): human readable flags of the event (from
+        @param file_path: path of the file which triggered the event
+        @param flags: human readable flags of the event (from
             internet.inotify)
-        @param site_root(LiberviaRootResource): root of the site
-        @param site_path(unicode): absolute path of the site
+        @param site_root: root of the site
+        @param site_path: absolute path of the site
         """
         if flags == ['create']:
             return
--- a/libervia/server/server.py	Mon May 22 11:57:49 2023 +0200
+++ b/libervia/server/server.py	Mon May 22 11:57:49 2023 +0200
@@ -531,7 +531,9 @@
                     self.files_watcher.watch_dir(
                         site_path, auto_add=True, recursive=True,
                         callback=LiberviaPage.on_file_change, site_root=res,
-                        site_path=site_path)
+                        # FIXME: site_path should always be a Path, check code above and
+                        # in template module
+                        site_path=Path(site_path))
 
                 LiberviaPage.import_pages(self, res)
                 # FIXME: default pages are accessible if not overriden by external website