@@ -613,10 +613,36 @@ class EnvironmentVariables:
613613 load_dotenv = None
614614
615615
616- def _load_dotenv_from_str (env_files : str ) -> None :
616+ def _paths_from_env_files (env_files : str ) -> list [Path ]:
617+ """Convert a string of paths separated by os.pathsep into a list of Path objects.
618+
619+ Args:
620+ env_files: The string of paths.
621+
622+ Returns:
623+ A list of Path objects.
624+ """
625+ # load env files in reverse order
626+ return list (
627+ reversed (
628+ [
629+ Path (path )
630+ for path_element in env_files .split (os .pathsep )
631+ if (path := path_element .strip ())
632+ ]
633+ )
634+ )
635+
636+
637+ def _load_dotenv_from_files (files : list [Path ]):
638+ """Load environment variables from a list of files.
639+
640+ Args:
641+ files: A list of Path objects representing the environment variable files.
642+ """
617643 from reflex .utils import console
618644
619- if not env_files :
645+ if not files :
620646 return
621647
622648 if load_dotenv is None :
@@ -625,19 +651,27 @@ def _load_dotenv_from_str(env_files: str) -> None:
625651 )
626652 return
627653
628- # load env files in reverse order if they exist
629- for env_file_path in [
630- Path (p ) for s in reversed (env_files .split (os .pathsep )) if (p := s .strip ())
631- ]:
632- if env_file_path .exists ():
633- load_dotenv (env_file_path , override = True )
654+ for env_file in files :
655+ if env_file .exists ():
656+ load_dotenv (env_file , override = True )
657+
658+
659+ def _paths_from_environment () -> list [Path ]:
660+ """Get the paths from the REFLEX_ENV_FILE environment variable.
661+
662+ Returns:
663+ A list of Path objects.
664+ """
665+ env_files = os .environ .get ("REFLEX_ENV_FILE" )
666+ if not env_files :
667+ return []
668+
669+ return _paths_from_env_files (env_files )
634670
635671
636672def _load_dotenv_from_env ():
637673 """Load environment variables from paths specified in REFLEX_ENV_FILE."""
638- env_env_file = os .environ .get ("REFLEX_ENV_FILE" )
639- if env_env_file :
640- _load_dotenv_from_str (env_env_file )
674+ _load_dotenv_from_files (_paths_from_environment ())
641675
642676
643677# Load the env files at import time if they are set in the ENV_FILE environment variable.
0 commit comments