1- import setuptools
2- import toml
31import 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+ )
0 commit comments