From 709c4a17496d4f9843ae98454c6196396bbba07b Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 7 Aug 2023 09:44:11 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(=5F=5Fmain=5F=5F.py):=20re?= =?UTF-8?q?factor=20serve=20function=20to=20improve=20readability=20and=20?= =?UTF-8?q?maintainability=20=E2=9C=A8=20feat(=5F=5Fmain=5F=5F.py):=20add?= =?UTF-8?q?=20support=20for=20custom=20components=20directory=20path=20as?= =?UTF-8?q?=20an=20environment=20variable=20=E2=9C=A8=20feat(=5F=5Fmain=5F?= =?UTF-8?q?=5F.py):=20set=20default=20value=20for=20config=20option=20to?= =?UTF-8?q?=20be=20the=20config.yaml=20file=20in=20the=20same=20directory?= =?UTF-8?q?=20as=20the=20script=20=E2=9C=A8=20feat(=5F=5Fmain=5F=5F.py):?= =?UTF-8?q?=20add=20support=20for=20specifying=20an=20.env=20file=20contai?= =?UTF-8?q?ning=20environment=20variables=20=E2=9C=A8=20feat(=5F=5Fmain=5F?= =?UTF-8?q?=5F.py):=20add=20backend=5Fonly=20option=20to=20run=20only=20th?= =?UTF-8?q?e=20backend=20server=20without=20the=20frontend=20=F0=9F=94=A7?= =?UTF-8?q?=20chore(=5F=5Fmain=5F=5F.py):=20refactor=20setup=5Fapp=20funct?= =?UTF-8?q?ion=20to=20pass=20backend=5Fonly=20option=20to=20the=20app=20se?= =?UTF-8?q?tup=20=E2=9C=A8=20feat(=5F=5Fmain=5F=5F.py):=20add=20check=20to?= =?UTF-8?q?=20skip=20server=20startup=20if=20running=20in=20pytest=20envir?= =?UTF-8?q?onment=20=F0=9F=94=A7=20chore(=5F=5Fmain=5F=5F.py):=20refactor?= =?UTF-8?q?=20serve=20function=20to=20improve=20readability=20and=20mainta?= =?UTF-8?q?inability=20=E2=9C=A8=20feat(=5F=5Fmain=5F=5F.py):=20add=20supp?= =?UTF-8?q?ort=20for=20running=20the=20server=20using=20uvicorn=20on=20Win?= =?UTF-8?q?dows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/__main__.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/backend/langflow/__main__.py b/src/backend/langflow/__main__.py index 82d8bacb8..43247b10f 100644 --- a/src/backend/langflow/__main__.py +++ b/src/backend/langflow/__main__.py @@ -106,7 +106,9 @@ def serve( help="Path to the directory containing custom components.", envvar="LANGFLOW_COMPONENTS_PATH", ), - config: str = typer.Option("config.yaml", help="Path to the configuration file."), + config: str = typer.Option( + Path(__file__).parent / "config.yaml", help="Path to the configuration file." + ), # .env file param env_file: Path = typer.Option( None, help="Path to the .env file containing environment variables." @@ -146,6 +148,11 @@ def serve( help="Remove API keys from the projects saved in the database.", envvar="LANGFLOW_REMOVE_API_KEYS", ), + backend_only: bool = typer.Option( + False, + help="Run only the backend server without the frontend.", + envvar="LANGFLOW_BACKEND_ONLY", + ), ): """ Run the Langflow server. @@ -167,7 +174,7 @@ def serve( ) # create path object if path is provided static_files_dir: Optional[Path] = Path(path) if path else None - app = setup_app(static_files_dir=static_files_dir) + app = setup_app(static_files_dir=static_files_dir, backend_only=backend_only) # check if port is being used if is_port_in_use(port, host): port = get_free_port(port) @@ -179,6 +186,10 @@ def serve( "timeout": timeout, } + # Define an env variable to know if we are just testing the server + if "pytest" in sys.modules: + return + if platform.system() in ["Windows"]: # Run using uvicorn on MacOS and Windows # Windows doesn't support gunicorn