Move frontend build check from setup.py to runtime server startup
• Remove complex setup.py build checks • Add runtime frontend validation • Update install docs with uv/bun steps • Simplify setup.py to minimal form • Check webui before server starts
This commit is contained in:
parent
6c05f0f837
commit
ee45ab5104
4 changed files with 54 additions and 76 deletions
|
|
@ -21,15 +21,24 @@ pip install "lightrag-hku[api]"
|
|||
* 从源代码安装
|
||||
|
||||
```bash
|
||||
# 克隆仓库
|
||||
# Clone the repository
|
||||
git clone https://github.com/HKUDS/lightrag.git
|
||||
|
||||
# 切换到仓库目录
|
||||
# Change to the repository directory
|
||||
cd lightrag
|
||||
|
||||
# 如有必要,创建 Python 虚拟环境
|
||||
# 以可编辑模式安装并支持 API
|
||||
# Create a Python virtual environment
|
||||
uv venv --seed --python 3.12
|
||||
source .venv/bin/acivate
|
||||
|
||||
# Install in editable mode with API support
|
||||
pip install -e ".[api]"
|
||||
|
||||
# Build front-end artifacts
|
||||
cd lightrag_webui
|
||||
bun install --frozen-lockfile --production
|
||||
bun run build --emptyOutDir
|
||||
cd ..
|
||||
```
|
||||
|
||||
### 启动 LightRAG 服务器前的准备
|
||||
|
|
|
|||
|
|
@ -27,9 +27,18 @@ git clone https://github.com/HKUDS/lightrag.git
|
|||
# Change to the repository directory
|
||||
cd lightrag
|
||||
|
||||
# create a Python virtual environment if necessary
|
||||
# Create a Python virtual environment
|
||||
uv venv --seed --python 3.12
|
||||
source .venv/bin/acivate
|
||||
|
||||
# Install in editable mode with API support
|
||||
pip install -e ".[api]"
|
||||
|
||||
# Build front-end artifacts
|
||||
cd lightrag_webui
|
||||
bun install --frozen-lockfile --production
|
||||
bun run build --emptyOutDir
|
||||
cd ..
|
||||
```
|
||||
|
||||
### Before Starting LightRAG Server
|
||||
|
|
|
|||
|
|
@ -145,7 +145,35 @@ class LLMConfigCache:
|
|||
self.ollama_embedding_options = {}
|
||||
|
||||
|
||||
def check_frontend_build():
|
||||
"""Check if frontend is built before starting server"""
|
||||
webui_dir = Path(__file__).parent / "webui"
|
||||
index_html = webui_dir / "index.html"
|
||||
|
||||
if not index_html.exists():
|
||||
ASCIIColors.red("\n" + "=" * 80)
|
||||
ASCIIColors.red("ERROR: Frontend Not Built")
|
||||
ASCIIColors.red("=" * 80)
|
||||
ASCIIColors.yellow("The WebUI frontend has not been built yet.")
|
||||
ASCIIColors.yellow(
|
||||
"Please build the frontend code first using the following commands:\n"
|
||||
)
|
||||
ASCIIColors.cyan(" cd lightrag_webui")
|
||||
ASCIIColors.cyan(" bun install")
|
||||
ASCIIColors.cyan(" bun run build")
|
||||
ASCIIColors.cyan(" cd ..")
|
||||
ASCIIColors.yellow("\nThen restart the service.\n")
|
||||
ASCIIColors.cyan(
|
||||
"Note: Make sure you have Bun installed. Visit https://bun.sh for installation."
|
||||
)
|
||||
ASCIIColors.red("=" * 80 + "\n")
|
||||
sys.exit(1) # Exit immediately
|
||||
|
||||
|
||||
def create_app(args):
|
||||
# Check frontend build first
|
||||
check_frontend_build()
|
||||
|
||||
# Setup logging
|
||||
logger.setLevel(args.log_level)
|
||||
set_verbose_debug(args.verbose)
|
||||
|
|
|
|||
74
setup.py
74
setup.py
|
|
@ -1,74 +1,6 @@
|
|||
"""Minimal setup.py for backward compatibility with frontend build check"""
|
||||
# Minimal setup.py for backward compatibility
|
||||
# Primary configuration is now in pyproject.toml
|
||||
|
||||
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"""
|
||||
|
||||
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
|
||||
|
||||
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]"
|
||||
|
||||
This allows you to build the frontend after installation.
|
||||
|
||||
╚══════════════════════════════════════════════════════════════════════════╝
|
||||
""")
|
||||
sys.exit(1)
|
||||
|
||||
print("✅ Proceeding with package build...")
|
||||
build_py.run(self)
|
||||
|
||||
|
||||
setup(
|
||||
cmdclass={
|
||||
"build_py": BuildPyCommand,
|
||||
}
|
||||
)
|
||||
setup()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue