Skip to content

Commit 77346b6

Browse files
author
Daniele Briggi
committed
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(license): using the right one
1 parent 61372d8 commit 77346b6

File tree

7 files changed

+69
-69
lines changed

7 files changed

+69
-69
lines changed

.github/workflows/python-package.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ jobs:
8787
- name: Build wheel
8888
env:
8989
PACKAGE_VERSION: ${{ steps.get_version.outputs.version }}
90+
PLAT_NAME: ${{ matrix.plat_name }}
9091
run: |
9192
cd packages/python
92-
python setup.py bdist_wheel --plat-name "${{ matrix.plat_name }}"
93+
python -m build --wheel
9394
9495
- name: Publish to PyPI
9596
uses: pypa/gh-action-pypi-publish@release/v1
@@ -99,4 +100,4 @@ jobs:
99100
# Avoid workflow to fail if the version has already been published
100101
skip-existing: true
101102
# Upload to Test Pypi for testing
102-
# repository-url: https://test.pypi.org/legacy/
103+
repository-url: https://test.pypi.org/legacy/

packages/python/LICENSE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../LICENSE.md

packages/python/MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
include README.md
2-
include LICENSE
2+
include LICENSE.md
33
recursive-include src/sqliteai/binaries *

packages/python/pyproject.toml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
11
[build-system]
2-
requires = ["setuptools>=61.0", "wheel", "toml"]
2+
requires = ["setuptools>=61.0", "build", "wheel"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "sqlite-ai"
7-
dynamic = ["version"]
7+
dynamic = ["version", "classifiers"]
88
description = "Python prebuilt binaries for SQLite AI extension for all supported platforms and architectures."
99
authors = [
1010
{ name = "SQLite AI Team" }
1111
]
1212
readme = "README.md"
13+
license = "Elastic-2.0"
14+
license-files = ["LICENSE.md"]
1315
requires-python = ">=3"
14-
classifiers = [
15-
"Programming Language :: Python :: 3",
16-
"Operating System :: POSIX :: Linux",
17-
"Operating System :: Microsoft :: Windows",
18-
"Operating System :: MacOS :: MacOS X"
19-
]
2016

2117
[project.urls]
2218
Homepage = "https://sqlite.ai"
2319
Documentation = "https://github.com/sqliteai/sqlite-ai/blob/main/API.md"
2420
Repository = "https://github.com/sqliteai/sqlite-ai"
2521
Issues = "https://github.com/sqliteai/sqlite-ai/issues"
22+
23+
[tool.setuptools]
24+
packages = {find = {where = ["src"]}}
25+
include-package-data = true
26+
27+
[tool.setuptools.dynamic]
28+
version = {attr = "sqliteai._version.__version__"}
29+
30+
[tool.bdist_wheel]
31+
# Force platform-specific wheels
32+
universal = false
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
requests
2-
toml
3-
wheel
2+
wheel
3+
build

packages/python/setup.py

Lines changed: 44 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,56 @@
1-
import setuptools
2-
import toml
31
import os
4-
import sys
2+
from setuptools import setup
3+
from setuptools.command.bdist_wheel import bdist_wheel
54

6-
usage = """
7-
Usage: python setup.py bdist_wheel --plat-name <platform>
8-
The PACKAGE_VERSION environment variable must be set to the desired version.
95

10-
Example:
11-
PACKAGE_VERSION=0.5.9 python setup.py bdist_wheel --plat-name linux_x86_64
12-
"""
6+
class PlatformSpecificWheel(bdist_wheel):
7+
"""Custom bdist_wheel to force platform-specific wheel."""
138

14-
with open("pyproject.toml", "r") as f:
15-
pyproject = toml.load(f)
9+
def finalize_options(self):
10+
bdist_wheel.finalize_options(self)
11+
# Force platform-specific wheel
12+
self.root_is_pure = False
1613

17-
project = pyproject["project"]
14+
# Set platform name from environment if provided
15+
plat_name = os.environ.get("PLAT_NAME")
16+
if plat_name:
17+
self.plat_name = plat_name
1818

19-
# Get version from environment or default
20-
version = os.environ.get("PACKAGE_VERSION", "")
21-
if not version:
22-
print("PACKAGE_VERSION environment variable is not set.")
23-
print(usage)
24-
sys.exit(1)
19+
def get_tag(self):
20+
# Force platform-specific tags with broader compatibility
21+
python_tag, abi_tag, platform_tag = bdist_wheel.get_tag(self)
2522

26-
# Get Python platform name from --plat-name argument
27-
plat_name = None
28-
for i, arg in enumerate(sys.argv):
29-
if arg == "--plat-name" and i + 1 < len(sys.argv):
30-
plat_name = sys.argv[i + 1]
31-
break
23+
# Override platform tag if specified
24+
plat_name = os.environ.get("PLAT_NAME")
25+
if plat_name:
26+
platform_tag = plat_name
3227

33-
if not plat_name:
34-
print("Error: --plat-name argument is required")
35-
print(usage)
36-
sys.exit(1)
28+
# Use py3 for broader Python compatibility since we have pre-built binaries
29+
python_tag = "py3"
30+
abi_tag = "none"
3731

38-
# Map plat_name to classifier
39-
classifier_map = {
40-
"manylinux2014_x86_64": "Operating System :: POSIX :: Linux",
41-
"manylinux2014_aarch64": "Operating System :: POSIX :: Linux",
42-
"win_amd64": "Operating System :: Microsoft :: Windows",
43-
"macosx_10_9_x86_64": "Operating System :: MacOS",
44-
"macosx_11_0_arm64": "Operating System :: MacOS",
45-
}
32+
return python_tag, abi_tag, platform_tag
4633

47-
classifier = classifier_map.get(plat_name)
48-
if not classifier:
49-
print(f"Unknown plat_name: {plat_name}")
50-
sys.exit(1)
5134

52-
with open("README.md", "r", encoding="utf-8") as f:
53-
long_description = f.read()
35+
def get_platform_classifiers():
36+
"""Get platform-specific classifiers based on PLAT_NAME environment variable."""
37+
classifier_map = {
38+
"manylinux2014_x86_64": ["Operating System :: POSIX :: Linux"],
39+
"manylinux2014_aarch64": ["Operating System :: POSIX :: Linux"],
40+
"win_amd64": ["Operating System :: Microsoft :: Windows"],
41+
"macosx_10_9_x86_64": ["Operating System :: MacOS"],
42+
"macosx_11_0_arm64": ["Operating System :: MacOS"],
43+
}
5444

55-
setuptools.setup(
56-
name=project["name"],
57-
version=version,
58-
description=project.get("description", ""),
59-
author=project["authors"][0]["name"] if project.get("authors") else "",
60-
long_description=long_description,
61-
long_description_content_type="text/markdown",
62-
url=project["urls"]["Homepage"],
63-
packages=setuptools.find_packages(where="src"),
64-
package_dir={"": "src"},
65-
include_package_data=True,
66-
python_requires=project.get("requires-python", ">=3"),
67-
classifiers=project.get("classifiers", []),
68-
)
45+
plat_name = os.environ.get("PLAT_NAME")
46+
if plat_name and plat_name in classifier_map:
47+
return ["Programming Language :: Python :: 3", classifier_map[plat_name]]
48+
49+
raise ValueError(f"Unsupported or missing PLAT_NAME: {plat_name}")
50+
51+
52+
if __name__ == "__main__":
53+
setup(
54+
cmdclass={"bdist_wheel": PlatformSpecificWheel},
55+
classifiers=get_platform_classifiers(),
56+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import os
2+
3+
__version__ = os.environ.get("PACKAGE_VERSION", "0.0.0")

0 commit comments

Comments
 (0)