11"""Hatchling build hook for generating Java stubs."""
22
3+ import logging
34import shutil
45from pathlib import Path
56
910
1011from scyjava ._stubs ._genstubs import generate_stubs
1112
13+ logger = logging .getLogger ("scyjava" )
14+
1215
1316class ScyjavaBuildHook (BuildHookInterface ):
1417 """Custom build hook for generating Java stubs."""
@@ -17,20 +20,22 @@ class ScyjavaBuildHook(BuildHookInterface):
1720
1821 def initialize (self , version : str , build_data : dict ) -> None :
1922 """Initialize the build hook with the version and build data."""
20- breakpoint ()
2123 if self .target_name != "wheel" :
2224 return
23- dest = Path (self .root , "src" )
24- shutil .rmtree (dest , ignore_errors = True ) # remove the old stubs
2525
26- # actually build the stubs
27- coord = f"{ self .config ['maven_coord' ]} :{ self .metadata .version } "
26+ endpoints = self .config .get ("maven_coordinates" , [])
27+ if not endpoints :
28+ logger .warning ("No maven coordinates provided. Skipping stub generation." )
29+ return
30+
2831 prefixes = self .config .get ("prefixes" , [])
29- generate_stubs ( endpoints = [ coord ], prefixes = prefixes , output_dir = dest )
32+ dest = Path ( self . root , "src" , "scyjava" , "types" )
3033
31- # add all packages to the build config
32- packages = [str (x .relative_to (self .root )) for x in dest .iterdir ()]
33- self .build_config .target_config .setdefault ("packages" , packages )
34+ # actually build the stubs
35+ generate_stubs (endpoints = endpoints , prefixes = prefixes , output_dir = dest )
36+ print (f"Generated stubs for { endpoints } in { dest } " )
37+ # add all new packages to the build config
38+ build_data ["artifacts" ].append ("src/scyjava/types" )
3439
3540
3641@hookimpl
0 commit comments