Get the reload paths for the backend. Returns: The reload paths for the backend. Raises: RuntimeError: If the `__init__.py` file is found in the app root directory.
()
| 492 | |
| 493 | |
| 494 | def get_reload_paths() -> Sequence[Path]: |
| 495 | """Get the reload paths for the backend. |
| 496 | |
| 497 | Returns: |
| 498 | The reload paths for the backend. |
| 499 | |
| 500 | Raises: |
| 501 | RuntimeError: If the `__init__.py` file is found in the app root directory. |
| 502 | """ |
| 503 | override_dirs = tuple( |
| 504 | map(Path.absolute, environment.REFLEX_HOT_RELOAD_OVERRIDE_PATHS.get()) |
| 505 | ) |
| 506 | |
| 507 | if override_dirs: |
| 508 | console.debug(f"Reload paths (override): {list(map(str, override_dirs))}") |
| 509 | return override_dirs |
| 510 | |
| 511 | config = get_config() |
| 512 | reload_paths = [Path.cwd()] |
| 513 | app_module = config.module |
| 514 | module_path = get_module_path(app_module) |
| 515 | if module_path is not None: |
| 516 | module_path = module_path.parent |
| 517 | |
| 518 | while module_path.parent.name and _has_child_file(module_path, "__init__.py"): |
| 519 | if ( |
| 520 | _has_child_file(module_path, "rxconfig.py") |
| 521 | and module_path == Path.cwd() |
| 522 | ): |
| 523 | init_file = module_path / "__init__.py" |
| 524 | init_file_content = init_file.read_text() |
| 525 | if init_file_content.strip(): |
| 526 | msg = "There should not be an `__init__.py` file in your app root directory" |
| 527 | raise RuntimeError(msg) |
| 528 | console.warn( |
| 529 | "Removing `__init__.py` file in the app root directory. " |
| 530 | "This file can cause issues with module imports. " |
| 531 | ) |
| 532 | init_file.unlink() |
| 533 | break |
| 534 | |
| 535 | # go up a level to find dir without `__init__.py` or with `rxconfig.py` |
| 536 | module_path = module_path.parent |
| 537 | |
| 538 | reload_paths = [module_path] |
| 539 | |
| 540 | include_dirs = tuple( |
| 541 | map(Path.absolute, environment.REFLEX_HOT_RELOAD_INCLUDE_PATHS.get()) |
| 542 | ) |
| 543 | exclude_dirs = tuple( |
| 544 | map(Path.absolute, environment.REFLEX_HOT_RELOAD_EXCLUDE_PATHS.get()) |
| 545 | ) |
| 546 | |
| 547 | def is_excluded_by_default(path: Path) -> bool: |
| 548 | if path.is_dir(): |
| 549 | if path.name.startswith("."): |
| 550 | # exclude hidden directories |
| 551 | return True |
no test coverage detected