diff --git a/scripts/ci/update_lf_base_dependency.py b/scripts/ci/update_lf_base_dependency.py index f4ba718343aa..c7fd7e7e35c5 100755 --- a/scripts/ci/update_lf_base_dependency.py +++ b/scripts/ci/update_lf_base_dependency.py @@ -57,5 +57,6 @@ def main() -> None: verify_pep440(base_version) update_base_dep("pyproject.toml", base_version) + if __name__ == "__main__": main() diff --git a/scripts/update_dependencies.py b/scripts/update_dependencies.py index 4ddca5f08da3..c4355da53992 100644 --- a/scripts/update_dependencies.py +++ b/scripts/update_dependencies.py @@ -30,6 +30,7 @@ def get_version_from_pypi(package_name): return json.loads(response.read())["info"]["version"] return None + def is_development_release(version): """ Determines if the version is a development version based on PEP 440. @@ -38,6 +39,7 @@ def is_development_release(version): """ return "dev" in version + def update_pyproject_dependency(pyproject_path, version, is_nightly): pattern = re.compile(r'langflow-base = \{ path = "\./src/backend/base", develop = true \}') if is_nightly: diff --git a/src/backend/base/langflow/__main__.py b/src/backend/base/langflow/__main__.py index c01111d2f825..6bf3bfe27cfe 100644 --- a/src/backend/base/langflow/__main__.py +++ b/src/backend/base/langflow/__main__.py @@ -80,15 +80,9 @@ def set_var_for_macos_issue(): @app.command() def run( - host: str = typer.Option( - "127.0.0.1", help="Host to bind the server to.", envvar="LANGFLOW_HOST" - ), - workers: int = typer.Option( - 1, help="Number of worker processes.", envvar="LANGFLOW_WORKERS" - ), - timeout: int = typer.Option( - 300, help="Worker timeout in seconds.", envvar="LANGFLOW_WORKER_TIMEOUT" - ), + host: str = typer.Option("127.0.0.1", help="Host to bind the server to.", envvar="LANGFLOW_HOST"), + workers: int = typer.Option(1, help="Number of worker processes.", envvar="LANGFLOW_WORKERS"), + timeout: int = typer.Option(300, help="Worker timeout in seconds.", envvar="LANGFLOW_WORKER_TIMEOUT"), port: int = typer.Option(7860, help="Port to listen on.", envvar="LANGFLOW_PORT"), components_path: Optional[Path] = typer.Option( Path(__file__).parent / "components", @@ -96,15 +90,9 @@ def run( envvar="LANGFLOW_COMPONENTS_PATH", ), # .env file param - env_file: Path = typer.Option( - None, help="Path to the .env file containing environment variables." - ), - log_level: str = typer.Option( - "critical", help="Logging level.", envvar="LANGFLOW_LOG_LEVEL" - ), - log_file: Path = typer.Option( - "logs/langflow.log", help="Path to the log file.", envvar="LANGFLOW_LOG_FILE" - ), + env_file: Path = typer.Option(None, help="Path to the .env file containing environment variables."), + log_level: str = typer.Option("critical", help="Logging level.", envvar="LANGFLOW_LOG_LEVEL"), + log_file: Path = typer.Option("logs/langflow.log", help="Path to the log file.", envvar="LANGFLOW_LOG_FILE"), cache: Optional[str] = typer.Option( envvar="LANGFLOW_LANGCHAIN_CACHE", help="Type of cache to use. (InMemoryCache, SQLiteCache)", @@ -228,9 +216,7 @@ def wait_for_server_ready(host, port): def run_on_mac_or_linux(host, port, log_level, options, app): - webapp_process = Process( - target=run_langflow, args=(host, port, log_level, options, app) - ) + webapp_process = Process(target=run_langflow, args=(host, port, log_level, options, app)) webapp_process.start() wait_for_server_ready(host, port) @@ -292,9 +278,7 @@ def get_letter_from_version(version: str): def build_version_notice(current_version: str, package_name: str) -> str: latest_version = fetch_latest_version(package_name, langflow_is_pre_release(current_version)) - if latest_version and pkg_version.parse(current_version) < pkg_version.parse( - latest_version - ): + if latest_version and pkg_version.parse(current_version) < pkg_version.parse(latest_version): release_type = "pre-release" if langflow_is_pre_release(latest_version) else "version" return f"A new {release_type} of {package_name} is available: {latest_version}" return "" @@ -344,18 +328,14 @@ def print_banner(host: str, port: int): notices.append(f"Run '{pip_command}' to update.") styled_notices = [f"[bold]{notice}[/bold]" for notice in notices if notice] - styled_package_name = stylize_text( - package_name, package_name, any("pre-release" in notice for notice in notices) - ) + styled_package_name = stylize_text(package_name, package_name, any("pre-release" in notice for notice in notices)) title = f"[bold]Welcome to :chains: {styled_package_name}[/bold]\n" info_text = "Collaborate, and contribute at our [bold][link=https://github.com/langflow-ai/langflow]GitHub Repo[/link][/bold] :star2:" telemetry_text = "We collect anonymous usage data to improve Langflow.\nYou can opt-out by setting [bold]DO_NOT_TRACK=true[/bold] in your environment." access_link = f"Access [link=http://{host}:{port}]http://{host}:{port}[/link]" - panel_content = "\n\n".join( - [title, *styled_notices, info_text, telemetry_text, access_link] - ) + panel_content = "\n\n".join([title, *styled_notices, info_text, telemetry_text, access_link]) panel = Panel(panel_content, box=box.ROUNDED, border_style="blue", expand=False) rprint(panel) @@ -387,12 +367,8 @@ def run_langflow(host, port, log_level, options, app): @app.command() def superuser( username: str = typer.Option(..., prompt=True, help="Username for the superuser."), - password: str = typer.Option( - ..., prompt=True, hide_input=True, help="Password for the superuser." - ), - log_level: str = typer.Option( - "error", help="Logging level.", envvar="LANGFLOW_LOG_LEVEL" - ), + password: str = typer.Option(..., prompt=True, hide_input=True, help="Password for the superuser."), + log_level: str = typer.Option("error", help="Logging level.", envvar="LANGFLOW_LOG_LEVEL"), ): """ Create a superuser. @@ -407,9 +383,7 @@ def superuser( # Verify that the superuser was created from langflow.services.database.models.user.model import User - user: User = session.exec( - select(User).where(User.username == username) - ).first() + user: User = session.exec(select(User).where(User.username == username)).first() if user is None or not user.is_superuser: typer.echo("Superuser creation failed.") return @@ -487,9 +461,7 @@ def migration( @app.command() def api_key( - log_level: str = typer.Option( - "error", help="Logging level.", envvar="LANGFLOW_LOG_LEVEL" - ), + log_level: str = typer.Option("error", help="Logging level.", envvar="LANGFLOW_LOG_LEVEL"), ): """ Creates an API key for the default superuser if AUTO_LOGIN is enabled. @@ -505,20 +477,14 @@ def api_key( settings_service = get_settings_service() auth_settings = settings_service.auth_settings if not auth_settings.AUTO_LOGIN: - typer.echo( - "Auto login is disabled. API keys cannot be created through the CLI." - ) + typer.echo("Auto login is disabled. API keys cannot be created through the CLI.") return with session_scope() as session: from langflow.services.database.models.user.model import User - superuser = session.exec( - select(User).where(User.username == DEFAULT_SUPERUSER) - ).first() + superuser = session.exec(select(User).where(User.username == DEFAULT_SUPERUSER)).first() if not superuser: - typer.echo( - "Default superuser not found. This command requires a superuser and AUTO_LOGIN to be enabled." - ) + typer.echo("Default superuser not found. This command requires a superuser and AUTO_LOGIN to be enabled.") return from langflow.services.database.models.api_key import ApiKey, ApiKeyCreate from langflow.services.database.models.api_key.crud import ( @@ -526,9 +492,7 @@ def api_key( delete_api_key, ) - api_key = session.exec( - select(ApiKey).where(ApiKey.user_id == superuser.id) - ).first() + api_key = session.exec(select(ApiKey).where(ApiKey.user_id == superuser.id)).first() if api_key: delete_api_key(session, api_key.id) diff --git a/src/backend/base/langflow/api/utils.py b/src/backend/base/langflow/api/utils.py index aa66308a9dc3..c75826a591b9 100644 --- a/src/backend/base/langflow/api/utils.py +++ b/src/backend/base/langflow/api/utils.py @@ -86,6 +86,7 @@ def get_is_component_from_data(data: dict): async def check_langflow_version(component: StoreComponentCreate): from langflow.version import get_version + __version__ = get_version() if not component.last_tested_version: diff --git a/src/backend/base/langflow/services/settings/base.py b/src/backend/base/langflow/services/settings/base.py index 085ee2afa284..223ea6707c07 100644 --- a/src/backend/base/langflow/services/settings/base.py +++ b/src/backend/base/langflow/services/settings/base.py @@ -221,7 +221,6 @@ def set_database_url(cls, value, info): if not info.data["config_dir"]: raise ValueError("config_dir not set, please set it or provide a database_url") - from langflow.utils.version import get_version_info from langflow.utils.version import is_pre_release as langflow_is_pre_release diff --git a/src/backend/base/langflow/utils/version.py b/src/backend/base/langflow/utils/version.py index 9a8bd337fec3..a2e1678f9811 100644 --- a/src/backend/base/langflow/utils/version.py +++ b/src/backend/base/langflow/utils/version.py @@ -52,6 +52,7 @@ def _get_version_info(): VERSION_INFO = _get_version_info() + def is_pre_release(v: str) -> bool: """ Returns a boolean indicating whether the version is a pre-release version, @@ -76,9 +77,7 @@ def fetch_latest_version(package_name: str, include_prerelease: bool) -> Optiona try: response = httpx.get(f"https://pypi.org/pypi/{package_name}/json") versions = response.json()["releases"].keys() - valid_versions = [ - v for v in versions if include_prerelease or not is_pre_release(v) - ] + valid_versions = [v for v in versions if include_prerelease or not is_pre_release(v)] except Exception as e: logger.exception(e) @@ -89,6 +88,5 @@ def fetch_latest_version(package_name: str, include_prerelease: bool) -> Optiona return max(valid_versions, key=lambda v: pkg_version.parse(v)) - def get_version_info(): return VERSION_INFO