🔧 chore(__main__.py): refactor serve function to improve readability and maintainability

 feat(__main__.py): add support for custom components directory path as an environment variable
 feat(__main__.py): set default value for config option to be the config.yaml file in the same directory as the script
 feat(__main__.py): add support for specifying an .env file containing environment variables
 feat(__main__.py): add backend_only option to run only the backend server without the frontend
🔧 chore(__main__.py): refactor setup_app function to pass backend_only option to the app setup
 feat(__main__.py): add check to skip server startup if running in pytest environment
🔧 chore(__main__.py): refactor serve function to improve readability and maintainability
 feat(__main__.py): add support for running the server using uvicorn on Windows
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-08-07 09:44:11 -03:00
commit 709c4a1749

View file

@ -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