cherry-pick ee45ab51
This commit is contained in:
parent
07d1361773
commit
ec0d9bd763
4 changed files with 7 additions and 193 deletions
|
|
@ -37,7 +37,7 @@ pip install -e ".[api]"
|
||||||
# Build front-end artifacts
|
# Build front-end artifacts
|
||||||
cd lightrag_webui
|
cd lightrag_webui
|
||||||
bun install --frozen-lockfile --production
|
bun install --frozen-lockfile --production
|
||||||
bun run build
|
bun run build --emptyOutDir
|
||||||
cd ..
|
cd ..
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ pip install -e ".[api]"
|
||||||
# Build front-end artifacts
|
# Build front-end artifacts
|
||||||
cd lightrag_webui
|
cd lightrag_webui
|
||||||
bun install --frozen-lockfile --production
|
bun install --frozen-lockfile --production
|
||||||
bun run build
|
bun run build --emptyOutDir
|
||||||
cd ..
|
cd ..
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -146,11 +146,10 @@ class LLMConfigCache:
|
||||||
|
|
||||||
|
|
||||||
def check_frontend_build():
|
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"
|
webui_dir = Path(__file__).parent / "webui"
|
||||||
index_html = webui_dir / "index.html"
|
index_html = webui_dir / "index.html"
|
||||||
|
|
||||||
# 1. Check if build files exist (required)
|
|
||||||
if not index_html.exists():
|
if not index_html.exists():
|
||||||
ASCIIColors.red("\n" + "=" * 80)
|
ASCIIColors.red("\n" + "=" * 80)
|
||||||
ASCIIColors.red("ERROR: Frontend Not Built")
|
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"
|
"Please build the frontend code first using the following commands:\n"
|
||||||
)
|
)
|
||||||
ASCIIColors.cyan(" cd lightrag_webui")
|
ASCIIColors.cyan(" cd lightrag_webui")
|
||||||
ASCIIColors.cyan(" bun install --frozen-lockfile")
|
ASCIIColors.cyan(" bun install")
|
||||||
ASCIIColors.cyan(" bun run build")
|
ASCIIColors.cyan(" bun run build")
|
||||||
ASCIIColors.cyan(" cd ..")
|
ASCIIColors.cyan(" cd ..")
|
||||||
ASCIIColors.yellow("\nThen restart the service.\n")
|
ASCIIColors.yellow("\nThen restart the service.\n")
|
||||||
|
|
@ -170,99 +169,6 @@ def check_frontend_build():
|
||||||
ASCIIColors.red("=" * 80 + "\n")
|
ASCIIColors.red("=" * 80 + "\n")
|
||||||
sys.exit(1) # Exit immediately
|
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):
|
def create_app(args):
|
||||||
# Check frontend build first
|
# Check frontend build first
|
||||||
|
|
|
||||||
98
setup.py
98
setup.py
|
|
@ -1,98 +1,6 @@
|
||||||
"""Minimal setup.py for backward compatibility with frontend build check"""
|
# Minimal setup.py for backward compatibility
|
||||||
<<<<<<< HEAD
|
# 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 import setup
|
||||||
from setuptools.command.build_py import build_py
|
|
||||||
import sys
|
|
||||||
|
|
||||||
|
setup()
|
||||||
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)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue