|
7 | 7 | import inspect |
8 | 8 | import os |
9 | 9 | import shutil |
| 10 | +import sys |
10 | 11 | import time |
11 | 12 | from pathlib import Path |
12 | 13 | from types import FrameType |
@@ -244,23 +245,38 @@ def warn(msg: str, *, dedupe: bool = False, **kwargs): |
244 | 245 | print_to_log_file(f"[orange1]Warning: {msg}[/orange1]", **kwargs) |
245 | 246 |
|
246 | 247 |
|
247 | | -def _get_first_non_framework_frame() -> FrameType | None: |
| 248 | +@once |
| 249 | +def _exclude_paths_from_frame_info() -> list[Path]: |
| 250 | + import importlib.util |
| 251 | + |
248 | 252 | import click |
| 253 | + import granian |
| 254 | + import socketio |
249 | 255 | import typing_extensions |
250 | 256 |
|
251 | 257 | import reflex as rx |
252 | 258 |
|
253 | 259 | # Exclude utility modules that should never be the source of deprecated reflex usage. |
254 | | - exclude_modules = [click, rx, typing_extensions] |
| 260 | + exclude_modules = [click, rx, typing_extensions, socketio, granian] |
| 261 | + modules_paths = [file for m in exclude_modules if (file := m.__file__)] + [ |
| 262 | + spec.origin |
| 263 | + for m in [*sys.builtin_module_names, *sys.stdlib_module_names] |
| 264 | + if (spec := importlib.util.find_spec(m)) and spec.origin |
| 265 | + ] |
255 | 266 | exclude_roots = [ |
256 | 267 | p.parent.resolve() if (p := Path(file)).name == "__init__.py" else p.resolve() |
257 | | - for m in exclude_modules |
258 | | - if (file := m.__file__) |
| 268 | + for file in modules_paths |
259 | 269 | ] |
260 | 270 | # Specifically exclude the reflex cli module. |
261 | 271 | if reflex_bin := shutil.which(b"reflex"): |
262 | 272 | exclude_roots.append(Path(reflex_bin.decode())) |
263 | 273 |
|
| 274 | + return exclude_roots |
| 275 | + |
| 276 | + |
| 277 | +def _get_first_non_framework_frame() -> FrameType | None: |
| 278 | + exclude_roots = _exclude_paths_from_frame_info() |
| 279 | + |
264 | 280 | frame = inspect.currentframe() |
265 | 281 | while frame := frame and frame.f_back: |
266 | 282 | frame_path = Path(inspect.getfile(frame)).resolve() |
@@ -297,13 +313,13 @@ def deprecate( |
297 | 313 | filename = Path(origin_frame.f_code.co_filename) |
298 | 314 | if filename.is_relative_to(Path.cwd()): |
299 | 315 | filename = filename.relative_to(Path.cwd()) |
300 | | - loc = f"{filename}:{origin_frame.f_lineno}" |
| 316 | + loc = f" ({filename}:{origin_frame.f_lineno})" |
301 | 317 | dedupe_key = f"{dedupe_key} {loc}" |
302 | 318 |
|
303 | 319 | if dedupe_key not in _EMITTED_DEPRECATION_WARNINGS: |
304 | 320 | msg = ( |
305 | 321 | f"{feature_name} has been deprecated in version {deprecation_version}. {reason.rstrip('.').lstrip('. ')}. It will be completely " |
306 | | - f"removed in {removal_version}. ({loc})" |
| 322 | + f"removed in {removal_version}.{loc}" |
307 | 323 | ) |
308 | 324 | if _LOG_LEVEL <= LogLevel.WARNING: |
309 | 325 | print(f"[yellow]DeprecationWarning: {msg}[/yellow]", **kwargs) |
|
0 commit comments