Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC for ragna-base package with just base dependencies #405

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
96297b8
Update pyproject.toml: to add dynamic optional dependencies
arjxn-py May 7, 2024
960a2c8
Merge branch 'main' into ragna-base-poc
arjxn-py May 9, 2024
f9b8c39
Add concurrent `setup.py` with almost same configurations as `pyproje…
arjxn-py May 11, 2024
65753f1
Use multiple pyproject in `scripts/` and wrap it inside nox to build …
arjxn-py May 14, 2024
aa565b8
Merge branch 'main' into ragna-base-poc
arjxn-py May 14, 2024
3201c1f
Also add pyproject in root for CI build and testing
arjxn-py May 14, 2024
551924d
Ignore semver warning in pyproject (this change was overlooked while …
arjxn-py May 14, 2024
a1a4f4f
Use `setup.py` as shim
arjxn-py May 17, 2024
12ac91f
Add some helping logging points in `setup`
arjxn-py May 22, 2024
ca5f58b
Add basic workflow to test build
arjxn-py May 22, 2024
43c2ec8
Use pipdeptree to visualise dependency tree of built package
arjxn-py May 22, 2024
75a040d
Merge branch 'Quansight:main' into ragna-base-poc
arjxn-py May 22, 2024
6c8f614
Temporarily run build workflow on PRs
arjxn-py May 22, 2024
05411b7
Build package with `nox` in workflow
arjxn-py May 22, 2024
0028f4e
Fix syntax error in workflow
arjxn-py May 22, 2024
fab9c7d
Delete splitted pyprojects & Switch to traditional build for now
arjxn-py May 30, 2024
c396b55
Try using pipx to build package
arjxn-py May 30, 2024
bd65487
Get rid of `noxfile` & `setup` try using helper script instead
arjxn-py May 30, 2024
7a36ba5
Merge branch 'main' into ragna-base-poc
arjxn-py May 30, 2024
241fab5
Fix dependency conflicts for docker build
arjxn-py Jun 2, 2024
855025d
Try fixing docker lockfile dailure
arjxn-py Jun 2, 2024
f042769
Modity `update_optional_dependencies` to update `requirements.txt`
arjxn-py Jun 2, 2024
a7c9a01
Apply suggestions from code review
arjxn-py Jun 6, 2024
2e70229
Modify `update_requirements_txt` -> `create_requirements_txt`
arjxn-py Jun 6, 2024
9b0f1c2
Bump `setuptools` & `setuptools_scm`
arjxn-py Jun 6, 2024
ba60010
Merge branch 'main' into ragna-base-poc
arjxn-py Jun 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/build_package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build Package

on:
pull_request:
push:
branches:
- release/*

jobs:
publish:
runs-on: ubuntu-latest
strategy:
matrix:
package:
- ragna
- ragna-base

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install build dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build toml

- name: Modify pyproject.toml
run: python scripts/build_helper.py ${{ matrix.package }}

- name: Build distribution
run: |
echo "Building package: ${{ matrix.package }}"
python -m build
echo "Build complete for ${{ matrix.package }}"

- name: Verify package
run: |
echo "Verifying package: ${{ matrix.package }}"
pip install dist/*.whl
pip check

- name: Visualize dependency tree of built package
run: |
pip install pipdeptree
pipdeptree -d 1
43 changes: 5 additions & 38 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[build-system]
requires = [
"setuptools>=45",
"setuptools_scm[toml]>=6.2",
"setuptools>=66",
"setuptools_scm[toml]>=8",
]
build-backend = "setuptools.build_meta"

Expand All @@ -20,49 +20,16 @@ classifiers = [
"Programming Language :: Python :: 3.11",
]
requires-python = ">=3.9"
dependencies = [
"aiofiles",
"emoji",
"fastapi",
"httpx",
"importlib_metadata>=4.6; python_version<'3.10'",
"packaging",
"panel==1.4.2",
"pydantic>=2",
"pydantic-core",
"pydantic-settings>=2",
"PyJWT",
"python-multipart",
"redis",
"questionary",
"rich",
"sqlalchemy>=2",
"starlette",
"tomlkit",
"typer",
"uvicorn",
]
dynamic = ["version"]
dynamic = ["dependencies", "version"]

[project.urls]
Homepage = "https://ragna.chat"
Documentation = "https://ragna.chat"
Changelog = "https://ragna.chat/en/stable/references/release-notes/"
Repository = "https://github.com/Quansight/ragna"

[project.optional-dependencies]
# to update the array below, run scripts/update_optional_dependencies.py
all = [
"chromadb>=0.4.13",
"httpx_sse",
"ijson",
"lancedb>=0.2",
"pyarrow",
"pymupdf>=1.23.6",
"python-docx",
"python-pptx",
"tiktoken",
]
[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}

[tool.setuptools_scm]
write_to = "ragna/_version.py"
Expand Down
20 changes: 20 additions & 0 deletions requirements-base.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
aiofiles
emoji
fastapi
httpx
importlib_metadata>=4.6; python_version<'3.10'
packaging
panel==1.4.2
pydantic>=2
pydantic-core
pydantic-settings>=2
PyJWT
python-multipart
redis
questionary
rich
sqlalchemy>=2
starlette
tomlkit
typer
uvicorn
29 changes: 29 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
PyJWT
aiofiles
chromadb>=0.4.13
emoji
fastapi
httpx
httpx_sse
ijson
importlib_metadata>=4.6; python_version<'3.10'
lancedb>=0.2
packaging
panel==1.4.2
pyarrow
pydantic-core
pydantic-settings>=2
pydantic>=2
pymupdf>=1.23.6
python-docx
python-multipart
python-pptx
questionary
redis
rich
sqlalchemy>=2
starlette
tiktoken
tomlkit
typer
uvicorn
34 changes: 34 additions & 0 deletions scripts/build_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import sys
from pathlib import Path

import toml

HERE = Path(__file__).parent
PROJECT_ROOT = HERE.parent
PYPROJECT_TOML = PROJECT_ROOT / "pyproject.toml"


def modify_pyproject(package_name):
with open(PYPROJECT_TOML, "r") as f:
pyproject_data = toml.load(f)

pyproject_data["project"]["name"] = package_name

pyproject_data["tool"]["setuptools"]["dynamic"]["dependencies"] = {
"file": [
"requirements-base.txt"
if package_name == "ragna-base"
else "requirements.txt"
]
}

with open(PYPROJECT_TOML, "w") as f:
toml.dump(pyproject_data, f)


if __name__ == "__main__":
package_name = sys.argv[1]
if package_name not in ["ragna", "ragna-base"]:
print("Invalid package name. Must be 'ragna' or 'ragna-base'.")
sys.exit(1)
modify_pyproject(package_name)
33 changes: 19 additions & 14 deletions scripts/update_optional_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
from functools import reduce
from pathlib import Path

import tomlkit
import tomlkit.items
from packaging.requirements import Requirement

import ragna
from ragna.core import Assistant, SourceStorage

HERE = Path(__file__).parent
PYPROJECT_TOML = HERE / ".." / "pyproject.toml"
PROJECT_ROOT = HERE.parent
REQUIREMENTS_TXT = PROJECT_ROOT / "requirements.txt"
REQUIREMENTS_BASE_TXT = PROJECT_ROOT / "requirements-base.txt"


def main():
optional_dependencies = make_optional_dependencies(
extract_builtin_document_handler_requirements(),
extract_builtin_component_requirements(),
)
update_pyproject_toml(optional_dependencies)
create_requirements_txt(optional_dependencies)


def make_optional_dependencies(*optional_requirements):
Expand Down Expand Up @@ -57,18 +57,23 @@ def extract_builtin_component_requirements():
return dict(requirements)


def update_pyproject_toml(optional_dependencies):
with open(PYPROJECT_TOML) as file:
document = tomlkit.load(file)
def create_requirements_txt(optional_dependencies):
# Read existing dependencies from requirements-base.txt
existing_dependencies = set()
if REQUIREMENTS_BASE_TXT.exists():
with open(REQUIREMENTS_BASE_TXT, "r") as file:
existing_dependencies = set(line.strip() for line in file)

document["project"]["optional-dependencies"]["all"] = tomlkit.items.Array(
list(map(tomlkit.items.String.from_raw, optional_dependencies)),
trivia=tomlkit.items.Trivia(),
multiline=True,
)
# Add optional dependencies
all_dependencies = existing_dependencies.union(optional_dependencies)

# Sort the dependencies to maintain a consistent order
sorted_dependencies = sorted(all_dependencies)

with open(PYPROJECT_TOML, "w") as file:
tomlkit.dump(document, file)
# Overwrite the requirements.txt file with the sorted dependencies
with open(REQUIREMENTS_TXT, "w") as file:
file.write("\n".join(sorted_dependencies))
file.write("\n")


def append_version_specifiers(version_specifiers, obj):
Expand Down