22
33from logging import getLogger
44from os import getenv
5+ from pathlib import Path
6+ from platform import machine as platform_machine
7+ from sys import platform as sys_platform , version_info
58from typing import Any
69
710from hatchling .builders .hooks .plugin .interface import BuildHookInterface
@@ -63,12 +66,12 @@ def initialize(self, version: str, build_data: dict[str, Any]) -> None:
6366 # Perform any cleanup actions
6467 build_plan .cleanup ()
6568
66- # if build_plan.libraries:
67- # # force include libraries
68- # # for library in build_plan.libraries:
69- # # name = library.get_qualified_name(build_plan.platform.platform)
70- # # build_data["force_include"][name] = name
69+ if not build_plan ._libraries :
70+ raise ValueError ("No libraries were created by the build." )
7171
72+ # force include libraries
73+ # for library in build_plan._libraries:
74+ # build_data["force_include"][library] = library
7275 # build_data["pure_python"] = False
7376 # machine = platform_machine()
7477 # version_major = version_info.major
@@ -83,28 +86,28 @@ def initialize(self, version: str, build_data: dict[str, Any]) -> None:
8386 # build_data["tag"] = f"cp{version_major}{version_minor}-abi3-{os_name}_{machine}"
8487 # else:
8588 # build_data["tag"] = f"cp{version_major}{version_minor}-cp{version_major}{version_minor}-{os_name}_{machine}"
86- # else:
87- # build_data["pure_python"] = False
88- # machine = platform_machine()
89- # version_major = version_info.major
90- # version_minor = version_info.minor
91- # # TODO abi3
92- # if "darwin" in sys_platform:
93- # os_name = "macosx_11_0"
94- # elif "linux" in sys_platform:
95- # os_name = "linux"
96- # else:
97- # os_name = "win"
98- # build_data["tag"] = f"cp{version_major}{version_minor}-cp{version_major}{version_minor}-{os_name}_{machine}"
99-
100- # # force include libraries
101- # for path in Path(".").rglob("*"):
102- # if path.is_dir():
103- # continue
104- # if str(path).startswith(str(build_plan.cmake.build) ) or str(path).startswith("dist"):
105- # continue
106- # if path.suffix in (".pyd", ".dll", ".so", ".dylib"):
107- # build_data["force_include"][str(path)] = str(path)
108-
109- # for path in build_data["force_include"]:
110- # self._logger.warning(f"Force include: {path}")
89+ build_data [ "pure_python" ] = False
90+ machine = platform_machine ()
91+ version_major = version_info . major
92+ version_minor = version_info .minor
93+
94+ # TODO abi3
95+ if "darwin" in sys_platform :
96+ os_name = "macosx_11_0"
97+ elif "linux" in sys_platform :
98+ os_name = "linux"
99+ else :
100+ os_name = "win"
101+ build_data ["tag" ] = f"cp{ version_major } { version_minor } -cp{ version_major } { version_minor } -{ os_name } _{ machine } "
102+
103+ # force include libraries
104+ for path in Path ("." ).rglob ("*" ):
105+ if path .is_dir ():
106+ continue
107+ if str (path ).startswith ("target" ) or str (path ).startswith ("dist" ):
108+ continue
109+ if path .suffix in (".pyd" , ".dll" , ".so" , ".dylib" ):
110+ build_data ["force_include" ][str (path )] = str (path )
111+
112+ for path in build_data ["force_include" ]:
113+ self ._logger .warning (f"Force include: { path } " )
0 commit comments