From ec0d9bd76323db3f004fece9e7dbd6fb6e7ef08a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20MANSUY?= Date: Thu, 4 Dec 2025 19:18:35 +0800 Subject: [PATCH] cherry-pick ee45ab51 --- lightrag/api/README-zh.md | 2 +- lightrag/api/README.md | 2 +- lightrag/api/lightrag_server.py | 98 +-------------------------------- setup.py | 98 +-------------------------------- 4 files changed, 7 insertions(+), 193 deletions(-) diff --git a/lightrag/api/README-zh.md b/lightrag/api/README-zh.md index 74d0e63e..62f581fd 100644 --- a/lightrag/api/README-zh.md +++ b/lightrag/api/README-zh.md @@ -37,7 +37,7 @@ pip install -e ".[api]" # Build front-end artifacts cd lightrag_webui bun install --frozen-lockfile --production -bun run build +bun run build --emptyOutDir cd .. ``` diff --git a/lightrag/api/README.md b/lightrag/api/README.md index 90ebd4db..09e2f0db 100644 --- a/lightrag/api/README.md +++ b/lightrag/api/README.md @@ -37,7 +37,7 @@ pip install -e ".[api]" # Build front-end artifacts cd lightrag_webui bun install --frozen-lockfile --production -bun run build +bun run build --emptyOutDir cd .. ``` diff --git a/lightrag/api/lightrag_server.py b/lightrag/api/lightrag_server.py index e8fdb700..0786e031 100644 --- a/lightrag/api/lightrag_server.py +++ b/lightrag/api/lightrag_server.py @@ -146,11 +146,10 @@ class LLMConfigCache: def check_frontend_build(): - """Check if frontend is built and optionally check if source is up-to-date""" + """Check if frontend is built before starting server""" webui_dir = Path(__file__).parent / "webui" index_html = webui_dir / "index.html" - # 1. Check if build files exist (required) if not index_html.exists(): ASCIIColors.red("\n" + "=" * 80) ASCIIColors.red("ERROR: Frontend Not Built") @@ -160,7 +159,7 @@ def check_frontend_build(): "Please build the frontend code first using the following commands:\n" ) ASCIIColors.cyan(" cd lightrag_webui") - ASCIIColors.cyan(" bun install --frozen-lockfile") + ASCIIColors.cyan(" bun install") ASCIIColors.cyan(" bun run build") ASCIIColors.cyan(" cd ..") ASCIIColors.yellow("\nThen restart the service.\n") @@ -170,99 +169,6 @@ def check_frontend_build(): ASCIIColors.red("=" * 80 + "\n") sys.exit(1) # Exit immediately - # 2. Check if this is a development environment (source directory exists) - try: - source_dir = Path(__file__).parent.parent.parent / "lightrag_webui" - src_dir = source_dir / "src" - - # Determine if this is a development environment: source directory exists and contains src directory - if not source_dir.exists() or not src_dir.exists(): - # Production environment, skip source code check - logger.debug( - "Production environment detected, skipping source freshness check" - ) - return - - # Development environment, perform source code timestamp check - logger.debug("Development environment detected, checking source freshness") - - # Source code file extensions (files to check) - source_extensions = { - ".ts", - ".tsx", - ".js", - ".jsx", - ".mjs", - ".cjs", # TypeScript/JavaScript - ".css", - ".scss", - ".sass", - ".less", # Style files - ".json", - ".jsonc", # Configuration/data files - ".html", - ".htm", # Template files - ".md", - ".mdx", # Markdown - } - - # Key configuration files (in lightrag_webui root directory) - key_files = [ - source_dir / "package.json", - source_dir / "bun.lock", - source_dir / "vite.config.ts", - source_dir / "tsconfig.json", - source_dir / "tailwind.config.js", - source_dir / "index.html", - ] - - # Get the latest modification time of source code - latest_source_time = 0 - - # Check source code files in src directory - for file_path in src_dir.rglob("*"): - if file_path.is_file(): - # Only check source code files, ignore temporary files and logs - if file_path.suffix.lower() in source_extensions: - mtime = file_path.stat().st_mtime - latest_source_time = max(latest_source_time, mtime) - - # Check key configuration files - for key_file in key_files: - if key_file.exists(): - mtime = key_file.stat().st_mtime - latest_source_time = max(latest_source_time, mtime) - - # Get build time - build_time = index_html.stat().st_mtime - - # Compare timestamps (5 second tolerance to avoid file system time precision issues) - if latest_source_time > build_time + 5: - ASCIIColors.yellow("\n" + "=" * 80) - ASCIIColors.yellow("WARNING: Frontend Source Code Has Been Updated") - ASCIIColors.yellow("=" * 80) - ASCIIColors.yellow( - "The frontend source code is newer than the current build." - ) - ASCIIColors.yellow( - "This might happen after 'git pull' or manual code changes.\n" - ) - ASCIIColors.cyan( - "Recommended: Rebuild the frontend to use the latest changes:" - ) - ASCIIColors.cyan(" cd lightrag_webui") - ASCIIColors.cyan(" bun install --frozen-lockfile") - ASCIIColors.cyan(" bun run build") - ASCIIColors.cyan(" cd ..") - ASCIIColors.yellow("\nThe server will continue with the current build.") - ASCIIColors.yellow("=" * 80 + "\n") - else: - logger.info("Frontend build is up-to-date") - - except Exception as e: - # If check fails, log warning but don't affect startup - logger.warning(f"Failed to check frontend source freshness: {e}") - def create_app(args): # Check frontend build first diff --git a/setup.py b/setup.py index 3a141420..655e2e9e 100644 --- a/setup.py +++ b/setup.py @@ -1,98 +1,6 @@ -"""Minimal setup.py for backward compatibility with frontend build check""" -<<<<<<< HEAD +# Minimal setup.py for backward compatibility +# Primary configuration is now in pyproject.toml -======= ->>>>>>> be9e6d16 (Exclude Frontend Build Artifacts from Git Repository) -from pathlib import Path from setuptools import setup -from setuptools.command.build_py import build_py -import sys - -def check_webui_exists(): - """Check if WebUI has been built""" - webui_index = Path("lightrag/api/webui/index.html") - return webui_index.exists() - - -class BuildPyCommand(build_py): - """Check WebUI build status before packaging/installation""" -<<<<<<< HEAD - - def run(self): - # Check if running in development mode - is_develop = any(arg in sys.argv for arg in ["develop", "egg_info"]) - is_editable = "--editable" in sys.argv or "-e" in sys.argv - -======= - - def run(self): - # Check if running in development mode - is_develop = any(arg in sys.argv for arg in ['develop', 'egg_info']) - is_editable = '--editable' in sys.argv or '-e' in sys.argv - ->>>>>>> be9e6d16 (Exclude Frontend Build Artifacts from Git Repository) - if is_develop or is_editable: - # Development mode: friendly reminder - if not check_webui_exists(): - print(""" -╔══════════════════════════════════════════════════════════════════════════╗ -║ ℹ️ Development Mode - WebUI not built yet ║ -╚══════════════════════════════════════════════════════════════════════════╝ - -You're installing in development mode. You can build the frontend later: - - cd lightrag_webui - bun install - bun run build - -The changes will take effect immediately (symlink mode). -╚══════════════════════════════════════════════════════════════════════════╝ -""") - else: - # Normal installation/packaging mode: frontend build required - if not check_webui_exists(): - print(""" -╔══════════════════════════════════════════════════════════════════════════╗ -║ ⚠️ ERROR: WebUI Not Built ║ -╚══════════════════════════════════════════════════════════════════════════╝ - -For normal installation (pip install .), you must build the frontend first: - - cd lightrag_webui - bun install - bun run build - cd .. - -Then run the installation again. - -💡 TIP: For development, use editable mode instead: - pip install -e ".[api]" -<<<<<<< HEAD - -======= - ->>>>>>> be9e6d16 (Exclude Frontend Build Artifacts from Git Repository) - This allows you to build the frontend after installation. - -╚══════════════════════════════════════════════════════════════════════════╝ -""") - sys.exit(1) -<<<<<<< HEAD - -======= - ->>>>>>> be9e6d16 (Exclude Frontend Build Artifacts from Git Repository) - print("✅ Proceeding with package build...") - build_py.run(self) - - -setup( - cmdclass={ -<<<<<<< HEAD - "build_py": BuildPyCommand, -======= - 'build_py': BuildPyCommand, ->>>>>>> be9e6d16 (Exclude Frontend Build Artifacts from Git Repository) - } -) +setup()