Key Enhancements:
Error Handling: Handled potential FileNotFoundError for README.md and requirements.txt. Checked for missing required metadata and raised an informative error if any are missing. Automated Package Discovery: Replaced packages=["lightrag"] with setuptools.find_packages() to automatically find sub-packages and exclude test or documentation directories. Additional Metadata: Added Development Status in classifiers to indicate a "Beta" release (modify based on the project's maturity). Used project_urls to link documentation, source code, and an issue tracker, which are standard for open-source projects. Compatibility: Included include_package_data=True to include additional files specified in MANIFEST.in. These changes enhance the readability, reliability, and openness of the code, making it more contributor-friendly and ensuring it’s ready for open-source distribution.
This commit is contained in:
74
setup.py
74
setup.py
@@ -1,39 +1,71 @@
|
|||||||
import setuptools
|
import setuptools
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
with open("README.md", "r", encoding="utf-8") as fh:
|
# Reading the long description from README.md
|
||||||
long_description = fh.read()
|
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
|
||||||
|
|
||||||
vars2find = ["__author__", "__version__", "__url__"]
|
# Reading dependencies from requirements.txt
|
||||||
vars2readme = {}
|
def read_requirements():
|
||||||
with open("./lightrag/__init__.py") as f:
|
deps = []
|
||||||
for line in f.readlines():
|
try:
|
||||||
for v in vars2find:
|
with open("./requirements.txt") as f:
|
||||||
if line.startswith(v):
|
deps = [line.strip() for line in f if line.strip()]
|
||||||
line = line.replace(" ", "").replace('"', "").replace("'", "").strip()
|
except FileNotFoundError:
|
||||||
vars2readme[v] = line.split("=")[1]
|
print("Warning: 'requirements.txt' not found. No dependencies will be installed.")
|
||||||
|
return deps
|
||||||
|
|
||||||
deps = []
|
metadata = retrieve_metadata()
|
||||||
with open("./requirements.txt") as f:
|
long_description = read_long_description()
|
||||||
for line in f.readlines():
|
requirements = read_requirements()
|
||||||
if not line.strip():
|
|
||||||
continue
|
|
||||||
deps.append(line.strip())
|
|
||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="lightrag-hku",
|
name="lightrag-hku",
|
||||||
url=vars2readme["__url__"],
|
url=metadata["__url__"],
|
||||||
version=vars2readme["__version__"],
|
version=metadata["__version__"],
|
||||||
author=vars2readme["__author__"],
|
author=metadata["__author__"],
|
||||||
description="LightRAG: Simple and Fast Retrieval-Augmented Generation",
|
description="LightRAG: Simple and Fast Retrieval-Augmented Generation",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
packages=["lightrag"],
|
packages=setuptools.find_packages(exclude=("tests*", "docs*")), # Automatically find packages
|
||||||
classifiers=[
|
classifiers=[
|
||||||
|
"Development Status :: 4 - Beta",
|
||||||
"Programming Language :: Python :: 3",
|
"Programming Language :: Python :: 3",
|
||||||
"License :: OSI Approved :: MIT License",
|
"License :: OSI Approved :: MIT License",
|
||||||
"Operating System :: OS Independent",
|
"Operating System :: OS Independent",
|
||||||
|
"Intended Audience :: Developers",
|
||||||
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||||
],
|
],
|
||||||
python_requires=">=3.9",
|
python_requires=">=3.9",
|
||||||
install_requires=deps,
|
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 ""
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user