move more variables to environment
This commit is contained in:
parent
5dffc77f33
commit
11da6ecb25
@ -178,6 +178,21 @@ def interpret_boolean_env(value: str) -> bool:
|
|||||||
raise ValueError(f"Invalid boolean value: {value}")
|
raise ValueError(f"Invalid boolean value: {value}")
|
||||||
|
|
||||||
|
|
||||||
|
def interpret_path_env(value: str) -> Path:
|
||||||
|
"""Interpret a path environment variable value.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
value: The environment variable value.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The interpreted value.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ValueError: If the value is invalid.
|
||||||
|
"""
|
||||||
|
return Path(value)
|
||||||
|
|
||||||
|
|
||||||
def interpret_env_var_value(value: str, field: dataclasses.Field) -> Any:
|
def interpret_env_var_value(value: str, field: dataclasses.Field) -> Any:
|
||||||
"""Interpret an environment variable value based on the field type.
|
"""Interpret an environment variable value based on the field type.
|
||||||
|
|
||||||
@ -199,6 +214,9 @@ def interpret_env_var_value(value: str, field: dataclasses.Field) -> Any:
|
|||||||
elif field_type is str:
|
elif field_type is str:
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
elif field_type is Path:
|
||||||
|
return interpret_path_env(value)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Invalid type for environment variable {field.name}: {field_type}. This is probably an issue in Reflex."
|
f"Invalid type for environment variable {field.name}: {field_type}. This is probably an issue in Reflex."
|
||||||
@ -215,6 +233,24 @@ class EnvironmentVariables:
|
|||||||
# The npm registry to use.
|
# The npm registry to use.
|
||||||
NPM_CONFIG_REGISTRY: Optional[str] = None
|
NPM_CONFIG_REGISTRY: Optional[str] = None
|
||||||
|
|
||||||
|
# Whether to use Granian for the backend. Otherwise, use Uvicorn.
|
||||||
|
REFLEX_USE_GRANIAN: bool = False
|
||||||
|
|
||||||
|
# The username to use for authentication on python package repository. Username and password must both be provided.
|
||||||
|
TWINE_USERNAME: Optional[str] = None
|
||||||
|
|
||||||
|
# The password to use for authentication on python package repository. Username and password must both be provided.
|
||||||
|
TWINE_PASSWORD: Optional[str] = None
|
||||||
|
|
||||||
|
# Whether to use the system installed bun. If set to false, bun will be bundled with the app.
|
||||||
|
REFLEX_USE_SYSTEM_BUN: bool = False
|
||||||
|
|
||||||
|
# Whether to use the system installed node and npm. If set to false, node and npm will be bundled with the app.
|
||||||
|
REFLEX_USE_SYSTEM_NODE: bool = False
|
||||||
|
|
||||||
|
# The working directory for the next.js commands.
|
||||||
|
REFLEX_WEB_WORKDIR: Path = Path(constants.Dirs.WEB)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Initialize the environment variables."""
|
"""Initialize the environment variables."""
|
||||||
for field in dataclasses.fields(self):
|
for field in dataclasses.fields(self):
|
||||||
|
@ -5,6 +5,8 @@ from __future__ import annotations
|
|||||||
import platform
|
import platform
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
|
|
||||||
|
from reflex.config import environment
|
||||||
|
|
||||||
from .base import IS_WINDOWS, Reflex
|
from .base import IS_WINDOWS, Reflex
|
||||||
|
|
||||||
|
|
||||||
@ -54,7 +56,7 @@ class Bun(SimpleNamespace):
|
|||||||
CONFIG_PATH = "bunfig.toml"
|
CONFIG_PATH = "bunfig.toml"
|
||||||
|
|
||||||
# The environment variable to use the system installed bun.
|
# The environment variable to use the system installed bun.
|
||||||
USE_SYSTEM_VAR = "REFLEX_USE_SYSTEM_BUN"
|
USE_SYSTEM = environment.REFLEX_USE_SYSTEM_BUN
|
||||||
|
|
||||||
|
|
||||||
# FNM config.
|
# FNM config.
|
||||||
@ -100,7 +102,7 @@ class Node(SimpleNamespace):
|
|||||||
NPM_PATH = BIN_PATH / "npm"
|
NPM_PATH = BIN_PATH / "npm"
|
||||||
|
|
||||||
# The environment variable to use the system installed node.
|
# The environment variable to use the system installed node.
|
||||||
USE_SYSTEM_VAR = "REFLEX_USE_SYSTEM_NODE"
|
USE_SYSTEM = environment.REFLEX_USE_SYSTEM_NODE
|
||||||
|
|
||||||
|
|
||||||
class PackageJson(SimpleNamespace):
|
class PackageJson(SimpleNamespace):
|
||||||
|
@ -17,7 +17,7 @@ import typer
|
|||||||
from tomlkit.exceptions import TOMLKitError
|
from tomlkit.exceptions import TOMLKitError
|
||||||
|
|
||||||
from reflex import constants
|
from reflex import constants
|
||||||
from reflex.config import get_config
|
from reflex.config import environment, get_config
|
||||||
from reflex.constants import CustomComponents
|
from reflex.constants import CustomComponents
|
||||||
from reflex.utils import console
|
from reflex.utils import console
|
||||||
|
|
||||||
@ -609,14 +609,14 @@ def publish(
|
|||||||
help="The API token to use for authentication on python package repository. If token is provided, no username/password should be provided at the same time",
|
help="The API token to use for authentication on python package repository. If token is provided, no username/password should be provided at the same time",
|
||||||
),
|
),
|
||||||
username: Optional[str] = typer.Option(
|
username: Optional[str] = typer.Option(
|
||||||
os.getenv("TWINE_USERNAME"),
|
environment.TWINE_USERNAME,
|
||||||
"-u",
|
"-u",
|
||||||
"--username",
|
"--username",
|
||||||
show_default="TWINE_USERNAME environment variable value if set",
|
show_default="TWINE_USERNAME environment variable value if set",
|
||||||
help="The username to use for authentication on python package repository. Username and password must both be provided.",
|
help="The username to use for authentication on python package repository. Username and password must both be provided.",
|
||||||
),
|
),
|
||||||
password: Optional[str] = typer.Option(
|
password: Optional[str] = typer.Option(
|
||||||
os.getenv("TWINE_PASSWORD"),
|
environment.TWINE_PASSWORD,
|
||||||
"-p",
|
"-p",
|
||||||
"--password",
|
"--password",
|
||||||
show_default="TWINE_PASSWORD environment variable value if set",
|
show_default="TWINE_PASSWORD environment variable value if set",
|
||||||
|
@ -15,7 +15,7 @@ from urllib.parse import urljoin
|
|||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
from reflex import constants
|
from reflex import constants
|
||||||
from reflex.config import get_config
|
from reflex.config import environment, get_config
|
||||||
from reflex.constants.base import LogLevel
|
from reflex.constants.base import LogLevel
|
||||||
from reflex.utils import console, path_ops
|
from reflex.utils import console, path_ops
|
||||||
from reflex.utils.prerequisites import get_web_dir
|
from reflex.utils.prerequisites import get_web_dir
|
||||||
@ -184,7 +184,7 @@ def should_use_granian():
|
|||||||
Returns:
|
Returns:
|
||||||
True if Granian should be used.
|
True if Granian should be used.
|
||||||
"""
|
"""
|
||||||
return os.getenv("REFLEX_USE_GRANIAN", "0") == "1"
|
return environment.REFLEX_USE_GRANIAN
|
||||||
|
|
||||||
|
|
||||||
def get_app_module():
|
def get_app_module():
|
||||||
|
@ -129,30 +129,13 @@ def which(program: str | Path) -> str | Path | None:
|
|||||||
return shutil.which(str(program))
|
return shutil.which(str(program))
|
||||||
|
|
||||||
|
|
||||||
def use_system_install(var_name: str) -> bool:
|
|
||||||
"""Check if the system install should be used.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
var_name: The name of the environment variable.
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
ValueError: If the variable name is invalid.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Whether the associated env var should use the system install.
|
|
||||||
"""
|
|
||||||
if not var_name.startswith("REFLEX_USE_SYSTEM_"):
|
|
||||||
raise ValueError("Invalid system install variable name.")
|
|
||||||
return os.getenv(var_name, "").lower() in ["true", "1", "yes"]
|
|
||||||
|
|
||||||
|
|
||||||
def use_system_node() -> bool:
|
def use_system_node() -> bool:
|
||||||
"""Check if the system node should be used.
|
"""Check if the system node should be used.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Whether the system node should be used.
|
Whether the system node should be used.
|
||||||
"""
|
"""
|
||||||
return use_system_install(constants.Node.USE_SYSTEM_VAR)
|
return constants.Node.USE_SYSTEM
|
||||||
|
|
||||||
|
|
||||||
def use_system_bun() -> bool:
|
def use_system_bun() -> bool:
|
||||||
@ -161,7 +144,7 @@ def use_system_bun() -> bool:
|
|||||||
Returns:
|
Returns:
|
||||||
Whether the system bun should be used.
|
Whether the system bun should be used.
|
||||||
"""
|
"""
|
||||||
return use_system_install(constants.Bun.USE_SYSTEM_VAR)
|
return constants.Bun.USE_SYSTEM
|
||||||
|
|
||||||
|
|
||||||
def get_node_bin_path() -> Path | None:
|
def get_node_bin_path() -> Path | None:
|
||||||
|
@ -69,8 +69,7 @@ def get_web_dir() -> Path:
|
|||||||
Returns:
|
Returns:
|
||||||
The working directory.
|
The working directory.
|
||||||
"""
|
"""
|
||||||
workdir = Path(os.getenv("REFLEX_WEB_WORKDIR", constants.Dirs.WEB))
|
return environment.REFLEX_WEB_WORKDIR
|
||||||
return workdir
|
|
||||||
|
|
||||||
|
|
||||||
def _python_version_check():
|
def _python_version_check():
|
||||||
|
Loading…
Reference in New Issue
Block a user