Refactor setup.py to utilize pyproject.toml for project installation.
This commit is contained in:
@@ -757,6 +757,8 @@ async def initialize_rag():
|
||||
|
||||
<details>
|
||||
<summary> <b>使用Faiss进行存储</b> </summary>
|
||||
在使用Faiss向量数据库之前必须手工安装`faiss-cpu`或`faiss-gpu`。
|
||||
|
||||
|
||||
- 安装所需依赖:
|
||||
|
||||
|
||||
@@ -819,6 +819,8 @@ For production level scenarios you will most likely want to leverage an enterpri
|
||||
|
||||
<details>
|
||||
<summary> <b>Using Faiss for Storage</b> </summary>
|
||||
You must manually install faiss-cpu or faiss-gpu before using FAISS vector db.
|
||||
Manually install `faiss-cpu` or `faiss-gpu` before using FAISS vector db.
|
||||
|
||||
- Install the required dependencies:
|
||||
|
||||
|
||||
@@ -17,11 +17,7 @@ from .shared_storage import (
|
||||
set_all_update_flags,
|
||||
)
|
||||
|
||||
USE_GPU = os.getenv("FAISS_USE_GPU", "0") == "1"
|
||||
FAISS_PACKAGE = "faiss-gpu" if USE_GPU else "faiss-cpu"
|
||||
if not pm.is_installed(FAISS_PACKAGE):
|
||||
pm.install(FAISS_PACKAGE)
|
||||
|
||||
# You must manually install faiss-cpu or faiss-gpu before using FAISS vector db
|
||||
import faiss # type: ignore
|
||||
|
||||
|
||||
|
||||
93
pyproject.toml
Normal file
93
pyproject.toml
Normal file
@@ -0,0 +1,93 @@
|
||||
[build-system]
|
||||
requires = ["setuptools>=64", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "lightrag-hku"
|
||||
dynamic = ["version"]
|
||||
authors = [
|
||||
{name = "Zirui Guo"}
|
||||
]
|
||||
description = "LightRAG: Simple and Fast Retrieval-Augmented Generation"
|
||||
readme = "README.md"
|
||||
license = {text = "MIT"}
|
||||
requires-python = ">=3.9"
|
||||
classifiers = [
|
||||
"Development Status :: 4 - Beta",
|
||||
"Programming Language :: Python :: 3",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Operating System :: OS Independent",
|
||||
"Intended Audience :: Developers",
|
||||
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||
]
|
||||
dependencies = [
|
||||
"aiohttp",
|
||||
"configparser",
|
||||
"dotenv",
|
||||
"future",
|
||||
"numpy",
|
||||
"pandas>=2.0.0",
|
||||
"pipmaster",
|
||||
"pydantic",
|
||||
"python-dotenv",
|
||||
"pyuca",
|
||||
"setuptools",
|
||||
"tenacity",
|
||||
"tiktoken",
|
||||
"xlsxwriter>=3.1.0",
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
api = [
|
||||
# Core dependencies
|
||||
"aiohttp",
|
||||
"configparser",
|
||||
"dotenv",
|
||||
"future",
|
||||
"numpy",
|
||||
"openai",
|
||||
"pandas>=2.0.0",
|
||||
"pipmaster",
|
||||
"pydantic",
|
||||
"python-dotenv",
|
||||
"pyuca",
|
||||
"setuptools",
|
||||
"tenacity",
|
||||
"tiktoken",
|
||||
"xlsxwriter>=3.1.0",
|
||||
# API-specific dependencies
|
||||
"aiofiles",
|
||||
"ascii_colors",
|
||||
"asyncpg",
|
||||
"distro",
|
||||
"fastapi",
|
||||
"httpcore",
|
||||
"httpx",
|
||||
"jiter",
|
||||
"passlib[bcrypt]",
|
||||
"PyJWT",
|
||||
"python-jose[cryptography]",
|
||||
"python-multipart",
|
||||
"pytz",
|
||||
"uvicorn",
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
lightrag-server = "lightrag.api.lightrag_server:main"
|
||||
lightrag-gunicorn = "lightrag.api.run_with_gunicorn:main"
|
||||
|
||||
[project.urls]
|
||||
Homepage = "https://github.com/HKUDS/LightRAG"
|
||||
Documentation = "https://github.com/HKUDS/LightRAG"
|
||||
Repository = "https://github.com/HKUDS/LightRAG"
|
||||
"Bug Tracker" = "https://github.com/HKUDS/LightRAG/issues"
|
||||
|
||||
[tool.setuptools]
|
||||
packages = ["lightrag"]
|
||||
include-package-data = true
|
||||
|
||||
[tool.setuptools.dynamic]
|
||||
version = {attr = "lightrag.__version__"}
|
||||
|
||||
[tool.setuptools.package-data]
|
||||
lightrag = ["api/webui/**/*"]
|
||||
108
setup.py
108
setup.py
@@ -1,106 +1,6 @@
|
||||
import setuptools
|
||||
from pathlib import Path
|
||||
# Minimal setup.py for backward compatibility
|
||||
# Primary configuration is now in pyproject.toml
|
||||
|
||||
from setuptools import setup
|
||||
|
||||
# Reading the long description from README.md
|
||||
def read_long_description():
|
||||
try:
|
||||
return Path("README.md").read_text(encoding="utf-8")
|
||||
except FileNotFoundError:
|
||||
return "A description of LightRAG is currently unavailable."
|
||||
|
||||
|
||||
# Retrieving metadata from __init__.py
|
||||
def retrieve_metadata():
|
||||
vars2find = ["__author__", "__version__", "__url__"]
|
||||
vars2readme = {}
|
||||
try:
|
||||
with open("./lightrag/__init__.py") as f:
|
||||
for line in f.readlines():
|
||||
for v in vars2find:
|
||||
if line.startswith(v):
|
||||
line = (
|
||||
line.replace(" ", "")
|
||||
.replace('"', "")
|
||||
.replace("'", "")
|
||||
.strip()
|
||||
)
|
||||
vars2readme[v] = line.split("=")[1]
|
||||
except FileNotFoundError:
|
||||
raise FileNotFoundError("Metadata file './lightrag/__init__.py' not found.")
|
||||
|
||||
# Checking if all required variables are found
|
||||
missing_vars = [v for v in vars2find if v not in vars2readme]
|
||||
if missing_vars:
|
||||
raise ValueError(
|
||||
f"Missing required metadata variables in __init__.py: {missing_vars}"
|
||||
)
|
||||
|
||||
return vars2readme
|
||||
|
||||
|
||||
# Reading dependencies from requirements.txt
|
||||
def read_requirements(file_path="requirements.txt"):
|
||||
deps = []
|
||||
try:
|
||||
with open(file_path) as f:
|
||||
deps = [
|
||||
line.strip() for line in f if line.strip() and not line.startswith("#")
|
||||
]
|
||||
except FileNotFoundError:
|
||||
print(f"Warning: '{file_path}' not found. No dependencies will be installed.")
|
||||
return deps
|
||||
|
||||
|
||||
def read_api_requirements():
|
||||
return read_requirements("lightrag/api/requirements.txt")
|
||||
|
||||
|
||||
def read_extra_requirements():
|
||||
return read_requirements("lightrag/tools/lightrag_visualizer/requirements.txt")
|
||||
|
||||
|
||||
metadata = retrieve_metadata()
|
||||
long_description = read_long_description()
|
||||
requirements = read_requirements()
|
||||
|
||||
setuptools.setup(
|
||||
name="lightrag-hku",
|
||||
url=metadata["__url__"],
|
||||
version=metadata["__version__"],
|
||||
author=metadata["__author__"],
|
||||
description="LightRAG: Simple and Fast Retrieval-Augmented Generation",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
packages=setuptools.find_packages(
|
||||
exclude=("tests*", "docs*")
|
||||
), # Automatically find packages
|
||||
classifiers=[
|
||||
"Development Status :: 4 - Beta",
|
||||
"Programming Language :: Python :: 3",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Operating System :: OS Independent",
|
||||
"Intended Audience :: Developers",
|
||||
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||
],
|
||||
python_requires=">=3.9",
|
||||
install_requires=requirements,
|
||||
include_package_data=True, # Includes non-code files from MANIFEST.in
|
||||
project_urls={ # Additional project metadata
|
||||
"Documentation": metadata.get("__url__", ""),
|
||||
"Source": metadata.get("__url__", ""),
|
||||
"Tracker": f"{metadata.get('__url__', '')}/issues"
|
||||
if metadata.get("__url__")
|
||||
else "",
|
||||
},
|
||||
extras_require={
|
||||
"api": requirements + read_api_requirements(),
|
||||
"tools": read_extra_requirements(), # API requirements as optional
|
||||
},
|
||||
entry_points={
|
||||
"console_scripts": [
|
||||
"lightrag-server=lightrag.api.lightrag_server:main [api]",
|
||||
"lightrag-gunicorn=lightrag.api.run_with_gunicorn:main [api]",
|
||||
],
|
||||
},
|
||||
)
|
||||
setup()
|
||||
|
||||
Reference in New Issue
Block a user