|
@@ -10,6 +10,7 @@ import re
|
|
|
import subprocess
|
|
|
import sys
|
|
|
from pathlib import Path
|
|
|
+from typing import Sequence
|
|
|
from urllib.parse import urljoin
|
|
|
|
|
|
import psutil
|
|
@@ -242,14 +243,14 @@ def run_backend(
|
|
|
run_uvicorn_backend(host, port, loglevel)
|
|
|
|
|
|
|
|
|
-def get_reload_dirs() -> list[Path]:
|
|
|
- """Get the reload directories for the backend.
|
|
|
+def get_reload_paths() -> Sequence[Path]:
|
|
|
+ """Get the reload paths for the backend.
|
|
|
|
|
|
Returns:
|
|
|
- The reload directories for the backend.
|
|
|
+ The reload paths for the backend.
|
|
|
"""
|
|
|
config = get_config()
|
|
|
- reload_dirs = [Path(config.app_name)]
|
|
|
+ reload_paths = [Path(config.app_name).parent]
|
|
|
if config.app_module is not None and config.app_module.__file__:
|
|
|
module_path = Path(config.app_module.__file__).resolve().parent
|
|
|
|
|
@@ -263,8 +264,43 @@ def get_reload_dirs() -> list[Path]:
|
|
|
else:
|
|
|
break
|
|
|
|
|
|
- reload_dirs = [module_path]
|
|
|
- return reload_dirs
|
|
|
+ reload_paths = [module_path]
|
|
|
+
|
|
|
+ include_dirs = tuple(
|
|
|
+ map(Path.absolute, environment.REFLEX_HOT_RELOAD_INCLUDE_PATHS.get())
|
|
|
+ )
|
|
|
+ exclude_dirs = tuple(
|
|
|
+ map(Path.absolute, environment.REFLEX_HOT_RELOAD_EXCLUDE_PATHS.get())
|
|
|
+ )
|
|
|
+
|
|
|
+ def is_excluded_by_default(path: Path) -> bool:
|
|
|
+ if path.is_dir():
|
|
|
+ if path.name.startswith("."):
|
|
|
+ # exclude hidden directories
|
|
|
+ return True
|
|
|
+ if path.name.startswith("__"):
|
|
|
+ # ignore things like __pycache__
|
|
|
+ return True
|
|
|
+ return path.name not in (".gitignore", "uploaded_files")
|
|
|
+
|
|
|
+ reload_paths = (
|
|
|
+ tuple(
|
|
|
+ path.absolute()
|
|
|
+ for dir in reload_paths
|
|
|
+ for path in dir.iterdir()
|
|
|
+ if not is_excluded_by_default(path)
|
|
|
+ )
|
|
|
+ + include_dirs
|
|
|
+ )
|
|
|
+
|
|
|
+ if exclude_dirs:
|
|
|
+ reload_paths = tuple(
|
|
|
+ path
|
|
|
+ for path in reload_paths
|
|
|
+ if all(not path.samefile(exclude) for exclude in exclude_dirs)
|
|
|
+ )
|
|
|
+
|
|
|
+ return reload_paths
|
|
|
|
|
|
|
|
|
def run_uvicorn_backend(host: str, port: int, loglevel: LogLevel):
|
|
@@ -283,7 +319,7 @@ def run_uvicorn_backend(host: str, port: int, loglevel: LogLevel):
|
|
|
port=port,
|
|
|
log_level=loglevel.value,
|
|
|
reload=True,
|
|
|
- reload_dirs=list(map(str, get_reload_dirs())),
|
|
|
+ reload_dirs=list(map(str, get_reload_paths())),
|
|
|
)
|
|
|
|
|
|
|
|
@@ -310,8 +346,7 @@ def run_granian_backend(host: str, port: int, loglevel: LogLevel):
|
|
|
interface=Interfaces.ASGI,
|
|
|
log_level=LogLevels(loglevel.value),
|
|
|
reload=True,
|
|
|
- reload_paths=get_reload_dirs(),
|
|
|
- reload_ignore_dirs=[".web", ".states"],
|
|
|
+ reload_paths=get_reload_paths(),
|
|
|
).serve()
|
|
|
except ImportError:
|
|
|
console.error(
|