77from hatchling .builders .hooks .plugin .interface import BuildHookInterface
88
99from .structs import HatchCppBuildConfig , HatchCppBuildPlan
10+ from .utils import import_string
1011
1112__all__ = ("HatchCppBuildHook" ,)
1213
@@ -19,28 +20,48 @@ class HatchCppBuildHook(BuildHookInterface[HatchCppBuildConfig]):
1920
2021 def initialize (self , version : str , _ : dict [str , t .Any ]) -> None :
2122 """Initialize the plugin."""
23+ # Log some basic information
24+ self ._logger .info ("Initializing hatch-cpp plugin version %s" , version )
2225 self ._logger .info ("Running hatch-cpp" )
2326
27+ # Only run if creating wheel
28+ # TODO: Add support for specify sdist-plan
2429 if self .target_name != "wheel" :
2530 self ._logger .info ("ignoring target name %s" , self .target_name )
2631 return
2732
33+ # Skip if SKIP_HATCH_CPP is set
34+ # TODO: Support CLI once https://github.com/pypa/hatch/pull/1743
2835 if os .getenv ("SKIP_HATCH_CPP" ):
2936 self ._logger .info ("Skipping the build hook since SKIP_HATCH_CPP was set" )
3037 return
3138
32- config = HatchCppBuildConfig (** self .config )
39+ # Get build config class or use default
40+ build_config_class = import_string (self .config ["build-config-class" ]) if "build-config-class" in self .config else HatchCppBuildConfig
3341
42+ # Instantiate build config
43+ config = build_config_class (** self .config )
44+
45+ # Grab libraries and platform
3446 libraries = config .libraries
3547 platform = config .platform
36- if config .toolchain == "raw" :
37- build_plan = HatchCppBuildPlan (libraries = libraries , platform = platform )
38- build_plan .generate ()
39- if config .verbose :
40- for command in build_plan .commands :
41- self ._logger .info (command )
42- build_plan .execute ()
43- build_plan .cleanup ()
44-
45- self ._logger .info ("Finished running hatch-cpp" )
46- return
48+
49+ # Get build plan class or use default
50+ build_plan_class = import_string (self .config ["build-plan-class" ]) if "build-plan-class" in self .config else HatchCppBuildPlan
51+
52+ # Instantiate builder
53+ build_plan = build_plan_class (libraries = libraries , platform = platform )
54+
55+ # Generate commands
56+ build_plan .generate ()
57+
58+ # Log commands if in verbose mode
59+ if config .verbose :
60+ for command in build_plan .commands :
61+ self ._logger .info (command )
62+
63+ # Execute build plan
64+ build_plan .execute ()
65+
66+ # Perform any cleanup actions
67+ build_plan .cleanup ()
0 commit comments