-
Notifications
You must be signed in to change notification settings - Fork 6
feat(python): workflow to build and upload the pypi package #9
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| name: build, test and release sqlite-ai | ||
| name: Build, Test and Release SQLite AI | ||
| on: | ||
| push: | ||
| workflow_dispatch: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Build directories | ||
| build/ | ||
| dist/ | ||
| *.egg-info/ | ||
|
|
||
| # Python cache | ||
| __pycache__/ | ||
| *.py[cod] | ||
| *$py.class | ||
| *.so | ||
|
|
||
| # Virtual environments | ||
| venv/ | ||
| env/ | ||
| ENV/ | ||
|
|
||
| # Package files | ||
| *.whl | ||
| *.tar.gz | ||
|
|
||
| # Temporary files | ||
| *.tmp | ||
| *.log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| include README.md | ||
| include LICENSE | ||
| recursive-include src/sqliteai/binaries * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| ## SQLite AI Python package | ||
|
|
||
| This package provides the sqlite-ai extension prebuilt binaries for multiple platforms and architectures. | ||
|
|
||
| ### SQLite-AI | ||
|
|
||
| SQLite-AI is an extension for SQLite that brings artificial intelligence capabilities directly into the database. It enables developers to run, fine-tune, and serve AI models from within SQLite using simple SQL queries — ideal for on-device and edge applications where low-latency and offline inference are critical. The extension is actively developed by [SQLite AI](https://sqlite.ai), some API and features are still evolving. | ||
|
|
||
| More details on the official repository [sqliteai/sqlite-ai](https://github.com/sqliteai/sqlite-ai). | ||
|
|
||
| ### Documentation | ||
|
|
||
| For detailed information on all available functions, their parameters, and examples, refer to the [comprehensive API Reference](https://github.com/sqliteai/sqlite-ai/blob/main/API.md). | ||
|
|
||
| ### Supported Platforms and Architectures | ||
|
|
||
| | Platform | Arch | Subpackage name | Binary name | | ||
| | ------------- | ------------ | ----------------------- | ----------- | | ||
| | Linux (CPU) | x86_64/arm64 | sqliteai.binaries.cpu | ai.so | | ||
| | Linux (GPU) | x86_64/arm64 | sqliteai.binaries.gpu | ai.so | | ||
| | Windows (CPU) | x86_64 | sqliteai.binaries.cpu | ai.dll | | ||
| | Windows (GPU) | x86_64 | sqliteai.binaries.gpu | ai.dll | | ||
| | macOS (CPU) | x86_64/arm64 | sqliteai.binaries.cpu | ai.dylib | | ||
|
|
||
| ## Usage | ||
|
|
||
| > **Note:** Some SQLite installations on certain operating systems may have extension loading disabled by default. | ||
| If you encounter issues loading the extension, refer to the [sqlite-extensions-guide](https://github.com/sqliteai/sqlite-extensions-guide/) for platform-specific instructions on enabling and using SQLite extensions. | ||
|
|
||
| ```python | ||
| import importlib.resources | ||
| import sqlite3 | ||
|
|
||
| # Connect to your SQLite database | ||
| conn = sqlite3.connect("example.db") | ||
|
|
||
| # Load the sqlite-ai extension | ||
| # pip will install the correct binary package for your platform and architecture | ||
| # Choose between CPU or GPU variant | ||
| ext_path = importlib.resources.files("sqliteai.binaries.cpu") / "ai" | ||
|
|
||
| conn.enable_load_extension(True) | ||
| conn.load_extension(str(ext_path)) | ||
| conn.enable_load_extension(False) | ||
|
|
||
|
|
||
| # Now you can use sqlite-ai features in your SQL queries | ||
| print(conn.execute("SELECT ai_version();").fetchone()) | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,99 @@ | ||||
| import sys | ||||
| import zipfile | ||||
| import requests | ||||
| from pathlib import Path | ||||
| import shutil | ||||
|
|
||||
|
|
||||
| # == USAGE == | ||||
| # python3 download_artifacts.py PLATFORM VERSION | ||||
| # eg: python3 download_artifacts.py linux_x86_64 "0.5.9" | ||||
|
|
||||
| REPO = "sqliteai/sqlite-ai" | ||||
| RELEASE_URL = f"https://github.com/{REPO}/releases/download" | ||||
|
|
||||
| # Map Python plat_name to artifact names | ||||
| ARTIFACTS = { | ||||
| "manylinux2014_x86_64": ["ai-linux-cpu-x86_64", "ai-linux-gpu-x86_64"], | ||||
| "manylinux2014_aarch64": [ | ||||
| "ai-linux-cpu-arm64", | ||||
| "ai-linux-gpu-arm64", | ||||
| ], | ||||
| "win_amd64": ["ai-windows-cpu-x86_64", "ai-windows-gpu-x86_64"], | ||||
| "macosx_10_9_x86_64": ["ai-macos"], | ||||
| "macosx_11_0_arm64": ["ai-macos"], | ||||
| } | ||||
|
|
||||
| BINARY_NAME = { | ||||
| "manylinux2014_x86_64": "ai.so", | ||||
| "manylinux2014_aarch64": "ai.so", | ||||
| "win_amd64": "ai.dll", | ||||
| "macosx_10_9_x86_64": "ai.dylib", | ||||
| "macosx_11_0_arm64": "ai.dylib", | ||||
| } | ||||
|
|
||||
| BINARIES_DIR = Path(__file__).parent / "src/sqliteai/binaries" | ||||
|
|
||||
|
|
||||
| def download_and_extract(artifact_name, bin_name, version): | ||||
| artifact = f"{artifact_name}-{version}.zip" | ||||
| url = f"{RELEASE_URL}/{version}/{artifact}" | ||||
| print(f"Downloading {url}") | ||||
|
|
||||
| r = requests.get(url) | ||||
| if r.status_code != 200: | ||||
| print(f"Failed to download {artifact}: {r.status_code}") | ||||
| sys.exit(1) | ||||
|
|
||||
| zip_path = BINARIES_DIR / artifact | ||||
| with open(zip_path, "wb") as f: | ||||
| f.write(r.content) | ||||
|
|
||||
| subdir = "gpu" if "gpu" in artifact_name else "cpu" | ||||
| out_dir = BINARIES_DIR / subdir | ||||
| out_dir.mkdir(parents=True, exist_ok=True) | ||||
|
|
||||
| with zipfile.ZipFile(zip_path, "r") as zip_ref: | ||||
| for member in zip_ref.namelist(): | ||||
| if member.endswith(bin_name): | ||||
| zip_ref.extract(member, out_dir) | ||||
|
|
||||
| # Move to expected name/location | ||||
| src = out_dir / member | ||||
| dst = out_dir / bin_name | ||||
| src.rename(dst) | ||||
|
|
||||
| print(f"Extracted {dst}") | ||||
|
|
||||
| zip_path.unlink() | ||||
|
|
||||
|
|
||||
| def main(): | ||||
| version = None | ||||
| platform = None | ||||
| if len(sys.argv) == 3: | ||||
| platform = sys.argv[1].lower() | ||||
| version = sys.argv[2] | ||||
|
|
||||
| if not version or not platform: | ||||
| print( | ||||
| 'Error: Version is not specified.\nUsage: \n python3 download_artifacts.py linux_x86_64 "0.5.9"' | ||||
| ) | ||||
| sys.exit(1) | ||||
|
|
||||
| print(BINARIES_DIR) | ||||
|
||||
| print(BINARIES_DIR) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| [build-system] | ||
| requires = ["setuptools>=61.0", "wheel", "toml"] | ||
| build-backend = "setuptools.build_meta" | ||
|
|
||
| [project] | ||
| name = "sqlite-ai" | ||
| dynamic = ["version"] | ||
| description = "Python prebuilt binaries for SQLite AI extension for all supported platforms and architectures." | ||
| authors = [ | ||
| { name = "SQLite AI Team" } | ||
| ] | ||
| readme = "README.md" | ||
| requires-python = ">=3" | ||
| classifiers = [ | ||
| "Programming Language :: Python :: 3", | ||
| "Operating System :: POSIX :: Linux", | ||
| "Operating System :: Microsoft :: Windows", | ||
| "Operating System :: MacOS :: MacOS X" | ||
| ] | ||
|
|
||
| [project.urls] | ||
| Homepage = "https://sqlite.ai" | ||
| Documentation = "https://github.com/sqliteai/sqlite-ai/blob/main/API.md" | ||
| Repository = "https://github.com/sqliteai/sqlite-ai" | ||
| Issues = "https://github.com/sqliteai/sqlite-ai/issues" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| requests | ||
| toml | ||
| wheel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import setuptools | ||
| import toml | ||
| import os | ||
| import sys | ||
|
|
||
| usage = """ | ||
| Usage: python setup.py bdist_wheel --plat-name <platform> | ||
| The PACKAGE_VERSION environment variable must be set to the desired version. | ||
|
|
||
| Example: | ||
| PACKAGE_VERSION=0.5.9 python setup.py bdist_wheel --plat-name linux_x86_64 | ||
| """ | ||
|
|
||
| with open("pyproject.toml", "r") as f: | ||
| pyproject = toml.load(f) | ||
|
|
||
| project = pyproject["project"] | ||
|
|
||
| # Get version from environment or default | ||
| version = os.environ.get("PACKAGE_VERSION", "") | ||
| if not version: | ||
| print("PACKAGE_VERSION environment variable is not set.") | ||
| print(usage) | ||
| sys.exit(1) | ||
|
|
||
| # Get Python platform name from --plat-name argument | ||
| plat_name = None | ||
| for i, arg in enumerate(sys.argv): | ||
| if arg == "--plat-name" and i + 1 < len(sys.argv): | ||
| plat_name = sys.argv[i + 1] | ||
| break | ||
|
|
||
| if not plat_name: | ||
danielebriggi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| print("Error: --plat-name argument is required") | ||
| print(usage) | ||
| sys.exit(1) | ||
|
|
||
| # Map plat_name to classifier | ||
| classifier_map = { | ||
| "manylinux2014_x86_64": "Operating System :: POSIX :: Linux", | ||
| "manylinux2014_aarch64": "Operating System :: POSIX :: Linux", | ||
| "win_amd64": "Operating System :: Microsoft :: Windows", | ||
| "macosx_10_9_x86_64": "Operating System :: MacOS", | ||
| "macosx_11_0_arm64": "Operating System :: MacOS", | ||
| } | ||
|
|
||
| classifier = classifier_map.get(plat_name) | ||
| if not classifier: | ||
| print(f"Unknown plat_name: {plat_name}") | ||
| sys.exit(1) | ||
|
|
||
| with open("README.md", "r", encoding="utf-8") as f: | ||
| long_description = f.read() | ||
|
|
||
| setuptools.setup( | ||
| name=project["name"], | ||
| version=version, | ||
| description=project.get("description", ""), | ||
| author=project["authors"][0]["name"] if project.get("authors") else "", | ||
danielebriggi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| long_description=long_description, | ||
| long_description_content_type="text/markdown", | ||
| url=project["urls"]["Homepage"], | ||
| packages=setuptools.find_packages(where="src"), | ||
| package_dir={"": "src"}, | ||
| include_package_data=True, | ||
| python_requires=project.get("requires-python", ">=3"), | ||
| classifiers=project.get("classifiers", []), | ||
| ) | ||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.