1+ import json
2+ import platform
3+ import subprocess
4+ import os
5+
6+ MANIFEST_FILE = "manifest.json"
7+ TEMP_MANIFEST_IN = "MANIFEST.in"
8+
9+ def get_platform_tag ():
10+ """Return the appropriate platform tag for wheel building."""
11+ system = platform .system ()
12+ if system == "Linux" :
13+ return "manylinux2014_x86_64"
14+ elif system == "Windows" :
15+ return "win_amd64"
16+ elif system == "Darwin" :
17+ return "macosx_10_9_universal2"
18+ else :
19+ raise RuntimeError (f"Unsupported platform: { system } " )
20+
21+ def create_manifest ():
22+ """Generate MANIFEST.in with the relevant platform-specific file."""
23+ with open (MANIFEST_FILE , "r" ) as f :
24+ data = json .load (f )
25+
26+ system = platform .system ().lower ()
27+ file_to_include = data .get (system )
28+
29+ if not file_to_include :
30+ raise RuntimeError (f"No relevant file found for platform: { system } " )
31+
32+ with open (TEMP_MANIFEST_IN , "w" ) as f :
33+ f .write (f"include { file_to_include } \n " )
34+
35+ def build_wheel ():
36+ """Build the wheel using the platform-specific command with --python-tag py3."""
37+ plat_name = get_platform_tag ()
38+ command = f"python setup.py bdist_wheel --python-tag py3 --plat-name { plat_name } "
39+
40+ print (f"Running: { command } " )
41+ subprocess .run (command , shell = True , check = True )
42+
43+ def cleanup ():
44+ """Remove the MANIFEST.in file after building."""
45+ if os .path .exists (TEMP_MANIFEST_IN ):
46+ os .remove (TEMP_MANIFEST_IN )
47+ print (f"Removed { TEMP_MANIFEST_IN } " )
48+
49+ if __name__ == "__main__" :
50+ create_manifest ()
51+ try :
52+ build_wheel ()
53+ finally :
54+ cleanup ()
0 commit comments