Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions reflex/reflex.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,9 @@ def _run(
*args,
**kwargs,
)
validation_result = compile_future.result()
compile_future.result()
else:
validation_result = app_task(*args, **kwargs)

if not validation_result:
raise click.exceptions.Exit(1)
app_task(*args, **kwargs)

# Get the frontend and backend commands, based on the environment.
setup_frontend = frontend_cmd = backend_cmd = None
Expand Down
79 changes: 8 additions & 71 deletions reflex/utils/prerequisites.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import functools
import importlib
import importlib.metadata
import importlib.util
import io
import json
import os
import platform
Expand Down Expand Up @@ -498,86 +496,25 @@ def compile_app(
)


def _can_colorize() -> bool:
"""Check if the output can be colorized.

Copied from _colorize.can_colorize.

https://raw.githubusercontent.com/python/cpython/refs/heads/main/Lib/_colorize.py

Returns:
If the output can be colorized
"""
file = sys.stdout

if not sys.flags.ignore_environment:
if os.environ.get("PYTHON_COLORS") == "0":
return False
if os.environ.get("PYTHON_COLORS") == "1":
return True
if os.environ.get("NO_COLOR"):
return False
if os.environ.get("FORCE_COLOR"):
return True
if os.environ.get("TERM") == "dumb":
return False

if not hasattr(file, "fileno"):
return False

if sys.platform == "win32":
try:
import nt

if not nt._supports_virtual_terminal():
return False
except (ImportError, AttributeError):
return False

try:
return os.isatty(file.fileno())
except io.UnsupportedOperation:
return file.isatty()


def compile_or_validate_app(
compile: bool = False,
check_if_schema_up_to_date: bool = False,
prerender_routes: bool = False,
) -> bool:
):
"""Compile or validate the app module based on the default config.

Args:
compile: Whether to compile the app.
check_if_schema_up_to_date: If True, check if the schema is up to date.
prerender_routes: Whether to prerender routes.

Returns:
If the app is compiled successfully.
"""
try:
if compile:
compile_app(
check_if_schema_up_to_date=check_if_schema_up_to_date,
prerender_routes=prerender_routes,
)
else:
validate_app(check_if_schema_up_to_date=check_if_schema_up_to_date)
except Exception as e:
if isinstance(e, click.exceptions.Exit):
return False

import traceback

sys_exception = sys.exception()

try:
colorize = _can_colorize()
traceback.print_exception(e, colorize=colorize) # pyright: ignore[reportCallIssue]
except Exception:
traceback.print_exception(sys_exception)
return False
return True
if compile:
compile_app(
check_if_schema_up_to_date=check_if_schema_up_to_date,
prerender_routes=prerender_routes,
)
else:
validate_app(check_if_schema_up_to_date=check_if_schema_up_to_date)


def get_redis() -> Redis | None:
Expand Down