|
19 | 19 | from reflex.constants.base import LogLevel |
20 | 20 | from reflex.environment import EnvironmentVariables as EnvironmentVariables |
21 | 21 | from reflex.environment import EnvVar as EnvVar |
22 | | -from reflex.environment import ExistingPath, interpret_env_var_value |
| 22 | +from reflex.environment import ( |
| 23 | + ExistingPath, |
| 24 | + _load_dotenv_from_str, |
| 25 | + interpret_env_var_value, |
| 26 | +) |
23 | 27 | from reflex.environment import env_var as env_var |
24 | 28 | from reflex.environment import environment as environment |
25 | 29 | from reflex.plugins import Plugin |
26 | 30 | from reflex.utils import console |
27 | 31 | from reflex.utils.exceptions import ConfigError |
28 | 32 | from reflex.utils.types import true_type_for_pydantic_field |
29 | 33 |
|
30 | | -try: |
31 | | - from dotenv import load_dotenv |
32 | | -except ImportError: |
33 | | - load_dotenv = None |
34 | | - |
35 | | - |
36 | | -def _load_dotenv_from_str(env_files: str) -> None: |
37 | | - if not env_files: |
38 | | - return |
39 | | - |
40 | | - if load_dotenv is None: |
41 | | - console.error( |
42 | | - """The `python-dotenv` package is required to load environment variables from a file. Run `pip install "python-dotenv>=1.1.0"`.""" |
43 | | - ) |
44 | | - return |
45 | | - |
46 | | - # load env files in reverse order if they exist |
47 | | - for env_file_path in [ |
48 | | - Path(p) for s in reversed(env_files.split(os.pathsep)) if (p := s.strip()) |
49 | | - ]: |
50 | | - if env_file_path.exists(): |
51 | | - load_dotenv(env_file_path, override=True) |
52 | | - |
53 | | - |
54 | | -def _load_dotenv_from_env(): |
55 | | - """Load environment variables from paths specified in REFLEX_ENV_FILE.""" |
56 | | - env_env_file = os.environ.get("REFLEX_ENV_FILE") |
57 | | - if env_env_file: |
58 | | - _load_dotenv_from_str(env_env_file) |
59 | | - |
60 | | - |
61 | | -# Load the env files at import time if they are set in the ENV_FILE environment variable. |
62 | | -_load_dotenv_from_env() |
63 | | - |
64 | 34 |
|
65 | 35 | class DBConfig(Base): |
66 | 36 | """Database config.""" |
|
0 commit comments