1
1
"""Hatchling build hook for generating Java stubs."""
2
2
3
+ import logging
3
4
import shutil
4
5
from pathlib import Path
5
6
9
10
10
11
from scyjava ._stubs ._genstubs import generate_stubs
11
12
13
+ logger = logging .getLogger ("scyjava" )
14
+
12
15
13
16
class ScyjavaBuildHook (BuildHookInterface ):
14
17
"""Custom build hook for generating Java stubs."""
@@ -17,20 +20,22 @@ class ScyjavaBuildHook(BuildHookInterface):
17
20
18
21
def initialize (self , version : str , build_data : dict ) -> None :
19
22
"""Initialize the build hook with the version and build data."""
20
- breakpoint ()
21
23
if self .target_name != "wheel" :
22
24
return
23
- dest = Path (self .root , "src" )
24
- shutil .rmtree (dest , ignore_errors = True ) # remove the old stubs
25
25
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
+
28
31
prefixes = self .config .get ("prefixes" , [])
29
- generate_stubs ( endpoints = [ coord ], prefixes = prefixes , output_dir = dest )
32
+ dest = Path ( self . root , "src" , "scyjava" , "types" )
30
33
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" )
34
39
35
40
36
41
@hookimpl
0 commit comments