From 4790f8d0203b7df016057add73a6e356a66fb64d Mon Sep 17 00:00:00 2001 From: Daniele Briggi <=> Date: Tue, 16 Sep 2025 17:19:56 +0200 Subject: [PATCH] chore(python): upgrade flow to python -m build The solution python setup.py bdist_wheel --plat-name is deprecated. Modernize the build flow but keeping the platform specific tag for the wheel and specific classifier. chore(package): binaries moved to `sqlite_vector.binaries` (with underscore) chore(license): using the right one --- .github/workflows/python-package.yml | 5 +- packages/python/LICENSE.md | 1 + packages/python/MANIFEST.in | 2 +- packages/python/README.md | 2 +- packages/python/pyproject.toml | 23 ++-- packages/python/requirements-dev.txt | 4 +- packages/python/setup.py | 108 +++++++++--------- .../__init__.py | 0 packages/python/src/sqlite_vector/_version.py | 3 + 9 files changed, 81 insertions(+), 67 deletions(-) create mode 120000 packages/python/LICENSE.md rename packages/python/src/{sqlite-vector => sqlite_vector}/__init__.py (100%) create mode 100644 packages/python/src/sqlite_vector/_version.py diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index d6062b6..e05c78b 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -91,9 +91,10 @@ jobs: - name: Build wheel env: PACKAGE_VERSION: ${{ steps.get_version.outputs.version }} + PLAT_NAME: ${{ matrix.plat_name }} run: | cd packages/python - python setup.py bdist_wheel --plat-name "${{ matrix.plat_name }}" + python -m build --wheel - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 @@ -103,4 +104,4 @@ jobs: # Avoid workflow to fail if the version has already been published skip-existing: true # Upload to Test Pypi for testing - # repository-url: https://test.pypi.org/legacy/ + #repository-url: https://test.pypi.org/legacy/ diff --git a/packages/python/LICENSE.md b/packages/python/LICENSE.md new file mode 120000 index 0000000..f0608a6 --- /dev/null +++ b/packages/python/LICENSE.md @@ -0,0 +1 @@ +../../LICENSE.md \ No newline at end of file diff --git a/packages/python/MANIFEST.in b/packages/python/MANIFEST.in index 610b692..3921982 100644 --- a/packages/python/MANIFEST.in +++ b/packages/python/MANIFEST.in @@ -1,3 +1,3 @@ include README.md -include LICENSE +include LICENSE.md recursive-include src/sqlite-vector/binaries * diff --git a/packages/python/README.md b/packages/python/README.md index cf8910e..40de2a9 100644 --- a/packages/python/README.md +++ b/packages/python/README.md @@ -34,7 +34,7 @@ conn = sqlite3.connect("example.db") # Load the sqlite-vector extension # pip will install the correct binary package for your platform and architecture -ext_path = importlib.resources.files("sqlite-vector.binaries") / "vector" +ext_path = importlib.resources.files("sqlite_vector.binaries") / "vector" conn.enable_load_extension(True) conn.load_extension(str(ext_path)) diff --git a/packages/python/pyproject.toml b/packages/python/pyproject.toml index ddf057f..f514d71 100644 --- a/packages/python/pyproject.toml +++ b/packages/python/pyproject.toml @@ -1,25 +1,32 @@ [build-system] -requires = ["setuptools>=61.0", "wheel", "toml"] +requires = ["setuptools>=61.0", "build", "wheel"] build-backend = "setuptools.build_meta" [project] name = "sqliteai-vector" -dynamic = ["version"] +dynamic = ["version", "classifiers"] description = "Python prebuilt binaries for SQLite Vector extension for all supported platforms and architectures." authors = [ { name = "SQLite AI Team" } ] readme = "README.md" +license = "LicenseRef-Elastic-2.0-Modified-For-Open-Source-Use" +license-files = ["LICENSE.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-vector/blob/main/API.md" Repository = "https://github.com/sqliteai/sqlite-vector" Issues = "https://github.com/sqliteai/sqlite-vector/issues" + +[tool.setuptools] +packages = {find = {where = ["src"]}} +include-package-data = true + +[tool.setuptools.dynamic] +version = {attr = "sqlite_vector._version.__version__"} + +[tool.bdist_wheel] +# Force platform-specific wheels +universal = false diff --git a/packages/python/requirements-dev.txt b/packages/python/requirements-dev.txt index 6760087..055c918 100644 --- a/packages/python/requirements-dev.txt +++ b/packages/python/requirements-dev.txt @@ -1,3 +1,3 @@ requests -toml -wheel \ No newline at end of file +wheel +build diff --git a/packages/python/setup.py b/packages/python/setup.py index baae9de..1759174 100644 --- a/packages/python/setup.py +++ b/packages/python/setup.py @@ -1,54 +1,56 @@ -import setuptools -import toml import os -import sys - -usage = """ -Usage: python setup.py bdist_wheel --plat-name -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: - print("Error: --plat-name argument is required") - print(usage) - 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"], - 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", []), -) +from setuptools import setup +from setuptools.command.bdist_wheel import bdist_wheel + + +class PlatformSpecificWheel(bdist_wheel): + """Custom bdist_wheel to force platform-specific wheel.""" + + def finalize_options(self): + bdist_wheel.finalize_options(self) + # Force platform-specific wheel + self.root_is_pure = False + + # Set platform name from environment if provided + plat_name = os.environ.get("PLAT_NAME") + if plat_name: + self.plat_name = plat_name + + def get_tag(self): + # Force platform-specific tags with broader compatibility + python_tag, abi_tag, platform_tag = bdist_wheel.get_tag(self) + + # Override platform tag if specified + plat_name = os.environ.get("PLAT_NAME") + if plat_name: + platform_tag = plat_name + + # Use py3 for broader Python compatibility since we have pre-built binaries + python_tag = "py3" + abi_tag = "none" + + return python_tag, abi_tag, platform_tag + + +def get_platform_classifiers(): + """Get platform-specific classifiers based on PLAT_NAME environment variable.""" + 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"], + } + + plat_name = os.environ.get("PLAT_NAME") + if plat_name and plat_name in classifier_map: + return ["Programming Language :: Python :: 3", classifier_map[plat_name][0]] + + raise ValueError(f"Unsupported or missing PLAT_NAME: {plat_name}") + + +if __name__ == "__main__": + setup( + cmdclass={"bdist_wheel": PlatformSpecificWheel}, + classifiers=get_platform_classifiers(), + ) diff --git a/packages/python/src/sqlite-vector/__init__.py b/packages/python/src/sqlite_vector/__init__.py similarity index 100% rename from packages/python/src/sqlite-vector/__init__.py rename to packages/python/src/sqlite_vector/__init__.py diff --git a/packages/python/src/sqlite_vector/_version.py b/packages/python/src/sqlite_vector/_version.py new file mode 100644 index 0000000..99f716b --- /dev/null +++ b/packages/python/src/sqlite_vector/_version.py @@ -0,0 +1,3 @@ +import os + +__version__ = os.environ.get("PACKAGE_VERSION", "0.0.0") \ No newline at end of file