Merge remote-tracking branch 'upstream/main' into more-env-var-cleanup
This commit is contained in:
commit
9e7e1084e0
@ -645,7 +645,7 @@ class Component(BaseComponent, ABC):
|
||||
# Look for component specific triggers,
|
||||
# e.g. variable declared as EventHandler types.
|
||||
for field in self.get_fields().values():
|
||||
if types._issubclass(field.type_, EventHandler):
|
||||
if types._issubclass(field.outer_type_, EventHandler):
|
||||
args_spec = None
|
||||
annotation = field.annotation
|
||||
if (metadata := getattr(annotation, "__metadata__", None)) is not None:
|
||||
|
@ -22,7 +22,7 @@ from typing import (
|
||||
get_args,
|
||||
)
|
||||
|
||||
from typing_extensions import get_type_hints
|
||||
from typing_extensions import Annotated, get_type_hints
|
||||
|
||||
from reflex.utils.exceptions import ConfigError, EnvironmentVarValueError
|
||||
from reflex.utils.types import GenericType, is_union, value_inside_optional
|
||||
@ -214,8 +214,8 @@ def interpret_int_env(value: str, field_name: str) -> int:
|
||||
) from ve
|
||||
|
||||
|
||||
def interpret_path_env(value: str, field_name: str) -> Path:
|
||||
"""Interpret a path environment variable value.
|
||||
def interpret_existing_path_env(value: str, field_name: str) -> ExistingPath:
|
||||
"""Interpret a path environment variable value as an existing path.
|
||||
|
||||
Args:
|
||||
value: The environment variable value.
|
||||
@ -233,6 +233,19 @@ def interpret_path_env(value: str, field_name: str) -> Path:
|
||||
return path
|
||||
|
||||
|
||||
def interpret_path_env(value: str, field_name: str) -> Path:
|
||||
"""Interpret a path environment variable value.
|
||||
|
||||
Args:
|
||||
value: The environment variable value.
|
||||
field_name: The field name.
|
||||
|
||||
Returns:
|
||||
The interpreted value.
|
||||
"""
|
||||
return Path(value)
|
||||
|
||||
|
||||
def interpret_enum_env(value: str, field_type: GenericType, field_name: str) -> Any:
|
||||
"""Interpret an enum environment variable value.
|
||||
|
||||
@ -286,6 +299,8 @@ def interpret_env_var_value(
|
||||
return interpret_int_env(value, field_name)
|
||||
elif field_type is Path:
|
||||
return interpret_path_env(value, field_name)
|
||||
elif field_type is ExistingPath:
|
||||
return interpret_existing_path_env(value, field_name)
|
||||
elif inspect.isclass(field_type) and issubclass(field_type, enum.Enum):
|
||||
return interpret_enum_env(value, field_type, field_name)
|
||||
|
||||
@ -410,6 +425,13 @@ if TYPE_CHECKING:
|
||||
return default
|
||||
|
||||
|
||||
class PathExistsFlag:
|
||||
"""Flag to indicate that a path must exist."""
|
||||
|
||||
|
||||
ExistingPath = Annotated[Path, PathExistsFlag]
|
||||
|
||||
|
||||
class EnvironmentVariables:
|
||||
"""Environment variables class to instantiate environment variables."""
|
||||
|
||||
@ -438,7 +460,7 @@ class EnvironmentVariables:
|
||||
REFLEX_WEB_WORKDIR: EnvVar[Path] = env_var(Path(constants.Dirs.WEB))
|
||||
|
||||
# Path to the alembic config file
|
||||
ALEMBIC_CONFIG: EnvVar[Path] = env_var(Path(constants.ALEMBIC_CONFIG))
|
||||
ALEMBIC_CONFIG: EnvVar[ExistingPath] = env_var(Path(constants.ALEMBIC_CONFIG))
|
||||
|
||||
# Disable SSL verification for HTTPX requests.
|
||||
SSL_NO_VERIFY: EnvVar[bool] = env_var(False)
|
||||
@ -567,7 +589,7 @@ class Config(Base):
|
||||
telemetry_enabled: bool = True
|
||||
|
||||
# The bun path
|
||||
bun_path: Path = constants.Bun.DEFAULT_PATH
|
||||
bun_path: ExistingPath = constants.Bun.DEFAULT_PATH
|
||||
|
||||
# List of origins that are allowed to connect to the backend API.
|
||||
cors_allowed_origins: List[str] = ["*"]
|
||||
@ -691,7 +713,7 @@ class Config(Base):
|
||||
)
|
||||
|
||||
# Interpret the value.
|
||||
value = interpret_env_var_value(env_var, field.type_, field.name)
|
||||
value = interpret_env_var_value(env_var, field.outer_type_, field.name)
|
||||
|
||||
# Set the value.
|
||||
updated_values[key] = value
|
||||
|
@ -1489,6 +1489,11 @@ if sys.version_info >= (3, 10):
|
||||
"""
|
||||
return self
|
||||
|
||||
@overload
|
||||
def __call__(
|
||||
self: EventCallback[Q, T],
|
||||
) -> EventCallback[Q, T]: ...
|
||||
|
||||
@overload
|
||||
def __call__(
|
||||
self: EventCallback[Concatenate[V, Q], T], value: V | Var[V]
|
||||
|
Loading…
Reference in New Issue
Block a user