@@ -42,8 +42,8 @@ const DEFAULTS_HELP_PURPOSE: &str = "to set project-wide defaults";
4242const NAMED_TARGET_HELP_PURPOSE : & str = "to build this target into that schema" ;
4343use crate :: bindings:: _helpers:: compile_attachment:: effective_config:: build_effective_connection_config;
4444use crate :: bindings:: _helpers:: compile_attachment:: effective_config:: build_effective_runtime_config;
45+ use crate :: bindings:: _helpers:: compile_attachment:: target:: resolved_target;
4546use crate :: bindings:: _helpers:: contracts:: spec_resolution:: resolve_target_config;
46- use crate :: bindings:: _helpers:: contracts:: spec_resolution:: resolve_target_name;
4747use crate :: bindings:: _helpers:: discovery:: guidance:: setting_help;
4848use crate :: bindings:: _helpers:: records:: construct:: error_class;
4949use crate :: bindings:: _helpers:: records:: fields:: field as native_field;
@@ -148,26 +148,20 @@ fn project_setting_help(
148148
149149/// Require shared-warehouse named targets to choose a schema strategy.
150150#[ pyfunction]
151- #[ pyo3( signature = ( * * options ) ) ]
151+ #[ pyo3( signature = ( * , discovered_inputs , adapter , selected_target , cli_vars = None ) ) ]
152152fn validate_named_target_schema_strategy < ' py > (
153- py : Python < ' py > ,
154- options : Option < Bound < ' py , PyDict > > ,
153+ discovered_inputs : & Bound < ' py , PyAny > ,
154+ adapter : & Bound < ' py , PyAny > ,
155+ selected_target : & Bound < ' py , PyAny > ,
156+ cli_vars : Option < Bound < ' py , PyAny > > ,
155157) -> Result < ( ) , PyErr > {
156- let arguments: KeywordArguments < ' py > = KeywordArguments :: read (
157- py,
158- "validate_named_target_schema_strategy" ,
159- options,
160- (
161- & [ "discovered_inputs" , "adapter" , "selected_target" ] ,
162- & [ "cli_vars" ] ,
163- ) ,
164- ) ?;
158+ let py: Python < ' py > = discovered_inputs. py ( ) ;
165159 named_target_schema_strategy (
166- & arguments . value ( " discovered_inputs" ) ? ,
167- & arguments . value ( " adapter" ) ? ,
160+ discovered_inputs,
161+ adapter,
168162 (
169- & arguments . value ( " selected_target" ) ? ,
170- & arguments . value ( "cli_vars" ) ? ,
163+ selected_target,
164+ & cli_vars . unwrap_or_else ( || py . None ( ) . into_bound ( py ) ) ,
171165 ) ,
172166 )
173167}
@@ -182,10 +176,10 @@ pub(crate) fn named_target_schema_strategy(
182176 if native_field ( adapter, "allows_implicit_managed_write_schema" ) ?. is_truthy ( ) ? {
183177 return Ok ( ( ) ) ;
184178 }
185- let Some ( ( target_name, target_config) ) = selected_target_config ( discovered, selected_target) ?
186- else {
179+ let ( target_name, target_config) = resolved_target ( discovered, selected_target) ?;
180+ if target_name . is_none ( ) {
187181 return Ok ( ( ) ) ;
188- } ;
182+ }
189183 let schema: Option < String > = text_or_none ( & native_field ( & target_config, "schema" ) ?) ?;
190184 if schema. is_some_and ( |schema| !python_strip ( & schema) . is_empty ( ) ) {
191185 return Ok ( ( ) ) ;
@@ -647,9 +641,10 @@ pub(crate) fn preserved_loader_schemas(
647641 loaders : & HashSet < String > ,
648642) -> PyResult < ( ) > {
649643 let py: Python < ' _ > = discovered. py ( ) ;
650- let Some ( ( _, target_config) ) = selected_target_config ( discovered, selected_target) ? else {
644+ let ( target_name, target_config) = resolved_target ( discovered, selected_target) ?;
645+ if target_name. is_none ( ) {
651646 return Ok ( ( ) ) ;
652- } ;
647+ }
653648 if !text_or_none ( & native_field ( & target_config, "schema" ) ?) ?
654649 . is_some_and ( |schema| python_strip ( & schema) == PRESERVE_TARGET_VALUE )
655650 {
@@ -676,30 +671,6 @@ pub(crate) fn preserved_loader_schemas(
676671 Ok ( ( ) )
677672}
678673
679- /// The selected target's name and configuration, or `None` when no named target is selected.
680- fn selected_target_config < ' py > (
681- discovered : & Bound < ' py , PyAny > ,
682- selected_target : & Bound < ' py , PyAny > ,
683- ) -> PyResult < Option < ( Bound < ' py , PyAny > , Bound < ' py , PyAny > ) > > {
684- let py: Python < ' py > = discovered. py ( ) ;
685- let project_config: Bound < ' py , PyAny > = native_field ( discovered, "project_config" ) ?;
686- let local_config: Bound < ' py , PyAny > = native_field ( discovered, "local_config" ) ?;
687- let target_name: Bound < ' py , PyAny > = resolve_target_name (
688- py,
689- & project_config. clone ( ) ,
690- & local_config. clone ( ) ,
691- & selected_target. clone ( ) ,
692- )
693- . and_then ( |value| value. into_bound_py_any ( py) ) ?;
694- if target_name. is_none ( ) {
695- return Ok ( None ) ;
696- }
697- let target_config: Bound < ' py , PyAny > =
698- resolve_target_config ( py, & project_config, & local_config, & target_name. clone ( ) )
699- . and_then ( |value| value. into_bound_py_any ( py) ) ?;
700- Ok ( Some ( ( target_name, target_config) ) )
701- }
702-
703674/// Raise when neither the resource nor the project names a physical write schema.
704675pub ( crate ) fn managed_write_schema (
705676 resource_label : & str ,
0 commit comments