@@ -15,15 +15,24 @@ use sqlbuild_core::freshness_text::main::render_freshness_text::render_freshness
1515use sqlbuild_core:: freshness_text:: models:: FreshnessSourceResult ;
1616
1717use crate :: bindings:: _helpers:: command_runtime:: adapters:: resolve_cli_adapter;
18+ use crate :: bindings:: _helpers:: command_runtime:: connection:: resolve_project_connection_config;
19+ use crate :: bindings:: _helpers:: compile_driver:: discovery:: discover_project_inputs;
20+ use crate :: bindings:: _helpers:: compile_driver:: project:: build_project_graph;
21+ use crate :: bindings:: _helpers:: contracts:: spec_resolution:: resolve_effective_adapter_name;
1822use crate :: bindings:: _helpers:: freshness:: freshness_observe:: { PreviousState , observe_freshness} ;
1923use crate :: bindings:: _helpers:: freshness:: observation:: Observer ;
2024use crate :: bindings:: _helpers:: freshness:: state_io:: { StateRead , read_latest} ;
25+ use crate :: bindings:: _helpers:: planner_selection:: selectors:: {
26+ expand_project_upstream_keys, select_project_graph,
27+ } ;
28+ use crate :: bindings:: _helpers:: planner_selection:: unit_tests:: reject_unit_test_selectors;
2129use crate :: bindings:: _helpers:: presentation_text:: terminal:: stdout_supports_color;
30+ use crate :: bindings:: _helpers:: result_output:: documents:: write_execution_json_output;
2231
2332const COMPILE_TYPES_MODULE : & str = "sqlbuild.compiler.compile.types" ;
2433use crate :: bindings:: _helpers:: native_host:: adapter:: AdapterHost ;
2534use crate :: bindings:: _helpers:: native_host:: host;
26- use crate :: bindings:: _helpers:: records:: ids:: { ErrorId , NativeAttr } ;
35+ use crate :: bindings:: _helpers:: records:: ids:: ErrorId ;
2736use crate :: bindings:: _helpers:: records:: registry;
2837use sqlbuild_core:: constants:: SOURCE_FRESHNESS_TABLE_NAME as STATE_TABLE_NAME ;
2938const STALE_REQUIRES_STATE_MESSAGE : & str = "freshness --fail-on-stale requires --state" ;
@@ -72,17 +81,11 @@ fn source_names_for_keys(
7281 let py: Python < ' _ > = graph. py ( ) ;
7382 let source_type: Bound < ' _ , PyAny > =
7483 imported ( py, COMPILE_TYPES_MODULE , "CompiledResourceType" ) ?. getattr ( "SOURCE" ) ?;
75- let expand: Bound < ' _ , PyAny > = registry:: native ( py, NativeAttr :: ExpandProjectUpstreamKeys ) ?;
7684 let upstream_deps: Bound < ' _ , PyAny > = graph. getattr ( "upstream_deps" ) ?;
7785 for key in keys. try_iter ( ) ? {
7886 let key: Bound < ' _ , PyAny > = key?;
79- let upstream: Bound < ' _ , PyAny > = expand. call (
80- ( ) ,
81- Some ( & keywords (
82- py,
83- & [ ( "key" , & key) , ( "upstream_deps" , & upstream_deps) ] ,
84- ) ?) ,
85- ) ?;
87+ let upstream: Bound < ' _ , PyAny > =
88+ expand_project_upstream_keys ( key. clone ( ) , & upstream_deps) ?. into_any ( ) ;
8689 for candidate in std:: iter:: once ( Ok ( key. clone ( ) ) ) . chain ( upstream. try_iter ( ) ?) {
8790 let candidate: Bound < ' _ , PyAny > = candidate?;
8891 if candidate. getattr ( "resource_type" ) ?. eq ( & source_type) ? {
@@ -99,13 +102,7 @@ fn graph_keys<'py>(
99102) -> PyResult < Bound < ' py , PyAny > > {
100103 let py: Python < ' py > = graph. py ( ) ;
101104 let empty: Bound < ' py , PyAny > = PyTuple :: empty ( py) . into_any ( ) ;
102- registry:: native ( py, NativeAttr :: SelectProjectGraph ) ?. call (
103- ( ) ,
104- Some ( & keywords (
105- py,
106- & [ ( "graph" , graph) , ( "select" , selectors) , ( "exclude" , & empty) ] ,
107- ) ?) ,
108- )
105+ Ok ( select_project_graph ( graph, selectors, & empty) ?. into_any ( ) )
109106}
110107
111108/// Selected source names, sorted: selected or all keys and their upstream sources, minus excluded.
@@ -206,19 +203,18 @@ fn observe(
206203 names : & [ String ] ,
207204) -> PyResult < Vec < FreshnessSourceResult > > {
208205 let py: Python < ' _ > = adapter. py ( ) ;
209- let connection_config: Bound < ' _ , PyAny > =
210- registry:: native ( py, NativeAttr :: ResolveProjectConnectionConfig ) ?. call (
211- ( ) ,
212- Some ( & keywords (
213- py,
214- & [
215- ( "discovered_inputs" , discovered) ,
216- ( "project_dir" , project_dir) ,
217- ( "selected_target" , & request. getattr ( "selected_target" ) ?) ,
218- ( "cli_vars" , & request. getattr ( "cli_vars" ) ?) ,
219- ] ,
220- ) ?) ,
221- ) ?;
206+ let connection_config: Bound < ' _ , PyAny > = resolve_project_connection_config (
207+ py,
208+ Some ( keywords (
209+ py,
210+ & [
211+ ( "discovered_inputs" , discovered) ,
212+ ( "project_dir" , project_dir) ,
213+ ( "selected_target" , & request. getattr ( "selected_target" ) ?) ,
214+ ( "cli_vars" , & request. getattr ( "cli_vars" ) ?) ,
215+ ] ,
216+ ) ?) ,
217+ ) ?;
222218 let connection: Bound < ' _ , PyAny > = adapter. call_method1 ( "connect" , ( connection_config, ) ) ?;
223219 let observed = ( || {
224220 let project: Bound < ' _ , PyAny > = graph. getattr ( "project" ) ?;
@@ -258,11 +254,12 @@ fn write_json_output(
258254 payload : & str ,
259255 ( json_output, json_output_path) : ( bool , & Bound < ' _ , PyAny > ) ,
260256) -> PyResult < ( ) > {
261- let options: Bound < ' _ , PyDict > = keywords ( py, & [ ( "json_output_path" , json_output_path) ] ) ?;
262- options. set_item ( "payload" , format ! ( "{payload}\n " ) ) ?;
263- options. set_item ( "json_output" , json_output) ?;
264- registry:: native ( py, NativeAttr :: WriteExecutionJsonOutput ) ?. call ( ( ) , Some ( & options) ) ?;
265- Ok ( ( ) )
257+ write_execution_json_output (
258+ py,
259+ PyString :: new ( py, & format ! ( "{payload}\n " ) ) . into_any ( ) ,
260+ json_output,
261+ json_output_path. clone ( ) ,
262+ )
266263}
267264
268265/// Run one `sqb freshness` request.
@@ -281,36 +278,19 @@ fn run_freshness_command(py: Python<'_>, request: &Bound<'_, PyAny>) -> PyResult
281278 directory if !directory. is_none ( ) => directory,
282279 _ => py. import ( "pathlib" ) ?. getattr ( "Path" ) ?. call_method0 ( "cwd" ) ?,
283280 } ;
284- let discovered: Bound < ' _ , PyAny > = registry :: native ( py , NativeAttr :: DiscoverProjectInputs ) ?
285- . call ( ( ) , Some ( & keywords ( py, & [ ( "project_dir" , & project_dir) ] ) ?) ) ?;
281+ let discovered: Bound < ' _ , PyAny > =
282+ discover_project_inputs ( py , Some ( keywords ( py, & [ ( "project_dir" , & project_dir) ] ) ?) ) ?;
286283 let select: Bound < ' _ , PyAny > = request. getattr ( "select" ) ?;
287284 let exclude: Bound < ' _ , PyAny > = request. getattr ( "exclude" ) ?;
288- registry:: native ( py, NativeAttr :: RejectUnitTestSelectors ) ?. call (
289- ( ) ,
290- Some ( & keywords (
291- py,
292- & [
293- ( "select" , & select) ,
294- ( "exclude" , & exclude) ,
295- ( "discovered_inputs" , & discovered) ,
296- ] ,
297- ) ?) ,
285+ reject_unit_test_selectors ( & select, & exclude, & discovered) ?;
286+ let adapter_name: Bound < ' _ , PyAny > = resolve_effective_adapter_name (
287+ & discovered. getattr ( "project_config" ) ?,
288+ & discovered. getattr ( "local_config" ) ?,
298289 ) ?;
299- let adapter_name: Bound < ' _ , PyAny > =
300- registry:: native ( py, NativeAttr :: ResolveEffectiveAdapterName ) ?. call (
301- ( ) ,
302- Some ( & keywords (
303- py,
304- & [
305- ( "project_config" , & discovered. getattr ( "project_config" ) ?) ,
306- ( "local_config" , & discovered. getattr ( "local_config" ) ?) ,
307- ] ,
308- ) ?) ,
309- ) ?;
310290 let adapter: Bound < ' _ , PyAny > = resolve_cli_adapter ( & adapter_name, & project_dir) ?;
311- let graph: Bound < ' _ , PyAny > = registry :: native ( py , NativeAttr :: BuildProjectGraph ) ? . call (
312- ( ) ,
313- Some ( & keywords (
291+ let graph: Bound < ' _ , PyAny > = build_project_graph (
292+ py ,
293+ Some ( keywords (
314294 py,
315295 & [
316296 ( "discovered_inputs" , & discovered) ,
0 commit comments