1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ import os
16+ import platform
1517import sys
1618
1719from hatchling .builders .hooks .plugin .interface import BuildHookInterface
@@ -29,17 +31,40 @@ def initialize(self, version, build_data):
2931 build_data ["pure_python" ] = False
3032 build_data ["infer_tag" ] = False
3133
32- # Get the platform tag using hatchling's logic (handles MACOSX_DEPLOYMENT_TARGET, etc.)
33- from packaging .tags import sys_tags
34+ if sys .platform == "darwin" :
35+ plat_tag = self ._get_macos_platform_tag ()
36+ else :
37+ from packaging .tags import sys_tags
3438
35- tag = next (
36- t for t in sys_tags () if "manylinux" not in t .platform and "musllinux" not in t .platform
37- )
38- platform = tag .platform
39+ tag = next (
40+ t
41+ for t in sys_tags ()
42+ if "manylinux" not in t .platform and "musllinux" not in t .platform
43+ )
44+ plat_tag = tag .platform
3945
40- if sys .platform == "darwin" :
41- from hatchling .builders .macos import process_macos_plat_tag
46+ build_data ["tag" ] = f"py3-none-{ plat_tag } "
47+
48+ def _get_macos_platform_tag (self ):
49+ """Build macOS platform tag from MACOSX_DEPLOYMENT_TARGET env var."""
50+ deployment_target = os .environ .get ("MACOSX_DEPLOYMENT_TARGET" )
51+ if not deployment_target :
52+ # Fall back to current macOS version
53+ deployment_target = platform .mac_ver ()[0 ]
54+ # Use only major.minor
55+ parts = deployment_target .split ("." )
56+ deployment_target = f"{ parts [0 ]} .{ parts [1 ] if len (parts ) > 1 else '0' } "
57+
58+ # Convert version to wheel tag format (e.g., "11.0" -> "11_0")
59+ version_tag = deployment_target .replace ("." , "_" )
4260
43- platform = process_macos_plat_tag (platform , compat = True )
61+ # Get architecture
62+ machine = platform .machine ()
63+ if machine == "x86_64" :
64+ arch = "x86_64"
65+ elif machine == "arm64" :
66+ arch = "arm64"
67+ else :
68+ arch = machine
4469
45- build_data [ "tag" ] = f"py3-none- { platform } "
70+ return f"macosx_ { version_tag } _ { arch } "
0 commit comments