add existing path subclass for env checks
This commit is contained in:
parent
8f07082eba
commit
6655b789e3
@ -204,6 +204,25 @@ def interpret_int_env(value: str, field_name: str) -> int:
|
|||||||
) from ve
|
) from ve
|
||||||
|
|
||||||
|
|
||||||
|
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.
|
||||||
|
field_name: The field name.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The interpreted value.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
EnvironmentVarValueError: If the path does not exist.
|
||||||
|
"""
|
||||||
|
path = ExistingPath(value)
|
||||||
|
if not path.exists():
|
||||||
|
raise EnvironmentVarValueError(f"Path does not exist: {path} for {field_name}")
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
def interpret_path_env(value: str, field_name: str) -> Path:
|
def interpret_path_env(value: str, field_name: str) -> Path:
|
||||||
"""Interpret a path environment variable value.
|
"""Interpret a path environment variable value.
|
||||||
|
|
||||||
@ -217,10 +236,7 @@ def interpret_path_env(value: str, field_name: str) -> Path:
|
|||||||
Raises:
|
Raises:
|
||||||
EnvironmentVarValueError: If the path does not exist.
|
EnvironmentVarValueError: If the path does not exist.
|
||||||
"""
|
"""
|
||||||
path = Path(value)
|
return Path(value)
|
||||||
if not path.exists():
|
|
||||||
raise EnvironmentVarValueError(f"Path does not exist: {path} for {field_name}")
|
|
||||||
return path
|
|
||||||
|
|
||||||
|
|
||||||
def interpret_enum_env(value: str, field_type: GenericType, field_name: str) -> Any:
|
def interpret_enum_env(value: str, field_type: GenericType, field_name: str) -> Any:
|
||||||
@ -276,6 +292,8 @@ def interpret_env_var_value(
|
|||||||
return interpret_int_env(value, field_name)
|
return interpret_int_env(value, field_name)
|
||||||
elif field_type is Path:
|
elif field_type is Path:
|
||||||
return interpret_path_env(value, field_name)
|
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):
|
elif inspect.isclass(field_type) and issubclass(field_type, enum.Enum):
|
||||||
return interpret_enum_env(value, field_type, field_name)
|
return interpret_enum_env(value, field_type, field_name)
|
||||||
|
|
||||||
@ -285,6 +303,10 @@ def interpret_env_var_value(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ExistingPath(Path):
|
||||||
|
"""A path that must exist."""
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(init=False)
|
@dataclasses.dataclass(init=False)
|
||||||
class EnvironmentVariables:
|
class EnvironmentVariables:
|
||||||
"""Environment variables class to instantiate environment variables."""
|
"""Environment variables class to instantiate environment variables."""
|
||||||
@ -314,7 +336,7 @@ class EnvironmentVariables:
|
|||||||
REFLEX_WEB_WORKDIR: Path = Path(constants.Dirs.WEB)
|
REFLEX_WEB_WORKDIR: Path = Path(constants.Dirs.WEB)
|
||||||
|
|
||||||
# Path to the alembic config file
|
# Path to the alembic config file
|
||||||
ALEMBIC_CONFIG: Path = Path(constants.ALEMBIC_CONFIG)
|
ALEMBIC_CONFIG: ExistingPath = ExistingPath(constants.ALEMBIC_CONFIG)
|
||||||
|
|
||||||
# Disable SSL verification for HTTPX requests.
|
# Disable SSL verification for HTTPX requests.
|
||||||
SSL_NO_VERIFY: bool = False
|
SSL_NO_VERIFY: bool = False
|
||||||
|
Loading…
Reference in New Issue
Block a user