|
1 | | -import setuptools |
2 | | -import toml |
3 | 1 | import os |
4 | | -import sys |
5 | | - |
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. |
9 | | -
|
10 | | -Example: |
11 | | - PACKAGE_VERSION=0.5.9 python setup.py bdist_wheel --plat-name linux_x86_64 |
12 | | -""" |
13 | | - |
14 | | -with open("pyproject.toml", "r") as f: |
15 | | - pyproject = toml.load(f) |
16 | | - |
17 | | -project = pyproject["project"] |
18 | | - |
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) |
25 | | - |
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 |
32 | | - |
33 | | -if not plat_name: |
34 | | - print("Error: --plat-name argument is required") |
35 | | - print(usage) |
36 | | - sys.exit(1) |
37 | | - |
38 | | -with open("README.md", "r", encoding="utf-8") as f: |
39 | | - long_description = f.read() |
40 | | - |
41 | | -setuptools.setup( |
42 | | - name=project["name"], |
43 | | - version=version, |
44 | | - description=project.get("description", ""), |
45 | | - author=project["authors"][0]["name"], |
46 | | - long_description=long_description, |
47 | | - long_description_content_type="text/markdown", |
48 | | - url=project["urls"]["Homepage"], |
49 | | - packages=setuptools.find_packages(where="src"), |
50 | | - package_dir={"": "src"}, |
51 | | - include_package_data=True, |
52 | | - python_requires=project.get("requires-python", ">=3"), |
53 | | - classifiers=project.get("classifiers", []), |
54 | | -) |
| 2 | +from setuptools import setup |
| 3 | +from setuptools.command.bdist_wheel import bdist_wheel |
| 4 | + |
| 5 | + |
| 6 | +class PlatformSpecificWheel(bdist_wheel): |
| 7 | + """Custom bdist_wheel to force platform-specific wheel.""" |
| 8 | + |
| 9 | + def finalize_options(self): |
| 10 | + bdist_wheel.finalize_options(self) |
| 11 | + # Force platform-specific wheel |
| 12 | + self.root_is_pure = False |
| 13 | + |
| 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 |
| 18 | + |
| 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) |
| 22 | + |
| 23 | + # Override platform tag if specified |
| 24 | + plat_name = os.environ.get("PLAT_NAME") |
| 25 | + if plat_name: |
| 26 | + platform_tag = plat_name |
| 27 | + |
| 28 | + # Use py3 for broader Python compatibility since we have pre-built binaries |
| 29 | + python_tag = "py3" |
| 30 | + abi_tag = "none" |
| 31 | + |
| 32 | + return python_tag, abi_tag, platform_tag |
| 33 | + |
| 34 | + |
| 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 | + } |
| 44 | + |
| 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][0]] |
| 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 | + ) |
0 commit comments