From d713d38ca75fbaaef15f6b0568bb07b99702768a Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 5 Jul 2023 11:50:07 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(=5F=5Fmain=5F=5F.py):=20re?= =?UTF-8?q?factor=20loading=20of=20environment=20variables=20to=20allow=20?= =?UTF-8?q?overriding=20with=20.env=20file=20The=20os=20module=20is=20impo?= =?UTF-8?q?rted=20to=20make=20use=20of=20the=20os.getenv()=20function.=20T?= =?UTF-8?q?he=20loading=20of=20the=20environment=20variables=20is=20refact?= =?UTF-8?q?ored=20to=20check=20for=20the=20presence=20of=20the=20"langflow?= =?UTF-8?q?=5Fdatabase=5Furl"=20environment=20variable=20and=20use=20it=20?= =?UTF-8?q?as=20the=20value=20for=20the=20database=5Furl=20variable=20if?= =?UTF-8?q?=20it=20is=20not=20provided.=20This=20allows=20for=20more=20fle?= =?UTF-8?q?xibility=20in=20configuring=20the=20database=20URL.=20Additiona?= =?UTF-8?q?lly,=20the=20loading=20of=20environment=20variables=20is=20refa?= =?UTF-8?q?ctored=20to=20allow=20overriding=20with=20a=20.env=20file=20if?= =?UTF-8?q?=20the=20env=5Ffile=20parameter=20is=20provided.=20This=20allow?= =?UTF-8?q?s=20for=20easier=20configuration=20management.=20=F0=9F=94=A7?= =?UTF-8?q?=20chore(=5F=5Fmain=5F=5F.py):=20import=20os=20module=20and=20r?= =?UTF-8?q?efactor=20loading=20of=20environment=20variables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/__main__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/backend/langflow/__main__.py b/src/backend/langflow/__main__.py index 322c6b6a9..a8dab586b 100644 --- a/src/backend/langflow/__main__.py +++ b/src/backend/langflow/__main__.py @@ -1,3 +1,4 @@ +import os import sys import time import httpx @@ -33,6 +34,10 @@ def update_settings( remove_api_keys: bool = False, ): """Update the settings from a config file.""" + + # Check for database_url in the environment variables + database_url = database_url or os.getenv("langflow_database_url") + if config: settings.update_from_yaml(config, dev=dev) if database_url: @@ -127,12 +132,13 @@ def serve( """ Run the Langflow server. """ + # override env variables with .env file + if env_file: + load_dotenv(env_file, override=True) if jcloud: return serve_on_jcloud() - load_dotenv(env_file) - configure(log_level=log_level, log_file=log_file) update_settings( config,