diff --git a/Cargo.lock b/Cargo.lock index c261373ad9..56a195c5bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4460,6 +4460,7 @@ dependencies = [ "sqlbuild-project", "sqlbuild-pysource", "sqlbuild-python-base", + "sqlbuild-python-front", "sqlbuild-recall", "sqlbuild-refactor", "sqlbuild-render", @@ -4468,7 +4469,6 @@ dependencies = [ "sqlbuild-sqltext", "sqlbuild-state", "sqlclean", - "stacker", "tokio", "uuid", ] @@ -4497,6 +4497,36 @@ dependencies = [ "sqlbuild-state", ] +[[package]] +name = "sqlbuild-python-front" +version = "0.0.0" +dependencies = [ + "chrono", + "chrono-tz", + "pyo3", + "serde_json", + "sqlbuild-analysis", + "sqlbuild-attachments", + "sqlbuild-cache", + "sqlbuild-cli", + "sqlbuild-config", + "sqlbuild-core", + "sqlbuild-cursor", + "sqlbuild-discovery", + "sqlbuild-host", + "sqlbuild-model-config", + "sqlbuild-orchestration", + "sqlbuild-pysource", + "sqlbuild-python-base", + "sqlbuild-refactor", + "sqlbuild-render", + "sqlbuild-scopes", + "sqlbuild-sqltext", + "sqlbuild-state", + "stacker", + "uuid", +] + [[package]] name = "sqlbuild-recall" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index 6b69927a79..f6fc2c295a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ members = [ "crates/sqlbuild-project", "crates/sqlbuild-cli", "crates/sqlbuild-python-base", + "crates/sqlbuild-python-front", "crates/sqlbuild-python", ] resolver = "2" @@ -57,9 +58,10 @@ order = [ "sqlbuild-project", "sqlbuild-cli", "sqlbuild-python-base", + "sqlbuild-python-front", "sqlbuild-python", ] -python-boundary = ["sqlbuild-python-base", "sqlbuild-python"] +python-boundary = ["sqlbuild-python-base", "sqlbuild-python-front", "sqlbuild-python"] polyglot-floor = "sqlbuild-analysis" [workspace.package] @@ -180,6 +182,7 @@ sqlbuild-orchestration = { path = "crates/sqlbuild-orchestration" } sqlbuild-process-ownership = { path = "crates/sqlbuild-process-ownership" } sqlbuild-project = { path = "crates/sqlbuild-project" } sqlbuild-python-base = { path = "crates/sqlbuild-python-base" } +sqlbuild-python-front = { path = "crates/sqlbuild-python-front" } sqlbuild-pysource = { path = "crates/sqlbuild-pysource" } sqlbuild-recall = { path = "crates/sqlbuild-recall" } sqlbuild-scopes = { path = "crates/sqlbuild-scopes" } diff --git a/crates/README.md b/crates/README.md index c0b283aff3..3b6a0de5bd 100644 --- a/crates/README.md +++ b/crates/README.md @@ -29,14 +29,15 @@ tested and benchmarked with `cargo test` alone. | `sqlbuild-project` | The compiled project as plain Rust: `CompiledProject` with the producers' facts and each resource's records (model inputs and schemas, compiled models and their analysis, sources, functions, audits and seeds), and what those records answer without Python, such as lineage rows, resolved namespaces and dependency keys. Values the host owns, such as user config and discovered files, and the views it builds lazily live in one slot per record, whose types `sqlbuild-python` supplies through the `ProjectHost` trait; reads that need Python stay in the bindings as extension traits. | | `sqlbuild-cli` | The `sqb` and `sqlbuild` executables: `--version`, unchanged compiles replayed from the shared reuse store with Python's exact streams, exit code and compute log capture, and a handoff of every other invocation to the installed `sqlbuild-python` script. Built as its own wheel (`crates/sqlbuild-cli/pyproject.toml`). | | `sqlbuild-python-base` | The base of the PyO3 bindings: native record, enum and error classes with their specs, registration, construction and field reads; keyword calls, imports, conversions and panics at the Python boundary; host entry calls; the process allocator; and the shared runtime the binding modules build on: the native store, compile context, diagnostics, progress and terminal text, warehouse access and orchestration reads. | -| `sqlbuild-python` | The `_native` module: its Python classes and functions and the conversions from Python objects, on top of `sqlbuild-python-base`. | +| `sqlbuild-python-front` | The front of the compile pipeline as PyO3 bindings, on top of `sqlbuild-python-base`: project discovery, model configuration and headers, scopes, macro rendering and authored values, SQL text, model attachment and the compile driver, cursors, contract and refactor facts, and the warehouse state tables of consumption, observations and audit results. | +| `sqlbuild-python` | The `_native` module: its Python classes and functions and the conversions from Python objects, on top of `sqlbuild-python-front` and `sqlbuild-python-base`. | ## Layering Dependencies point one way, from the top of this graph to the bottom: ```text -sqlbuild-python -> sqlbuild-python-base +sqlbuild-python -> sqlbuild-python-front -> sqlbuild-python-base -> sqlbuild-project -> sqlbuild-refactor -> sqlbuild-rules -> sqlbuild-analysis -> sqlbuild-attachments -> sqlbuild-model-config -> sqlbuild-scopes -> sqlbuild-render -> sqlbuild-discovery -> sqlbuild-host -> sqlbuild-config -> sqlbuild-sqltext -> sqlbuild-cache -> sqlbuild-pysource -> sqlbuild-state -> sqlbuild-cursor -> sqlbuild-core diff --git a/crates/sqlbuild-python-front/Cargo.toml b/crates/sqlbuild-python-front/Cargo.toml new file mode 100644 index 0000000000..a89a503d5e --- /dev/null +++ b/crates/sqlbuild-python-front/Cargo.toml @@ -0,0 +1,37 @@ +[package] +name = "sqlbuild-python-front" +description = "The front layer of the sqlbuild._native bindings: discovery, model configuration, scopes, rendering and SQL text." +version.workspace = true +edition.workspace = true +license.workspace = true +publish.workspace = true +rust-version.workspace = true + +[dependencies] +chrono.workspace = true +chrono-tz.workspace = true +pyo3.workspace = true +serde_json.workspace = true +sqlbuild-analysis.workspace = true +sqlbuild-attachments.workspace = true +sqlbuild-cache.workspace = true +sqlbuild-cli.workspace = true +sqlbuild-config.workspace = true +sqlbuild-core.workspace = true +sqlbuild-cursor.workspace = true +sqlbuild-discovery.workspace = true +sqlbuild-host.workspace = true +sqlbuild-model-config.workspace = true +sqlbuild-orchestration.workspace = true +sqlbuild-pysource.workspace = true +sqlbuild-python-base.workspace = true +sqlbuild-refactor.workspace = true +sqlbuild-render.workspace = true +sqlbuild-scopes.workspace = true +sqlbuild-sqltext.workspace = true +sqlbuild-state.workspace = true +stacker.workspace = true +uuid.workspace = true + +[lints] +workspace = true diff --git a/crates/sqlbuild-python/src/bindings/_helpers/attachments/argument_values.rs b/crates/sqlbuild-python-front/src/attachments/_helpers/argument_values.rs similarity index 96% rename from crates/sqlbuild-python/src/bindings/_helpers/attachments/argument_values.rs rename to crates/sqlbuild-python-front/src/attachments/_helpers/argument_values.rs index cad5b27291..4b5621ff57 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/attachments/argument_values.rs +++ b/crates/sqlbuild-python-front/src/attachments/_helpers/argument_values.rs @@ -1,6 +1,7 @@ //! Python audit argument values read as plain argument values. -use crate::bindings::_helpers::model_config::config_nodes::{PyConfigNode, config_object}; +use crate::model_config::main::config::config_object::config_object; +use crate::model_config::types::PyConfigNode; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; use pyo3::types::{ PyBool, PyDict, PyDictMethods, PyFloat, PyInt, PyList, PyListMethods, PyString, diff --git a/crates/sqlbuild-python/src/bindings/_helpers/attachments/ceremonial_select.rs b/crates/sqlbuild-python-front/src/attachments/_helpers/ceremonial_select.rs similarity index 93% rename from crates/sqlbuild-python/src/bindings/_helpers/attachments/ceremonial_select.rs rename to crates/sqlbuild-python-front/src/attachments/_helpers/ceremonial_select.rs index 1ffcd001fa..9e154442e5 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/attachments/ceremonial_select.rs +++ b/crates/sqlbuild-python-front/src/attachments/_helpers/ceremonial_select.rs @@ -6,7 +6,7 @@ use sqlbuild_attachments::ceremonial_select::main::omitted_select_offset::omitte use sqlbuild_attachments::ceremonial_select::models::OmittedSelect; use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; -use crate::bindings::_helpers::sqltext::lexical_syntax::LexicalSyntaxInput; +use crate::sqltext::models::LexicalSyntaxInput; use sqlbuild_python_base::boundary::main::compiler_guard::compiler_guard; /// The code-point offset to insert `SELECT 1` at, or `None`. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/attachments/cursor_intrinsics.rs b/crates/sqlbuild-python-front/src/attachments/_helpers/cursor_intrinsics.rs similarity index 95% rename from crates/sqlbuild-python/src/bindings/_helpers/attachments/cursor_intrinsics.rs rename to crates/sqlbuild-python-front/src/attachments/_helpers/cursor_intrinsics.rs index 6d52d7f64c..a6222f0c50 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/attachments/cursor_intrinsics.rs +++ b/crates/sqlbuild-python-front/src/attachments/_helpers/cursor_intrinsics.rs @@ -1,5 +1,7 @@ //! Cursor intrinsic validation, rejection and rendering. +use crate::attachments::constants::MICROBATCH_END_SENTINEL; +use crate::attachments::constants::MICROBATCH_START_SENTINEL; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyModule, PyModuleMethods, PyResult}; use pyo3::types::{PyString, PyStringMethods}; use pyo3::{Python, pyfunction, wrap_pyfunction}; @@ -23,10 +25,7 @@ const INTEGER_ANALYSIS_BOUND: &str = "CAST(0 AS BIGINT)"; const TIMESTAMP_ANALYSIS_BOUND: &str = "CAST('2000-01-01 00:00:00' AS TIMESTAMP)"; const MODEL_SQL_CONTEXT: &str = "Model SQL"; const SQL_CONTEXT: &str = "SQL"; -/// Executor placeholder replaced with a microbatch's start bound. -pub(crate) const MICROBATCH_START_SENTINEL: &str = "__SQB_CURSOR_START__"; -/// Executor placeholder replaced with a microbatch's end bound. -pub(crate) const MICROBATCH_END_SENTINEL: &str = "__SQB_CURSOR_END__"; + const RESERVED_CURSOR_MARKERS: [&str; 2] = [MICROBATCH_START_SENTINEL, MICROBATCH_END_SENTINEL]; /// The reserved executor bound markers no authored SQL may contain. @@ -53,7 +52,7 @@ fn text_value(value: &Bound<'_, PyAny>) -> Option { } /// `sql` with each intrinsic replaced by its bound and whether any was, raising for `context`. -fn replaced( +pub(crate) fn replaced( py: Python<'_>, sql: &str, context: &str, diff --git a/crates/sqlbuild-python/src/bindings/_helpers/attachments/function_headers.rs b/crates/sqlbuild-python-front/src/attachments/_helpers/function_headers.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/attachments/function_headers.rs rename to crates/sqlbuild-python-front/src/attachments/_helpers/function_headers.rs diff --git a/crates/sqlbuild-python-front/src/attachments/_helpers/mod.rs b/crates/sqlbuild-python-front/src/attachments/_helpers/mod.rs new file mode 100644 index 0000000000..791c2acc02 --- /dev/null +++ b/crates/sqlbuild-python-front/src/attachments/_helpers/mod.rs @@ -0,0 +1,5 @@ +pub(crate) mod argument_values; +pub(crate) mod ceremonial_select; +pub(crate) mod cursor_intrinsics; +pub(crate) mod function_headers; +pub(crate) mod reference_markers; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/attachments/reference_markers.rs b/crates/sqlbuild-python-front/src/attachments/_helpers/reference_markers.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/attachments/reference_markers.rs rename to crates/sqlbuild-python-front/src/attachments/_helpers/reference_markers.rs diff --git a/crates/sqlbuild-python-front/src/attachments/constants.rs b/crates/sqlbuild-python-front/src/attachments/constants.rs new file mode 100644 index 0000000000..2f9c28b99c --- /dev/null +++ b/crates/sqlbuild-python-front/src/attachments/constants.rs @@ -0,0 +1,7 @@ +//! Public constants of attachments. + +/// Executor placeholder replaced with a microbatch's start bound. +pub const MICROBATCH_START_SENTINEL: &str = "__SQB_CURSOR_START__"; + +/// Executor placeholder replaced with a microbatch's end bound. +pub const MICROBATCH_END_SENTINEL: &str = "__SQB_CURSOR_END__"; diff --git a/crates/sqlbuild-python-front/src/attachments/main/analysis_cursor_splices.rs b/crates/sqlbuild-python-front/src/attachments/main/analysis_cursor_splices.rs new file mode 100644 index 0000000000..f7caf3f420 --- /dev/null +++ b/crates/sqlbuild-python-front/src/attachments/main/analysis_cursor_splices.rs @@ -0,0 +1,13 @@ +//! `analysis_cursor_sql` with each replaced call as a splice of `sql`. + +use crate::attachments::_helpers::cursor_intrinsics; +use sqlbuild_analysis::sql_macros::models::TextSplice; + +/// `analysis_cursor_sql` with each replaced call as a splice of `sql`. +#[inline] +pub fn analysis_cursor_splices( + sql: &str, + cursor_type: Option<&str>, +) -> Result<(String, Vec), String> { + cursor_intrinsics::analysis_cursor_splices(sql, cursor_type) +} diff --git a/crates/sqlbuild-python-front/src/attachments/main/analysis_cursor_sql.rs b/crates/sqlbuild-python-front/src/attachments/main/analysis_cursor_sql.rs new file mode 100644 index 0000000000..6aa9f8b277 --- /dev/null +++ b/crates/sqlbuild-python-front/src/attachments/main/analysis_cursor_sql.rs @@ -0,0 +1,17 @@ +//! `sql` with intrinsics replaced by stable typed literals, only for static SQL analysis. + +use crate::attachments::_helpers::cursor_intrinsics; +use pyo3::Python; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// `sql` with intrinsics replaced by stable typed literals, only for static SQL analysis. +#[inline] +pub fn analysis_cursor_sql( + py: Python<'_>, + sql: &str, + cursor_type: &Bound<'_, PyAny>, +) -> PyResult { + cursor_intrinsics::analysis_cursor_sql(py, sql, cursor_type) +} diff --git a/crates/sqlbuild-python-front/src/attachments/main/argument_pairs.rs b/crates/sqlbuild-python-front/src/attachments/main/argument_pairs.rs new file mode 100644 index 0000000000..9b2119bd47 --- /dev/null +++ b/crates/sqlbuild-python-front/src/attachments/main/argument_pairs.rs @@ -0,0 +1,13 @@ +//! Read a `dict[str, object]` in insertion order, leaving out keys no parameter can name. + +use crate::attachments::_helpers::argument_values; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::types::PyDict; +use sqlbuild_attachments::audits::models::ArgumentValue; + +/// Read a `dict[str, object]` in insertion order, leaving out keys no parameter can name. +#[inline] +pub fn argument_pairs(arguments: &Bound<'_, PyDict>) -> PyResult> { + argument_values::argument_pairs(arguments) +} diff --git a/crates/sqlbuild-python-front/src/attachments/main/assert_no_unresolved_sql_markers.rs b/crates/sqlbuild-python-front/src/attachments/main/assert_no_unresolved_sql_markers.rs new file mode 100644 index 0000000000..67a209e017 --- /dev/null +++ b/crates/sqlbuild-python-front/src/attachments/main/assert_no_unresolved_sql_markers.rs @@ -0,0 +1,17 @@ +//! Fail if executable SQL still contains unresolved reference markers or an unclosed construct. + +use crate::attachments::_helpers::reference_markers; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::types::PyString; + +/// Fail if executable SQL still contains unresolved reference markers or an unclosed construct. +#[inline] +pub fn assert_no_unresolved_sql_markers( + py: Python<'_>, + sql: &Bound<'_, PyString>, + context: &str, +) -> PyResult<()> { + reference_markers::assert_no_unresolved_sql_markers(py, sql, context) +} diff --git a/crates/sqlbuild-python-front/src/attachments/main/compile_input_error.rs b/crates/sqlbuild-python-front/src/attachments/main/compile_input_error.rs new file mode 100644 index 0000000000..72483c1606 --- /dev/null +++ b/crates/sqlbuild-python-front/src/attachments/main/compile_input_error.rs @@ -0,0 +1,12 @@ +//! A `CompileInputError` carrying `message`. + +use crate::attachments::_helpers::cursor_intrinsics; +use pyo3::Python; +use pyo3::prelude::PyErr; +use pyo3::prelude::PyResult; + +/// A `CompileInputError` carrying `message`. +#[inline] +pub fn compile_input_error(py: Python<'_>, message: String) -> PyResult { + cursor_intrinsics::compile_input_error(py, message) +} diff --git a/crates/sqlbuild-python-front/src/attachments/main/config_argument_value.rs b/crates/sqlbuild-python-front/src/attachments/main/config_argument_value.rs new file mode 100644 index 0000000000..e7f68a7202 --- /dev/null +++ b/crates/sqlbuild-python-front/src/attachments/main/config_argument_value.rs @@ -0,0 +1,13 @@ +//! Native-built argument containers need no intermediate Python list or tuple. + +use crate::attachments::_helpers::argument_values; +use crate::model_config::types::PyConfigNode; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use sqlbuild_attachments::audits::models::ArgumentValue; + +/// Native-built argument containers need no intermediate Python list or tuple. +#[inline] +pub fn config_argument_value(py: Python<'_>, value: &PyConfigNode) -> PyResult { + argument_values::config_argument_value(py, value) +} diff --git a/crates/sqlbuild-python-front/src/attachments/main/mod.rs b/crates/sqlbuild-python-front/src/attachments/main/mod.rs new file mode 100644 index 0000000000..9dbfdd42c4 --- /dev/null +++ b/crates/sqlbuild-python-front/src/attachments/main/mod.rs @@ -0,0 +1,13 @@ +pub mod analysis_cursor_splices; +pub mod analysis_cursor_sql; +pub mod argument_pairs; +pub mod assert_no_unresolved_sql_markers; +pub mod compile_input_error; +pub mod config_argument_value; +pub mod parsed_header; +pub mod register_ceremonial_select; +pub mod register_cursor_intrinsics; +pub mod register_reference_markers; +pub mod reserved_cursor_markers; +pub mod resolve_cursor_intrinsics; +pub mod validated_model_cursor_sql; diff --git a/crates/sqlbuild-python-front/src/attachments/main/parsed_header.rs b/crates/sqlbuild-python-front/src/attachments/main/parsed_header.rs new file mode 100644 index 0000000000..ca1c8b5033 --- /dev/null +++ b/crates/sqlbuild-python-front/src/attachments/main/parsed_header.rs @@ -0,0 +1,17 @@ +//! One function file's parsed header; non-string keys and `None` values are never read. + +use crate::attachments::_helpers::function_headers; +use pyo3::prelude::Bound; +use pyo3::types::PyDict; +use sqlbuild_attachments::functions::models::FunctionHeader; +use sqlbuild_attachments::functions::models::FunctionLanguage; + +/// One function file's parsed header; non-string keys and `None` values are never read. +#[inline] +pub fn parsed_header( + header_values: &Bound<'_, PyDict>, + language: FunctionLanguage, + relative_path: &str, +) -> FunctionHeader { + function_headers::parsed_header(header_values, language, relative_path) +} diff --git a/crates/sqlbuild-python-front/src/attachments/main/register_ceremonial_select.rs b/crates/sqlbuild-python-front/src/attachments/main/register_ceremonial_select.rs new file mode 100644 index 0000000000..a84d8eb71e --- /dev/null +++ b/crates/sqlbuild-python-front/src/attachments/main/register_ceremonial_select.rs @@ -0,0 +1,12 @@ +//! Register the ceremonial select functions and classes. + +use crate::attachments::_helpers::ceremonial_select; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the ceremonial select functions and classes. +#[inline] +pub fn register_ceremonial_select(module: &Bound<'_, PyModule>) -> PyResult<()> { + ceremonial_select::register(module) +} diff --git a/crates/sqlbuild-python-front/src/attachments/main/register_cursor_intrinsics.rs b/crates/sqlbuild-python-front/src/attachments/main/register_cursor_intrinsics.rs new file mode 100644 index 0000000000..4efba4d901 --- /dev/null +++ b/crates/sqlbuild-python-front/src/attachments/main/register_cursor_intrinsics.rs @@ -0,0 +1,12 @@ +//! Register the cursor intrinsics functions and classes. + +use crate::attachments::_helpers::cursor_intrinsics; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the cursor intrinsics functions and classes. +#[inline] +pub fn register_cursor_intrinsics(module: &Bound<'_, PyModule>) -> PyResult<()> { + cursor_intrinsics::register(module) +} diff --git a/crates/sqlbuild-python-front/src/attachments/main/register_reference_markers.rs b/crates/sqlbuild-python-front/src/attachments/main/register_reference_markers.rs new file mode 100644 index 0000000000..9f79437e34 --- /dev/null +++ b/crates/sqlbuild-python-front/src/attachments/main/register_reference_markers.rs @@ -0,0 +1,12 @@ +//! Register the reference markers functions and classes. + +use crate::attachments::_helpers::reference_markers; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the reference markers functions and classes. +#[inline] +pub fn register_reference_markers(module: &Bound<'_, PyModule>) -> PyResult<()> { + reference_markers::register(module) +} diff --git a/crates/sqlbuild-python-front/src/attachments/main/reserved_cursor_markers.rs b/crates/sqlbuild-python-front/src/attachments/main/reserved_cursor_markers.rs new file mode 100644 index 0000000000..1b3973bc25 --- /dev/null +++ b/crates/sqlbuild-python-front/src/attachments/main/reserved_cursor_markers.rs @@ -0,0 +1,9 @@ +//! The reserved executor bound markers no authored SQL may contain. + +use crate::attachments::_helpers::cursor_intrinsics; + +/// The reserved executor bound markers no authored SQL may contain. +#[inline] +pub fn reserved_cursor_markers() -> Vec { + cursor_intrinsics::reserved_cursor_markers() +} diff --git a/crates/sqlbuild-python-front/src/attachments/main/resolve_cursor_intrinsics.rs b/crates/sqlbuild-python-front/src/attachments/main/resolve_cursor_intrinsics.rs new file mode 100644 index 0000000000..752c0d4d25 --- /dev/null +++ b/crates/sqlbuild-python-front/src/attachments/main/resolve_cursor_intrinsics.rs @@ -0,0 +1,16 @@ +//! Whether `sql` uses cursor intrinsics, and `sql` with both bounds rendered when given. + +use crate::attachments::_helpers::cursor_intrinsics; +use pyo3::Python; +use pyo3::prelude::PyResult; + +/// Whether `sql` uses cursor intrinsics, and `sql` with both bounds rendered when given. +#[inline] +pub fn resolve_cursor_intrinsics( + py: Python<'_>, + sql: &str, + start_sql: Option<&str>, + end_sql: Option<&str>, +) -> PyResult<(String, bool)> { + cursor_intrinsics::resolve_cursor_intrinsics(py, sql, start_sql, end_sql) +} diff --git a/crates/sqlbuild-python-front/src/attachments/main/validated_model_cursor_sql.rs b/crates/sqlbuild-python-front/src/attachments/main/validated_model_cursor_sql.rs new file mode 100644 index 0000000000..e93c8a78c7 --- /dev/null +++ b/crates/sqlbuild-python-front/src/attachments/main/validated_model_cursor_sql.rs @@ -0,0 +1,17 @@ +//! One model query with canonical intrinsic calls, raising when the model may not use them. + +use crate::attachments::_helpers::cursor_intrinsics; +use pyo3::Python; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// One model query with canonical intrinsic calls, raising when the model may not use them. +#[inline] +pub fn validated_model_cursor_sql( + py: Python<'_>, + sql: &str, + (model_name, config_values): (&str, &Bound<'_, PyAny>), +) -> PyResult { + cursor_intrinsics::validated_model_cursor_sql(py, sql, (model_name, config_values)) +} diff --git a/crates/sqlbuild-python-front/src/attachments/mod.rs b/crates/sqlbuild-python-front/src/attachments/mod.rs new file mode 100644 index 0000000000..ec9bd3513c --- /dev/null +++ b/crates/sqlbuild-python-front/src/attachments/mod.rs @@ -0,0 +1,5 @@ +//! Authored SQL attachments: argument values, cursor intrinsics, function headers and reference markers. + +pub(crate) mod _helpers; +pub mod constants; +pub mod main; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/authored_values/fields.rs b/crates/sqlbuild-python-front/src/authored_values/_helpers/fields.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/authored_values/fields.rs rename to crates/sqlbuild-python-front/src/authored_values/_helpers/fields.rs diff --git a/crates/sqlbuild-python-front/src/authored_values/_helpers/mod.rs b/crates/sqlbuild-python-front/src/authored_values/_helpers/mod.rs new file mode 100644 index 0000000000..8f6fc721c3 --- /dev/null +++ b/crates/sqlbuild-python-front/src/authored_values/_helpers/mod.rs @@ -0,0 +1,4 @@ +pub(crate) mod fields; +pub(crate) mod project_vars; +pub(crate) mod python_nodes; +pub(crate) mod sql_values; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/authored_values/project_vars.rs b/crates/sqlbuild-python-front/src/authored_values/_helpers/project_vars.rs similarity index 92% rename from crates/sqlbuild-python/src/bindings/_helpers/authored_values/project_vars.rs rename to crates/sqlbuild-python-front/src/authored_values/_helpers/project_vars.rs index 3d2fafc277..605701b73f 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/authored_values/project_vars.rs +++ b/crates/sqlbuild-python-front/src/authored_values/_helpers/project_vars.rs @@ -87,3 +87,10 @@ pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { module.add_function(wrap_pyfunction!(render_project_var_text, module)?)?; Ok(()) } + +/// `render_project_var_text` as a Python function. +pub(crate) fn render_project_var_text_function( + py: pyo3::Python<'_>, +) -> pyo3::PyResult> { + pyo3::wrap_pyfunction!(render_project_var_text, py) +} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/authored_values/python_nodes.rs b/crates/sqlbuild-python-front/src/authored_values/_helpers/python_nodes.rs similarity index 99% rename from crates/sqlbuild-python/src/bindings/_helpers/authored_values/python_nodes.rs rename to crates/sqlbuild-python-front/src/authored_values/_helpers/python_nodes.rs index aa668a4b4c..d6f912de6c 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/authored_values/python_nodes.rs +++ b/crates/sqlbuild-python-front/src/authored_values/_helpers/python_nodes.rs @@ -14,7 +14,7 @@ use sqlbuild_host::entries::models::{FacadeHost, UserCodeHost}; use sqlbuild_model_config::header_metadata::main::json_meta_problem::json_meta_problem; use sqlbuild_python_base::native_host::main::host_error::host_error; -use crate::bindings::_helpers::model_config::authored_nodes::PyNode; +use crate::model_config::models::PyNode; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::models::Request; use sqlbuild_python_base::native_host::main::host_entry::host_entry; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/authored_values/sql_values.rs b/crates/sqlbuild-python-front/src/authored_values/_helpers/sql_values.rs similarity index 88% rename from crates/sqlbuild-python/src/bindings/_helpers/authored_values/sql_values.rs rename to crates/sqlbuild-python-front/src/authored_values/_helpers/sql_values.rs index 598c9906ca..b0be7fdc1d 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/authored_values/sql_values.rs +++ b/crates/sqlbuild-python-front/src/authored_values/_helpers/sql_values.rs @@ -1,5 +1,6 @@ //! Typed SQL value normalization between Python authored values and native `SqlValue`s. +use crate::authored_values::models::SqlValueClasses; use pyo3::prelude::{ Bound, PyAny, PyAnyMethods, PyErr, PyModule, PyModuleMethods, PyResult, Python, }; @@ -13,35 +14,11 @@ use sqlbuild_model_config::sql_values::errors::SqlValueFailure; use sqlbuild_model_config::sql_values::main::normalize_sql_value::normalize_sql_value as normalized; use sqlbuild_model_config::sql_values::models::{RawKey, RawSqlValue, SqlValueLimits}; use sqlbuild_python_base::records::main::construct::new_record::new_record; -use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::registry::native_attr::native_attr; use sqlbuild_python_base::records::types::NativeAttr; use sqlbuild_python_base::records::types::RecordId; -/// The Python classes authored values are told apart by and normalized values are built from. -pub(crate) struct SqlValueClasses<'py> { - decimal: Bound<'py, PyAny>, - authored_set: Bound<'py, PyAny>, - value_call: Bound<'py, PyAny>, - sql_value: Bound<'py, PyAny>, - logical_type: Bound<'py, PyAny>, - kind: Bound<'py, PyAny>, -} - -impl<'py> SqlValueClasses<'py> { - pub(crate) fn load(py: Python<'py>) -> PyResult { - Ok(Self { - decimal: py.import("decimal")?.getattr("Decimal")?, - authored_set: record_class(py, RecordId::AuthoredSqlSet)?, - value_call: record_class(py, RecordId::AuthoredSqlValueCall)?, - sql_value: record_class(py, RecordId::SqlValue)?, - logical_type: record_class(py, RecordId::SqlLogicalType)?, - kind: record_class(py, RecordId::SqlValueKind)?, - }) - } -} - fn is_exactly(value: &Bound<'_, PyAny>, class: &Bound<'_, PyAny>) -> bool { value.get_type().is(class) } @@ -121,7 +98,7 @@ pub(crate) fn raw_value( )) } -fn logical_type<'py>( +pub(crate) fn logical_type<'py>( logical: &SqlLogicalType, classes: &SqlValueClasses<'py>, ) -> PyResult> { diff --git a/crates/sqlbuild-python-front/src/authored_values/main/mod.rs b/crates/sqlbuild-python-front/src/authored_values/main/mod.rs new file mode 100644 index 0000000000..aa6faab84c --- /dev/null +++ b/crates/sqlbuild-python-front/src/authored_values/main/mod.rs @@ -0,0 +1,10 @@ +pub mod project_var_text; +pub mod raw_value; +pub mod register_fields; +pub mod register_project_vars; +pub mod register_python_nodes; +pub mod register_sql_values; +pub mod render_project_var_text; +pub mod render_project_var_text_function; +pub mod sql_value; +pub mod sql_value_error; diff --git a/crates/sqlbuild-python-front/src/authored_values/main/project_var_text.rs b/crates/sqlbuild-python-front/src/authored_values/main/project_var_text.rs new file mode 100644 index 0000000000..81300b47ea --- /dev/null +++ b/crates/sqlbuild-python-front/src/authored_values/main/project_var_text.rs @@ -0,0 +1,12 @@ +//! One project var value as interpolated text; structured values are rejected. + +use crate::authored_values::_helpers::project_vars; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// One project var value as interpolated text; structured values are rejected. +#[inline] +pub fn project_var_text(value: &Bound<'_, PyAny>, label: &str) -> PyResult { + project_vars::project_var_text(value, label) +} diff --git a/crates/sqlbuild-python-front/src/authored_values/main/raw_value.rs b/crates/sqlbuild-python-front/src/authored_values/main/raw_value.rs new file mode 100644 index 0000000000..1415e788e2 --- /dev/null +++ b/crates/sqlbuild-python-front/src/authored_values/main/raw_value.rs @@ -0,0 +1,14 @@ +//! An authored Python value read by exact type, as `normalize_sql_value` dispatches. + +use crate::authored_values::_helpers::sql_values; +use crate::authored_values::models::SqlValueClasses; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_model_config::sql_values::models::RawSqlValue; + +/// An authored Python value read by exact type, as `normalize_sql_value` dispatches. +#[inline] +pub fn raw_value(value: &Bound<'_, PyAny>, classes: &SqlValueClasses<'_>) -> PyResult { + sql_values::raw_value(value, classes) +} diff --git a/crates/sqlbuild-python-front/src/authored_values/main/register_fields.rs b/crates/sqlbuild-python-front/src/authored_values/main/register_fields.rs new file mode 100644 index 0000000000..a47e495da2 --- /dev/null +++ b/crates/sqlbuild-python-front/src/authored_values/main/register_fields.rs @@ -0,0 +1,12 @@ +//! Register the fields functions and classes. + +use crate::authored_values::_helpers::fields; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the fields functions and classes. +#[inline] +pub fn register_fields(module: &Bound<'_, PyModule>) -> PyResult<()> { + fields::register(module) +} diff --git a/crates/sqlbuild-python-front/src/authored_values/main/register_project_vars.rs b/crates/sqlbuild-python-front/src/authored_values/main/register_project_vars.rs new file mode 100644 index 0000000000..52821b1733 --- /dev/null +++ b/crates/sqlbuild-python-front/src/authored_values/main/register_project_vars.rs @@ -0,0 +1,12 @@ +//! Register the project vars functions and classes. + +use crate::authored_values::_helpers::project_vars; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the project vars functions and classes. +#[inline] +pub fn register_project_vars(module: &Bound<'_, PyModule>) -> PyResult<()> { + project_vars::register(module) +} diff --git a/crates/sqlbuild-python-front/src/authored_values/main/register_python_nodes.rs b/crates/sqlbuild-python-front/src/authored_values/main/register_python_nodes.rs new file mode 100644 index 0000000000..7db72c6561 --- /dev/null +++ b/crates/sqlbuild-python-front/src/authored_values/main/register_python_nodes.rs @@ -0,0 +1,12 @@ +//! Register the python nodes functions and classes. + +use crate::authored_values::_helpers::python_nodes; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the python nodes functions and classes. +#[inline] +pub fn register_python_nodes(module: &Bound<'_, PyModule>) -> PyResult<()> { + python_nodes::register(module) +} diff --git a/crates/sqlbuild-python-front/src/authored_values/main/register_sql_values.rs b/crates/sqlbuild-python-front/src/authored_values/main/register_sql_values.rs new file mode 100644 index 0000000000..07a16cc1d4 --- /dev/null +++ b/crates/sqlbuild-python-front/src/authored_values/main/register_sql_values.rs @@ -0,0 +1,12 @@ +//! Register the sql values functions and classes. + +use crate::authored_values::_helpers::sql_values; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the sql values functions and classes. +#[inline] +pub fn register_sql_values(module: &Bound<'_, PyModule>) -> PyResult<()> { + sql_values::register(module) +} diff --git a/crates/sqlbuild-python-front/src/authored_values/main/render_project_var_text.rs b/crates/sqlbuild-python-front/src/authored_values/main/render_project_var_text.rs new file mode 100644 index 0000000000..d3a2aac8df --- /dev/null +++ b/crates/sqlbuild-python-front/src/authored_values/main/render_project_var_text.rs @@ -0,0 +1,12 @@ +//! One project var value as interpolated text; structured values are rejected. + +use crate::authored_values::_helpers::project_vars; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// One project var value as interpolated text; structured values are rejected. +#[inline] +pub fn render_project_var_text(value: &Bound<'_, PyAny>, label: &str) -> PyResult { + project_vars::render_project_var_text(value, label) +} diff --git a/crates/sqlbuild-python-front/src/authored_values/main/render_project_var_text_function.rs b/crates/sqlbuild-python-front/src/authored_values/main/render_project_var_text_function.rs new file mode 100644 index 0000000000..9cfdde9bd9 --- /dev/null +++ b/crates/sqlbuild-python-front/src/authored_values/main/render_project_var_text_function.rs @@ -0,0 +1,11 @@ +//! `render_project_var_text` as a Python function. + +use crate::authored_values::_helpers::project_vars; + +/// `render_project_var_text` as a Python function. +#[inline] +pub fn render_project_var_text_function( + py: pyo3::Python<'_>, +) -> pyo3::PyResult> { + project_vars::render_project_var_text_function(py) +} diff --git a/crates/sqlbuild-python-front/src/authored_values/main/sql_value.rs b/crates/sqlbuild-python-front/src/authored_values/main/sql_value.rs new file mode 100644 index 0000000000..24b7318920 --- /dev/null +++ b/crates/sqlbuild-python-front/src/authored_values/main/sql_value.rs @@ -0,0 +1,17 @@ +//! A Python `SqlValue` for a native one. + +use crate::authored_values::_helpers::sql_values; +use crate::authored_values::models::SqlValueClasses; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_core::models::SqlValue; + +/// A Python `SqlValue` for a native one. +#[inline] +pub fn sql_value<'py>( + value: &SqlValue, + classes: &SqlValueClasses<'py>, +) -> PyResult> { + sql_values::sql_value(value, classes) +} diff --git a/crates/sqlbuild-python-front/src/authored_values/main/sql_value_error.rs b/crates/sqlbuild-python-front/src/authored_values/main/sql_value_error.rs new file mode 100644 index 0000000000..a3fbc75484 --- /dev/null +++ b/crates/sqlbuild-python-front/src/authored_values/main/sql_value_error.rs @@ -0,0 +1,13 @@ +//! The exception a normalization failure raises. + +use crate::authored_values::_helpers::sql_values; +use pyo3::prelude::PyErr; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use sqlbuild_model_config::sql_values::errors::SqlValueFailure; + +/// The exception a normalization failure raises. +#[inline] +pub fn sql_value_error(py: Python<'_>, failure: SqlValueFailure) -> PyResult { + sql_values::sql_value_error(py, failure) +} diff --git a/crates/sqlbuild-python-front/src/authored_values/mod.rs b/crates/sqlbuild-python-front/src/authored_values/mod.rs new file mode 100644 index 0000000000..b0d56982ab --- /dev/null +++ b/crates/sqlbuild-python-front/src/authored_values/mod.rs @@ -0,0 +1,5 @@ +//! Values authored in project files: fields, project variables, Python nodes and SQL values. + +pub(crate) mod _helpers; +pub mod main; +pub mod models; diff --git a/crates/sqlbuild-python-front/src/authored_values/models.rs b/crates/sqlbuild-python-front/src/authored_values/models.rs new file mode 100644 index 0000000000..1597333a81 --- /dev/null +++ b/crates/sqlbuild-python-front/src/authored_values/models.rs @@ -0,0 +1,33 @@ +//! Public records of authored values. + +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyAnyMethods; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use sqlbuild_python_base::records::main::construct::record_class::record_class; +use sqlbuild_python_base::records::types::RecordId; + +/// The Python classes authored values are told apart by and normalized values are built from. +#[derive(Debug)] +pub struct SqlValueClasses<'py> { + pub(crate) decimal: Bound<'py, PyAny>, + pub(crate) authored_set: Bound<'py, PyAny>, + pub(crate) value_call: Bound<'py, PyAny>, + pub(crate) sql_value: Bound<'py, PyAny>, + pub(crate) logical_type: Bound<'py, PyAny>, + pub(crate) kind: Bound<'py, PyAny>, +} + +impl<'py> SqlValueClasses<'py> { + pub fn load(py: Python<'py>) -> PyResult { + Ok(Self { + decimal: py.import("decimal")?.getattr("Decimal")?, + authored_set: record_class(py, RecordId::AuthoredSqlSet)?, + value_call: record_class(py, RecordId::AuthoredSqlValueCall)?, + sql_value: record_class(py, RecordId::SqlValue)?, + logical_type: record_class(py, RecordId::SqlLogicalType)?, + kind: record_class(py, RecordId::SqlValueKind)?, + }) + } +} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/command_runtime/concurrency.rs b/crates/sqlbuild-python-front/src/command_runtime/_helpers/concurrency.rs similarity index 90% rename from crates/sqlbuild-python/src/bindings/_helpers/command_runtime/concurrency.rs rename to crates/sqlbuild-python-front/src/command_runtime/_helpers/concurrency.rs index 047a888def..41f7b25158 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/command_runtime/concurrency.rs +++ b/crates/sqlbuild-python-front/src/command_runtime/_helpers/concurrency.rs @@ -4,10 +4,9 @@ use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult}; use sqlbuild_config::effective::main::effective_concurrency::effective_concurrency; use sqlbuild_config::effective::models::{ConcurrencyLayers, EffectiveConcurrency}; -use crate::bindings::_helpers::compile_attachment::effective_config::build_effective_settings; -use crate::bindings::_helpers::contracts::spec_resolution::{ - resolve_target_config, resolve_target_name, -}; +use crate::compile_attachment::main::build_effective_settings::build_effective_settings; +use crate::contracts::main::resolve_target_config::resolve_target_config; +use crate::contracts::main::resolve_target_name::resolve_target_name; use sqlbuild_python_base::records::main::fields::field::field as native_field; const CONCURRENCY: &str = "concurrency"; diff --git a/crates/sqlbuild-python-front/src/command_runtime/_helpers/mod.rs b/crates/sqlbuild-python-front/src/command_runtime/_helpers/mod.rs new file mode 100644 index 0000000000..afd92b7347 --- /dev/null +++ b/crates/sqlbuild-python-front/src/command_runtime/_helpers/mod.rs @@ -0,0 +1 @@ +pub(crate) mod concurrency; diff --git a/crates/sqlbuild-python-front/src/command_runtime/main/mod.rs b/crates/sqlbuild-python-front/src/command_runtime/main/mod.rs new file mode 100644 index 0000000000..7482b588aa --- /dev/null +++ b/crates/sqlbuild-python-front/src/command_runtime/main/mod.rs @@ -0,0 +1,2 @@ +pub mod resolve_concurrency; +pub mod resolve_configured_concurrency; diff --git a/crates/sqlbuild-python-front/src/command_runtime/main/resolve_concurrency.rs b/crates/sqlbuild-python-front/src/command_runtime/main/resolve_concurrency.rs new file mode 100644 index 0000000000..0c69f9bdda --- /dev/null +++ b/crates/sqlbuild-python-front/src/command_runtime/main/resolve_concurrency.rs @@ -0,0 +1,17 @@ +//! The effective concurrency of a command on `selected_target`, and the layer that set it. + +use crate::command_runtime::_helpers::concurrency; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_config::effective::models::EffectiveConcurrency; + +/// The effective concurrency of a command on `selected_target`, and the layer that set it. +#[inline] +pub fn resolve_concurrency( + requested: &Bound<'_, PyAny>, + discovered: &Bound<'_, PyAny>, + selected_target: &Bound<'_, PyAny>, +) -> PyResult { + concurrency::resolve_concurrency(requested, discovered, selected_target) +} diff --git a/crates/sqlbuild-python-front/src/command_runtime/main/resolve_configured_concurrency.rs b/crates/sqlbuild-python-front/src/command_runtime/main/resolve_configured_concurrency.rs new file mode 100644 index 0000000000..5faa1fac25 --- /dev/null +++ b/crates/sqlbuild-python-front/src/command_runtime/main/resolve_configured_concurrency.rs @@ -0,0 +1,21 @@ +//! `resolve_concurrency` from the project and local configs themselves. + +use crate::command_runtime::_helpers::concurrency; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_config::effective::models::EffectiveConcurrency; + +/// `resolve_concurrency` from the project and local configs themselves. +#[inline] +pub fn resolve_configured_concurrency( + requested: &Bound<'_, PyAny>, + (project_config, local_config): (&Bound<'_, PyAny>, &Bound<'_, PyAny>), + selected_target: &Bound<'_, PyAny>, +) -> PyResult { + concurrency::resolve_configured_concurrency( + requested, + (project_config, local_config), + selected_target, + ) +} diff --git a/crates/sqlbuild-python-front/src/command_runtime/mod.rs b/crates/sqlbuild-python-front/src/command_runtime/mod.rs new file mode 100644 index 0000000000..0d218ebb66 --- /dev/null +++ b/crates/sqlbuild-python-front/src/command_runtime/mod.rs @@ -0,0 +1,4 @@ +//! Concurrency limits that commands read from configuration. + +pub(crate) mod _helpers; +pub mod main; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/effective_config.rs b/crates/sqlbuild-python-front/src/compile_attachment/_helpers/effective_config.rs similarity index 76% rename from crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/effective_config.rs rename to crates/sqlbuild-python-front/src/compile_attachment/_helpers/effective_config.rs index e16814e876..30d675df80 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/effective_config.rs +++ b/crates/sqlbuild-python-front/src/compile_attachment/_helpers/effective_config.rs @@ -6,15 +6,14 @@ use pyo3::types::{PyDict, PyString, PyTuple}; use sqlbuild_model_config::templates::models::TemplateOptions; -use crate::bindings::_helpers::contracts::effective_config::effective_config_settings; -use crate::bindings::_helpers::contracts::effective_config::effective_config_vars; -use crate::bindings::_helpers::contracts::effective_config::effective_connection_fields; -use crate::bindings::_helpers::contracts::spec_resolution::{ - resolve_target_config, resolve_target_name, -}; -use crate::bindings::_helpers::model_config::template_data::{ - expanded_effective_vars, expanded_template_data, run_id, -}; +use crate::contracts::main::effective_config_settings::effective_config_settings; +use crate::contracts::main::effective_config_vars::effective_config_vars; +use crate::contracts::main::effective_connection_fields::effective_connection_fields; +use crate::contracts::main::resolve_target_config::resolve_target_config; +use crate::contracts::main::resolve_target_name::resolve_target_name; +use crate::model_config::main::config::expanded_effective_vars::expanded_effective_vars; +use crate::model_config::main::config::expanded_template_data::expanded_template_data; +use crate::model_config::main::config::run_id::run_id; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::construct::new_record::new_record; @@ -234,3 +233,52 @@ pub(crate) fn project_vars<'py>( PyDict::new(discovered.py()).as_any(), ) } + +/// `build_effective_connection` as a function of `module`. +pub(crate) fn build_effective_connection_function<'py>( + module: &pyo3::Bound<'py, pyo3::types::PyModule>, +) -> pyo3::PyResult> { + pyo3::wrap_pyfunction!(build_effective_connection, module) +} + +/// `build_effective_connection_config` as a function of `module`. +pub(crate) fn build_effective_connection_config_function<'py>( + module: &pyo3::Bound<'py, pyo3::types::PyModule>, +) -> pyo3::PyResult> { + pyo3::wrap_pyfunction!(build_effective_connection_config, module) +} + +/// `build_effective_runtime_config` as a function of `module`. +pub(crate) fn build_effective_runtime_config_function<'py>( + module: &pyo3::Bound<'py, pyo3::types::PyModule>, +) -> pyo3::PyResult> { + pyo3::wrap_pyfunction!(build_effective_runtime_config, module) +} + +/// `build_effective_settings` as a function of `module`. +pub(crate) fn build_effective_settings_function<'py>( + module: &pyo3::Bound<'py, pyo3::types::PyModule>, +) -> pyo3::PyResult> { + pyo3::wrap_pyfunction!(build_effective_settings, module) +} + +/// `build_effective_settings_config` as a function of `module`. +pub(crate) fn build_effective_settings_config_function<'py>( + module: &pyo3::Bound<'py, pyo3::types::PyModule>, +) -> pyo3::PyResult> { + pyo3::wrap_pyfunction!(build_effective_settings_config, module) +} + +/// `build_effective_target_config` as a function of `module`. +pub(crate) fn build_effective_target_config_function<'py>( + module: &pyo3::Bound<'py, pyo3::types::PyModule>, +) -> pyo3::PyResult> { + pyo3::wrap_pyfunction!(build_effective_target_config, module) +} + +/// `build_effective_vars` as a function of `module`. +pub(crate) fn build_effective_vars_function<'py>( + module: &pyo3::Bound<'py, pyo3::types::PyModule>, +) -> pyo3::PyResult> { + pyo3::wrap_pyfunction!(build_effective_vars, module) +} diff --git a/crates/sqlbuild-python-front/src/compile_attachment/_helpers/mod.rs b/crates/sqlbuild-python-front/src/compile_attachment/_helpers/mod.rs new file mode 100644 index 0000000000..89e5014658 --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_attachment/_helpers/mod.rs @@ -0,0 +1 @@ +pub(crate) mod effective_config; diff --git a/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_connection.rs b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_connection.rs new file mode 100644 index 0000000000..1e07462d8f --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_connection.rs @@ -0,0 +1,22 @@ +//! Merge base project connection with the selected environment overrides. + +use crate::compile_attachment::_helpers::effective_config; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Merge base project connection with the selected environment overrides. +#[inline] +pub fn build_effective_connection<'py>( + project_config: &Bound<'py, PyAny>, + local_config: &Bound<'py, PyAny>, + target_config: &Bound<'py, PyAny>, + effective_vars: &Bound<'py, PyAny>, +) -> PyResult> { + effective_config::build_effective_connection( + project_config, + local_config, + target_config, + effective_vars, + ) +} diff --git a/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_connection_config.rs b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_connection_config.rs new file mode 100644 index 0000000000..6bde72927b --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_connection_config.rs @@ -0,0 +1,22 @@ +//! Build the effective project connection config without compiling resources. + +use crate::compile_attachment::_helpers::effective_config; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Build the effective project connection config without compiling resources. +#[inline] +pub fn build_effective_connection_config<'py>( + discovered_inputs: &Bound<'py, PyAny>, + selected_target: Option>, + cli_vars: Option>, + catalog: bool, +) -> PyResult> { + effective_config::build_effective_connection_config( + discovered_inputs, + selected_target, + cli_vars, + catalog, + ) +} diff --git a/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_connection_config_function.rs b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_connection_config_function.rs new file mode 100644 index 0000000000..74e098cc13 --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_connection_config_function.rs @@ -0,0 +1,11 @@ +//! `build_effective_connection_config` as a function of `module`. + +use crate::compile_attachment::_helpers::effective_config; + +/// `build_effective_connection_config` as a function of `module`. +#[inline] +pub fn build_effective_connection_config_function<'py>( + module: &pyo3::Bound<'py, pyo3::types::PyModule>, +) -> pyo3::PyResult> { + effective_config::build_effective_connection_config_function(module) +} diff --git a/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_connection_function.rs b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_connection_function.rs new file mode 100644 index 0000000000..1fd50f688d --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_connection_function.rs @@ -0,0 +1,11 @@ +//! `build_effective_connection` as a function of `module`. + +use crate::compile_attachment::_helpers::effective_config; + +/// `build_effective_connection` as a function of `module`. +#[inline] +pub fn build_effective_connection_function<'py>( + module: &pyo3::Bound<'py, pyo3::types::PyModule>, +) -> pyo3::PyResult> { + effective_config::build_effective_connection_function(module) +} diff --git a/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_runtime_config.rs b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_runtime_config.rs new file mode 100644 index 0000000000..c4eeb120e1 --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_runtime_config.rs @@ -0,0 +1,17 @@ +//! Build environment, vars and invocation id without compiling resources. + +use crate::compile_attachment::_helpers::effective_config; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// Build environment, vars and invocation id without compiling resources. +#[inline] +pub fn build_effective_runtime_config<'py>( + discovered_inputs: &Bound<'py, PyAny>, + selected_target: Option>, + cli_vars: Option>, +) -> PyResult> { + effective_config::build_effective_runtime_config(discovered_inputs, selected_target, cli_vars) +} diff --git a/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_runtime_config_function.rs b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_runtime_config_function.rs new file mode 100644 index 0000000000..2626522098 --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_runtime_config_function.rs @@ -0,0 +1,11 @@ +//! `build_effective_runtime_config` as a function of `module`. + +use crate::compile_attachment::_helpers::effective_config; + +/// `build_effective_runtime_config` as a function of `module`. +#[inline] +pub fn build_effective_runtime_config_function<'py>( + module: &pyo3::Bound<'py, pyo3::types::PyModule>, +) -> pyo3::PyResult> { + effective_config::build_effective_runtime_config_function(module) +} diff --git a/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_settings.rs b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_settings.rs new file mode 100644 index 0000000000..d5b3f04d24 --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_settings.rs @@ -0,0 +1,15 @@ +//! Merge project settings with local developer overrides. + +use crate::compile_attachment::_helpers::effective_config; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Merge project settings with local developer overrides. +#[inline] +pub fn build_effective_settings<'py>( + project_config: &Bound<'py, PyAny>, + local_config: &Bound<'py, PyAny>, +) -> PyResult> { + effective_config::build_effective_settings(project_config, local_config) +} diff --git a/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_settings_config.rs b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_settings_config.rs new file mode 100644 index 0000000000..7212e9a1bc --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_settings_config.rs @@ -0,0 +1,14 @@ +//! Build effective settings without compiling resources. + +use crate::compile_attachment::_helpers::effective_config; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Build effective settings without compiling resources. +#[inline] +pub fn build_effective_settings_config<'py>( + discovered_inputs: &Bound<'py, PyAny>, +) -> PyResult> { + effective_config::build_effective_settings_config(discovered_inputs) +} diff --git a/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_settings_config_function.rs b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_settings_config_function.rs new file mode 100644 index 0000000000..2bc134c68c --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_settings_config_function.rs @@ -0,0 +1,11 @@ +//! `build_effective_settings_config` as a function of `module`. + +use crate::compile_attachment::_helpers::effective_config; + +/// `build_effective_settings_config` as a function of `module`. +#[inline] +pub fn build_effective_settings_config_function<'py>( + module: &pyo3::Bound<'py, pyo3::types::PyModule>, +) -> pyo3::PyResult> { + effective_config::build_effective_settings_config_function(module) +} diff --git a/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_settings_function.rs b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_settings_function.rs new file mode 100644 index 0000000000..4031736371 --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_settings_function.rs @@ -0,0 +1,11 @@ +//! `build_effective_settings` as a function of `module`. + +use crate::compile_attachment::_helpers::effective_config; + +/// `build_effective_settings` as a function of `module`. +#[inline] +pub fn build_effective_settings_function<'py>( + module: &pyo3::Bound<'py, pyo3::types::PyModule>, +) -> pyo3::PyResult> { + effective_config::build_effective_settings_function(module) +} diff --git a/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_target_config.rs b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_target_config.rs new file mode 100644 index 0000000000..e7f58c2b4e --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_target_config.rs @@ -0,0 +1,15 @@ +//! Build effective target config without compiling resources. + +use crate::compile_attachment::_helpers::effective_config; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Build effective target config without compiling resources. +#[inline] +pub fn build_effective_target_config<'py>( + discovered_inputs: &Bound<'py, PyAny>, + selected_target: Option>, +) -> PyResult> { + effective_config::build_effective_target_config(discovered_inputs, selected_target) +} diff --git a/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_target_config_function.rs b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_target_config_function.rs new file mode 100644 index 0000000000..c15c82fa8c --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_target_config_function.rs @@ -0,0 +1,11 @@ +//! `build_effective_target_config` as a function of `module`. + +use crate::compile_attachment::_helpers::effective_config; + +/// `build_effective_target_config` as a function of `module`. +#[inline] +pub fn build_effective_target_config_function<'py>( + module: &pyo3::Bound<'py, pyo3::types::PyModule>, +) -> pyo3::PyResult> { + effective_config::build_effective_target_config_function(module) +} diff --git a/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_vars.rs b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_vars.rs new file mode 100644 index 0000000000..5225b0caad --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_vars.rs @@ -0,0 +1,17 @@ +//! Merge effective vars using the locked precedence order. + +use crate::compile_attachment::_helpers::effective_config; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Merge effective vars using the locked precedence order. +#[inline] +pub fn build_effective_vars<'py>( + project_config: &Bound<'py, PyAny>, + local_config: &Bound<'py, PyAny>, + target_config: &Bound<'py, PyAny>, + cli_vars: &Bound<'py, PyAny>, +) -> PyResult> { + effective_config::build_effective_vars(project_config, local_config, target_config, cli_vars) +} diff --git a/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_vars_function.rs b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_vars_function.rs new file mode 100644 index 0000000000..fa6d8a7d07 --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_vars_function.rs @@ -0,0 +1,11 @@ +//! `build_effective_vars` as a function of `module`. + +use crate::compile_attachment::_helpers::effective_config; + +/// `build_effective_vars` as a function of `module`. +#[inline] +pub fn build_effective_vars_function<'py>( + module: &pyo3::Bound<'py, pyo3::types::PyModule>, +) -> pyo3::PyResult> { + effective_config::build_effective_vars_function(module) +} diff --git a/crates/sqlbuild-python-front/src/compile_attachment/main/mod.rs b/crates/sqlbuild-python-front/src/compile_attachment/main/mod.rs new file mode 100644 index 0000000000..0e39ae7323 --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_attachment/main/mod.rs @@ -0,0 +1,16 @@ +pub mod build_effective_connection; +pub mod build_effective_connection_config; +pub mod build_effective_connection_config_function; +pub mod build_effective_connection_function; +pub mod build_effective_runtime_config; +pub mod build_effective_runtime_config_function; +pub mod build_effective_settings; +pub mod build_effective_settings_config; +pub mod build_effective_settings_config_function; +pub mod build_effective_settings_function; +pub mod build_effective_target_config; +pub mod build_effective_target_config_function; +pub mod build_effective_vars; +pub mod build_effective_vars_function; +pub mod project_vars; +pub mod target_selection; diff --git a/crates/sqlbuild-python-front/src/compile_attachment/main/project_vars.rs b/crates/sqlbuild-python-front/src/compile_attachment/main/project_vars.rs new file mode 100644 index 0000000000..3215cf81e9 --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_attachment/main/project_vars.rs @@ -0,0 +1,15 @@ +//! `build_effective_vars` for a discovered project and target, without CLI vars. + +use crate::compile_attachment::_helpers::effective_config; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// `build_effective_vars` for a discovered project and target, without CLI vars. +#[inline] +pub fn project_vars<'py>( + discovered: &Bound<'py, PyAny>, + target_config: &Bound<'py, PyAny>, +) -> PyResult> { + effective_config::project_vars(discovered, target_config) +} diff --git a/crates/sqlbuild-python-front/src/compile_attachment/main/target_selection.rs b/crates/sqlbuild-python-front/src/compile_attachment/main/target_selection.rs new file mode 100644 index 0000000000..db99738dd0 --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_attachment/main/target_selection.rs @@ -0,0 +1,15 @@ +//! The selected target name of a discovered project and its effective config, if any. + +use crate::compile_attachment::_helpers::effective_config; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// The selected target name of a discovered project and its effective config, if any. +#[inline] +pub fn target_selection<'py>( + discovered: &Bound<'py, PyAny>, + selected: Option>, +) -> PyResult<(Bound<'py, PyAny>, Bound<'py, PyAny>)> { + effective_config::target_selection(discovered, selected) +} diff --git a/crates/sqlbuild-python-front/src/compile_attachment/mod.rs b/crates/sqlbuild-python-front/src/compile_attachment/mod.rs new file mode 100644 index 0000000000..a775d94fbe --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_attachment/mod.rs @@ -0,0 +1,4 @@ +//! The effective model configuration a compile attaches to each node. + +pub(crate) mod _helpers; +pub mod main; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/config_validation.rs b/crates/sqlbuild-python-front/src/compile_driver/_helpers/config_validation.rs similarity index 93% rename from crates/sqlbuild-python/src/bindings/_helpers/compile_driver/config_validation.rs rename to crates/sqlbuild-python-front/src/compile_driver/_helpers/config_validation.rs index ed882ddeec..3cc8fdb394 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/config_validation.rs +++ b/crates/sqlbuild-python-front/src/compile_driver/_helpers/config_validation.rs @@ -1,5 +1,6 @@ //! Validate loaded project and local configuration before discovery reads project files. +use crate::compile_driver::models::ProjectConfiguration; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult, Python}; use pyo3::types::{PyBool, PyDict, PyString, PyTuple}; use sqlbuild_config::project::main::unsupported_target_warehouse::unsupported_target_warehouse; @@ -8,12 +9,10 @@ use sqlbuild_host::entries::models::AdapterHost; use sqlbuild_python_base::boundary::main::call_with::call_with; -use crate::bindings::_helpers::contracts::spec_resolution::{ - resolve_effective_adapter_name, resolve_target_config, -}; -use crate::bindings::_helpers::discovery::project_config::{ - resolve_config_file_path, validate_local_sql_analysis, -}; +use crate::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use crate::contracts::main::resolve_target_config::resolve_target_config; +use crate::discovery::main::project::resolve_config_file_path::resolve_config_file_path; +use crate::discovery::main::project::validate_local_sql_analysis::validate_local_sql_analysis; use pyo3::IntoPyObjectExt; use sqlbuild_core::constants::PROJECT_CONFIG_FILENAME; use sqlbuild_python_base::native_host::main::host_entry::host_entry; @@ -25,13 +24,6 @@ const SQL_ANALYSIS_KEY: &str = "sql_analysis"; /// `WarehouseGroup` members in declaration order. const WAREHOUSE_GROUPS: [&str; 2] = ["build", "query"]; -/// The loaded configuration of one project. -pub(crate) struct ProjectConfiguration<'a, 'py> { - pub(crate) project_dir: &'a Bound<'py, PyAny>, - pub(crate) project_config: &'a Bound<'py, PyAny>, - pub(crate) local_config: &'a Bound<'py, PyAny>, -} - fn project_config_error(py: Python<'_>, message: &str, help: Option<&str>) -> PyErr { let raised = (|| -> PyResult> { let keywords: Bound<'_, PyDict> = PyDict::new(py); diff --git a/crates/sqlbuild-python-front/src/compile_driver/_helpers/mod.rs b/crates/sqlbuild-python-front/src/compile_driver/_helpers/mod.rs new file mode 100644 index 0000000000..d59a71cbdd --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_driver/_helpers/mod.rs @@ -0,0 +1 @@ +pub(crate) mod config_validation; diff --git a/crates/sqlbuild-python-front/src/compile_driver/main/mod.rs b/crates/sqlbuild-python-front/src/compile_driver/main/mod.rs new file mode 100644 index 0000000000..908dcdd46b --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_driver/main/mod.rs @@ -0,0 +1,3 @@ +pub mod reject_invalid_connection_configuration; +pub mod reject_invalid_project_configuration; +pub mod session_warehouse_support; diff --git a/crates/sqlbuild-python-front/src/compile_driver/main/reject_invalid_connection_configuration.rs b/crates/sqlbuild-python-front/src/compile_driver/main/reject_invalid_connection_configuration.rs new file mode 100644 index 0000000000..4dab78eccb --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_driver/main/reject_invalid_connection_configuration.rs @@ -0,0 +1,13 @@ +//! Validate the target warehouses and target connections a warehouse connection depends on. + +use crate::compile_driver::_helpers::config_validation; +use crate::compile_driver::models::ProjectConfiguration; +use pyo3::prelude::PyResult; + +/// Validate the target warehouses and target connections a warehouse connection depends on. +#[inline] +pub fn reject_invalid_connection_configuration( + config: &ProjectConfiguration<'_, '_>, +) -> PyResult<()> { + config_validation::reject_invalid_connection_configuration(config) +} diff --git a/crates/sqlbuild-python-front/src/compile_driver/main/reject_invalid_project_configuration.rs b/crates/sqlbuild-python-front/src/compile_driver/main/reject_invalid_project_configuration.rs new file mode 100644 index 0000000000..f7afdf5744 --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_driver/main/reject_invalid_project_configuration.rs @@ -0,0 +1,11 @@ +//! Validate the SQL analysis policy, target warehouses and target connections, in that order. + +use crate::compile_driver::_helpers::config_validation; +use crate::compile_driver::models::ProjectConfiguration; +use pyo3::prelude::PyResult; + +/// Validate the SQL analysis policy, target warehouses and target connections, in that order. +#[inline] +pub fn reject_invalid_project_configuration(config: &ProjectConfiguration<'_, '_>) -> PyResult<()> { + config_validation::reject_invalid_project_configuration(config) +} diff --git a/crates/sqlbuild-python-front/src/compile_driver/main/session_warehouse_support.rs b/crates/sqlbuild-python-front/src/compile_driver/main/session_warehouse_support.rs new file mode 100644 index 0000000000..72ca9d4c1e --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_driver/main/session_warehouse_support.rs @@ -0,0 +1,17 @@ +//! Whether the adapter can switch warehouses per session, as the adapter host answers. + +use crate::compile_driver::_helpers::config_validation; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// Whether the adapter can switch warehouses per session, as the adapter host answers. +#[inline] +pub fn session_warehouse_support( + py: Python<'_>, + adapter_name: &Bound<'_, PyAny>, + project_dir: &Bound<'_, PyAny>, +) -> PyResult { + config_validation::session_warehouse_support(py, adapter_name, project_dir) +} diff --git a/crates/sqlbuild-python-front/src/compile_driver/mod.rs b/crates/sqlbuild-python-front/src/compile_driver/mod.rs new file mode 100644 index 0000000000..3892f4cd62 --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_driver/mod.rs @@ -0,0 +1,5 @@ +//! Validation of the project configuration before a compile starts. + +pub(crate) mod _helpers; +pub mod main; +pub mod models; diff --git a/crates/sqlbuild-python-front/src/compile_driver/models.rs b/crates/sqlbuild-python-front/src/compile_driver/models.rs new file mode 100644 index 0000000000..a119c3b8ac --- /dev/null +++ b/crates/sqlbuild-python-front/src/compile_driver/models.rs @@ -0,0 +1,12 @@ +//! Public records of compile driver. + +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; + +/// The loaded configuration of one project. +#[derive(Debug)] +pub struct ProjectConfiguration<'a, 'py> { + pub project_dir: &'a Bound<'py, PyAny>, + pub project_config: &'a Bound<'py, PyAny>, + pub local_config: &'a Bound<'py, PyAny>, +} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/contracts/effective_config.rs b/crates/sqlbuild-python-front/src/contracts/_helpers/effective_config.rs similarity index 99% rename from crates/sqlbuild-python/src/bindings/_helpers/contracts/effective_config.rs rename to crates/sqlbuild-python-front/src/contracts/_helpers/effective_config.rs index d8b03c59bc..4539fa9c21 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/contracts/effective_config.rs +++ b/crates/sqlbuild-python-front/src/contracts/_helpers/effective_config.rs @@ -64,7 +64,7 @@ type Pairs<'py> = Entries, Value<'py>>; /// `(group, name, value)` of each merged `TargetConfig` field. type FieldRow<'py> = (Option<&'static str>, &'static str, Value<'py>); /// A result, else the precedence failure message. -type Outcome<'py, T> = (Option, Option>); +pub(crate) type Outcome<'py, T> = (Option, Option>); fn key<'py>(value: &Bound<'py, PyAny>) -> PyResult> { let handle: Bound<'py, PyString> = value.downcast::()?.clone(); diff --git a/crates/sqlbuild-python-front/src/contracts/_helpers/mod.rs b/crates/sqlbuild-python-front/src/contracts/_helpers/mod.rs new file mode 100644 index 0000000000..4027e9787a --- /dev/null +++ b/crates/sqlbuild-python-front/src/contracts/_helpers/mod.rs @@ -0,0 +1,2 @@ +pub(crate) mod effective_config; +pub(crate) mod spec_resolution; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/contracts/spec_resolution.rs b/crates/sqlbuild-python-front/src/contracts/_helpers/spec_resolution.rs similarity index 98% rename from crates/sqlbuild-python/src/bindings/_helpers/contracts/spec_resolution.rs rename to crates/sqlbuild-python-front/src/contracts/_helpers/spec_resolution.rs index 7d7525be19..6fd358ee29 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/contracts/spec_resolution.rs +++ b/crates/sqlbuild-python-front/src/contracts/_helpers/spec_resolution.rs @@ -12,9 +12,8 @@ use pyo3::{pyfunction, wrap_pyfunction}; use sqlbuild_model_config::name_patterns::main::compile_name_pattern::compile_name_pattern; use sqlbuild_model_config::name_patterns::models::NamePattern; -use crate::bindings::_helpers::contracts::effective_config::{ - effective_config_target_fields, effective_config_target_name, -}; +use crate::contracts::_helpers::effective_config::effective_config_target_fields; +use crate::contracts::_helpers::effective_config::effective_config_target_name; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; diff --git a/crates/sqlbuild-python-front/src/contracts/main/effective_config_settings.rs b/crates/sqlbuild-python-front/src/contracts/main/effective_config_settings.rs new file mode 100644 index 0000000000..bfe3c29867 --- /dev/null +++ b/crates/sqlbuild-python-front/src/contracts/main/effective_config_settings.rs @@ -0,0 +1,20 @@ +//! `build_effective_settings`: setting values by field name, local overrides applied. + +use crate::contracts::_helpers::effective_config; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::types::PyDict; +use pyo3::types::PyString; + +/// `build_effective_settings`: setting values by field name, local overrides applied. +#[inline] +pub fn effective_config_settings<'py>( + py: Python<'py>, + settings: (Bound<'py, PyAny>, Bound<'py, PyAny>), + overrides: &Bound<'py, PyAny>, + names: Vec>, +) -> PyResult> { + effective_config::effective_config_settings(py, settings, overrides, names) +} diff --git a/crates/sqlbuild-python-front/src/contracts/main/effective_config_vars.rs b/crates/sqlbuild-python-front/src/contracts/main/effective_config_vars.rs new file mode 100644 index 0000000000..f1cad2a5b6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/contracts/main/effective_config_vars.rs @@ -0,0 +1,19 @@ +//! `build_effective_vars` before template expansion. + +use crate::contracts::_helpers::effective_config; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::types::PyDict; + +/// `build_effective_vars` before template expansion. +#[inline] +pub fn effective_config_vars<'py>( + py: Python<'py>, + configs: (Bound<'py, PyAny>, Bound<'py, PyAny>), + target_config: &Bound<'py, PyAny>, + cli_vars: &Bound<'py, PyAny>, +) -> PyResult> { + effective_config::effective_config_vars(py, configs, target_config, cli_vars) +} diff --git a/crates/sqlbuild-python-front/src/contracts/main/effective_connection_fields.rs b/crates/sqlbuild-python-front/src/contracts/main/effective_connection_fields.rs new file mode 100644 index 0000000000..24e86bbc01 --- /dev/null +++ b/crates/sqlbuild-python-front/src/contracts/main/effective_connection_fields.rs @@ -0,0 +1,25 @@ +//! Catalog selection uses the same named-layer resolver, with no writer layers. + +use crate::contracts::_helpers::effective_config; +use crate::contracts::_helpers::effective_config::Outcome; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::types::PyDict; + +/// Catalog selection uses the same named-layer resolver, with no writer layers. +#[inline] +pub fn effective_connection_fields<'py>( + py: Python<'py>, + (project_config, local_config): (&Bound<'py, PyAny>, &Bound<'py, PyAny>), + target_config: &Bound<'py, PyAny>, + catalog: bool, +) -> PyResult>> { + effective_config::effective_connection_fields( + py, + (project_config, local_config), + target_config, + catalog, + ) +} diff --git a/crates/sqlbuild-python-front/src/contracts/main/loader_destination_parts.rs b/crates/sqlbuild-python-front/src/contracts/main/loader_destination_parts.rs new file mode 100644 index 0000000000..77dd1720fb --- /dev/null +++ b/crates/sqlbuild-python-front/src/contracts/main/loader_destination_parts.rs @@ -0,0 +1,18 @@ +//! Parse a one-, two-, or three-part loader destination. + +use crate::contracts::_helpers::spec_resolution; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// Parse a one-, two-, or three-part loader destination. +#[inline] +pub fn loader_destination_parts<'py>( + py: Python<'py>, + destination: &str, + default_database: Option>, + default_schema: Option>, +) -> PyResult> { + spec_resolution::loader_destination_parts(py, destination, default_database, default_schema) +} diff --git a/crates/sqlbuild-python-front/src/contracts/main/loader_parts.rs b/crates/sqlbuild-python-front/src/contracts/main/loader_parts.rs new file mode 100644 index 0000000000..b710005f65 --- /dev/null +++ b/crates/sqlbuild-python-front/src/contracts/main/loader_parts.rs @@ -0,0 +1,17 @@ +//! Loader parts. + +use crate::contracts::_helpers::spec_resolution; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// Loader parts. +#[inline] +pub fn loader_parts<'py>( + py: Python<'py>, + destination: &str, + (default_database, default_schema): (Option>, Option>), +) -> PyResult> { + spec_resolution::loader_parts(py, destination, (default_database, default_schema)) +} diff --git a/crates/sqlbuild-python-front/src/contracts/main/matching_dynamic_families.rs b/crates/sqlbuild-python-front/src/contracts/main/matching_dynamic_families.rs new file mode 100644 index 0000000000..22ee8aafaf --- /dev/null +++ b/crates/sqlbuild-python-front/src/contracts/main/matching_dynamic_families.rs @@ -0,0 +1,16 @@ +//! Return declared dynamic families accepting a physical column name. + +use crate::contracts::_helpers::spec_resolution; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// Return declared dynamic families accepting a physical column name. +#[inline] +pub fn matching_dynamic_families<'py>( + families: &Bound<'py, PyAny>, + column_name: &str, +) -> PyResult> { + spec_resolution::matching_dynamic_families(families, column_name) +} diff --git a/crates/sqlbuild-python-front/src/contracts/main/mod.rs b/crates/sqlbuild-python-front/src/contracts/main/mod.rs new file mode 100644 index 0000000000..d4e642d29a --- /dev/null +++ b/crates/sqlbuild-python-front/src/contracts/main/mod.rs @@ -0,0 +1,13 @@ +pub mod effective_config_settings; +pub mod effective_config_vars; +pub mod effective_connection_fields; +pub mod loader_destination_parts; +pub mod loader_parts; +pub mod matching_dynamic_families; +pub mod register_effective_config; +pub mod register_spec_resolution; +pub mod resolve_effective_adapter_name; +pub mod resolve_effective_collection_rendering; +pub mod resolve_effective_scenario_config; +pub mod resolve_target_config; +pub mod resolve_target_name; diff --git a/crates/sqlbuild-python-front/src/contracts/main/register_effective_config.rs b/crates/sqlbuild-python-front/src/contracts/main/register_effective_config.rs new file mode 100644 index 0000000000..489cc16675 --- /dev/null +++ b/crates/sqlbuild-python-front/src/contracts/main/register_effective_config.rs @@ -0,0 +1,12 @@ +//! Register the effective config functions and classes. + +use crate::contracts::_helpers::effective_config; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the effective config functions and classes. +#[inline] +pub fn register_effective_config(module: &Bound<'_, PyModule>) -> PyResult<()> { + effective_config::register(module) +} diff --git a/crates/sqlbuild-python-front/src/contracts/main/register_spec_resolution.rs b/crates/sqlbuild-python-front/src/contracts/main/register_spec_resolution.rs new file mode 100644 index 0000000000..f866a7667f --- /dev/null +++ b/crates/sqlbuild-python-front/src/contracts/main/register_spec_resolution.rs @@ -0,0 +1,12 @@ +//! Register the spec resolution functions and classes. + +use crate::contracts::_helpers::spec_resolution; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the spec resolution functions and classes. +#[inline] +pub fn register_spec_resolution(module: &Bound<'_, PyModule>) -> PyResult<()> { + spec_resolution::register(module) +} diff --git a/crates/sqlbuild-python-front/src/contracts/main/resolve_effective_adapter_name.rs b/crates/sqlbuild-python-front/src/contracts/main/resolve_effective_adapter_name.rs new file mode 100644 index 0000000000..5da624dbdf --- /dev/null +++ b/crates/sqlbuild-python-front/src/contracts/main/resolve_effective_adapter_name.rs @@ -0,0 +1,15 @@ +//! Resolve the effective adapter name, allowing local override. + +use crate::contracts::_helpers::spec_resolution; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Resolve the effective adapter name, allowing local override. +#[inline] +pub fn resolve_effective_adapter_name<'py>( + project_config: &Bound<'py, PyAny>, + local_config: &Bound<'py, PyAny>, +) -> PyResult> { + spec_resolution::resolve_effective_adapter_name(project_config, local_config) +} diff --git a/crates/sqlbuild-python-front/src/contracts/main/resolve_effective_collection_rendering.rs b/crates/sqlbuild-python-front/src/contracts/main/resolve_effective_collection_rendering.rs new file mode 100644 index 0000000000..9c29dfa1aa --- /dev/null +++ b/crates/sqlbuild-python-front/src/contracts/main/resolve_effective_collection_rendering.rs @@ -0,0 +1,15 @@ +//! Resolve declaration rendering over project configuration. + +use crate::contracts::_helpers::spec_resolution; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Resolve declaration rendering over project configuration. +#[inline] +pub fn resolve_effective_collection_rendering<'py>( + project_config: &Bound<'py, PyAny>, + declaration_override: &Bound<'py, PyAny>, +) -> PyResult> { + spec_resolution::resolve_effective_collection_rendering(project_config, declaration_override) +} diff --git a/crates/sqlbuild-python-front/src/contracts/main/resolve_effective_scenario_config.rs b/crates/sqlbuild-python-front/src/contracts/main/resolve_effective_scenario_config.rs new file mode 100644 index 0000000000..edce6d7b7b --- /dev/null +++ b/crates/sqlbuild-python-front/src/contracts/main/resolve_effective_scenario_config.rs @@ -0,0 +1,15 @@ +//! Resolve scenario config, allowing local overrides to replace project rules. + +use crate::contracts::_helpers::spec_resolution; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Resolve scenario config, allowing local overrides to replace project rules. +#[inline] +pub fn resolve_effective_scenario_config<'py>( + project_config: &Bound<'py, PyAny>, + local_config: &Bound<'py, PyAny>, +) -> PyResult> { + spec_resolution::resolve_effective_scenario_config(project_config, local_config) +} diff --git a/crates/sqlbuild-python-front/src/contracts/main/resolve_target_config.rs b/crates/sqlbuild-python-front/src/contracts/main/resolve_target_config.rs new file mode 100644 index 0000000000..1b48b4863a --- /dev/null +++ b/crates/sqlbuild-python-front/src/contracts/main/resolve_target_config.rs @@ -0,0 +1,18 @@ +//! Merge project target config with local developer overrides. + +use crate::contracts::_helpers::spec_resolution; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// Merge project target config with local developer overrides. +#[inline] +pub fn resolve_target_config<'py>( + py: Python<'py>, + project_config: &Bound<'py, PyAny>, + local_config: &Bound<'py, PyAny>, + target_name: &Bound<'py, PyAny>, +) -> PyResult> { + spec_resolution::resolve_target_config(py, project_config, local_config, target_name) +} diff --git a/crates/sqlbuild-python-front/src/contracts/main/resolve_target_name.rs b/crates/sqlbuild-python-front/src/contracts/main/resolve_target_name.rs new file mode 100644 index 0000000000..ea408772b6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/contracts/main/resolve_target_name.rs @@ -0,0 +1,19 @@ +//! Resolve the effective target name. + +use crate::contracts::_helpers::spec_resolution; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::types::PyString; + +/// Resolve the effective target name. +#[inline] +pub fn resolve_target_name<'py>( + py: Python<'py>, + project_config: &Bound<'py, PyAny>, + local_config: &Bound<'py, PyAny>, + selected_target: &Bound<'py, PyAny>, +) -> PyResult>> { + spec_resolution::resolve_target_name(py, project_config, local_config, selected_target) +} diff --git a/crates/sqlbuild-python-front/src/contracts/mod.rs b/crates/sqlbuild-python-front/src/contracts/mod.rs new file mode 100644 index 0000000000..28ac569e0d --- /dev/null +++ b/crates/sqlbuild-python-front/src/contracts/mod.rs @@ -0,0 +1,4 @@ +//! Effective contract configuration and contract spec resolution. + +pub(crate) mod _helpers; +pub mod main; diff --git a/crates/sqlbuild-python-front/src/cursor/_helpers/conversion.rs b/crates/sqlbuild-python-front/src/cursor/_helpers/conversion.rs new file mode 100644 index 0000000000..3e3dd1995e --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/_helpers/conversion.rs @@ -0,0 +1,11 @@ +//! One call's cursor values read from and built as the native cursor value records. + +use sqlbuild_python_base::native_host::main::host_error::host_error; + +use pyo3::prelude::{PyErr, Python}; +use sqlbuild_host::entries::models::FacadeHost; + +/// `CursorAlgebraError(message)`. +pub(crate) fn algebra_error(py: Python<'_>, message: &str) -> PyErr { + host_error(py, FacadeHost::CursorAlgebraError, message) +} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/cursor/durations.rs b/crates/sqlbuild-python-front/src/cursor/_helpers/durations.rs similarity index 93% rename from crates/sqlbuild-python/src/bindings/_helpers/cursor/durations.rs rename to crates/sqlbuild-python-front/src/cursor/_helpers/durations.rs index a3d345c172..93150ef70a 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/cursor/durations.rs +++ b/crates/sqlbuild-python-front/src/cursor/_helpers/durations.rs @@ -8,10 +8,11 @@ use sqlbuild_cursor::algebra::main::parse_duration::parse_duration; use sqlbuild_cursor::algebra::main::shift_by_duration::shift_by_duration; use sqlbuild_cursor::algebra::models::{DurationDigits, DurationSpan, Moment}; -use crate::bindings::_helpers::cursor::conversion::CursorSession; -use crate::bindings::_helpers::cursor::values::{ - DATETIME_MODULE, civil_date, local_date_time, replaced, -}; +use crate::cursor::_helpers::values::civil_date; +use crate::cursor::_helpers::values::local_date_time; +use crate::cursor::_helpers::values::replaced; +use crate::cursor::constants::DATETIME_MODULE; +use crate::cursor::models::CursorSession; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::records::main::fields::field::field as native_field; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/cursor/intervals.rs b/crates/sqlbuild-python-front/src/cursor/_helpers/intervals.rs similarity index 98% rename from crates/sqlbuild-python/src/bindings/_helpers/cursor/intervals.rs rename to crates/sqlbuild-python-front/src/cursor/_helpers/intervals.rs index 01f2d9d977..a63c908d17 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/cursor/intervals.rs +++ b/crates/sqlbuild-python-front/src/cursor/_helpers/intervals.rs @@ -18,8 +18,8 @@ use sqlbuild_cursor::algebra::main::validate_interval::validate_interval; use sqlbuild_cursor::algebra::models::{Interval, Scalar}; use sqlbuild_host::entries::models::ExecutorHost; -use crate::bindings::_helpers::cursor::conversion::CursorSession; -use crate::bindings::_helpers::cursor::scalars::as_scalar; +use crate::cursor::_helpers::scalars::as_scalar; +use crate::cursor::models::CursorSession; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::fields::field::field as native_field; diff --git a/crates/sqlbuild-python-front/src/cursor/_helpers/mod.rs b/crates/sqlbuild-python-front/src/cursor/_helpers/mod.rs new file mode 100644 index 0000000000..fffa7c18fe --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/_helpers/mod.rs @@ -0,0 +1,6 @@ +pub(crate) mod conversion; +pub(crate) mod durations; +pub(crate) mod intervals; +pub(crate) mod overrides; +pub(crate) mod scalars; +pub(crate) mod values; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/cursor/overrides.rs b/crates/sqlbuild-python-front/src/cursor/_helpers/overrides.rs similarity index 95% rename from crates/sqlbuild-python/src/bindings/_helpers/cursor/overrides.rs rename to crates/sqlbuild-python-front/src/cursor/_helpers/overrides.rs index 635960276c..05e7930c02 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/cursor/overrides.rs +++ b/crates/sqlbuild-python-front/src/cursor/_helpers/overrides.rs @@ -5,8 +5,8 @@ use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; use pyo3::types::{PyInt, PyString, PyStringMethods}; use sqlbuild_cursor::algebra::main::parse_integer_text::parse_integer_text; -use crate::bindings::_helpers::cursor::conversion::algebra_error; -use crate::bindings::_helpers::cursor::values::DATETIME_MODULE; +use crate::cursor::_helpers::conversion::algebra_error; +use crate::cursor::constants::DATETIME_MODULE; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/cursor/scalars.rs b/crates/sqlbuild-python-front/src/cursor/_helpers/scalars.rs similarity index 99% rename from crates/sqlbuild-python/src/bindings/_helpers/cursor/scalars.rs rename to crates/sqlbuild-python-front/src/cursor/_helpers/scalars.rs index 7efb469c6c..a7cdb7c2f3 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/cursor/scalars.rs +++ b/crates/sqlbuild-python-front/src/cursor/_helpers/scalars.rs @@ -25,8 +25,9 @@ use sqlbuild_cursor::algebra::main::render::render; use sqlbuild_cursor::algebra::models::{Extreme, Grain, Scalar, SortKey}; use sqlbuild_host::entries::models::ExecutorHost; -use crate::bindings::_helpers::cursor::conversion::{CursorSession, algebra_error}; -use crate::bindings::_helpers::cursor::values::DATETIME_MODULE; +use crate::cursor::_helpers::conversion::algebra_error; +use crate::cursor::constants::DATETIME_MODULE; +use crate::cursor::models::CursorSession; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/cursor/values.rs b/crates/sqlbuild-python-front/src/cursor/_helpers/values.rs similarity index 98% rename from crates/sqlbuild-python/src/bindings/_helpers/cursor/values.rs rename to crates/sqlbuild-python-front/src/cursor/_helpers/values.rs index 30e3e7bd88..de30f9f798 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/cursor/values.rs +++ b/crates/sqlbuild-python-front/src/cursor/_helpers/values.rs @@ -1,5 +1,6 @@ //! Python `date`, `datetime` and `timedelta` objects read into and built from cursor values. +use crate::cursor::constants::DATETIME_MODULE; use pyo3::IntoPyObject; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; use sqlbuild_cursor::algebra::models::{CivilDate, LocalDateTime}; @@ -8,7 +9,6 @@ use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::records::main::fields::field::field as native_field; -pub(crate) const DATETIME_MODULE: &str = "datetime"; const MICROS_PER_SECOND: i64 = 1_000_000; const SECONDS_PER_DAY: i64 = 86_400; diff --git a/crates/sqlbuild-python-front/src/cursor/constants.rs b/crates/sqlbuild-python-front/src/cursor/constants.rs new file mode 100644 index 0000000000..064954ef2f --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/constants.rs @@ -0,0 +1,15 @@ +//! Public constants of cursor. + +use sqlbuild_cursor::algebra::models::Grain; + +/// Cursor grain names, finest first. +pub const GRAIN_NAMES: [(&str, Grain); 6] = [ + ("second", Grain::Second), + ("minute", Grain::Minute), + ("hour", Grain::Hour), + ("day", Grain::Day), + ("month", Grain::Month), + ("year", Grain::Year), +]; + +pub const DATETIME_MODULE: &str = "datetime"; diff --git a/crates/sqlbuild-python-front/src/cursor/main/conversion/algebra_error.rs b/crates/sqlbuild-python-front/src/cursor/main/conversion/algebra_error.rs new file mode 100644 index 0000000000..67da83f9c4 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/conversion/algebra_error.rs @@ -0,0 +1,11 @@ +//! `CursorAlgebraError(message)`. + +use crate::cursor::_helpers::conversion; +use pyo3::prelude::PyErr; +use pyo3::prelude::Python; + +/// `CursorAlgebraError(message)`. +#[inline] +pub fn algebra_error(py: Python<'_>, message: &str) -> PyErr { + conversion::algebra_error(py, message) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/conversion/mod.rs b/crates/sqlbuild-python-front/src/cursor/main/conversion/mod.rs new file mode 100644 index 0000000000..8327b9ff89 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/conversion/mod.rs @@ -0,0 +1 @@ +pub mod algebra_error; diff --git a/crates/sqlbuild-python-front/src/cursor/main/durations/mod.rs b/crates/sqlbuild-python-front/src/cursor/main/durations/mod.rs new file mode 100644 index 0000000000..ab6c53c122 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/durations/mod.rs @@ -0,0 +1,4 @@ +pub mod parse_cursor_duration; +pub mod register_durations; +pub mod shift_by_cursor_duration; +pub mod shifted_moment; diff --git a/crates/sqlbuild-python-front/src/cursor/main/durations/parse_cursor_duration.rs b/crates/sqlbuild-python-front/src/cursor/main/durations/parse_cursor_duration.rs new file mode 100644 index 0000000000..932140f66b --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/durations/parse_cursor_duration.rs @@ -0,0 +1,16 @@ +//! `(years, months, days, hours, minutes, seconds)` of a duration like `1y6mo` or `30d`. + +use crate::cursor::_helpers::durations; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::types::PyTuple; + +/// `(years, months, days, hours, minutes, seconds)` of a duration like `1y6mo` or `30d`. +#[inline] +pub fn parse_cursor_duration<'py>( + py: Python<'py>, + value: &str, +) -> PyResult>> { + durations::parse_cursor_duration(py, value) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/durations/register_durations.rs b/crates/sqlbuild-python-front/src/cursor/main/durations/register_durations.rs new file mode 100644 index 0000000000..77d1ebdb29 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/durations/register_durations.rs @@ -0,0 +1,12 @@ +//! Register the durations functions and classes. + +use crate::cursor::_helpers::durations; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the durations functions and classes. +#[inline] +pub fn register_durations(module: &Bound<'_, PyModule>) -> PyResult<()> { + durations::register(module) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/durations/shift_by_cursor_duration.rs b/crates/sqlbuild-python-front/src/cursor/main/durations/shift_by_cursor_duration.rs new file mode 100644 index 0000000000..9037da5d56 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/durations/shift_by_cursor_duration.rs @@ -0,0 +1,16 @@ +//! `moment` moved forward (`direction` 1) or back (`direction` -1) by `duration`. + +use crate::cursor::_helpers::durations; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// `moment` moved forward (`direction` 1) or back (`direction` -1) by `duration`. +#[inline] +pub fn shift_by_cursor_duration<'py>( + moment: &Bound<'py, PyAny>, + duration: &Bound<'py, PyAny>, + direction: i64, +) -> PyResult> { + durations::shift_by_cursor_duration(moment, duration, direction) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/durations/shifted_moment.rs b/crates/sqlbuild-python-front/src/cursor/main/durations/shifted_moment.rs new file mode 100644 index 0000000000..c92de35127 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/durations/shifted_moment.rs @@ -0,0 +1,17 @@ +//! `moment` (a `date` or `datetime`) moved by `span` in `direction`, keeping its type and `tzinfo`. + +use crate::cursor::_helpers::durations; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_cursor::algebra::models::DurationSpan; + +/// `moment` (a `date` or `datetime`) moved by `span` in `direction`, keeping its type and `tzinfo`. +#[inline] +pub fn shifted_moment<'py>( + moment: &Bound<'py, PyAny>, + span: &DurationSpan, + direction: i64, +) -> PyResult> { + durations::shifted_moment(moment, span, direction) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/intervals/interval_validation.rs b/crates/sqlbuild-python-front/src/cursor/main/intervals/interval_validation.rs new file mode 100644 index 0000000000..549343ce56 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/intervals/interval_validation.rs @@ -0,0 +1,16 @@ +//! Raise `CursorAlgebraError` unless the ends form a valid aligned interval. + +use crate::cursor::_helpers::intervals; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Raise `CursorAlgebraError` unless the ends form a valid aligned interval. +#[inline] +pub fn interval_validation( + start: &Bound<'_, PyAny>, + end: &Bound<'_, PyAny>, + grain: &Bound<'_, PyAny>, +) -> PyResult<()> { + intervals::interval_validation(start, end, grain) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/intervals/mod.rs b/crates/sqlbuild-python-front/src/cursor/main/intervals/mod.rs new file mode 100644 index 0000000000..1388ee87e4 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/intervals/mod.rs @@ -0,0 +1,3 @@ +pub mod interval_validation; +pub mod partition; +pub mod register_intervals; diff --git a/crates/sqlbuild-python-front/src/cursor/main/intervals/partition.rs b/crates/sqlbuild-python-front/src/cursor/main/intervals/partition.rs new file mode 100644 index 0000000000..7509cc126b --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/intervals/partition.rs @@ -0,0 +1,15 @@ +//! The canonical partition containing an observed physical value. + +use crate::cursor::_helpers::intervals; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// The canonical partition containing an observed physical value. +#[inline] +pub fn partition<'py>( + value: &Bound<'py, PyAny>, + grain: &Bound<'py, PyAny>, +) -> PyResult> { + intervals::partition(value, grain) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/intervals/register_intervals.rs b/crates/sqlbuild-python-front/src/cursor/main/intervals/register_intervals.rs new file mode 100644 index 0000000000..33e94ed6ad --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/intervals/register_intervals.rs @@ -0,0 +1,12 @@ +//! Register the intervals functions and classes. + +use crate::cursor::_helpers::intervals; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the intervals functions and classes. +#[inline] +pub fn register_intervals(module: &Bound<'_, PyModule>) -> PyResult<()> { + intervals::register(module) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/mod.rs b/crates/sqlbuild-python-front/src/cursor/main/mod.rs new file mode 100644 index 0000000000..b90e1ad95e --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/mod.rs @@ -0,0 +1,6 @@ +pub mod conversion; +pub mod durations; +pub mod intervals; +pub mod overrides; +pub mod scalars; +pub mod values; diff --git a/crates/sqlbuild-python-front/src/cursor/main/overrides/cursor_integer.rs b/crates/sqlbuild-python-front/src/cursor/main/overrides/cursor_integer.rs new file mode 100644 index 0000000000..a7fc01d88c --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/overrides/cursor_integer.rs @@ -0,0 +1,12 @@ +//! An integer override as an `int`; text is read the way `int(Decimal(text))` reads it. + +use crate::cursor::_helpers::overrides; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// An integer override as an `int`; text is read the way `int(Decimal(text))` reads it. +#[inline] +pub fn cursor_integer<'py>(value: &Bound<'py, PyAny>) -> PyResult> { + overrides::cursor_integer(value) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/overrides/cursor_timestamp.rs b/crates/sqlbuild-python-front/src/cursor/main/overrides/cursor_timestamp.rs new file mode 100644 index 0000000000..193365f411 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/overrides/cursor_timestamp.rs @@ -0,0 +1,12 @@ +//! A timestamp override as a `datetime`; dates start at midnight and text is ISO 8601. + +use crate::cursor::_helpers::overrides; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// A timestamp override as a `datetime`; dates start at midnight and text is ISO 8601. +#[inline] +pub fn cursor_timestamp<'py>(value: &Bound<'py, PyAny>) -> PyResult> { + overrides::cursor_timestamp(value) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/overrides/mod.rs b/crates/sqlbuild-python-front/src/cursor/main/overrides/mod.rs new file mode 100644 index 0000000000..24e520f716 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/overrides/mod.rs @@ -0,0 +1,2 @@ +pub mod cursor_integer; +pub mod cursor_timestamp; diff --git a/crates/sqlbuild-python-front/src/cursor/main/scalars/as_scalar.rs b/crates/sqlbuild-python-front/src/cursor/main/scalars/as_scalar.rs new file mode 100644 index 0000000000..56617ed205 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/scalars/as_scalar.rs @@ -0,0 +1,18 @@ +//! `raw` unchanged when it is already a typed value, else parsed. + +use crate::cursor::_helpers::scalars; +use crate::cursor::models::CursorSession; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_cursor::algebra::models::Scalar; + +/// `raw` unchanged when it is already a typed value, else parsed. +#[inline] +pub fn as_scalar<'py>( + session: &CursorSession<'py>, + raw: &Bound<'py, PyAny>, + cursor_type: &Bound<'py, PyAny>, +) -> PyResult { + scalars::as_scalar(session, raw, cursor_type) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/scalars/compare_values.rs b/crates/sqlbuild-python-front/src/cursor/main/scalars/compare_values.rs new file mode 100644 index 0000000000..d8a1465d67 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/scalars/compare_values.rs @@ -0,0 +1,12 @@ +//! `-1`, `0` or `1` as `left` orders against `right`. + +use crate::cursor::_helpers::scalars; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// `-1`, `0` or `1` as `left` orders against `right`. +#[inline] +pub fn compare_values(left: &Bound<'_, PyAny>, right: &Bound<'_, PyAny>) -> PyResult { + scalars::compare_values(left, right) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/scalars/mod.rs b/crates/sqlbuild-python-front/src/cursor/main/scalars/mod.rs new file mode 100644 index 0000000000..e4d7f7ee55 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/scalars/mod.rs @@ -0,0 +1,10 @@ +pub mod as_scalar; +pub mod compare_values; +pub mod parse; +pub mod parse_value; +pub mod register_scalars; +pub mod render_value; +pub mod sentinel_to_token; +pub mod to_exclusive; +pub mod to_inclusive; +pub mod try_parse; diff --git a/crates/sqlbuild-python-front/src/cursor/main/scalars/parse.rs b/crates/sqlbuild-python-front/src/cursor/main/scalars/parse.rs new file mode 100644 index 0000000000..b9d0b5af14 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/scalars/parse.rs @@ -0,0 +1,15 @@ +//! One cursor scalar, preserving date-ness and timestamp offsets. + +use crate::cursor::_helpers::scalars; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// One cursor scalar, preserving date-ness and timestamp offsets. +#[inline] +pub fn parse<'py>( + raw: &Bound<'py, PyAny>, + cursor_type: &Bound<'py, PyAny>, +) -> PyResult> { + scalars::parse(raw, cursor_type) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/scalars/parse_value.rs b/crates/sqlbuild-python-front/src/cursor/main/scalars/parse_value.rs new file mode 100644 index 0000000000..198f84f246 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/scalars/parse_value.rs @@ -0,0 +1,15 @@ +//! One cursor value parsed from its boundary representation, keeping date-ness and offsets. + +use crate::cursor::_helpers::scalars; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// One cursor value parsed from its boundary representation, keeping date-ness and offsets. +#[inline] +pub fn parse_value<'py>( + raw: &Bound<'py, PyAny>, + cursor_type: &Bound<'py, PyAny>, +) -> PyResult> { + scalars::parse_value(raw, cursor_type) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/scalars/register_scalars.rs b/crates/sqlbuild-python-front/src/cursor/main/scalars/register_scalars.rs new file mode 100644 index 0000000000..5d54f46a04 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/scalars/register_scalars.rs @@ -0,0 +1,12 @@ +//! Register the scalars functions and classes. + +use crate::cursor::_helpers::scalars; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the scalars functions and classes. +#[inline] +pub fn register_scalars(module: &Bound<'_, PyModule>) -> PyResult<()> { + scalars::register(module) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/scalars/render_value.rs b/crates/sqlbuild-python-front/src/cursor/main/scalars/render_value.rs new file mode 100644 index 0000000000..cc7c06fb71 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/scalars/render_value.rs @@ -0,0 +1,12 @@ +//! A scalar in the existing cursor output format. + +use crate::cursor::_helpers::scalars; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// A scalar in the existing cursor output format. +#[inline] +pub fn render_value(value: &Bound<'_, PyAny>) -> PyResult { + scalars::render_value(value) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/scalars/sentinel_to_token.rs b/crates/sqlbuild-python-front/src/cursor/main/scalars/sentinel_to_token.rs new file mode 100644 index 0000000000..fd2abf4730 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/scalars/sentinel_to_token.rs @@ -0,0 +1,12 @@ +//! A sentinel's token, or a scalar rendered. + +use crate::cursor::_helpers::scalars; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// A sentinel's token, or a scalar rendered. +#[inline] +pub fn sentinel_to_token(sentinel: &Bound<'_, PyAny>) -> PyResult { + scalars::sentinel_to_token(sentinel) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/scalars/to_exclusive.rs b/crates/sqlbuild-python-front/src/cursor/main/scalars/to_exclusive.rs new file mode 100644 index 0000000000..3f71c47689 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/scalars/to_exclusive.rs @@ -0,0 +1,15 @@ +//! An operator-declared inclusive bound advanced by one cursor unit. + +use crate::cursor::_helpers::scalars; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// An operator-declared inclusive bound advanced by one cursor unit. +#[inline] +pub fn to_exclusive<'py>( + value: &Bound<'py, PyAny>, + grain: &Bound<'py, PyAny>, +) -> PyResult> { + scalars::to_exclusive(value, grain) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/scalars/to_inclusive.rs b/crates/sqlbuild-python-front/src/cursor/main/scalars/to_inclusive.rs new file mode 100644 index 0000000000..49da0d7d19 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/scalars/to_inclusive.rs @@ -0,0 +1,15 @@ +//! An exclusive bound moved back by one cursor unit. + +use crate::cursor::_helpers::scalars; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// An exclusive bound moved back by one cursor unit. +#[inline] +pub fn to_inclusive<'py>( + value: &Bound<'py, PyAny>, + grain: &Bound<'py, PyAny>, +) -> PyResult> { + scalars::to_inclusive(value, grain) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/scalars/try_parse.rs b/crates/sqlbuild-python-front/src/cursor/main/scalars/try_parse.rs new file mode 100644 index 0000000000..aac8b2cfb1 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/scalars/try_parse.rs @@ -0,0 +1,15 @@ +//! Discovery values that may be dates or timestamps, or `None` when they do not parse. + +use crate::cursor::_helpers::scalars; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Discovery values that may be dates or timestamps, or `None` when they do not parse. +#[inline] +pub fn try_parse<'py>( + raw: &Bound<'py, PyAny>, + cursor_type: &Bound<'py, PyAny>, +) -> PyResult>> { + scalars::try_parse(raw, cursor_type) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/values/local_date_time.rs b/crates/sqlbuild-python-front/src/cursor/main/values/local_date_time.rs new file mode 100644 index 0000000000..4a4809c85d --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/values/local_date_time.rs @@ -0,0 +1,13 @@ +//! The wall-clock fields of a `datetime`. + +use crate::cursor::_helpers::values; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_cursor::algebra::models::LocalDateTime; + +/// The wall-clock fields of a `datetime`. +#[inline] +pub fn local_date_time(value: &Bound<'_, PyAny>) -> PyResult { + values::local_date_time(value) +} diff --git a/crates/sqlbuild-python-front/src/cursor/main/values/mod.rs b/crates/sqlbuild-python-front/src/cursor/main/values/mod.rs new file mode 100644 index 0000000000..462025e030 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/values/mod.rs @@ -0,0 +1,2 @@ +pub mod local_date_time; +pub mod replaced; diff --git a/crates/sqlbuild-python-front/src/cursor/main/values/replaced.rs b/crates/sqlbuild-python-front/src/cursor/main/values/replaced.rs new file mode 100644 index 0000000000..c6d6e8c946 --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/main/values/replaced.rs @@ -0,0 +1,17 @@ +//! `template.replace(...)` with the wall time and fold of `local`, keeping type and `tzinfo`. + +use crate::cursor::_helpers::values; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_cursor::algebra::models::LocalDateTime; + +/// `template.replace(...)` with the wall time and fold of `local`, keeping type and `tzinfo`. +#[inline] +pub fn replaced<'py>( + template: &Bound<'py, PyAny>, + local: &LocalDateTime, + fold: bool, +) -> PyResult> { + values::replaced(template, local, fold) +} diff --git a/crates/sqlbuild-python-front/src/cursor/mod.rs b/crates/sqlbuild-python-front/src/cursor/mod.rs new file mode 100644 index 0000000000..b934be571e --- /dev/null +++ b/crates/sqlbuild-python-front/src/cursor/mod.rs @@ -0,0 +1,6 @@ +//! Cursor values, intervals, durations and overrides converted between Python and Rust. + +pub(crate) mod _helpers; +pub mod constants; +pub mod main; +pub mod models; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/cursor/conversion.rs b/crates/sqlbuild-python-front/src/cursor/models.rs similarity index 74% rename from crates/sqlbuild-python/src/bindings/_helpers/cursor/conversion.rs rename to crates/sqlbuild-python-front/src/cursor/models.rs index 366ecd2dd1..7a7a17b513 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/cursor/conversion.rs +++ b/crates/sqlbuild-python-front/src/cursor/models.rs @@ -1,24 +1,35 @@ -//! One call's cursor values read from and built as the native cursor value records. - -use sqlbuild_python_base::native_host::main::host_error::host_error; -use std::cell::RefCell; +//! Public records of cursor. +use crate::cursor::_helpers::conversion::algebra_error; +use crate::cursor::_helpers::values::civil_date; +use crate::cursor::_helpers::values::local_date_time; +use crate::cursor::_helpers::values::naive_date_time; +use crate::cursor::_helpers::values::plain_date; +use crate::cursor::_helpers::values::replaced; +use crate::cursor::_helpers::values::timedelta_micros; +use crate::cursor::constants::DATETIME_MODULE; +use crate::cursor::constants::GRAIN_NAMES; use pyo3::IntoPyObject; -use pyo3::exceptions::{PyOverflowError, PyTypeError, PyValueError}; -use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult, Python}; +use pyo3::exceptions::PyOverflowError; +use pyo3::exceptions::PyTypeError; +use pyo3::exceptions::PyValueError; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyAnyMethods; +use pyo3::prelude::PyErr; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; use pyo3::types::PyString; use pyo3::types::PyStringMethods; use sqlbuild_cursor::algebra::errors::CursorError; -use sqlbuild_cursor::algebra::models::{ - Grain, Interval, LocalDateTime, Scalar, ScalarValue, Timestamp, ZoneOffset, -}; +use sqlbuild_cursor::algebra::models::Grain; +use sqlbuild_cursor::algebra::models::Interval; +use sqlbuild_cursor::algebra::models::LocalDateTime; +use sqlbuild_cursor::algebra::models::Scalar; +use sqlbuild_cursor::algebra::models::ScalarValue; +use sqlbuild_cursor::algebra::models::Timestamp; +use sqlbuild_cursor::algebra::models::ZoneOffset; use sqlbuild_cursor::algebra::types::ZoneRules; -use sqlbuild_host::entries::models::FacadeHost; - -use crate::bindings::_helpers::cursor::values::{ - DATETIME_MODULE, civil_date, local_date_time, naive_date_time, plain_date, replaced, - timedelta_micros, -}; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::records::main::construct::enum_from_value::enum_from_value; @@ -26,36 +37,30 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; - -/// Cursor grain names, finest first. -pub(crate) const GRAIN_NAMES: [(&str, Grain); 6] = [ - ("second", Grain::Second), - ("minute", Grain::Minute), - ("hour", Grain::Hour), - ("day", Grain::Day), - ("month", Grain::Month), - ("year", Grain::Year), -]; - -/// `CursorAlgebraError(message)`. -pub(crate) fn algebra_error(py: Python<'_>, message: &str) -> PyErr { - host_error(py, FacadeHost::CursorAlgebraError, message) -} +use std::cell::RefCell; /// The cursor values one native call reads, so unchanged inputs come back as the same objects. -pub(crate) struct CursorSession<'py> { - py: Python<'py>, - timestamp_class: Bound<'py, PyAny>, - date_class: Bound<'py, PyAny>, - integer_class: Bound<'py, PyAny>, +pub struct CursorSession<'py> { + pub(crate) py: Python<'py>, + pub(crate) timestamp_class: Bound<'py, PyAny>, + pub(crate) date_class: Bound<'py, PyAny>, + pub(crate) integer_class: Bound<'py, PyAny>, /// Each input value object and the `date`, `datetime` or `int` it holds. - inputs: RefCell, Bound<'py, PyAny>)>>, + pub(crate) inputs: RefCell, Bound<'py, PyAny>)>>, /// The Python error a zone lookup raised, re-raised in place of the algebra's error. - failure: RefCell>, + pub(crate) failure: RefCell>, +} + +impl std::fmt::Debug for CursorSession<'_> { + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + formatter + .debug_struct("CursorSession") + .finish_non_exhaustive() + } } impl<'py> CursorSession<'py> { - pub(crate) fn new(py: Python<'py>) -> PyResult { + pub fn new(py: Python<'py>) -> PyResult { Ok(Self { py, timestamp_class: record_class(py, RecordId::TimestampValue)?, @@ -66,18 +71,22 @@ impl<'py> CursorSession<'py> { }) } - pub(crate) fn py(&self) -> Python<'py> { + pub fn py(&self) -> Python<'py> { self.py } /// Whether `value` is one of the three typed cursor values. - pub(crate) fn scalar_typed(&self, value: &Bound<'py, PyAny>) -> PyResult { + pub fn scalar_typed(&self, value: &Bound<'py, PyAny>) -> PyResult { Ok(value.is_instance(&self.timestamp_class)? || value.is_instance(&self.date_class)? || value.is_instance(&self.integer_class)?) } - fn timestamp(&self, inner: &Bound<'py, PyAny>, handle: usize) -> PyResult { + pub(crate) fn timestamp( + &self, + inner: &Bound<'py, PyAny>, + handle: usize, + ) -> PyResult { let tzinfo: Bound<'py, PyAny> = native_field(inner, "tzinfo")?; let offset: ZoneOffset = if tzinfo.is_none() { ZoneOffset::Naive @@ -101,7 +110,7 @@ impl<'py> CursorSession<'py> { } /// A typed cursor value object as a scalar remembering the object. - pub(crate) fn scalar(&self, value: &Bound<'py, PyAny>) -> PyResult { + pub fn scalar(&self, value: &Bound<'py, PyAny>) -> PyResult { let inner: Bound<'py, PyAny> = native_field(value, "value")?; let handle: usize = self.inputs.borrow().len(); let typed: ScalarValue = if value.is_instance(&self.integer_class)? { @@ -124,7 +133,7 @@ impl<'py> CursorSession<'py> { } /// `CursorGrain | None` as a grain; an unknown name fails as `CursorGrain(name)` does. - pub(crate) fn grain(&self, grain: &Bound<'py, PyAny>) -> PyResult> { + pub fn grain(&self, grain: &Bound<'py, PyAny>) -> PyResult> { if grain.is_none() { return Ok(None); } @@ -139,7 +148,7 @@ impl<'py> CursorSession<'py> { } /// An `AlignedInterval` as an interval. - pub(crate) fn interval(&self, interval: &Bound<'py, PyAny>) -> PyResult { + pub fn interval(&self, interval: &Bound<'py, PyAny>) -> PyResult { Ok(Interval { start: self.scalar(&native_field(interval, "start")?)?, end: self.scalar(&native_field(interval, "end")?)?, @@ -147,14 +156,14 @@ impl<'py> CursorSession<'py> { }) } - fn input(&self, handle: usize, inner: bool) -> Bound<'py, PyAny> { + pub(crate) fn input(&self, handle: usize, inner: bool) -> Bound<'py, PyAny> { let inputs = self.inputs.borrow(); let (value, held) = &inputs[handle]; if inner { held.clone() } else { value.clone() } } /// The `datetime` holding `local` in the zone and type of input `template`. - fn date_time(&self, timestamp: &Timestamp) -> PyResult> { + pub(crate) fn date_time(&self, timestamp: &Timestamp) -> PyResult> { match timestamp.template { Some(template) => replaced( &self.input(template, true), @@ -166,7 +175,7 @@ impl<'py> CursorSession<'py> { } /// The input object for an unchanged value, else a new typed cursor value. - pub(crate) fn python_scalar(&self, scalar: &Scalar) -> PyResult> { + pub fn python_scalar(&self, scalar: &Scalar) -> PyResult> { if let Some(handle) = scalar.handle { return Ok(self.input(handle, false)); } @@ -184,7 +193,7 @@ impl<'py> CursorSession<'py> { } /// A grain as its `CursorGrain` member. - pub(crate) fn python_grain(&self, grain: Option) -> PyResult> { + pub fn python_grain(&self, grain: Option) -> PyResult> { let Some(grain) = grain else { return Ok(self.py.None().into_bound(self.py)); }; @@ -196,7 +205,7 @@ impl<'py> CursorSession<'py> { } /// A new `AlignedInterval`, validated as its constructor validates. - pub(crate) fn python_interval(&self, interval: &Interval) -> PyResult> { + pub fn python_interval(&self, interval: &Interval) -> PyResult> { new_record_with( self.py, RecordId::AlignedInterval, @@ -209,7 +218,7 @@ impl<'py> CursorSession<'py> { } /// The Python exception for a failed cursor operation. - pub(crate) fn error(&self, error: CursorError) -> PyErr { + pub fn error(&self, error: CursorError) -> PyErr { if let Some(failure) = self.failure.borrow_mut().take() { return failure; } @@ -222,11 +231,11 @@ impl<'py> CursorSession<'py> { } /// `result`, with a cursor error raised as its Python exception. - pub(crate) fn checked(&self, result: Result) -> PyResult { + pub fn checked(&self, result: Result) -> PyResult { result.map_err(|error| self.error(error)) } - fn zone_call( + pub(crate) fn zone_call( &self, template: usize, local: &LocalDateTime, @@ -235,7 +244,7 @@ impl<'py> CursorSession<'py> { replaced(&self.input(template, true), local, fold) } - fn remember(&self, error: PyErr) -> CursorError { + pub(crate) fn remember(&self, error: PyErr) -> CursorError { let message: String = error.to_string(); *self.failure.borrow_mut() = Some(error); CursorError::Algebra(message) diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/faults.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/failures/faults.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/faults.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/failures/faults.rs diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/guidance.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/failures/guidance.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/guidance.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/failures/guidance.rs diff --git a/crates/sqlbuild-python-front/src/discovery/_helpers/failures/mod.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/failures/mod.rs new file mode 100644 index 0000000000..516ceedfe5 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/failures/mod.rs @@ -0,0 +1,3 @@ +pub(crate) mod faults; +pub(crate) mod guidance; +pub(crate) mod raised; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/raised.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/failures/raised.rs similarity index 98% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/raised.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/failures/raised.rs index c41e4f6ce8..51e2e48d0c 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/raised.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/failures/raised.rs @@ -9,7 +9,7 @@ use pyo3::{pyfunction, wrap_pyfunction}; use sqlbuild_discovery::models::{DiscoveryFailure, ReadFailure, StageFailure}; use sqlbuild_discovery::tree::models::ProjectTree; -use crate::bindings::_helpers::discovery::project_files::path_object; +use crate::discovery::_helpers::project::project_files::path_object; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/header_declarations.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/headers/header_declarations.rs similarity index 96% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/header_declarations.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/headers/header_declarations.rs index 9b3cbd0570..4fe5562215 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/header_declarations.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/headers/header_declarations.rs @@ -15,9 +15,10 @@ use sqlbuild_model_config::declarations::models::{ use sqlbuild_model_config::sql_values::errors::SqlValueFailure; use sqlbuild_model_config::sql_values::models::RawSqlValue; -use crate::bindings::_helpers::authored_values::sql_values::{ - SqlValueClasses, raw_value, sql_value, sql_value_error, -}; +use crate::authored_values::main::raw_value::raw_value; +use crate::authored_values::main::sql_value::sql_value; +use crate::authored_values::main::sql_value_error::sql_value_error; +use crate::authored_values::models::SqlValueClasses; use sqlbuild_python_base::records::main::construct::enum_from_value::enum_from_value; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::construct::new_record::new_record; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/header_keys.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/headers/header_keys.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/header_keys.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/headers/header_keys.rs diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/header_values.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/headers/header_values.rs similarity index 95% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/header_values.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/headers/header_values.rs index 392338f405..d3418c38d6 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/header_values.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/headers/header_values.rs @@ -5,9 +5,11 @@ use pyo3::sync::PyOnceLock; use pyo3::types::{PyDict, PyDictMethods, PyList, PyListMethods, PyTuple}; use pyo3::{pyfunction, wrap_pyfunction}; -use crate::bindings::_helpers::sqltext::model_headers::{ - ColumnLocation, ParsedModelHeader, header_failure, model_output_columns, parse_model_headers, -}; +use crate::sqltext::main::header_failure::header_failure; +use crate::sqltext::main::model_output_columns::model_output_columns; +use crate::sqltext::main::parse_model_headers::parse_model_headers; +use crate::sqltext::models::ColumnLocation; +use crate::sqltext::types::ParsedModelHeader; use sqlbuild_python_base::boundary::models::Request; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::construct::new_record::new_record; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/hook_entries.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/headers/hook_entries.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/hook_entries.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/headers/hook_entries.rs diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/key_checks.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/headers/key_checks.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/key_checks.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/headers/key_checks.rs diff --git a/crates/sqlbuild-python-front/src/discovery/_helpers/headers/mod.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/headers/mod.rs new file mode 100644 index 0000000000..02655c3b04 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/headers/mod.rs @@ -0,0 +1,5 @@ +pub(crate) mod header_declarations; +pub(crate) mod header_keys; +pub(crate) mod header_values; +pub(crate) mod hook_entries; +pub(crate) mod key_checks; diff --git a/crates/sqlbuild-python-front/src/discovery/_helpers/mod.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/mod.rs new file mode 100644 index 0000000000..217565b656 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/mod.rs @@ -0,0 +1,7 @@ +pub(crate) mod failures; +pub(crate) mod headers; +pub(crate) mod project; +pub(crate) mod python_files; +pub(crate) mod records; +pub(crate) mod snapshots; +pub(crate) mod sources; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/configuration.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/project/configuration.rs similarity index 85% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/configuration.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/project/configuration.rs index 74959af2a0..5e720d022e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/configuration.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/project/configuration.rs @@ -4,15 +4,14 @@ use pyo3::prelude::{Bound, PyAny, PyResult, Python}; use pyo3::types::PyString; use sqlbuild_host::entries::models::ExecutorHost; -use crate::bindings::_helpers::compile_driver::config_validation::{ - ProjectConfiguration, reject_invalid_connection_configuration, - reject_invalid_project_configuration, -}; -use crate::bindings::_helpers::discovery::imported_providers::discover_provider_classes; -use crate::bindings::_helpers::discovery::project_config::{ - load_local_config_file, load_project_config_file, warn_deprecated_settings, -}; -use crate::bindings::_helpers::discovery::provider_secrets::SecretPolicy; +use crate::compile_driver::main::reject_invalid_connection_configuration::reject_invalid_connection_configuration; +use crate::compile_driver::main::reject_invalid_project_configuration::reject_invalid_project_configuration; +use crate::compile_driver::models::ProjectConfiguration; +use crate::discovery::_helpers::project::project_config::load_local_config_file; +use crate::discovery::_helpers::project::project_config::load_project_config_file; +use crate::discovery::_helpers::project::project_config::warn_deprecated_settings; +use crate::discovery::_helpers::python_files::imported_providers::discover_provider_classes; +use crate::discovery::models::SecretPolicy; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::within::within; use sqlbuild_python_base::native_host::main::host_entry::host_entry; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/locations.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/project/locations.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/locations.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/project/locations.rs diff --git a/crates/sqlbuild-python-front/src/discovery/_helpers/project/mod.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/project/mod.rs new file mode 100644 index 0000000000..f7641386da --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/project/mod.rs @@ -0,0 +1,6 @@ +pub(crate) mod configuration; +pub(crate) mod locations; +pub(crate) mod project_config; +pub(crate) mod project_facts; +pub(crate) mod project_files; +pub(crate) mod project_validation; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/project_config.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/project/project_config.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/project_config.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/project/project_config.rs diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/project_facts.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/project/project_facts.rs similarity index 96% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/project_facts.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/project/project_facts.rs index a2dca5cebf..003e2a881e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/project_facts.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/project/project_facts.rs @@ -1,7 +1,8 @@ //! The facts cross-file validation reads, taken from Python's `DiscoveredProjectInputs`. -use crate::bindings::_helpers::discovery::model_file_record::{ModelFileTexts, NativeModelFile}; -use pyo3::FromPyObject; +use crate::discovery::models::ModelFileTexts; +use crate::discovery::models::NativeModelFile; +use crate::discovery::models::NodeRow; use pyo3::exceptions::{PyTypeError, PyValueError}; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; use pyo3::types::{PyDict, PyDictMethods, PyTuple, PyTypeMethods}; @@ -29,18 +30,7 @@ const PYTHON_NODE_FIELDS: [(&str, &str); 4] = [ const PRIVATE_SCOPE: &str = "private"; /// `(SQL resource name, owning node index, decorated name)` of one dependency. -type DependencyRow = (Option, Option, Option); - -/// A decorated Python node as the facade describes it. -#[derive(FromPyObject)] -#[pyo3(from_item_all)] -pub(crate) struct NodeRow { - kind: String, - name: String, - path: String, - decorator_config: bool, - depends_on: Vec, -} +pub(crate) type DependencyRow = (Option, Option, Option); /// The facts of `inputs`, with the Python nodes the facade has described. pub(crate) fn project_facts( diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/project_files.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/project/project_files.rs similarity index 84% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/project_files.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/project/project_files.rs index d591fd8e50..c60e8febc9 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/project_files.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/project/project_files.rs @@ -11,16 +11,17 @@ use sqlbuild_discovery::model_files::models::{DiscoveredModelFile, ModelFileOpti use sqlbuild_discovery::tree::models::ProjectTree; use std::path::Path; -use crate::bindings::_helpers::discovery::declaration_records::source_locations; -use crate::bindings::_helpers::discovery::header_declarations::model_header_declarations; -use crate::bindings::_helpers::discovery::model_file_record::{ - DiscoveredPaths, ModelFileParts, NativeModelFile, PendingModelFile, -}; -use crate::bindings::_helpers::discovery::raised::failure_error; -use crate::bindings::_helpers::sqltext::authored_values::{ - map_to_python, optional_authored_value_to_python, -}; -use crate::bindings::models::{ModelTextRequest, NativeProjectTree}; +use crate::discovery::_helpers::failures::raised::failure_error; +use crate::discovery::_helpers::headers::header_declarations::model_header_declarations; +use crate::discovery::_helpers::records::declaration_records::source_locations; +use crate::discovery::_helpers::records::model_file_record::DiscoveredPaths; +use crate::discovery::_helpers::records::model_file_record::ModelFileParts; +use crate::discovery::_helpers::records::model_file_record::PendingModelFile; +use crate::discovery::_helpers::snapshots::native_classes::ModelTextRequest; +use crate::discovery::_helpers::snapshots::native_classes::NativeProjectTree; +use crate::discovery::models::NativeModelFile; +use crate::sqltext::main::map_to_python::map_to_python; +use crate::sqltext::main::optional_authored_value_to_python::optional_authored_value_to_python; use sqlbuild_python_base::types::CompilerDetach; pub(crate) type PyObject = Py; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/project_validation.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/project/project_validation.rs similarity index 90% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/project_validation.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/project/project_validation.rs index f10ad200cf..9086c6bdb8 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/project_validation.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/project/project_validation.rs @@ -8,9 +8,11 @@ use pyo3::{pyfunction, wrap_pyfunction}; use sqlbuild_discovery::project_validation::main::validate_project_inputs::validate_project_inputs; use sqlbuild_discovery::project_validation::models::{ProjectFacts, ValidationFailure}; -use crate::bindings::_helpers::discovery::orchestration_files::orchestration_declarations; -use crate::bindings::_helpers::discovery::project_facts::{NodeRow, project_facts}; -use crate::bindings::_helpers::discovery::raised::{failure_error, read_error}; +use crate::discovery::_helpers::failures::raised::failure_error; +use crate::discovery::_helpers::failures::raised::read_error; +use crate::discovery::_helpers::project::project_facts::project_facts; +use crate::discovery::_helpers::sources::orchestration_files::orchestration_declarations; +use crate::discovery::models::NodeRow; use sqlbuild_python_base::records::main::fields::field::field as native_field; const CSV_MODULE: &str = "csv"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/imported_modules.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/python_files/imported_modules.rs similarity index 97% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/imported_modules.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/python_files/imported_modules.rs index 434dbf3a20..7e04bf4870 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/imported_modules.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/python_files/imported_modules.rs @@ -7,8 +7,8 @@ use sqlbuild_python_base::records::main::construct::new_plain_error::new_plain_e use sqlbuild_host::entries::models::UserCodeHost; -use crate::bindings::_helpers::discovery::locations::project_relative_path; -use crate::bindings::_helpers::discovery::python_module_files::discover_python_module_files; +use crate::discovery::_helpers::project::locations::project_relative_path; +use crate::discovery::_helpers::python_files::python_module_files::discover_python_module_files; use pyo3::IntoPyObjectExt; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::event_exporting::main::current_scope::current_scope; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/imported_providers.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/python_files/imported_providers.rs similarity index 96% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/imported_providers.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/python_files/imported_providers.rs index baa821e746..c592f4f592 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/imported_providers.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/python_files/imported_providers.rs @@ -9,12 +9,17 @@ use pyo3::sync::PyOnceLock; use pyo3::types::{PyDict, PyDictMethods, PyType}; use sqlbuild_host::entries::models::UserCodeHost; -use crate::bindings::_helpers::discovery::constants::ALLOW_MISSING_SECRETS_FLAG; -use crate::bindings::_helpers::discovery::imported_modules::{ - ProjectDir, discovered, discovery_error, discovery_error_from, module_functions, - provider_by_name, provider_usages, shim, tuple_of, -}; -use crate::bindings::_helpers::discovery::provider_secrets::SecretPolicy; +use crate::discovery::_helpers::python_files::imported_modules::ProjectDir; +use crate::discovery::_helpers::python_files::imported_modules::discovered; +use crate::discovery::_helpers::python_files::imported_modules::discovery_error; +use crate::discovery::_helpers::python_files::imported_modules::discovery_error_from; +use crate::discovery::_helpers::python_files::imported_modules::module_functions; +use crate::discovery::_helpers::python_files::imported_modules::provider_by_name; +use crate::discovery::_helpers::python_files::imported_modules::provider_usages; +use crate::discovery::_helpers::python_files::imported_modules::shim; +use crate::discovery::_helpers::python_files::imported_modules::tuple_of; +use crate::discovery::constants::ALLOW_MISSING_SECRETS_FLAG; +use crate::discovery::models::SecretPolicy; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::compile_context::main::input_reads::record_settings_class_read::record_settings_class_read; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/imported_python_nodes.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/python_files/imported_python_nodes.rs similarity index 93% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/imported_python_nodes.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/python_files/imported_python_nodes.rs index b83d6e6cf2..68221f5848 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/imported_python_nodes.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/python_files/imported_python_nodes.rs @@ -9,12 +9,22 @@ use pyo3::{IntoPyObjectExt, pyfunction, wrap_pyfunction}; use sqlbuild_core::constants::PYTHON_NODE_ROOT; use sqlbuild_host::entries::models::UserCodeHost; -use crate::bindings::_helpers::discovery::imported_modules::{ - ProjectDir, definition, discovered, discovery_error, discovery_error_from, is_exception, - module_functions, provider_by_name, provider_usages, shim, tuple_of, -}; -use crate::bindings::_helpers::discovery::imported_providers; -use crate::bindings::_helpers::discovery::python_hook_files::discover_python_hook_files; +use crate::discovery::_helpers::python_files::imported_modules::ProjectDir; +use crate::discovery::_helpers::python_files::imported_modules::definition; +use crate::discovery::_helpers::python_files::imported_modules::discovered; +use crate::discovery::_helpers::python_files::imported_modules::discovery_error; +use crate::discovery::_helpers::python_files::imported_modules::discovery_error_from; +use crate::discovery::_helpers::python_files::imported_modules::is_exception; +use crate::discovery::_helpers::python_files::imported_modules::module_functions; +use crate::discovery::_helpers::python_files::imported_modules::provider_by_name; +use crate::discovery::_helpers::python_files::imported_modules::provider_usages; +use crate::discovery::_helpers::python_files::imported_modules::shim; +use crate::discovery::_helpers::python_files::imported_modules::tuple_of; +use crate::discovery::_helpers::python_files::imported_providers::bind_event_exporter_declarations; +use crate::discovery::_helpers::python_files::imported_providers::discover_event_exporter_declarations; +use crate::discovery::_helpers::python_files::imported_providers::discover_event_exporter_functions; +use crate::discovery::_helpers::python_files::imported_providers::discover_provider_classes; +use crate::discovery::_helpers::python_files::python_hook_files::discover_python_hook_files; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::construct::new_record::new_record; @@ -561,22 +571,13 @@ pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { module.add_function(wrap_pyfunction!(discover_python_node_functions, module)?)?; module.add_function(wrap_pyfunction!(discover_hook_functions, module)?)?; module.add_function(wrap_pyfunction!(discover_materialization_files, module)?)?; + module.add_function(wrap_pyfunction!(discover_provider_classes, module)?)?; module.add_function(wrap_pyfunction!( - imported_providers::discover_provider_classes, + discover_event_exporter_declarations, module )?)?; - module.add_function(wrap_pyfunction!( - imported_providers::discover_event_exporter_declarations, - module - )?)?; - module.add_function(wrap_pyfunction!( - imported_providers::bind_event_exporter_declarations, - module - )?)?; - module.add_function(wrap_pyfunction!( - imported_providers::discover_event_exporter_functions, - module - )?) + module.add_function(wrap_pyfunction!(bind_event_exporter_declarations, module)?)?; + module.add_function(wrap_pyfunction!(discover_event_exporter_functions, module)?) } fn optional_value<'py>(value: &Bound<'py, PyAny>) -> PyResult> { diff --git a/crates/sqlbuild-python-front/src/discovery/_helpers/python_files/mod.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/python_files/mod.rs new file mode 100644 index 0000000000..fee2f4e219 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/python_files/mod.rs @@ -0,0 +1,7 @@ +pub(crate) mod imported_modules; +pub(crate) mod imported_providers; +pub(crate) mod imported_python_nodes; +pub(crate) mod python_function_files; +pub(crate) mod python_hook_files; +pub(crate) mod python_module_files; +pub(crate) mod python_paths; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/python_function_files.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/python_files/python_function_files.rs similarity index 95% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/python_function_files.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/python_files/python_function_files.rs index e175f76fe8..68aa0b7878 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/python_function_files.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/python_files/python_function_files.rs @@ -16,11 +16,15 @@ use sqlbuild_pysource::udf_functions::constants::UDF_KEYS; use sqlbuild_pysource::udf_functions::main::udf_function::udf_function; use sqlbuild_pysource::udf_functions::models::{UdfFunction, UdfShape}; -use crate::bindings::_helpers::discovery::declaration_records::path_class; -use crate::bindings::_helpers::discovery::project_files::path_object; -use crate::bindings::_helpers::discovery::raised::{failure_error, read_error, stage_error}; -use crate::bindings::_helpers::discovery::snapshot::{in_snapshot, project_root, project_tree}; -use crate::bindings::models::NativeProjectTree; +use crate::discovery::_helpers::failures::raised::failure_error; +use crate::discovery::_helpers::failures::raised::read_error; +use crate::discovery::_helpers::failures::raised::stage_error; +use crate::discovery::_helpers::project::project_files::path_object; +use crate::discovery::_helpers::records::declaration_records::path_class; +use crate::discovery::_helpers::snapshots::native_classes::NativeProjectTree; +use crate::discovery::_helpers::snapshots::snapshot::in_snapshot; +use crate::discovery::_helpers::snapshots::snapshot::project_root; +use crate::discovery::_helpers::snapshots::snapshot::project_tree; use sqlbuild_python_base::boundary::main::compiler_error::compiler_error; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/python_hook_files.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/python_files/python_hook_files.rs similarity index 76% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/python_hook_files.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/python_files/python_hook_files.rs index 4caad201fe..ded9531391 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/python_hook_files.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/python_files/python_hook_files.rs @@ -9,13 +9,16 @@ use sqlbuild_discovery::declaration_files::models::{ }; use sqlbuild_discovery::tree::models::ProjectTree; -use crate::bindings::_helpers::discovery::declaration_records::{ - add_scope_fields, discovery_session, path_class, -}; -use crate::bindings::_helpers::discovery::project_files::path_object; -use crate::bindings::_helpers::discovery::raised::{failure_error, stage_error}; -use crate::bindings::_helpers::discovery::snapshot::{in_snapshot, project_tree}; -use crate::bindings::models::{NativeDiscoverySession, NativeProjectTree}; +use crate::discovery::_helpers::failures::raised::failure_error; +use crate::discovery::_helpers::failures::raised::stage_error; +use crate::discovery::_helpers::project::project_files::path_object; +use crate::discovery::_helpers::records::declaration_records::add_scope_fields; +use crate::discovery::_helpers::records::declaration_records::discovery_session; +use crate::discovery::_helpers::records::declaration_records::path_class; +use crate::discovery::_helpers::snapshots::native_classes::NativeDiscoverySession; +use crate::discovery::_helpers::snapshots::native_classes::NativeProjectTree; +use crate::discovery::_helpers::snapshots::snapshot::in_snapshot; +use crate::discovery::_helpers::snapshots::snapshot::project_tree; /// Each public Python hook file as `file_path`, `relative_path` and its role's scope fields. #[pyfunction] diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/python_module_files.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/python_files/python_module_files.rs similarity index 83% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/python_module_files.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/python_files/python_module_files.rs index be655ab2fc..2afbf6ce18 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/python_module_files.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/python_files/python_module_files.rs @@ -6,10 +6,10 @@ use pyo3::{pyfunction, wrap_pyfunction}; use sqlbuild_discovery::declaration_files::main::python_module_files::python_module_files; use sqlbuild_discovery::tree::models::ProjectTree; -use crate::bindings::_helpers::discovery::project_files::path_object; -use crate::bindings::_helpers::discovery::raised::stage_error; -use crate::bindings::_helpers::discovery::snapshot::project_tree; -use crate::bindings::models::NativeProjectTree; +use crate::discovery::_helpers::failures::raised::stage_error; +use crate::discovery::_helpers::project::project_files::path_object; +use crate::discovery::_helpers::snapshots::native_classes::NativeProjectTree; +use crate::discovery::_helpers::snapshots::snapshot::project_tree; /// `sorted((project_dir / root).rglob("*.py"))` without `__init__` modules, or `_` parts too. #[pyfunction] diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/python_paths.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/python_files/python_paths.rs similarity index 94% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/python_paths.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/python_files/python_paths.rs index d5aafff79f..07873c43ed 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/python_paths.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/python_files/python_paths.rs @@ -5,7 +5,7 @@ use std::path::PathBuf; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult}; use sqlbuild_discovery::python_paths::main::unsupported_python_paths::unsupported_python_paths; -use crate::bindings::_helpers::discovery::raised::discovery_error; +use crate::discovery::_helpers::failures::raised::discovery_error; const PYTHON_PATH_HELP: &str = "Move pipeline Python nodes and the helper modules they import under \ python/, or move SQLBuild extensions under their documented extension path."; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/declaration_records.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/records/declaration_records.rs similarity index 96% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/declaration_records.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/records/declaration_records.rs index d3f4e5685f..0e0bb863b9 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/declaration_records.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/records/declaration_records.rs @@ -17,16 +17,21 @@ use sqlbuild_host::entries::models::FacadeHost; use sqlbuild_sqltext::compiler::models::AuthoredValue; use std::sync::Arc; -use crate::bindings::_helpers::discovery::faults::{FileFaults, record_tuple}; -use crate::bindings::_helpers::discovery::header_declarations::typed_constant_record; -use crate::bindings::_helpers::discovery::project_files::path_object; -use crate::bindings::_helpers::discovery::raised::{failure_error, read_error, stage_error}; -use crate::bindings::_helpers::discovery::snapshot::{ - in_snapshot, project_root, project_tree, snapshot_memo, -}; -use crate::bindings::_helpers::model_config::header_columns::schema_columns; -use crate::bindings::_helpers::sqltext::authored_values::map_to_python; -use crate::bindings::models::{NativeDiscoverySession, NativeProjectTree}; +use crate::discovery::_helpers::failures::faults::FileFaults; +use crate::discovery::_helpers::failures::faults::record_tuple; +use crate::discovery::_helpers::failures::raised::failure_error; +use crate::discovery::_helpers::failures::raised::read_error; +use crate::discovery::_helpers::failures::raised::stage_error; +use crate::discovery::_helpers::headers::header_declarations::typed_constant_record; +use crate::discovery::_helpers::project::project_files::path_object; +use crate::discovery::_helpers::snapshots::native_classes::NativeDiscoverySession; +use crate::discovery::_helpers::snapshots::native_classes::NativeProjectTree; +use crate::discovery::_helpers::snapshots::snapshot::in_snapshot; +use crate::discovery::_helpers::snapshots::snapshot::project_root; +use crate::discovery::_helpers::snapshots::snapshot::project_tree; +use crate::discovery::_helpers::snapshots::snapshot::snapshot_memo; +use crate::model_config::main::headers::schema_columns::schema_columns; +use crate::sqltext::main::map_to_python::map_to_python; use sqlbuild_discovery::declaration_files::main::declaration_file_options::declaration_file_options; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::keywords::keywords; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/description_inputs.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/records/description_inputs.rs similarity index 82% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/description_inputs.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/records/description_inputs.rs index 81870f4eda..8789e2ac0e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/description_inputs.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/records/description_inputs.rs @@ -4,14 +4,13 @@ use pyo3::prelude::{Bound, PyAny, PyModule, PyModuleMethods, PyResult, Python}; use pyo3::types::{PyCFunction, PyDict, PyFrozenSet}; use pyo3::{pyfunction, wrap_pyfunction}; -use crate::bindings::_helpers::discovery::declaration_records::discover_model_schema_files; -use crate::bindings::_helpers::discovery::model_records::{ - ModelFileSelection, discovered_model_files, -}; -use crate::bindings::_helpers::discovery::project_config::load_project_config_file; -use crate::bindings::_helpers::discovery::snapshot::in_snapshot; -use crate::bindings::_helpers::model_config::described_models::externally_described_models as described_models; -use crate::bindings::_helpers::render::declaration_indexes::public_model_schema_index; +use crate::discovery::_helpers::project::project_config::load_project_config_file; +use crate::discovery::_helpers::records::declaration_records::discover_model_schema_files; +use crate::discovery::_helpers::records::model_records::discovered_model_files; +use crate::discovery::_helpers::snapshots::snapshot::in_snapshot; +use crate::discovery::models::ModelFileSelection; +use crate::model_config::main::model_nodes::externally_described_models::externally_described_models as described_models; +use crate::render::main::declarations::public_model_schema_index::public_model_schema_index; use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::types::RecordId; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/getters.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/records/getters.rs similarity index 75% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/getters.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/records/getters.rs index 05142b07d6..08e5c1db33 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/getters.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/records/getters.rs @@ -3,24 +3,10 @@ use pyo3::IntoPyObjectExt; use pyo3::prelude::{Bound, PyAny, PyResult, Python}; -use crate::bindings::_helpers::discovery::model_file_record::NativeModelFile; -use crate::bindings::models::NativeDirectorySnapshot; -use sqlbuild_python_base::records::main::registry::class_of::class_of; -use sqlbuild_python_base::records::models::GetterEntry; +use crate::discovery::_helpers::snapshots::native_classes::NativeDirectorySnapshot; +use crate::discovery::models::NativeModelFile; -/// The getter readers of this module's native pyclasses. -pub(crate) const GETTERS: &[GetterEntry] = &[ - GetterEntry { - class: class_of::, - read: read_native_model_file, - }, - GetterEntry { - class: class_of::, - read: read_native_directory_snapshot, - }, -]; - -fn read_native_model_file<'py>( +pub(crate) fn read_native_model_file<'py>( value: &Bound<'py, PyAny>, name: &str, ) -> Option>> { @@ -58,7 +44,7 @@ fn read_native_model_file<'py>( }) } -fn read_native_directory_snapshot<'py>( +pub(crate) fn read_native_directory_snapshot<'py>( value: &Bound<'py, PyAny>, name: &str, ) -> Option>> { diff --git a/crates/sqlbuild-python-front/src/discovery/_helpers/records/mod.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/records/mod.rs new file mode 100644 index 0000000000..3437db58de --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/records/mod.rs @@ -0,0 +1,7 @@ +pub(crate) mod declaration_records; +pub(crate) mod description_inputs; +pub(crate) mod getters; +pub(crate) mod model_file_record; +pub(crate) mod model_records; +pub(crate) mod sql_test_records; +pub(crate) mod yaml_records; diff --git a/crates/sqlbuild-python-front/src/discovery/_helpers/records/model_file_record.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/records/model_file_record.rs new file mode 100644 index 0000000000..7c0b3caf9b --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/records/model_file_record.rs @@ -0,0 +1,383 @@ +//! A discovered SQL model file as a native record whose Python attributes are built on demand. + +use crate::discovery::models::ModelFileTexts; +use crate::discovery::models::NativeModelFile; +use std::path::PathBuf; +use std::sync::Arc; + +use crate::sqltext::main::map_to_python::map_to_python; +use pyo3::exceptions::PyRuntimeError; +use pyo3::prelude::{Bound, Py, PyAny, PyAnyMethods, PyResult, Python}; +use pyo3::sync::PyOnceLock; +use pyo3::types::{PyDict, PyDictMethods, PyString, PyStringMethods, PyTuple}; +use pyo3::{FromPyObject, IntoPyObject}; +use sqlbuild_discovery::model_files::main::model_file_stem::model_file_stem; +use sqlbuild_discovery::models::LineColumnSpan; +use sqlbuild_python_base::records::main::construct::new_record::new_record; +use sqlbuild_python_base::records::main::fields::field::field; +use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_sqltext::compiler::models::AuthoredValue; + +pub(crate) const FIELD_NAMES: [&str; 10] = [ + "file_path", + "relative_path", + "contents", + "header_values", + "header_column_locations", + "output_column_locations", + "query_sql", + "enum_declarations", + "constant_declarations", + "extract_implicit_alias_columns", +]; +const STEM_ATTRIBUTE: &str = "stem"; + +/// Authored locations: native rows until Python reads them, then a cached dict. +pub(crate) struct Locations { + pub(crate) rows: Vec<(String, LineColumnSpan)>, + pub(crate) projected: PyOnceLock>, +} + +impl std::fmt::Debug for Locations { + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + formatter.debug_struct("Locations").finish_non_exhaustive() + } +} + +impl Locations { + pub(crate) fn from_rows(rows: Vec<(String, LineColumnSpan)>) -> Self { + Self { + rows, + projected: PyOnceLock::new(), + } + } + + /// These locations for another record: the rows, and the dict once Python has read it. + pub(crate) fn shared(&self, py: Python<'_>) -> Self { + let projected: PyOnceLock> = shared_projection(py, &self.projected); + Self { + rows: self.rows.clone(), + projected, + } + } + + pub(crate) fn from_dict(py: Python<'_>, dict: Py) -> Self { + let projected: PyOnceLock> = PyOnceLock::new(); + let _ = projected.set(py, dict); + Self { + rows: Vec::new(), + projected, + } + } + + /// Python's `{name: SourceLocation(...)}`: a repeated name keeps its first position and last value. + pub(crate) fn dict<'py>(&self, path: &Bound<'py, PyAny>) -> PyResult> { + let py: Python<'py> = path.py(); + Ok(self + .projected + .get_or_try_init(py, || { + let dict: Bound<'py, PyDict> = PyDict::new(py); + for (name, span) in &self.rows { + let location: Bound<'py, PyAny> = new_record( + py, + RecordId::SourceLocation, + (path, span.line, span.column, span.end_line, span.end_column), + None, + )?; + dict.set_item(name, location)?; + } + Ok::<_, pyo3::PyErr>(dict.unbind()) + })? + .bind(py) + .clone()) + } +} + +/// A model file's paths: native text, with the Python path objects built on first read. +pub(crate) struct ModelFilePaths { + pub(crate) native_file_path: PathBuf, + /// `None` when a path is not text Python can encode, so readers raise as Python does. + pub(crate) texts: Option, + /// `(file_path, relative_path)` as Python path objects. + pub(crate) objects: PyOnceLock<(Py, Py)>, + /// The relative path the objects are built from, unless they were given. + pub(crate) relative: Option, +} + +impl std::fmt::Debug for ModelFilePaths { + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + formatter + .debug_struct("ModelFilePaths") + .finish_non_exhaustive() + } +} + +impl ModelFilePaths { + /// Paths given as Python objects; their text is read once, here. + pub(crate) fn given( + py: Python<'_>, + file_path: Py, + relative_path: Py, + ) -> PyResult { + let native_file_path: PathBuf = file_path.bind(py).extract()?; + let relative: PathBuf = relative_path.bind(py).extract()?; + let texts: Option = + native_file_path + .to_str() + .zip(relative.to_str()) + .map(|(file_text, relative_text)| ModelFileTexts { + name: model_file_stem(&posix(file_text)).to_owned(), + posix_path: posix(relative_text), + relative_path: relative_text.to_owned(), + file_path: file_text.to_owned(), + }); + let objects: PyOnceLock<(Py, Py)> = PyOnceLock::new(); + let _ = objects.set(py, (file_path, relative_path)); + Ok(Self { + native_file_path, + texts, + objects, + relative: None, + }) + } + + /// Paths native discovery named; their Python path objects are built only when read. + pub(crate) fn discovered(relative_path: &str, file_path: String) -> Self { + let name: String = model_file_stem(relative_path).to_owned(); + Self { + native_file_path: PathBuf::from(&file_path), + texts: Some(ModelFileTexts { + name, + posix_path: relative_path.to_owned(), + relative_path: relative_path.replace('/', std::path::MAIN_SEPARATOR_STR), + file_path, + }), + objects: PyOnceLock::new(), + relative: Some(PathBuf::from(relative_path)), + } + } + + pub(crate) fn shared(&self, py: Python<'_>) -> Self { + let objects: PyOnceLock<(Py, Py)> = PyOnceLock::new(); + if let Some((file_path, relative_path)) = self.objects.get(py) { + let _ = objects.set(py, (file_path.clone_ref(py), relative_path.clone_ref(py))); + } + Self { + native_file_path: self.native_file_path.clone(), + texts: self.texts.clone(), + objects, + relative: self.relative.clone(), + } + } + + /// `(file_path, relative_path)` as the `pathlib` objects discovery names the file by. + pub(crate) fn objects<'py>( + &self, + py: Python<'py>, + ) -> PyResult<(Bound<'py, PyAny>, Bound<'py, PyAny>)> { + let (file_path, relative_path) = self.objects.get_or_try_init(py, || { + let Some(relative) = &self.relative else { + return Err(PyRuntimeError::new_err("a model file has no paths")); + }; + Ok::<_, pyo3::PyErr>(( + self.native_file_path.as_path().into_pyobject(py)?.unbind(), + relative.as_path().into_pyobject(py)?.unbind(), + )) + })?; + Ok((file_path.bind(py).clone(), relative_path.bind(py).clone())) + } + + /// The file's names, or the error Python raises reading a name that is not UTF-8 text. + pub(crate) fn texts(&self, py: Python<'_>) -> PyResult<&ModelFileTexts> { + if let Some(texts) = &self.texts { + return Ok(texts); + } + let (file_path, relative_path) = self.objects(py)?; + for path in [file_path, relative_path] { + path.str()?.to_str()?; + } + Err(PyRuntimeError::new_err("a model file path is not text")) + } +} + +/// `text` with the platform's path separator spelled `/`, as `PurePath.as_posix` spells it. +fn posix(text: &str) -> String { + text.replace(std::path::MAIN_SEPARATOR, "/") +} + +/// `text` as the Python string `cache` shares with every reader, built on first read. +pub(crate) fn projected_text<'py>( + py: Python<'py>, + cache: &PyOnceLock>, + text: &str, +) -> Bound<'py, PyString> { + cache + .get_or_init(py, || PyString::new(py, text).unbind()) + .bind(py) + .clone() +} + +/// A model header's authored values: native entries, with the Python dict built on first read. +pub(crate) struct HeaderValues { + pub(crate) native: Option>, + pub(crate) projected: PyOnceLock>, +} + +impl std::fmt::Debug for HeaderValues { + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + formatter + .debug_struct("HeaderValues") + .finish_non_exhaustive() + } +} + +impl HeaderValues { + pub(crate) fn native(values: Vec<(String, AuthoredValue)>) -> Self { + Self { + native: Some(values.into()), + projected: PyOnceLock::new(), + } + } + + pub(crate) fn given(py: Python<'_>, values: Py) -> Self { + let projected: PyOnceLock> = PyOnceLock::new(); + let _ = projected.set(py, values); + Self { + native: None, + projected, + } + } + + pub(crate) fn shared(&self, py: Python<'_>) -> Self { + let projected: PyOnceLock> = shared_projection(py, &self.projected); + Self { + native: self.native.clone(), + projected, + } + } + + pub(crate) fn dict<'py>(&self, py: Python<'py>) -> PyResult> { + Ok(self + .projected + .get_or_try_init(py, || { + let values: &[(String, AuthoredValue)] = self.native.as_deref().unwrap_or_default(); + map_to_python(py, values)? + .into_bound(py) + .downcast_into::() + .map(Bound::unbind) + .map_err(pyo3::PyErr::from) + })? + .bind(py) + .clone()) + } +} + +/// What native discovery read for one model file. +pub(crate) struct ModelFileParts { + pub(crate) contents: String, + pub(crate) header_values: Vec<(String, AuthoredValue)>, + pub(crate) header_column_locations: Vec<(String, LineColumnSpan)>, + pub(crate) output_column_locations: Vec<(String, LineColumnSpan)>, + pub(crate) query_sql: String, + pub(crate) extract_implicit_alias_columns: bool, +} + +/// How discovery names a model file: natively, or by Python paths for names Python escapes. +pub(crate) enum DiscoveredPaths { + /// The `/`-separated relative path and `str(project_dir / relative_path)`. + Native(String, String), + /// `(file_path, relative_path)` built by Python. + Python(Py, Py), +} + +/// A model file before its header declarations are attached. +pub(crate) struct PendingModelFile { + paths: ModelFilePaths, + parts: ModelFileParts, +} + +impl PendingModelFile { + pub(crate) fn new( + py: Python<'_>, + paths: DiscoveredPaths, + parts: ModelFileParts, + ) -> PyResult { + let paths: ModelFilePaths = match paths { + DiscoveredPaths::Native(relative_path, file_path) => { + ModelFilePaths::discovered(&relative_path, file_path) + } + DiscoveredPaths::Python(file_path, relative_path) => { + ModelFilePaths::given(py, file_path, relative_path)? + } + }; + Ok(Self { paths, parts }) + } + + /// The model's name, its file stem. + pub(crate) fn name(&self, py: Python<'_>) -> PyResult { + match &self.paths.texts { + Some(texts) => Ok(texts.name.clone()), + None => field(&self.paths.objects(py)?.0, STEM_ATTRIBUTE)?.extract(), + } + } + + /// The relative path as the Python path object the record keeps. + pub(crate) fn relative_path<'py>(&self, py: Python<'py>) -> PyResult> { + Ok(self.paths.objects(py)?.1) + } + + /// The authored header value of `key`. + pub(crate) fn header_value(&self, key: &str) -> Option<&AuthoredValue> { + self.parts + .header_values + .iter() + .rev() + .find(|(name, _)| name == key) + .map(|(_, value)| value) + } + + pub(crate) fn finished(self, declarations: (Py, Py)) -> NativeModelFile { + let (enum_declarations, constant_declarations) = declarations; + let parts: ModelFileParts = self.parts; + NativeModelFile { + paths: self.paths, + contents: parts.contents.into(), + projected_texts: (PyOnceLock::new(), PyOnceLock::new()), + header_values: HeaderValues::native(parts.header_values), + header_column_locations: Locations::from_rows(parts.header_column_locations), + output_column_locations: Locations::from_rows(parts.output_column_locations), + query_sql: parts.query_sql.into(), + enum_declarations, + constant_declarations, + extract_implicit_alias_columns: parts.extract_implicit_alias_columns, + } + } +} + +/// The keyword fields Python constructs a model file record with. +#[derive(FromPyObject)] +#[pyo3(from_item_all)] +pub(crate) struct ModelFileFields { + pub(crate) file_path: Py, + pub(crate) relative_path: Py, + pub(crate) contents: Py, + pub(crate) header_values: Py, + pub(crate) header_column_locations: Py, + pub(crate) output_column_locations: Py, + pub(crate) query_sql: Py, + #[pyo3(default)] + pub(crate) enum_declarations: Option>, + #[pyo3(default)] + pub(crate) constant_declarations: Option>, + #[pyo3(default = true)] + pub(crate) extract_implicit_alias_columns: bool, +} + +/// A new cache holding the dict `projected` already holds, if Python has read it. +fn shared_projection(py: Python<'_>, projected: &PyOnceLock>) -> PyOnceLock> { + let shared: PyOnceLock> = PyOnceLock::new(); + if let Some(dict) = projected.get(py) { + let _ = shared.set(py, dict.clone_ref(py)); + } + shared +} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/model_records.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/records/model_records.rs similarity index 88% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/model_records.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/records/model_records.rs index 9c8b60bc56..606e49bb74 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/model_records.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/records/model_records.rs @@ -1,5 +1,6 @@ //! SQL model files discovered natively and built as Python discovery records. +use crate::discovery::models::ModelFileSelection; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyModule, PyModuleMethods, PyResult, Python}; use pyo3::types::{PyDict, PyString, PyTuple}; use pyo3::{IntoPyObject, pyfunction, wrap_pyfunction}; @@ -9,12 +10,18 @@ use sqlbuild_discovery::model_files::models::{DiscoveredModelFile, ModelFileOpti use sqlbuild_discovery::models::{DiscoveredFile, FileOutcome, StageFailure}; use std::path::Path; -use crate::bindings::_helpers::discovery::faults::{FileFaults, record_tuple}; -use crate::bindings::_helpers::discovery::model_file_record::DiscoveredPaths; -use crate::bindings::_helpers::discovery::project_files::{model_record, path_object}; -use crate::bindings::_helpers::discovery::raised::{failure_error, read_error, stage_error}; -use crate::bindings::_helpers::discovery::snapshot::{in_snapshot, project_root, project_tree}; -use crate::bindings::models::NativeProjectTree; +use crate::discovery::_helpers::failures::faults::FileFaults; +use crate::discovery::_helpers::failures::faults::record_tuple; +use crate::discovery::_helpers::failures::raised::failure_error; +use crate::discovery::_helpers::failures::raised::read_error; +use crate::discovery::_helpers::failures::raised::stage_error; +use crate::discovery::_helpers::project::project_files::model_record; +use crate::discovery::_helpers::project::project_files::path_object; +use crate::discovery::_helpers::records::model_file_record::DiscoveredPaths; +use crate::discovery::_helpers::snapshots::native_classes::NativeProjectTree; +use crate::discovery::_helpers::snapshots::snapshot::in_snapshot; +use crate::discovery::_helpers::snapshots::snapshot::project_root; +use crate::discovery::_helpers::snapshots::snapshot::project_tree; use sqlbuild_discovery::model_files::main::model_file_options::model_file_options; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::models::KeywordArguments; @@ -69,7 +76,7 @@ fn model_items<'py>( for file in files { let raw: bool = tree.get().inner.raw_relative(&file.relative_path).is_some(); if !raw && let FileOutcome::Parsed(model) = file.outcome { - crate::bindings::_helpers::discovery::header_keys::record_header_keys( + crate::discovery::_helpers::headers::header_keys::record_header_keys( &file.relative_path, &model.header_values, ); @@ -100,12 +107,6 @@ fn model_items<'py>( }) } -/// Which discovered model files to build, and where failing files are reported. -pub(crate) struct ModelFileSelection<'py> { - pub(crate) selected_model_names: Option>, - pub(crate) on_fault: Option>, -} - /// The (selected) model files; `extraction` is `(implicit alias columns, output locations)`. pub(crate) fn discovered_model_files<'py>( project_dir: &Bound<'py, PyAny>, diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/sql_test_records.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/records/sql_test_records.rs similarity index 93% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/sql_test_records.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/records/sql_test_records.rs index 5ce345c80d..1dd3ed910b 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/sql_test_records.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/records/sql_test_records.rs @@ -16,17 +16,20 @@ use sqlbuild_discovery::sql_tests::models::{ use sqlbuild_discovery::tree::models::ProjectTree; use sqlbuild_model_config::execution_limits::main::parse_execution_limit::parse_execution_limit; -use crate::bindings::_helpers::discovery::faults::{FileFaults, record_tuple}; -use crate::bindings::_helpers::discovery::project_files::path_object; -use crate::bindings::_helpers::discovery::raised::{ - discovery_error, failure_error, read_error, stage_error, -}; -use crate::bindings::_helpers::discovery::snapshot::{in_snapshot, project_root, project_tree}; -use crate::bindings::_helpers::discovery::sql_test_blocks::{ - sql_test_block_records, validate_block_names, -}; -use crate::bindings::_helpers::sqltext::authored_values::map_to_python; -use crate::bindings::models::NativeProjectTree; +use crate::discovery::_helpers::failures::faults::FileFaults; +use crate::discovery::_helpers::failures::faults::record_tuple; +use crate::discovery::_helpers::failures::raised::discovery_error; +use crate::discovery::_helpers::failures::raised::failure_error; +use crate::discovery::_helpers::failures::raised::read_error; +use crate::discovery::_helpers::failures::raised::stage_error; +use crate::discovery::_helpers::project::project_files::path_object; +use crate::discovery::_helpers::snapshots::native_classes::NativeProjectTree; +use crate::discovery::_helpers::snapshots::snapshot::in_snapshot; +use crate::discovery::_helpers::snapshots::snapshot::project_root; +use crate::discovery::_helpers::snapshots::snapshot::project_tree; +use crate::discovery::_helpers::sources::sql_test_blocks::sql_test_block_records; +use crate::discovery::_helpers::sources::sql_test_blocks::validate_block_names; +use crate::sqltext::main::map_to_python::map_to_python; use sqlbuild_discovery::constants; use sqlbuild_discovery::sql_tests::main::sql_test_file_options::sql_test_file_options; use sqlbuild_python_base::boundary::main::imported::imported; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/yaml_records.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/records/yaml_records.rs similarity index 93% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/yaml_records.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/records/yaml_records.rs index 5db87ecd59..964e001533 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/yaml_records.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/records/yaml_records.rs @@ -17,18 +17,21 @@ use sqlbuild_discovery::yaml_files::models::{YamlFileOutcome, YamlPathFailure}; use sqlbuild_python_base::compile_context::main::yaml_cache::retain_read_sources::retain_read_sources; use std::path::PathBuf; -use crate::bindings::_helpers::discovery::faults::{FileFaults, record_tuple}; -use crate::bindings::_helpers::discovery::project_files::path_object; -use crate::bindings::_helpers::discovery::raised::{ - discovery_error, failure_error, read_error, stage_error, -}; -use crate::bindings::_helpers::discovery::snapshot::{ - escaped, in_snapshot, project_root, project_tree, -}; -use crate::bindings::_helpers::discovery::yaml_entries::{ - parse_schema_document, parse_sources_document, -}; -use crate::bindings::models::{NativeProjectTree, YamlDiscoveryRequest}; +use crate::discovery::_helpers::failures::faults::FileFaults; +use crate::discovery::_helpers::failures::faults::record_tuple; +use crate::discovery::_helpers::failures::raised::discovery_error; +use crate::discovery::_helpers::failures::raised::failure_error; +use crate::discovery::_helpers::failures::raised::read_error; +use crate::discovery::_helpers::failures::raised::stage_error; +use crate::discovery::_helpers::project::project_files::path_object; +use crate::discovery::_helpers::snapshots::native_classes::NativeProjectTree; +use crate::discovery::_helpers::snapshots::native_classes::YamlDiscoveryRequest; +use crate::discovery::_helpers::snapshots::snapshot::escaped; +use crate::discovery::_helpers::snapshots::snapshot::in_snapshot; +use crate::discovery::_helpers::snapshots::snapshot::project_root; +use crate::discovery::_helpers::snapshots::snapshot::project_tree; +use crate::discovery::_helpers::sources::yaml_entries::parse_schema_document; +use crate::discovery::_helpers::sources::yaml_entries::parse_sources_document; use sqlbuild_python_base::boundary::main::config_value_to_python::config_value_to_python; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; diff --git a/crates/sqlbuild-python-front/src/discovery/_helpers/snapshots/mod.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/snapshots/mod.rs new file mode 100644 index 0000000000..6fa2f0f6ac --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/snapshots/mod.rs @@ -0,0 +1,3 @@ +pub(crate) mod native_classes; +pub(crate) mod scope_snapshot; +pub(crate) mod snapshot; diff --git a/crates/sqlbuild-python-front/src/discovery/_helpers/snapshots/native_classes.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/snapshots/native_classes.rs new file mode 100644 index 0000000000..6d3dca266f --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/snapshots/native_classes.rs @@ -0,0 +1,55 @@ +//! Discovery's Python classes and the mapping requests its native calls read. + +use pyo3::{FromPyObject, pyclass}; + +/// The directory listings one discovery pass shares across its native calls. +#[pyclass(module = "sqlbuild._native", frozen)] +#[derive(Debug)] +pub(crate) struct NativeProjectTree { + pub(crate) inner: sqlbuild_discovery::tree::models::ProjectTree, +} + +/// One discovery pass of a project: the memo its native calls share, active inside its scope. +#[pyclass(module = "sqlbuild._native", frozen)] +#[derive(Debug)] +pub(crate) struct NativeDirectorySnapshot { + pub(crate) project_dir: pyo3::Py, + pub(crate) memo: pyo3::Py, +} + +/// One native YAML file discovery request; `kind` is `source` or `schema`. +#[derive(FromPyObject, Debug)] +#[pyo3(from_item_all)] +pub(crate) struct YamlDiscoveryRequest { + pub(crate) project_dir: String, + pub(crate) display_prefix: String, + pub(crate) kind: String, +} + +/// One in-memory SQL model parse request; `file_path` is the path messages name. +#[derive(FromPyObject, Debug)] +#[pyo3(from_item_all)] +pub(crate) struct ModelTextRequest { + pub(crate) file_path: String, + pub(crate) supported_keys: Vec, + pub(crate) removed_keys: Vec, + pub(crate) extract_implicit_alias_columns: bool, + pub(crate) extract_output_column_locations: bool, +} + +/// The declaration collections one Python discovery pass read natively, kept for later stages. +#[pyclass(module = "sqlbuild._native", frozen)] +#[derive(Debug)] +pub(crate) struct NativeDiscoverySession { + pub(crate) inner: sqlbuild_discovery::declaration_files::models::DiscoverySession, +} + +/// One in-memory declaration file parse request; `kind` names the collection it belongs to. +#[derive(FromPyObject, Debug)] +#[pyo3(from_item_all)] +pub(crate) struct DeclarationTextRequest { + pub(crate) kind: String, + pub(crate) function_keys: Vec, + pub(crate) audit_keys: Vec, + pub(crate) hook_keys: Vec, +} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/scope_snapshot.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/snapshots/scope_snapshot.rs similarity index 88% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/scope_snapshot.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/snapshots/scope_snapshot.rs index 4be9b1b1b5..ccffda6237 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/scope_snapshot.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/snapshots/scope_snapshot.rs @@ -7,21 +7,22 @@ use pyo3::prelude::{ use pyo3::types::{PyDict, PyDictMethods, PyList, PyListMethods, PyString, PyTuple}; use pyo3::{pyfunction, wrap_pyfunction}; -use crate::bindings::_helpers::discovery::declaration_records::{ - discover_audit_files, discover_constant_files, discover_enum_files, discover_macro_files, - discover_model_schema_files, discover_sql_function_files, discover_sql_hook_files, path_class, -}; -use crate::bindings::_helpers::discovery::model_records::{ - ModelFileSelection, discovered_model_files, -}; -use crate::bindings::_helpers::discovery::project_config::{ - load_local_config_file, load_project_config_file, -}; -use crate::bindings::_helpers::discovery::snapshot::in_snapshot; -use crate::bindings::_helpers::discovery::sql_test_records::{ - discover_scenario_files, discover_test_files, -}; -use crate::bindings::_helpers::discovery::yaml_records::discover_source_files; +use crate::discovery::_helpers::project::project_config::load_local_config_file; +use crate::discovery::_helpers::project::project_config::load_project_config_file; +use crate::discovery::_helpers::records::declaration_records::discover_audit_files; +use crate::discovery::_helpers::records::declaration_records::discover_constant_files; +use crate::discovery::_helpers::records::declaration_records::discover_enum_files; +use crate::discovery::_helpers::records::declaration_records::discover_macro_files; +use crate::discovery::_helpers::records::declaration_records::discover_model_schema_files; +use crate::discovery::_helpers::records::declaration_records::discover_sql_function_files; +use crate::discovery::_helpers::records::declaration_records::discover_sql_hook_files; +use crate::discovery::_helpers::records::declaration_records::path_class; +use crate::discovery::_helpers::records::model_records::discovered_model_files; +use crate::discovery::_helpers::records::sql_test_records::discover_scenario_files; +use crate::discovery::_helpers::records::sql_test_records::discover_test_files; +use crate::discovery::_helpers::records::yaml_records::discover_source_files; +use crate::discovery::_helpers::snapshots::snapshot::in_snapshot; +use crate::discovery::models::ModelFileSelection; use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/snapshot.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/snapshots/snapshot.rs similarity index 96% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/snapshot.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/snapshots/snapshot.rs index 82b5c7185e..a8d137b27b 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/snapshot.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/snapshots/snapshot.rs @@ -11,10 +11,10 @@ use sqlbuild_discovery::tree::models::ProjectTree; use sqlbuild_python_base::boundary::main::context_variable::context_variable; use std::path::PathBuf; -use crate::bindings::_helpers::discovery::raised::discovery_error; -use crate::bindings::models::{ - NativeDirectorySnapshot, NativeDirectorySnapshotScope, NativeProjectTree, -}; +use crate::discovery::_helpers::failures::raised::discovery_error; +use crate::discovery::_helpers::snapshots::native_classes::NativeDirectorySnapshot; +use crate::discovery::_helpers::snapshots::native_classes::NativeProjectTree; +use crate::discovery::models::NativeDirectorySnapshotScope; const SNAPSHOT_VARIABLE: &str = "sqlbuild_directory_snapshot"; const TREE_MEMO_KEY: &str = "native_project_tree"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/declaration_files.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/sources/declaration_files.rs similarity index 93% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/declaration_files.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/sources/declaration_files.rs index 97cd48cae0..029e093f42 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/declaration_files.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/sources/declaration_files.rs @@ -9,7 +9,8 @@ use sqlbuild_discovery::declaration_files::models::{ }; use sqlbuild_discovery::models::FileOutcome; -use crate::bindings::models::{DeclarationTextRequest, NativeDiscoverySession}; +use crate::discovery::_helpers::snapshots::native_classes::DeclarationTextRequest; +use crate::discovery::_helpers::snapshots::native_classes::NativeDiscoverySession; use sqlbuild_python_base::types::CompilerDetach; const PARSED_TAG: &str = "ok"; diff --git a/crates/sqlbuild-python-front/src/discovery/_helpers/sources/mod.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/sources/mod.rs new file mode 100644 index 0000000000..73b1922f12 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/sources/mod.rs @@ -0,0 +1,6 @@ +pub(crate) mod declaration_files; +pub(crate) mod orchestration_files; +pub(crate) mod orchestration_values; +pub(crate) mod provider_secrets; +pub(crate) mod sql_test_blocks; +pub(crate) mod yaml_entries; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/orchestration_files.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/sources/orchestration_files.rs similarity index 85% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/orchestration_files.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/sources/orchestration_files.rs index 91ec165356..43e1733cdd 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/orchestration_files.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/sources/orchestration_files.rs @@ -9,10 +9,10 @@ use sqlbuild_discovery::orchestration_files::models::{ }; use sqlbuild_discovery::tree::models::ProjectTree; -use crate::bindings::_helpers::discovery::orchestration_values::check_orchestration_values; -use crate::bindings::_helpers::discovery::raised::{ - failure_error, relative_read_error, stage_error, -}; +use crate::discovery::_helpers::failures::raised::failure_error; +use crate::discovery::_helpers::failures::raised::relative_read_error; +use crate::discovery::_helpers::failures::raised::stage_error; +use crate::discovery::_helpers::sources::orchestration_values::check_orchestration_values; /// Every job, job group, calendar and sensor of `project_dir`, or `OrchestrationDeclarationError` (D017). pub(crate) fn orchestration_declarations( diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/orchestration_values.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/sources/orchestration_values.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/orchestration_values.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/sources/orchestration_values.rs diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/provider_secrets.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/sources/provider_secrets.rs similarity index 76% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/provider_secrets.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/sources/provider_secrets.rs index e80a1f7e5a..2b83ef870b 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/provider_secrets.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/sources/provider_secrets.rs @@ -2,7 +2,6 @@ use std::cell::Cell; -use pyo3::exceptions::PyValueError; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; use sqlbuild_python_base::orchestration_reads::main::missing_secrets::missing_secrets; @@ -15,26 +14,7 @@ const SINK_COLLECTIONS: [&str; 2] = ["event_exporters", "command_output_sinks"]; thread_local! { /// Whether the invocation running on this thread passed `--allow-missing-secrets`. - static INVOCATION_ALLOWS_MISSING_SECRETS: Cell = const { Cell::new(false) }; -} - -/// `--allow-missing-secrets` for one invocation, restored when the invocation ends. -pub(crate) struct MissingSecretsScope { - previous: bool, -} - -impl MissingSecretsScope { - pub(crate) fn enter(allowed: bool) -> Self { - Self { - previous: INVOCATION_ALLOWS_MISSING_SECRETS.replace(allowed), - } - } -} - -impl Drop for MissingSecretsScope { - fn drop(&mut self) { - INVOCATION_ALLOWS_MISSING_SECRETS.set(self.previous); - } + pub(crate) static INVOCATION_ALLOWS_MISSING_SECRETS: Cell = const { Cell::new(false) }; } /// Whether the running invocation passed `--allow-missing-secrets`. @@ -42,35 +22,6 @@ pub(crate) fn invocation_allows_missing_secrets() -> bool { INVOCATION_ALLOWS_MISSING_SECRETS.get() } -/// What discovery does when a provider's required secrets are unset. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub(crate) enum SecretPolicy { - /// Fail with D012: static commands by default. - Require, - /// Continue and list the providers on stderr: static commands that opted out. - Allow, - /// Continue silently; the command checks the providers it uses before running anything. - Defer, -} - -impl SecretPolicy { - /// The keyword value that selects the policy. - pub(crate) const fn name(self) -> &'static str { - match self { - Self::Require => "require", - Self::Allow => "allow", - Self::Defer => "defer", - } - } - - pub(crate) fn parse(value: &str) -> PyResult { - [Self::Require, Self::Allow, Self::Defer] - .into_iter() - .find(|policy| policy.name() == value) - .ok_or_else(|| PyValueError::new_err(format!("unknown secret policy '{value}'"))) - } -} - /// `(provider, consumer)` for each usage, named by the usage's own `consumer_name` or else by `consumer`. pub(crate) fn provider_uses( usages: &Bound<'_, PyAny>, diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/sql_test_blocks.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/sources/sql_test_blocks.rs similarity index 97% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/sql_test_blocks.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/sources/sql_test_blocks.rs index 935e061d38..927a0d89ce 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/sql_test_blocks.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/sources/sql_test_blocks.rs @@ -14,9 +14,9 @@ use sqlbuild_model_config::sql_tests::main::sql_test_names_failure::sql_test_nam use sqlbuild_model_config::sql_tests::models::{SqlTestBlock, SqlTestCase}; use sqlbuild_model_config::sql_values::models::{RawKey, RawSqlValue}; -use crate::bindings::_helpers::authored_values::sql_values::{ - SqlValueClasses, raw_value, sql_value, -}; +use crate::authored_values::main::raw_value::raw_value; +use crate::authored_values::main::sql_value::sql_value; +use crate::authored_values::models::SqlValueClasses; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::construct::enum_from_value::enum_from_value; use sqlbuild_python_base::records::main::construct::error_class::error_class; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/yaml_entries.rs b/crates/sqlbuild-python-front/src/discovery/_helpers/sources/yaml_entries.rs similarity index 98% rename from crates/sqlbuild-python/src/bindings/_helpers/discovery/yaml_entries.rs rename to crates/sqlbuild-python-front/src/discovery/_helpers/sources/yaml_entries.rs index e04bf5ca27..74a8d6921f 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/yaml_entries.rs +++ b/crates/sqlbuild-python-front/src/discovery/_helpers/sources/yaml_entries.rs @@ -13,9 +13,10 @@ use sqlbuild_discovery::yaml_entries::models::{ }; use sqlbuild_model_config::errors::{ConfigError, ErrorClass}; -use crate::bindings::_helpers::model_config::authored_nodes::PyNode; -use crate::bindings::_helpers::model_config::contract_classes::yaml_entry_classes; -use crate::bindings::_helpers::model_config::header_metadata::{ContractClasses, audit_tuple}; +use crate::model_config::main::headers::audit_tuple::audit_tuple; +use crate::model_config::main::model_nodes::yaml_entry_classes::yaml_entry_classes; +use crate::model_config::models::ContractClasses; +use crate::model_config::models::PyNode; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::types::ErrorId; diff --git a/crates/sqlbuild-python-front/src/discovery/constants.rs b/crates/sqlbuild-python-front/src/discovery/constants.rs new file mode 100644 index 0000000000..0f5b228000 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/constants.rs @@ -0,0 +1,42 @@ +//! Public constants of discovery. + +use crate::discovery::_helpers::records::getters::read_native_directory_snapshot; +use crate::discovery::_helpers::records::getters::read_native_model_file; +use crate::discovery::_helpers::snapshots::native_classes::NativeDirectorySnapshot; +use crate::discovery::models::NativeModelFile; +use sqlbuild_python_base::records::main::registry::class_of::class_of; +use sqlbuild_python_base::records::models::GetterEntry; + +/// The fields a SQL hook entry reports, in output order. +pub const SQL_HOOK_OUTPUT_FIELDS: [&str; 6] = [ + "statement", + "name", + "relative_path", + "definition_sql", + "kwargs", + "description", +]; + +/// The flag of the static commands that lets them compile without provider secrets. +pub(crate) const ALLOW_MISSING_SECRETS_FLAG: &str = "--allow-missing-secrets"; + +/// The environment variable that sets `--allow-missing-secrets`. +pub const ALLOW_MISSING_SECRETS_ENV: &str = "SQLBUILD_ALLOW_MISSING_SECRETS"; + +/// The `[settings]` key of `sqlbuild_local.toml` that sets `--allow-missing-secrets`. +pub const ALLOW_MISSING_SECRETS_SETTING: &str = "allow_missing_secrets"; + +/// Environment values that switch a boolean `SQLBUILD_*` variable on. +pub const TRUE_ENV_VALUES: [&str; 4] = ["1", "on", "true", "yes"]; + +/// The getter readers of this module's native pyclasses. +pub const GETTERS: &[GetterEntry] = &[ + GetterEntry { + class: class_of::, + read: read_native_model_file, + }, + GetterEntry { + class: class_of::, + read: read_native_directory_snapshot, + }, +]; diff --git a/crates/sqlbuild-python-front/src/discovery/main/failures/explicit_references_help.rs b/crates/sqlbuild-python-front/src/discovery/main/failures/explicit_references_help.rs new file mode 100644 index 0000000000..9fbbcfeb55 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/failures/explicit_references_help.rs @@ -0,0 +1,9 @@ +//! Explicit references help. + +use crate::discovery::_helpers::failures::guidance; + +/// Explicit references help. +#[inline] +pub fn explicit_references_help(allowed: &str) -> String { + guidance::explicit_references_help(allowed) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/failures/microbatch_guidance.rs b/crates/sqlbuild-python-front/src/discovery/main/failures/microbatch_guidance.rs new file mode 100644 index 0000000000..6b6a9694f2 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/failures/microbatch_guidance.rs @@ -0,0 +1,9 @@ +//! Microbatch guidance. + +use crate::discovery::_helpers::failures::guidance; + +/// Microbatch guidance. +#[inline] +pub fn microbatch_guidance() -> (String, String) { + guidance::microbatch_guidance() +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/failures/mod.rs b/crates/sqlbuild-python-front/src/discovery/main/failures/mod.rs new file mode 100644 index 0000000000..c845fc4dea --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/failures/mod.rs @@ -0,0 +1,6 @@ +pub mod explicit_references_help; +pub mod microbatch_guidance; +pub mod register_guidance; +pub mod register_raised; +pub mod setting_help; +pub mod sql_analysis_guidance; diff --git a/crates/sqlbuild-python-front/src/discovery/main/failures/register_guidance.rs b/crates/sqlbuild-python-front/src/discovery/main/failures/register_guidance.rs new file mode 100644 index 0000000000..1de4ee6af6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/failures/register_guidance.rs @@ -0,0 +1,12 @@ +//! Register the guidance functions and classes. + +use crate::discovery::_helpers::failures::guidance; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the guidance functions and classes. +#[inline] +pub fn register_guidance(module: &Bound<'_, PyModule>) -> PyResult<()> { + guidance::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/failures/register_raised.rs b/crates/sqlbuild-python-front/src/discovery/main/failures/register_raised.rs new file mode 100644 index 0000000000..923c3390b6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/failures/register_raised.rs @@ -0,0 +1,12 @@ +//! Register the raised functions and classes. + +use crate::discovery::_helpers::failures::raised; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the raised functions and classes. +#[inline] +pub fn register_raised(module: &Bound<'_, PyModule>) -> PyResult<()> { + raised::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/failures/setting_help.rs b/crates/sqlbuild-python-front/src/discovery/main/failures/setting_help.rs new file mode 100644 index 0000000000..e63a8de597 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/failures/setting_help.rs @@ -0,0 +1,13 @@ +//! Render `, set this in :` followed by the exact TOML section and key. + +use crate::discovery::_helpers::failures::guidance; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::types::PyDict; + +/// Render `, set this in :` followed by the exact TOML section and key. +#[inline] +pub fn setting_help<'py>(py: Python<'py>, options: Option>) -> PyResult { + guidance::setting_help(py, options) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/failures/sql_analysis_guidance.rs b/crates/sqlbuild-python-front/src/discovery/main/failures/sql_analysis_guidance.rs new file mode 100644 index 0000000000..4073b59569 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/failures/sql_analysis_guidance.rs @@ -0,0 +1,15 @@ +//! The note and help for turning SQL analysis on, or `None` when it is effectively on. + +use crate::discovery::_helpers::failures::guidance; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// The note and help for turning SQL analysis on, or `None` when it is effectively on. +#[inline] +pub fn sql_analysis_guidance( + discovered_inputs: &Bound<'_, PyAny>, + purpose: &str, +) -> PyResult> { + guidance::sql_analysis_guidance(discovered_inputs, purpose) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/headers/hook_entries.rs b/crates/sqlbuild-python-front/src/discovery/main/headers/hook_entries.rs new file mode 100644 index 0000000000..5467e5d106 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/headers/hook_entries.rs @@ -0,0 +1,18 @@ +//! Serialize SQL and Python hook entries; other values serialize to no hooks. + +use crate::discovery::_helpers::headers::hook_entries; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyDict; +use pyo3::types::PyList; + +/// Serialize SQL and Python hook entries; other values serialize to no hooks. +#[inline] +pub fn hook_entries<'py>( + value: &Bound<'py, PyAny>, + sql_fields: &[String], + python_hook_fields: Option<&Bound<'py, PyDict>>, +) -> PyResult> { + hook_entries::hook_entries(value, sql_fields, python_hook_fields) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/headers/mod.rs b/crates/sqlbuild-python-front/src/discovery/main/headers/mod.rs new file mode 100644 index 0000000000..e0c664d7db --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/headers/mod.rs @@ -0,0 +1,5 @@ +pub mod hook_entries; +pub mod register_header_declarations; +pub mod register_header_values; +pub mod register_hook_entries; +pub mod register_key_checks; diff --git a/crates/sqlbuild-python-front/src/discovery/main/headers/register_header_declarations.rs b/crates/sqlbuild-python-front/src/discovery/main/headers/register_header_declarations.rs new file mode 100644 index 0000000000..fda14402b4 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/headers/register_header_declarations.rs @@ -0,0 +1,12 @@ +//! Register the header declarations functions and classes. + +use crate::discovery::_helpers::headers::header_declarations; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the header declarations functions and classes. +#[inline] +pub fn register_header_declarations(module: &Bound<'_, PyModule>) -> PyResult<()> { + header_declarations::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/headers/register_header_values.rs b/crates/sqlbuild-python-front/src/discovery/main/headers/register_header_values.rs new file mode 100644 index 0000000000..ae668cb5c5 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/headers/register_header_values.rs @@ -0,0 +1,12 @@ +//! Register the header values functions and classes. + +use crate::discovery::_helpers::headers::header_values; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the header values functions and classes. +#[inline] +pub fn register_header_values(module: &Bound<'_, PyModule>) -> PyResult<()> { + header_values::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/headers/register_hook_entries.rs b/crates/sqlbuild-python-front/src/discovery/main/headers/register_hook_entries.rs new file mode 100644 index 0000000000..cd409be58a --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/headers/register_hook_entries.rs @@ -0,0 +1,12 @@ +//! Register the hook entries functions and classes. + +use crate::discovery::_helpers::headers::hook_entries; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the hook entries functions and classes. +#[inline] +pub fn register_hook_entries(module: &Bound<'_, PyModule>) -> PyResult<()> { + hook_entries::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/headers/register_key_checks.rs b/crates/sqlbuild-python-front/src/discovery/main/headers/register_key_checks.rs new file mode 100644 index 0000000000..c09f4fc734 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/headers/register_key_checks.rs @@ -0,0 +1,12 @@ +//! Register the key checks functions and classes. + +use crate::discovery::_helpers::headers::key_checks; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the key checks functions and classes. +#[inline] +pub fn register_key_checks(module: &Bound<'_, PyModule>) -> PyResult<()> { + key_checks::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/mod.rs b/crates/sqlbuild-python-front/src/discovery/main/mod.rs new file mode 100644 index 0000000000..6955d56242 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/mod.rs @@ -0,0 +1,7 @@ +pub mod failures; +pub mod headers; +pub mod project; +pub mod python_files; +pub mod records; +pub mod snapshots; +pub mod sources; diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/column_name.rs b/crates/sqlbuild-python-front/src/discovery/main/project/column_name.rs new file mode 100644 index 0000000000..6c6a3da67e --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/column_name.rs @@ -0,0 +1,12 @@ +//! Column name. + +use crate::discovery::_helpers::project::project_facts; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Column name. +#[inline] +pub fn column_name(column: &Bound<'_, PyAny>) -> PyResult { + project_facts::column_name(column) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/configured_changes.rs b/crates/sqlbuild-python-front/src/discovery/main/project/configured_changes.rs new file mode 100644 index 0000000000..c647110437 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/configured_changes.rs @@ -0,0 +1,13 @@ +//! `[changes]` of the project at `project_dir`: what `--changed` counts and reaches by default. + +use crate::discovery::_helpers::project::project_config; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_config::project::models::ChangesConfig; + +/// `[changes]` of the project at `project_dir`: what `--changed` counts and reaches by default. +#[inline] +pub fn configured_changes(project_dir: &Bound<'_, PyAny>) -> PyResult { + project_config::configured_changes(project_dir) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/configured_git_base_ref.rs b/crates/sqlbuild-python-front/src/discovery/main/project/configured_git_base_ref.rs new file mode 100644 index 0000000000..453f1ecffe --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/configured_git_base_ref.rs @@ -0,0 +1,12 @@ +//! `[git] base_ref` of the project at `project_dir`, which `--since @base` names. + +use crate::discovery::_helpers::project::project_config; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// `[git] base_ref` of the project at `project_dir`, which `--since @base` names. +#[inline] +pub fn configured_git_base_ref(project_dir: &Bound<'_, PyAny>) -> PyResult> { + project_config::configured_git_base_ref(project_dir) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/configured_review.rs b/crates/sqlbuild-python-front/src/discovery/main/project/configured_review.rs new file mode 100644 index 0000000000..37b4f3abc4 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/configured_review.rs @@ -0,0 +1,13 @@ +//! `[review]` of the project at `project_dir`: the defaults `sqb review` falls back to. + +use crate::discovery::_helpers::project::project_config; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_config::project::models::ReviewConfig; + +/// `[review]` of the project at `project_dir`: the defaults `sqb review` falls back to. +#[inline] +pub fn configured_review(project_dir: &Bound<'_, PyAny>) -> PyResult { + project_config::configured_review(project_dir) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/discover_configured_providers.rs b/crates/sqlbuild-python-front/src/discovery/main/project/discover_configured_providers.rs new file mode 100644 index 0000000000..5a7dc7607d --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/discover_configured_providers.rs @@ -0,0 +1,18 @@ +//! The configuration with discovery's checks and warnings, and the provider classes, without importing any other project Python. + +use crate::discovery::_helpers::project::configuration; +use crate::discovery::models::SecretPolicy; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// The configuration with discovery's checks and warnings, and the provider classes, without importing any other project Python. +#[inline] +pub fn discover_configured_providers<'py>( + py: Python<'py>, + project_dir: &Bound<'py, PyAny>, + secret_policy: SecretPolicy, +) -> PyResult> { + configuration::discover_configured_providers(py, project_dir, secret_policy) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/discover_connection_configuration.rs b/crates/sqlbuild-python-front/src/discovery/main/project/discover_connection_configuration.rs new file mode 100644 index 0000000000..72edfe0943 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/discover_connection_configuration.rs @@ -0,0 +1,16 @@ +//! The validated configuration without a discovery lifecycle, which reading two files never needs. + +use crate::discovery::_helpers::project::configuration; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// The validated configuration without a discovery lifecycle, which reading two files never needs. +#[inline] +pub fn discover_connection_configuration<'py>( + py: Python<'py>, + project_dir: &Bound<'py, PyAny>, +) -> PyResult> { + configuration::discover_connection_configuration(py, project_dir) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/discover_project_configuration.rs b/crates/sqlbuild-python-front/src/discovery/main/project/discover_project_configuration.rs new file mode 100644 index 0000000000..cec76516c8 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/discover_project_configuration.rs @@ -0,0 +1,16 @@ +//! `DiscoveredProjectInputs` with the loaded configuration, inside the project discovery lifecycle. + +use crate::discovery::_helpers::project::configuration; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// `DiscoveredProjectInputs` with the loaded configuration, inside the project discovery lifecycle. +#[inline] +pub fn discover_project_configuration<'py>( + py: Python<'py>, + project_dir: &Bound<'py, PyAny>, +) -> PyResult> { + configuration::discover_project_configuration(py, project_dir) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/each.rs b/crates/sqlbuild-python-front/src/discovery/main/project/each.rs new file mode 100644 index 0000000000..55055191f5 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/each.rs @@ -0,0 +1,16 @@ +//! `read` applied to each item of the iterable attribute `name` of `owner`. + +use crate::discovery::_helpers::project::project_facts; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// `read` applied to each item of the iterable attribute `name` of `owner`. +#[inline] +pub fn each( + owner: &Bound<'_, PyAny>, + name: &str, + read: impl Fn(&Bound<'_, PyAny>) -> PyResult, +) -> PyResult> { + project_facts::each(owner, name, read) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/load_local_config_file.rs b/crates/sqlbuild-python-front/src/discovery/main/project/load_local_config_file.rs new file mode 100644 index 0000000000..cf145a6ad4 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/load_local_config_file.rs @@ -0,0 +1,17 @@ +//! `load_local_config`: the validated `LocalConfig` of `project_dir`, or the default. + +use crate::discovery::_helpers::project::project_config; +use pyo3::prelude::Bound; +use pyo3::prelude::Py; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// `load_local_config`: the validated `LocalConfig` of `project_dir`, or the default. +#[inline] +pub fn load_local_config_file( + py: Python<'_>, + project_dir: &Bound<'_, PyAny>, +) -> PyResult> { + project_config::load_local_config_file(py, project_dir) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/load_project_config_file.rs b/crates/sqlbuild-python-front/src/discovery/main/project/load_project_config_file.rs new file mode 100644 index 0000000000..e72087f8ec --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/load_project_config_file.rs @@ -0,0 +1,17 @@ +//! `load_project_config`: the validated `ProjectConfig` of `project_dir`. + +use crate::discovery::_helpers::project::project_config; +use pyo3::prelude::Bound; +use pyo3::prelude::Py; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// `load_project_config`: the validated `ProjectConfig` of `project_dir`. +#[inline] +pub fn load_project_config_file( + py: Python<'_>, + project_dir: &Bound<'_, PyAny>, +) -> PyResult> { + project_config::load_project_config_file(py, project_dir) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/mod.rs b/crates/sqlbuild-python-front/src/discovery/main/project/mod.rs new file mode 100644 index 0000000000..00673e75cd --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/mod.rs @@ -0,0 +1,23 @@ +pub mod column_name; +pub mod configured_changes; +pub mod configured_git_base_ref; +pub mod configured_review; +pub mod discover_configured_providers; +pub mod discover_connection_configuration; +pub mod discover_project_configuration; +pub mod each; +pub mod load_local_config_file; +pub mod load_project_config_file; +pub mod named_node_rows; +pub mod project_facts; +pub mod register_locations; +pub mod register_project_config; +pub mod register_project_files; +pub mod register_project_validation; +pub mod resolve_config_file_path; +pub mod seed_csv_settings; +pub mod stem; +pub mod validate_local_sql_analysis; +pub mod validation_error; +pub mod warn_deprecated_settings; +pub mod yaml_entry_line; diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/named_node_rows.rs b/crates/sqlbuild-python-front/src/discovery/main/project/named_node_rows.rs new file mode 100644 index 0000000000..c7291aa22e --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/named_node_rows.rs @@ -0,0 +1,13 @@ +//! The discovered Python nodes by kind, name and path only, as the resource-name check reads them. + +use crate::discovery::_helpers::project::project_facts; +use crate::discovery::models::NodeRow; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// The discovered Python nodes by kind, name and path only, as the resource-name check reads them. +#[inline] +pub fn named_node_rows(inputs: &Bound<'_, PyAny>) -> PyResult> { + project_facts::named_node_rows(inputs) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/project_facts.rs b/crates/sqlbuild-python-front/src/discovery/main/project/project_facts.rs new file mode 100644 index 0000000000..4cd226e6e7 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/project_facts.rs @@ -0,0 +1,19 @@ +//! The facts of `inputs`, with the Python nodes the facade has described. + +use crate::discovery::_helpers::project::project_facts; +use crate::discovery::models::NodeRow; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use sqlbuild_discovery::project_validation::models::ProjectFacts; + +/// The facts of `inputs`, with the Python nodes the facade has described. +#[inline] +pub fn project_facts( + py: Python<'_>, + inputs: &Bound<'_, PyAny>, + nodes: Vec, +) -> PyResult { + project_facts::project_facts(py, inputs, nodes) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/register_locations.rs b/crates/sqlbuild-python-front/src/discovery/main/project/register_locations.rs new file mode 100644 index 0000000000..8765670175 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/register_locations.rs @@ -0,0 +1,12 @@ +//! Register the locations functions and classes. + +use crate::discovery::_helpers::project::locations; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the locations functions and classes. +#[inline] +pub fn register_locations(module: &Bound<'_, PyModule>) -> PyResult<()> { + locations::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/register_project_config.rs b/crates/sqlbuild-python-front/src/discovery/main/project/register_project_config.rs new file mode 100644 index 0000000000..065654f6f6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/register_project_config.rs @@ -0,0 +1,12 @@ +//! Register the project config functions and classes. + +use crate::discovery::_helpers::project::project_config; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the project config functions and classes. +#[inline] +pub fn register_project_config(module: &Bound<'_, PyModule>) -> PyResult<()> { + project_config::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/register_project_files.rs b/crates/sqlbuild-python-front/src/discovery/main/project/register_project_files.rs new file mode 100644 index 0000000000..117895dbe5 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/register_project_files.rs @@ -0,0 +1,12 @@ +//! Whether native discovery reproduces the string semantics of this Python and Unicode version. + +use crate::discovery::_helpers::project::project_files; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Whether native discovery reproduces the string semantics of this Python and Unicode version. +#[inline] +pub fn register_project_files(module: &Bound<'_, PyModule>) -> PyResult<()> { + project_files::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/register_project_validation.rs b/crates/sqlbuild-python-front/src/discovery/main/project/register_project_validation.rs new file mode 100644 index 0000000000..b2f59cb128 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/register_project_validation.rs @@ -0,0 +1,12 @@ +//! Register the project validation functions and classes. + +use crate::discovery::_helpers::project::project_validation; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the project validation functions and classes. +#[inline] +pub fn register_project_validation(module: &Bound<'_, PyModule>) -> PyResult<()> { + project_validation::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/resolve_config_file_path.rs b/crates/sqlbuild-python-front/src/discovery/main/project/resolve_config_file_path.rs new file mode 100644 index 0000000000..72d5f0368a --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/resolve_config_file_path.rs @@ -0,0 +1,17 @@ +//! The project or local configuration file path, rejecting an unconverted legacy file. + +use crate::discovery::_helpers::project::project_config; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// The project or local configuration file path, rejecting an unconverted legacy file. +#[inline] +pub fn resolve_config_file_path<'py>( + py: Python<'py>, + project_dir: &Bound<'py, PyAny>, + local: bool, +) -> PyResult> { + project_config::resolve_config_file_path(py, project_dir, local) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/seed_csv_settings.rs b/crates/sqlbuild-python-front/src/discovery/main/project/seed_csv_settings.rs new file mode 100644 index 0000000000..c8f03c42c9 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/seed_csv_settings.rs @@ -0,0 +1,13 @@ +//! The CSV reader settings a seed declaration authors, without the dialect check. + +use crate::discovery::_helpers::project::project_facts; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_discovery::project_validation::models::CsvSettings; + +/// The CSV reader settings a seed declaration authors, without the dialect check. +#[inline] +pub fn seed_csv_settings(entry: &Bound<'_, PyAny>) -> PyResult { + project_facts::seed_csv_settings(entry) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/stem.rs b/crates/sqlbuild-python-front/src/discovery/main/project/stem.rs new file mode 100644 index 0000000000..aadcc56de9 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/stem.rs @@ -0,0 +1,12 @@ +//! `str(Path(...).stem)` of the path attribute `name`. + +use crate::discovery::_helpers::project::project_facts; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// `str(Path(...).stem)` of the path attribute `name`. +#[inline] +pub fn stem(owner: &Bound<'_, PyAny>, name: &str) -> PyResult { + project_facts::stem(owner, name) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/validate_local_sql_analysis.rs b/crates/sqlbuild-python-front/src/discovery/main/project/validate_local_sql_analysis.rs new file mode 100644 index 0000000000..9b0eb51bbd --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/validate_local_sql_analysis.rs @@ -0,0 +1,17 @@ +//! `validate_local_sql_analysis_policy` from the project requirement and the local setting. + +use crate::discovery::_helpers::project::project_config; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyErr; +use pyo3::prelude::Python; + +/// `validate_local_sql_analysis_policy` from the project requirement and the local setting. +#[inline] +pub fn validate_local_sql_analysis( + py: Python<'_>, + project_dir: &Bound<'_, PyAny>, + flags: (bool, bool, bool), +) -> Result<(), PyErr> { + project_config::validate_local_sql_analysis(py, project_dir, flags) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/validation_error.rs b/crates/sqlbuild-python-front/src/discovery/main/project/validation_error.rs new file mode 100644 index 0000000000..f8785d84ce --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/validation_error.rs @@ -0,0 +1,12 @@ +//! The Python exception a failed project validation raises. + +use crate::discovery::_helpers::project::project_validation; +use pyo3::prelude::PyErr; +use pyo3::prelude::Python; +use sqlbuild_discovery::project_validation::models::ValidationFailure; + +/// The Python exception a failed project validation raises. +#[inline] +pub fn validation_error(py: Python<'_>, failure: ValidationFailure) -> PyErr { + project_validation::validation_error(py, failure) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/warn_deprecated_settings.rs b/crates/sqlbuild-python-front/src/discovery/main/project/warn_deprecated_settings.rs new file mode 100644 index 0000000000..d3b3a3bf12 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/warn_deprecated_settings.rs @@ -0,0 +1,13 @@ +//! Write a warning line to stderr for each deprecated setting alias `project_dir` still sets. + +use crate::discovery::_helpers::project::project_config; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// Write a warning line to stderr for each deprecated setting alias `project_dir` still sets. +#[inline] +pub fn warn_deprecated_settings(py: Python<'_>, project_dir: &Bound<'_, PyAny>) -> PyResult<()> { + project_config::warn_deprecated_settings(py, project_dir) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/project/yaml_entry_line.rs b/crates/sqlbuild-python-front/src/discovery/main/project/yaml_entry_line.rs new file mode 100644 index 0000000000..b524063a91 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/project/yaml_entry_line.rs @@ -0,0 +1,9 @@ +//! The 1-based line of the outermost `- name: ` entry, if present. + +use crate::discovery::_helpers::project::locations; + +/// The 1-based line of the outermost `- name: ` entry, if present. +#[inline] +pub fn yaml_entry_line(contents: &str, name: &str) -> Option { + locations::yaml_entry_line(contents, name) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/python_files/discover_event_exporter_functions.rs b/crates/sqlbuild-python-front/src/discovery/main/python_files/discover_event_exporter_functions.rs new file mode 100644 index 0000000000..acb768a560 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/python_files/discover_event_exporter_functions.rs @@ -0,0 +1,15 @@ +//! Validated lifecycle-event sink declarations under sinks/, bound to providers; Recall replacement sinks are left out. + +use crate::discovery::_helpers::python_files::imported_providers; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Validated lifecycle-event sink declarations under sinks/, bound to providers; Recall replacement sinks are left out. +#[inline] +pub fn discover_event_exporter_functions<'py>( + project_dir: Bound<'py, PyAny>, + providers: Option>, +) -> PyResult> { + imported_providers::discover_event_exporter_functions(project_dir, providers) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/python_files/discover_hook_functions.rs b/crates/sqlbuild-python-front/src/discovery/main/python_files/discover_hook_functions.rs new file mode 100644 index 0000000000..f046e4db10 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/python_files/discover_hook_functions.rs @@ -0,0 +1,15 @@ +//! Decorated model lifecycle hook functions under hooks/python/. + +use crate::discovery::_helpers::python_files::imported_python_nodes; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Decorated model lifecycle hook functions under hooks/python/. +#[inline] +pub fn discover_hook_functions<'py>( + project_dir: Bound<'py, PyAny>, + providers: Option>, +) -> PyResult> { + imported_python_nodes::discover_hook_functions(project_dir, providers) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/python_files/discover_materialization_files.rs b/crates/sqlbuild-python-front/src/discovery/main/python_files/discover_materialization_files.rs new file mode 100644 index 0000000000..2b665bfcc1 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/python_files/discover_materialization_files.rs @@ -0,0 +1,15 @@ +//! Custom materialization Python files under materializations/. + +use crate::discovery::_helpers::python_files::imported_python_nodes; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Custom materialization Python files under materializations/. +#[inline] +pub fn discover_materialization_files<'py>( + project_dir: Bound<'py, PyAny>, + providers: Option>, +) -> PyResult> { + imported_python_nodes::discover_materialization_files(project_dir, providers) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/python_files/discover_provider_classes.rs b/crates/sqlbuild-python-front/src/discovery/main/python_files/discover_provider_classes.rs new file mode 100644 index 0000000000..c261a096ca --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/python_files/discover_provider_classes.rs @@ -0,0 +1,15 @@ +//! Provider classes under providers/. + +use crate::discovery::_helpers::python_files::imported_providers; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Provider classes under providers/. +#[inline] +pub fn discover_provider_classes<'py>( + project_dir: Bound<'py, PyAny>, + secret_policy: &str, +) -> PyResult> { + imported_providers::discover_provider_classes(project_dir, secret_policy) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/python_files/discover_python_function_files.rs b/crates/sqlbuild-python-front/src/discovery/main/python_files/discover_python_function_files.rs new file mode 100644 index 0000000000..89093f5de4 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/python_files/discover_python_function_files.rs @@ -0,0 +1,15 @@ +//! Discover the `@udf(...)` Python function files under `functions/python/`. + +use crate::discovery::_helpers::python_files::python_function_files; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// Discover the `@udf(...)` Python function files under `functions/python/`. +#[inline] +pub fn discover_python_function_files<'py>( + project_dir: &Bound<'py, PyAny>, +) -> PyResult> { + python_function_files::discover_python_function_files(project_dir) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/python_files/discover_python_node_functions.rs b/crates/sqlbuild-python-front/src/discovery/main/python_files/discover_python_node_functions.rs new file mode 100644 index 0000000000..ab6f9875ce --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/python_files/discover_python_node_functions.rs @@ -0,0 +1,15 @@ +//! Decorated Python DAG node functions under python/. + +use crate::discovery::_helpers::python_files::imported_python_nodes; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Decorated Python DAG node functions under python/. +#[inline] +pub fn discover_python_node_functions<'py>( + project_dir: Bound<'py, PyAny>, + providers: Option>, +) -> PyResult> { + imported_python_nodes::discover_python_node_functions(project_dir, providers) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/python_files/install_recall_writer.rs b/crates/sqlbuild-python-front/src/discovery/main/python_files/install_recall_writer.rs new file mode 100644 index 0000000000..7cfe250281 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/python_files/install_recall_writer.rs @@ -0,0 +1,11 @@ +//! Install the `RecallWriter` class sink parameters are recognised by, once, at registration. + +use crate::discovery::_helpers::python_files::imported_providers; +use pyo3::prelude::Bound; +use pyo3::types::PyType; + +/// Install the `RecallWriter` class sink parameters are recognised by, once, at registration. +#[inline] +pub fn install_recall_writer(writer: &Bound<'_, PyType>) { + imported_providers::install_recall_writer(writer) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/python_files/mod.rs b/crates/sqlbuild-python-front/src/discovery/main/python_files/mod.rs new file mode 100644 index 0000000000..4b4b592968 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/python_files/mod.rs @@ -0,0 +1,15 @@ +pub mod discover_event_exporter_functions; +pub mod discover_hook_functions; +pub mod discover_materialization_files; +pub mod discover_provider_classes; +pub mod discover_python_function_files; +pub mod discover_python_node_functions; +pub mod install_recall_writer; +pub mod node_identity; +pub mod provider_by_name; +pub mod provider_usages; +pub mod register_imported_python_nodes; +pub mod register_python_function_files; +pub mod register_python_hook_files; +pub mod register_python_module_files; +pub mod reject_unsupported_python_paths; diff --git a/crates/sqlbuild-python-front/src/discovery/main/python_files/node_identity.rs b/crates/sqlbuild-python-front/src/discovery/main/python_files/node_identity.rs new file mode 100644 index 0000000000..49f66190e2 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/python_files/node_identity.rs @@ -0,0 +1,17 @@ +//! The identity of one discovered node of `(kind, documented)`, hashed once by the user-code host. + +use crate::discovery::_helpers::python_files::imported_python_nodes; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// The identity of one discovered node of `(kind, documented)`, hashed once by the user-code host. +#[inline] +pub fn node_identity<'py>( + py: Python<'py>, + (kind, documented): (&str, bool), + get: &dyn Fn(&str) -> PyResult>, +) -> PyResult> { + imported_python_nodes::node_identity(py, (kind, documented), get) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/python_files/provider_by_name.rs b/crates/sqlbuild-python-front/src/discovery/main/python_files/provider_by_name.rs new file mode 100644 index 0000000000..24098feb21 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/python_files/provider_by_name.rs @@ -0,0 +1,13 @@ +//! `{provider.name: provider for provider in providers}`. + +use crate::discovery::_helpers::python_files::imported_modules; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyDict; + +/// `{provider.name: provider for provider in providers}`. +#[inline] +pub fn provider_by_name<'py>(providers: &Bound<'py, PyAny>) -> PyResult> { + imported_modules::provider_by_name(providers) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/python_files/provider_usages.rs b/crates/sqlbuild-python-front/src/discovery/main/python_files/provider_usages.rs new file mode 100644 index 0000000000..5685f5b30d --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/python_files/provider_usages.rs @@ -0,0 +1,16 @@ +//! The provider parameters of one loaded user function. + +use crate::discovery::_helpers::python_files::imported_modules; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyDict; + +/// The provider parameters of one loaded user function. +#[inline] +pub fn provider_usages<'py>( + function: &Bound<'py, PyAny>, + provider_by_name: &Bound<'py, PyDict>, +) -> PyResult> { + imported_modules::provider_usages(function, provider_by_name) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/python_files/register_imported_python_nodes.rs b/crates/sqlbuild-python-front/src/discovery/main/python_files/register_imported_python_nodes.rs new file mode 100644 index 0000000000..ea02864cab --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/python_files/register_imported_python_nodes.rs @@ -0,0 +1,12 @@ +//! Register the imported python nodes functions and classes. + +use crate::discovery::_helpers::python_files::imported_python_nodes; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the imported python nodes functions and classes. +#[inline] +pub fn register_imported_python_nodes(module: &Bound<'_, PyModule>) -> PyResult<()> { + imported_python_nodes::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/python_files/register_python_function_files.rs b/crates/sqlbuild-python-front/src/discovery/main/python_files/register_python_function_files.rs new file mode 100644 index 0000000000..8913e46dae --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/python_files/register_python_function_files.rs @@ -0,0 +1,12 @@ +//! Register the python function files functions and classes. + +use crate::discovery::_helpers::python_files::python_function_files; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the python function files functions and classes. +#[inline] +pub fn register_python_function_files(module: &Bound<'_, PyModule>) -> PyResult<()> { + python_function_files::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/python_files/register_python_hook_files.rs b/crates/sqlbuild-python-front/src/discovery/main/python_files/register_python_hook_files.rs new file mode 100644 index 0000000000..3c7f62435a --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/python_files/register_python_hook_files.rs @@ -0,0 +1,12 @@ +//! Register the python hook files functions and classes. + +use crate::discovery::_helpers::python_files::python_hook_files; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the python hook files functions and classes. +#[inline] +pub fn register_python_hook_files(module: &Bound<'_, PyModule>) -> PyResult<()> { + python_hook_files::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/python_files/register_python_module_files.rs b/crates/sqlbuild-python-front/src/discovery/main/python_files/register_python_module_files.rs new file mode 100644 index 0000000000..8939ee1aec --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/python_files/register_python_module_files.rs @@ -0,0 +1,12 @@ +//! Register the python module files functions and classes. + +use crate::discovery::_helpers::python_files::python_module_files; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the python module files functions and classes. +#[inline] +pub fn register_python_module_files(module: &Bound<'_, PyModule>) -> PyResult<()> { + python_module_files::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/python_files/reject_unsupported_python_paths.rs b/crates/sqlbuild-python-front/src/discovery/main/python_files/reject_unsupported_python_paths.rs new file mode 100644 index 0000000000..af1736586b --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/python_files/reject_unsupported_python_paths.rs @@ -0,0 +1,12 @@ +//! Raise `ProjectPythonPathError` naming every unsupported Python file below `project_dir`. + +use crate::discovery::_helpers::python_files::python_paths; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Raise `ProjectPythonPathError` naming every unsupported Python file below `project_dir`. +#[inline] +pub fn reject_unsupported_python_paths(project_dir: &Bound<'_, PyAny>) -> PyResult<()> { + python_paths::reject_unsupported_python_paths(project_dir) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/discover_adapter_file.rs b/crates/sqlbuild-python-front/src/discovery/main/records/discover_adapter_file.rs new file mode 100644 index 0000000000..e4962b97a9 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/discover_adapter_file.rs @@ -0,0 +1,12 @@ +//! Detect a project-level adapter.py without importing it. + +use crate::discovery::_helpers::records::declaration_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Detect a project-level adapter.py without importing it. +#[inline] +pub fn discover_adapter_file<'py>(project_dir: &Bound<'py, PyAny>) -> PyResult> { + declaration_records::discover_adapter_file(project_dir) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/discover_audit_files.rs b/crates/sqlbuild-python-front/src/discovery/main/records/discover_audit_files.rs new file mode 100644 index 0000000000..19af629ec1 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/discover_audit_files.rs @@ -0,0 +1,16 @@ +//! Discover generic and singular audit SQL files in their project-wide and scoped roles. + +use crate::discovery::_helpers::records::declaration_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// Discover generic and singular audit SQL files in their project-wide and scoped roles. +#[inline] +pub fn discover_audit_files<'py>( + project_dir: &Bound<'py, PyAny>, + on_fault: Option>, +) -> PyResult> { + declaration_records::discover_audit_files(project_dir, on_fault) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/discover_constant_files.rs b/crates/sqlbuild-python-front/src/discovery/main/records/discover_constant_files.rs new file mode 100644 index 0000000000..05ec7b9656 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/discover_constant_files.rs @@ -0,0 +1,17 @@ +//! Discover global and scoped constant declaration files. + +use crate::discovery::_helpers::records::declaration_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// Discover global and scoped constant declaration files. +#[inline] +pub fn discover_constant_files<'py>( + project_dir: &Bound<'py, PyAny>, + on_fault: Option>, + isolate_declaration_kind: bool, +) -> PyResult> { + declaration_records::discover_constant_files(project_dir, on_fault, isolate_declaration_kind) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/discover_enum_files.rs b/crates/sqlbuild-python-front/src/discovery/main/records/discover_enum_files.rs new file mode 100644 index 0000000000..d9eacb8305 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/discover_enum_files.rs @@ -0,0 +1,17 @@ +//! Discover global and scoped enum declaration files. + +use crate::discovery::_helpers::records::declaration_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// Discover global and scoped enum declaration files. +#[inline] +pub fn discover_enum_files<'py>( + project_dir: &Bound<'py, PyAny>, + on_fault: Option>, + isolate_declaration_kind: bool, +) -> PyResult> { + declaration_records::discover_enum_files(project_dir, on_fault, isolate_declaration_kind) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/discover_macro_files.rs b/crates/sqlbuild-python-front/src/discovery/main/records/discover_macro_files.rs new file mode 100644 index 0000000000..fbd7a0a5da --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/discover_macro_files.rs @@ -0,0 +1,16 @@ +//! Discover global and scoped project macro Python files. + +use crate::discovery::_helpers::records::declaration_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// Discover global and scoped project macro Python files. +#[inline] +pub fn discover_macro_files<'py>( + project_dir: &Bound<'py, PyAny>, + isolate_declaration_kind: bool, +) -> PyResult> { + declaration_records::discover_macro_files(project_dir, isolate_declaration_kind) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/discover_model_files.rs b/crates/sqlbuild-python-front/src/discovery/main/records/discover_model_files.rs new file mode 100644 index 0000000000..2ac5e14538 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/discover_model_files.rs @@ -0,0 +1,17 @@ +//! Discover the (selected) model files natively, reporting failing files to `on_fault`. + +use crate::discovery::_helpers::records::model_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::types::PyDict; +use pyo3::types::PyTuple; + +/// Discover the (selected) model files natively, reporting failing files to `on_fault`. +#[inline] +pub fn discover_model_files<'py>( + py: Python<'py>, + options: Option>, +) -> PyResult> { + model_records::discover_model_files(py, options) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/discover_model_schema_files.rs b/crates/sqlbuild-python-front/src/discovery/main/records/discover_model_schema_files.rs new file mode 100644 index 0000000000..9c886cd419 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/discover_model_schema_files.rs @@ -0,0 +1,16 @@ +//! Discover project-wide and scoped reusable model schemas. + +use crate::discovery::_helpers::records::declaration_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// Discover project-wide and scoped reusable model schemas. +#[inline] +pub fn discover_model_schema_files<'py>( + project_dir: &Bound<'py, PyAny>, + on_fault: Option>, +) -> PyResult> { + declaration_records::discover_model_schema_files(project_dir, on_fault) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/discover_scenario_files.rs b/crates/sqlbuild-python-front/src/discovery/main/records/discover_scenario_files.rs new file mode 100644 index 0000000000..1dd47a45dc --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/discover_scenario_files.rs @@ -0,0 +1,16 @@ +//! Discover scenario files natively, reporting failing files to `on_fault`. + +use crate::discovery::_helpers::records::sql_test_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// Discover scenario files natively, reporting failing files to `on_fault`. +#[inline] +pub fn discover_scenario_files<'py>( + project_dir: &Bound<'py, PyAny>, + on_fault: Option>, +) -> PyResult> { + sql_test_records::discover_scenario_files(project_dir, on_fault) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/discover_schema_files.rs b/crates/sqlbuild-python-front/src/discovery/main/records/discover_schema_files.rs new file mode 100644 index 0000000000..3481d9f5bd --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/discover_schema_files.rs @@ -0,0 +1,15 @@ +//! Discover model schema.yml and seed declaration files natively. + +use crate::discovery::_helpers::records::yaml_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// Discover model schema.yml and seed declaration files natively. +#[inline] +pub fn discover_schema_files<'py>( + project_dir: &Bound<'py, PyAny>, +) -> PyResult> { + yaml_records::discover_schema_files(project_dir) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/discover_seed_files.rs b/crates/sqlbuild-python-front/src/discovery/main/records/discover_seed_files.rs new file mode 100644 index 0000000000..89c3cc5a60 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/discover_seed_files.rs @@ -0,0 +1,13 @@ +//! Discover seed CSV files under seeds/. + +use crate::discovery::_helpers::records::declaration_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// Discover seed CSV files under seeds/. +#[inline] +pub fn discover_seed_files<'py>(project_dir: &Bound<'py, PyAny>) -> PyResult> { + declaration_records::discover_seed_files(project_dir) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/discover_source_files.rs b/crates/sqlbuild-python-front/src/discovery/main/records/discover_source_files.rs new file mode 100644 index 0000000000..bd3e3d36ef --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/discover_source_files.rs @@ -0,0 +1,16 @@ +//! Discover source YAML files natively, reporting failing files to `on_fault`. + +use crate::discovery::_helpers::records::yaml_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// Discover source YAML files natively, reporting failing files to `on_fault`. +#[inline] +pub fn discover_source_files<'py>( + project_dir: &Bound<'py, PyAny>, + on_fault: Option>, +) -> PyResult> { + yaml_records::discover_source_files(project_dir, on_fault) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/discover_sql_function_files.rs b/crates/sqlbuild-python-front/src/discovery/main/records/discover_sql_function_files.rs new file mode 100644 index 0000000000..2cb6438195 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/discover_sql_function_files.rs @@ -0,0 +1,16 @@ +//! Discover SQL function files under functions/sql/. + +use crate::discovery::_helpers::records::declaration_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// Discover SQL function files under functions/sql/. +#[inline] +pub fn discover_sql_function_files<'py>( + project_dir: &Bound<'py, PyAny>, + on_fault: Option>, +) -> PyResult> { + declaration_records::discover_sql_function_files(project_dir, on_fault) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/discover_sql_hook_files.rs b/crates/sqlbuild-python-front/src/discovery/main/records/discover_sql_hook_files.rs new file mode 100644 index 0000000000..6d970cbb61 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/discover_sql_hook_files.rs @@ -0,0 +1,16 @@ +//! Discover named SQL lifecycle hooks in their project-wide and scoped roles. + +use crate::discovery::_helpers::records::declaration_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// Discover named SQL lifecycle hooks in their project-wide and scoped roles. +#[inline] +pub fn discover_sql_hook_files<'py>( + project_dir: &Bound<'py, PyAny>, + on_fault: Option>, +) -> PyResult> { + declaration_records::discover_sql_hook_files(project_dir, on_fault) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/discover_test_files.rs b/crates/sqlbuild-python-front/src/discovery/main/records/discover_test_files.rs new file mode 100644 index 0000000000..3f73ba9034 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/discover_test_files.rs @@ -0,0 +1,17 @@ +//! Discover the (selected) SQL test files natively, reporting failing files to `on_fault`. + +use crate::discovery::_helpers::records::sql_test_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// Discover the (selected) SQL test files natively, reporting failing files to `on_fault`. +#[inline] +pub fn discover_test_files<'py>( + project_dir: &Bound<'py, PyAny>, + selected_paths: Option>, + on_fault: Option>, +) -> PyResult> { + sql_test_records::discover_test_files(project_dir, selected_paths, on_fault) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/discovered_model_files.rs b/crates/sqlbuild-python-front/src/discovery/main/records/discovered_model_files.rs new file mode 100644 index 0000000000..9df1381eaf --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/discovered_model_files.rs @@ -0,0 +1,18 @@ +//! The (selected) model files; `extraction` is `(implicit alias columns, output locations)`. + +use crate::discovery::_helpers::records::model_records; +use crate::discovery::models::ModelFileSelection; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// The (selected) model files; `extraction` is `(implicit alias columns, output locations)`. +#[inline] +pub fn discovered_model_files<'py>( + project_dir: &Bound<'py, PyAny>, + extraction: (bool, bool), + selection: ModelFileSelection<'py>, +) -> PyResult> { + model_records::discovered_model_files(project_dir, extraction, selection) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/externally_described_models.rs b/crates/sqlbuild-python-front/src/discovery/main/records/externally_described_models.rs new file mode 100644 index 0000000000..fd6cd14803 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/externally_described_models.rs @@ -0,0 +1,15 @@ +//! Model files that `[defaults]`, `[path_defaults]` or a model schema describe. + +use crate::discovery::_helpers::records::description_inputs; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyFrozenSet; + +/// Model files that `[defaults]`, `[path_defaults]` or a model schema describe. +#[inline] +pub fn externally_described_models<'py>( + project_dir: &Bound<'py, PyAny>, +) -> PyResult> { + description_inputs::externally_described_models(project_dir) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/mod.rs b/crates/sqlbuild-python-front/src/discovery/main/records/mod.rs new file mode 100644 index 0000000000..3e85c0fcd2 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/mod.rs @@ -0,0 +1,24 @@ +pub mod discover_adapter_file; +pub mod discover_audit_files; +pub mod discover_constant_files; +pub mod discover_enum_files; +pub mod discover_macro_files; +pub mod discover_model_files; +pub mod discover_model_schema_files; +pub mod discover_scenario_files; +pub mod discover_schema_files; +pub mod discover_seed_files; +pub mod discover_source_files; +pub mod discover_sql_function_files; +pub mod discover_sql_hook_files; +pub mod discover_test_files; +pub mod discovered_model_files; +pub mod externally_described_models; +pub mod parse_sql_test_file; +pub mod projected_text; +pub mod register_declaration_records; +pub mod register_description_inputs; +pub mod register_model_records; +pub mod register_sql_test_records; +pub mod register_yaml_records; +pub mod retained_discovery_session; diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/parse_sql_test_file.rs b/crates/sqlbuild-python-front/src/discovery/main/records/parse_sql_test_file.rs new file mode 100644 index 0000000000..c10bd475da --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/parse_sql_test_file.rs @@ -0,0 +1,16 @@ +//! Parse in-memory SQL test contents into ordered blocks, as test discovery does. + +use crate::discovery::_helpers::records::sql_test_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// Parse in-memory SQL test contents into ordered blocks, as test discovery does. +#[inline] +pub fn parse_sql_test_file<'py>( + contents: String, + file_path: &Bound<'py, PyAny>, +) -> PyResult> { + sql_test_records::parse_sql_test_file(contents, file_path) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/projected_text.rs b/crates/sqlbuild-python-front/src/discovery/main/records/projected_text.rs new file mode 100644 index 0000000000..2c1eadeda9 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/projected_text.rs @@ -0,0 +1,18 @@ +//! `text` as the Python string `cache` shares with every reader, built on first read. + +use crate::discovery::_helpers::records::model_file_record; +use pyo3::prelude::Bound; +use pyo3::prelude::Py; +use pyo3::prelude::Python; +use pyo3::sync::PyOnceLock; +use pyo3::types::PyString; + +/// `text` as the Python string `cache` shares with every reader, built on first read. +#[inline] +pub fn projected_text<'py>( + py: Python<'py>, + cache: &PyOnceLock>, + text: &str, +) -> Bound<'py, PyString> { + model_file_record::projected_text(py, cache, text) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/register_declaration_records.rs b/crates/sqlbuild-python-front/src/discovery/main/records/register_declaration_records.rs new file mode 100644 index 0000000000..19486f7f7c --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/register_declaration_records.rs @@ -0,0 +1,12 @@ +//! Register the declaration records functions and classes. + +use crate::discovery::_helpers::records::declaration_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the declaration records functions and classes. +#[inline] +pub fn register_declaration_records(module: &Bound<'_, PyModule>) -> PyResult<()> { + declaration_records::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/register_description_inputs.rs b/crates/sqlbuild-python-front/src/discovery/main/records/register_description_inputs.rs new file mode 100644 index 0000000000..f633072057 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/register_description_inputs.rs @@ -0,0 +1,12 @@ +//! Register the description inputs functions and classes. + +use crate::discovery::_helpers::records::description_inputs; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the description inputs functions and classes. +#[inline] +pub fn register_description_inputs(module: &Bound<'_, PyModule>) -> PyResult<()> { + description_inputs::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/register_model_records.rs b/crates/sqlbuild-python-front/src/discovery/main/records/register_model_records.rs new file mode 100644 index 0000000000..1ca1846266 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/register_model_records.rs @@ -0,0 +1,12 @@ +//! Register the model records functions and classes. + +use crate::discovery::_helpers::records::model_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the model records functions and classes. +#[inline] +pub fn register_model_records(module: &Bound<'_, PyModule>) -> PyResult<()> { + model_records::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/register_sql_test_records.rs b/crates/sqlbuild-python-front/src/discovery/main/records/register_sql_test_records.rs new file mode 100644 index 0000000000..ab0033786d --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/register_sql_test_records.rs @@ -0,0 +1,12 @@ +//! Register the sql test records functions and classes. + +use crate::discovery::_helpers::records::sql_test_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the sql test records functions and classes. +#[inline] +pub fn register_sql_test_records(module: &Bound<'_, PyModule>) -> PyResult<()> { + sql_test_records::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/register_yaml_records.rs b/crates/sqlbuild-python-front/src/discovery/main/records/register_yaml_records.rs new file mode 100644 index 0000000000..9f117e1b44 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/register_yaml_records.rs @@ -0,0 +1,12 @@ +//! Register the yaml records functions and classes. + +use crate::discovery::_helpers::records::yaml_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the yaml records functions and classes. +#[inline] +pub fn register_yaml_records(module: &Bound<'_, PyModule>) -> PyResult<()> { + yaml_records::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/records/retained_discovery_session.rs b/crates/sqlbuild-python-front/src/discovery/main/records/retained_discovery_session.rs new file mode 100644 index 0000000000..75b0fd3daf --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/records/retained_discovery_session.rs @@ -0,0 +1,14 @@ +//! The session this discovery pass read its declaration files with, if any. + +use crate::discovery::_helpers::records::declaration_records; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// The session this discovery pass read its declaration files with, if any. +#[inline] +pub fn retained_discovery_session<'py>( + project_dir: &Bound<'py, PyAny>, +) -> PyResult> { + declaration_records::retained_discovery_session(project_dir) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/snapshots/directory_snapshot_scope.rs b/crates/sqlbuild-python-front/src/discovery/main/snapshots/directory_snapshot_scope.rs new file mode 100644 index 0000000000..611b9a2b24 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/snapshots/directory_snapshot_scope.rs @@ -0,0 +1,12 @@ +//! Share one directory snapshot across every discovery call for `project_dir` inside the scope. + +use crate::discovery::_helpers::snapshots::snapshot; +use crate::discovery::models::NativeDirectorySnapshotScope; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; + +/// Share one directory snapshot across every discovery call for `project_dir` inside the scope. +#[inline] +pub fn directory_snapshot_scope(project_dir: Bound<'_, PyAny>) -> NativeDirectorySnapshotScope { + snapshot::directory_snapshot_scope(project_dir) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/snapshots/discover_scope_snapshot.rs b/crates/sqlbuild-python-front/src/discovery/main/snapshots/discover_scope_snapshot.rs new file mode 100644 index 0000000000..bbd45acb50 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/snapshots/discover_scope_snapshot.rs @@ -0,0 +1,14 @@ +//! Parse the scope-relevant authored roots while retaining independent file faults. + +use crate::discovery::_helpers::snapshots::scope_snapshot; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Parse the scope-relevant authored roots while retaining independent file faults. +#[inline] +pub fn discover_scope_snapshot<'py>( + project_dir: &Bound<'py, PyAny>, +) -> PyResult> { + scope_snapshot::discover_scope_snapshot(project_dir) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/snapshots/escaped.rs b/crates/sqlbuild-python-front/src/discovery/main/snapshots/escaped.rs new file mode 100644 index 0000000000..860c66ec23 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/snapshots/escaped.rs @@ -0,0 +1,12 @@ +//! Python's `_escaped`: undecodable name bytes as `\xNN`, other lone surrogates as `\uXXXX`. + +use crate::discovery::_helpers::snapshots::snapshot; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::types::PyString; + +/// Python's `_escaped`: undecodable name bytes as `\xNN`, other lone surrogates as `\uXXXX`. +#[inline] +pub fn escaped(text: &Bound<'_, PyString>) -> PyResult { + snapshot::escaped(text) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/snapshots/in_snapshot.rs b/crates/sqlbuild-python-front/src/discovery/main/snapshots/in_snapshot.rs new file mode 100644 index 0000000000..c21854391c --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/snapshots/in_snapshot.rs @@ -0,0 +1,15 @@ +//! Run `body` with one snapshot of `project_dir` shared by every discovery call inside it. + +use crate::discovery::_helpers::snapshots::snapshot; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Run `body` with one snapshot of `project_dir` shared by every discovery call inside it. +#[inline] +pub fn in_snapshot<'py, T>( + project_dir: &Bound<'py, PyAny>, + body: impl FnOnce() -> PyResult, +) -> PyResult { + snapshot::in_snapshot(project_dir, body) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/snapshots/mod.rs b/crates/sqlbuild-python-front/src/discovery/main/snapshots/mod.rs new file mode 100644 index 0000000000..f4f42321ca --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/snapshots/mod.rs @@ -0,0 +1,6 @@ +pub mod directory_snapshot_scope; +pub mod discover_scope_snapshot; +pub mod escaped; +pub mod in_snapshot; +pub mod register_scope_snapshot; +pub mod register_snapshot; diff --git a/crates/sqlbuild-python-front/src/discovery/main/snapshots/register_scope_snapshot.rs b/crates/sqlbuild-python-front/src/discovery/main/snapshots/register_scope_snapshot.rs new file mode 100644 index 0000000000..de088e3cb1 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/snapshots/register_scope_snapshot.rs @@ -0,0 +1,12 @@ +//! Register the scope snapshot functions and classes. + +use crate::discovery::_helpers::snapshots::scope_snapshot; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the scope snapshot functions and classes. +#[inline] +pub fn register_scope_snapshot(module: &Bound<'_, PyModule>) -> PyResult<()> { + scope_snapshot::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/snapshots/register_snapshot.rs b/crates/sqlbuild-python-front/src/discovery/main/snapshots/register_snapshot.rs new file mode 100644 index 0000000000..e29fc29827 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/snapshots/register_snapshot.rs @@ -0,0 +1,12 @@ +//! Register the snapshot functions and classes. + +use crate::discovery::_helpers::snapshots::snapshot; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the snapshot functions and classes. +#[inline] +pub fn register_snapshot(module: &Bound<'_, PyModule>) -> PyResult<()> { + snapshot::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/sources/consumer_uses.rs b/crates/sqlbuild-python-front/src/discovery/main/sources/consumer_uses.rs new file mode 100644 index 0000000000..bf17b61bf6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/sources/consumer_uses.rs @@ -0,0 +1,12 @@ +//! `(provider, consumer)` for each provider the named consumers, such as checks or loaders, inject. + +use crate::discovery::_helpers::sources::provider_secrets; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// `(provider, consumer)` for each provider the named consumers, such as checks or loaders, inject. +#[inline] +pub fn consumer_uses(consumers: &Bound<'_, PyAny>) -> PyResult> { + provider_secrets::consumer_uses(consumers) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/sources/invocation_allows_missing_secrets.rs b/crates/sqlbuild-python-front/src/discovery/main/sources/invocation_allows_missing_secrets.rs new file mode 100644 index 0000000000..95d0bc0f90 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/sources/invocation_allows_missing_secrets.rs @@ -0,0 +1,9 @@ +//! Whether the running invocation passed `--allow-missing-secrets`. + +use crate::discovery::_helpers::sources::provider_secrets; + +/// Whether the running invocation passed `--allow-missing-secrets`. +#[inline] +pub fn invocation_allows_missing_secrets() -> bool { + provider_secrets::invocation_allows_missing_secrets() +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/sources/mod.rs b/crates/sqlbuild-python-front/src/discovery/main/sources/mod.rs new file mode 100644 index 0000000000..a23aea17c6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/sources/mod.rs @@ -0,0 +1,8 @@ +pub mod consumer_uses; +pub mod invocation_allows_missing_secrets; +pub mod orchestration_declarations; +pub mod provider_uses; +pub mod register_declaration_files; +pub mod register_yaml_entries; +pub mod require_used_secrets; +pub mod sink_uses; diff --git a/crates/sqlbuild-python-front/src/discovery/main/sources/orchestration_declarations.rs b/crates/sqlbuild-python-front/src/discovery/main/sources/orchestration_declarations.rs new file mode 100644 index 0000000000..915c41e145 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/sources/orchestration_declarations.rs @@ -0,0 +1,15 @@ +//! Every job, job group, calendar and sensor of `project_dir`, or `OrchestrationDeclarationError` (D017). + +use crate::discovery::_helpers::sources::orchestration_files; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_discovery::orchestration_files::models::OrchestrationInventory; + +/// Every job, job group, calendar and sensor of `project_dir`, or `OrchestrationDeclarationError` (D017). +#[inline] +pub fn orchestration_declarations( + project_dir: &Bound<'_, PyAny>, +) -> PyResult { + orchestration_files::orchestration_declarations(project_dir) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/sources/provider_uses.rs b/crates/sqlbuild-python-front/src/discovery/main/sources/provider_uses.rs new file mode 100644 index 0000000000..872118c52d --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/sources/provider_uses.rs @@ -0,0 +1,15 @@ +//! `(provider, consumer)` for each usage, named by the usage's own `consumer_name` or else by `consumer`. + +use crate::discovery::_helpers::sources::provider_secrets; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// `(provider, consumer)` for each usage, named by the usage's own `consumer_name` or else by `consumer`. +#[inline] +pub fn provider_uses( + usages: &Bound<'_, PyAny>, + consumer: Option<&str>, +) -> PyResult> { + provider_secrets::provider_uses(usages, consumer) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/sources/register_declaration_files.rs b/crates/sqlbuild-python-front/src/discovery/main/sources/register_declaration_files.rs new file mode 100644 index 0000000000..407e5eb323 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/sources/register_declaration_files.rs @@ -0,0 +1,12 @@ +//! Register the declaration files functions and classes. + +use crate::discovery::_helpers::sources::declaration_files; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the declaration files functions and classes. +#[inline] +pub fn register_declaration_files(module: &Bound<'_, PyModule>) -> PyResult<()> { + declaration_files::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/sources/register_yaml_entries.rs b/crates/sqlbuild-python-front/src/discovery/main/sources/register_yaml_entries.rs new file mode 100644 index 0000000000..37f5ed9420 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/sources/register_yaml_entries.rs @@ -0,0 +1,12 @@ +//! Register the yaml entries functions and classes. + +use crate::discovery::_helpers::sources::yaml_entries; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the yaml entries functions and classes. +#[inline] +pub fn register_yaml_entries(module: &Bound<'_, PyModule>) -> PyResult<()> { + yaml_entries::register(module) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/sources/require_used_secrets.rs b/crates/sqlbuild-python-front/src/discovery/main/sources/require_used_secrets.rs new file mode 100644 index 0000000000..7342258da8 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/sources/require_used_secrets.rs @@ -0,0 +1,15 @@ +//! Fail before anything runs when a provider in `uses` lacks required secrets, listing each with what needs it. + +use crate::discovery::_helpers::sources::provider_secrets; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Fail before anything runs when a provider in `uses` lacks required secrets, listing each with what needs it. +#[inline] +pub fn require_used_secrets( + discovered: &Bound<'_, PyAny>, + uses: &[(String, String)], +) -> PyResult<()> { + provider_secrets::require_used_secrets(discovered, uses) +} diff --git a/crates/sqlbuild-python-front/src/discovery/main/sources/sink_uses.rs b/crates/sqlbuild-python-front/src/discovery/main/sources/sink_uses.rs new file mode 100644 index 0000000000..5d4fc617cf --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/main/sources/sink_uses.rs @@ -0,0 +1,12 @@ +//! The providers the project's lifecycle and command-output sinks use, which run with every command. + +use crate::discovery::_helpers::sources::provider_secrets; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// The providers the project's lifecycle and command-output sinks use, which run with every command. +#[inline] +pub fn sink_uses(discovered: &Bound<'_, PyAny>) -> PyResult> { + provider_secrets::sink_uses(discovered) +} diff --git a/crates/sqlbuild-python-front/src/discovery/mod.rs b/crates/sqlbuild-python-front/src/discovery/mod.rs new file mode 100644 index 0000000000..e3636f2cd8 --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/mod.rs @@ -0,0 +1,6 @@ +//! Project discovery: configuration, declaration files, providers, Python nodes and the project facts read from them. + +pub(crate) mod _helpers; +pub mod constants; +pub mod main; +pub mod models; diff --git a/crates/sqlbuild-python-front/src/discovery/models.rs b/crates/sqlbuild-python-front/src/discovery/models.rs new file mode 100644 index 0000000000..df8f05bc3b --- /dev/null +++ b/crates/sqlbuild-python-front/src/discovery/models.rs @@ -0,0 +1,391 @@ +//! Public records of discovery. + +use crate::discovery::_helpers::project::project_facts::DependencyRow; +use crate::discovery::_helpers::records::model_file_record::FIELD_NAMES; +use crate::discovery::_helpers::records::model_file_record::HeaderValues; +use crate::discovery::_helpers::records::model_file_record::Locations; +use crate::discovery::_helpers::records::model_file_record::ModelFileFields; +use crate::discovery::_helpers::records::model_file_record::ModelFilePaths; +use crate::discovery::_helpers::records::model_file_record::projected_text; +use crate::discovery::_helpers::sources::provider_secrets::INVOCATION_ALLOWS_MISSING_SECRETS; +use pyo3::FromPyObject; +use pyo3::IntoPyObjectExt; +use pyo3::exceptions::PyTypeError; +use pyo3::exceptions::PyValueError; +use pyo3::prelude::Bound; +use pyo3::prelude::Py; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyAnyMethods; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::pyclass; +use pyo3::pymethods; +use pyo3::sync::PyOnceLock; +use pyo3::types::PyDict; +use pyo3::types::PyDictMethods; +use pyo3::types::PyString; +use pyo3::types::PyStringMethods; +use pyo3::types::PyTuple; +use sqlbuild_discovery::models::LineColumnSpan; +use sqlbuild_sqltext::compiler::models::AuthoredValue; +use std::path::PathBuf; +use std::sync::Arc; + +/// The names a model file is known by, as Python's `pathlib` spells them. +#[derive(Debug, Clone)] +pub struct ModelFileTexts { + /// `file_path.stem`, the model's name. + pub name: String, + /// `relative_path.as_posix()`. + pub posix_path: String, + /// `str(relative_path)`. + pub relative_path: String, + /// `str(file_path)`. + pub file_path: String, +} + +/// A discovered SQL model file and its raw contents. +#[pyclass(module = "sqlbuild._native", name = "DiscoveredSqlModelFile", frozen)] +pub struct NativeModelFile { + pub(crate) paths: ModelFilePaths, + pub(crate) contents: Arc, + /// `contents` and `query_sql` as the Python strings readers share, built on first read. + pub(crate) projected_texts: (PyOnceLock>, PyOnceLock>), + pub(crate) header_values: HeaderValues, + pub(crate) header_column_locations: Locations, + pub(crate) output_column_locations: Locations, + pub(crate) query_sql: Arc, + pub(crate) enum_declarations: Py, + pub(crate) constant_declarations: Py, + pub(crate) extract_implicit_alias_columns: bool, +} + +impl std::fmt::Debug for NativeModelFile { + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + formatter + .debug_struct("NativeModelFile") + .finish_non_exhaustive() + } +} + +impl NativeModelFile { + pub fn header_locations<'py>(&self, py: Python<'py>) -> PyResult> { + self.header_column_locations + .dict(&self.paths.objects(py)?.1) + } + + /// The header's authored values as the Python dict config builds read. + pub fn header_value_dict<'py>(&self, py: Python<'py>) -> PyResult> { + self.header_values.dict(py) + } + + /// The header columns' authored locations, unless Python constructed this record. + pub fn header_location_rows(&self) -> &[(String, LineColumnSpan)] { + &self.header_column_locations.rows + } + + /// The header's native authored values, unless Python constructed this record. + pub fn native_header_values(&self) -> Option<&Arc<[(String, AuthoredValue)]>> { + self.header_values.native.as_ref() + } + + pub fn declaration_tuples<'py>( + &self, + py: Python<'py>, + ) -> (&Bound<'py, PyTuple>, &Bound<'py, PyTuple>) { + ( + self.enum_declarations.bind(py), + self.constant_declarations.bind(py), + ) + } + + /// The file path as a native path. + pub fn file_path_buf(&self) -> PathBuf { + self.paths.native_file_path.clone() + } + + /// The file's names, or the error Python raises reading a name that is not UTF-8 text. + pub fn path_texts(&self, py: Python<'_>) -> PyResult { + self.paths.texts(py).cloned() + } + + /// `relative_path.as_posix()`. + pub fn posix_path(&self, py: Python<'_>) -> PyResult { + Ok(self.paths.texts(py)?.posix_path.clone()) + } + + /// `str(relative_path)`. + pub fn relative_text(&self, py: Python<'_>) -> PyResult { + Ok(self.paths.texts(py)?.relative_path.clone()) + } + + /// `str(relative_path.parent)`, the folder project graphs group the model by. + pub fn folder(&self, py: Python<'_>) -> PyResult { + Ok(self + .paths + .texts(py)? + .relative_path + .rsplit_once(std::path::MAIN_SEPARATOR) + .map_or_else(|| ".".to_owned(), |(folder, _)| folder.to_owned())) + } + + /// `(file_path, relative_path)` as Python path objects. + pub fn path_objects<'py>( + &self, + py: Python<'py>, + ) -> PyResult<(Bound<'py, PyAny>, Bound<'py, PyAny>)> { + self.paths.objects(py) + } + + /// The authored query below the header. + pub fn query_text(&self) -> &Arc { + &self.query_sql + } + + /// The whole authored file. + pub fn contents_text(&self) -> &Arc { + &self.contents + } + + pub(crate) fn fields<'py>(&self, py: Python<'py>) -> PyResult>> { + let (file_path, relative_path) = self.paths.objects(py)?; + Ok(vec![ + file_path, + relative_path.clone(), + self.contents(py).into_any(), + self.header_values.dict(py)?.into_any(), + self.header_column_locations + .dict(&relative_path)? + .into_any(), + self.output_column_locations + .dict(&relative_path)? + .into_any(), + self.query_sql(py).into_any(), + self.enum_declarations.bind(py).clone().into_any(), + self.constant_declarations.bind(py).clone().into_any(), + pyo3::types::PyBool::new(py, self.extract_implicit_alias_columns) + .to_owned() + .into_any(), + ]) + } +} + +#[pymethods] +impl NativeModelFile { + #[new] + #[pyo3(signature = (**fields))] + pub(crate) fn new(py: Python<'_>, fields: Option>) -> PyResult { + let Some(fields) = fields else { + return Err(PyTypeError::new_err( + "DiscoveredSqlModelFile requires its fields", + )); + }; + for key in fields.keys() { + let key: String = key.extract()?; + if !FIELD_NAMES.contains(&key.as_str()) { + return Err(PyTypeError::new_err(format!( + "DiscoveredSqlModelFile got an unexpected keyword argument '{key}'" + ))); + } + } + let fields: ModelFileFields = fields.extract()?; + Ok(Self { + paths: ModelFilePaths::given(py, fields.file_path, fields.relative_path)?, + contents: fields.contents.bind(py).to_str()?.into(), + projected_texts: (PyOnceLock::new(), PyOnceLock::new()), + header_values: HeaderValues::given(py, fields.header_values), + header_column_locations: Locations::from_dict(py, fields.header_column_locations), + output_column_locations: Locations::from_dict(py, fields.output_column_locations), + query_sql: fields.query_sql.bind(py).to_str()?.into(), + enum_declarations: fields + .enum_declarations + .unwrap_or_else(|| PyTuple::empty(py).unbind()), + constant_declarations: fields + .constant_declarations + .unwrap_or_else(|| PyTuple::empty(py).unbind()), + extract_implicit_alias_columns: fields.extract_implicit_alias_columns, + }) + } + + /// This file with edited contents and query, as `dataclasses.replace` would make it. + pub fn with_text( + &self, + py: Python<'_>, + contents: Py, + query_sql: Py, + ) -> PyResult { + Ok(Self { + paths: self.paths.shared(py), + contents: contents.bind(py).to_str()?.into(), + projected_texts: (PyOnceLock::new(), PyOnceLock::new()), + header_values: self.header_values.shared(py), + header_column_locations: self.header_column_locations.shared(py), + output_column_locations: self.output_column_locations.shared(py), + query_sql: query_sql.bind(py).to_str()?.into(), + enum_declarations: self.enum_declarations.clone_ref(py), + constant_declarations: self.constant_declarations.clone_ref(py), + extract_implicit_alias_columns: self.extract_implicit_alias_columns, + }) + } + + #[getter] + pub fn file_path(&self, py: Python<'_>) -> PyResult> { + Ok(self.paths.objects(py)?.0.unbind()) + } + + #[getter] + pub fn relative_path(&self, py: Python<'_>) -> PyResult> { + Ok(self.paths.objects(py)?.1.unbind()) + } + + #[getter] + pub fn contents<'py>(&self, py: Python<'py>) -> Bound<'py, PyString> { + projected_text(py, &self.projected_texts.0, &self.contents) + } + + #[getter] + pub fn header_values(&self, py: Python<'_>) -> PyResult> { + Ok(self.header_values.dict(py)?.unbind()) + } + + #[getter] + pub fn header_column_locations<'py>(&self, py: Python<'py>) -> PyResult> { + self.header_locations(py) + } + + #[getter] + pub fn output_column_locations<'py>(&self, py: Python<'py>) -> PyResult> { + self.output_column_locations + .dict(&self.paths.objects(py)?.1) + } + + #[getter] + pub fn query_sql<'py>(&self, py: Python<'py>) -> Bound<'py, PyString> { + projected_text(py, &self.projected_texts.1, &self.query_sql) + } + + #[getter] + pub fn enum_declarations(&self, py: Python<'_>) -> Py { + self.enum_declarations.clone_ref(py) + } + + #[getter] + pub fn constant_declarations(&self, py: Python<'_>) -> Py { + self.constant_declarations.clone_ref(py) + } + + #[getter] + pub fn extract_implicit_alias_columns(&self) -> bool { + self.extract_implicit_alias_columns + } + + pub(crate) fn __eq__(&self, py: Python<'_>, other: &Bound<'_, PyAny>) -> PyResult> { + let Ok(other) = other.downcast::() else { + return Ok(py.NotImplemented()); + }; + let other: &NativeModelFile = other.get(); + for (left, right) in self.fields(py)?.iter().zip(other.fields(py)?) { + if !left.eq(right)? { + return false.into_py_any(py); + } + } + true.into_py_any(py) + } + + pub(crate) fn __repr__(&self, py: Python<'_>) -> PyResult { + let fields: Vec = FIELD_NAMES + .iter() + .zip(self.fields(py)?) + .map(|(name, value)| Ok(format!("{name}={}", value.repr()?))) + .collect::>()?; + Ok(format!("DiscoveredSqlModelFile({})", fields.join(", "))) + } + + /// The keyword fields `copy` and `pickle` rebuild this record from. + pub(crate) fn __getnewargs_ex__<'py>( + slf: &Bound<'py, Self>, + ) -> PyResult<(Bound<'py, PyTuple>, Bound<'py, PyDict>)> { + let py: Python<'py> = slf.py(); + let keywords: Bound<'py, PyDict> = PyDict::new(py); + for (name, value) in FIELD_NAMES.iter().zip(slf.get().fields(py)?) { + keywords.set_item(name, value)?; + } + Ok((PyTuple::empty(py), keywords)) + } +} + +/// Which discovered model files to build, and where failing files are reported. +#[derive(Debug)] +pub struct ModelFileSelection<'py> { + pub selected_model_names: Option>, + pub on_fault: Option>, +} + +/// A decorated Python node as the facade describes it. +#[derive(Debug, FromPyObject)] +#[pyo3(from_item_all)] +pub struct NodeRow { + pub(crate) kind: String, + pub(crate) name: String, + pub(crate) path: String, + pub(crate) decorator_config: bool, + pub(crate) depends_on: Vec, +} + +/// `--allow-missing-secrets` for one invocation, restored when the invocation ends. +#[derive(Debug)] +pub struct MissingSecretsScope { + pub(crate) previous: bool, +} + +impl MissingSecretsScope { + pub fn enter(allowed: bool) -> Self { + Self { + previous: INVOCATION_ALLOWS_MISSING_SECRETS.replace(allowed), + } + } +} + +impl Drop for MissingSecretsScope { + fn drop(&mut self) { + INVOCATION_ALLOWS_MISSING_SECRETS.set(self.previous); + } +} + +/// What discovery does when a provider's required secrets are unset. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum SecretPolicy { + /// Fail with D012: static commands by default. + Require, + /// Continue and list the providers on stderr: static commands that opted out. + Allow, + /// Continue silently; the command checks the providers it uses before running anything. + Defer, +} + +impl SecretPolicy { + /// The keyword value that selects the policy. + pub const fn name(self) -> &'static str { + match self { + Self::Require => "require", + Self::Allow => "allow", + Self::Defer => "defer", + } + } + + pub fn parse(value: &str) -> PyResult { + [Self::Require, Self::Allow, Self::Defer] + .into_iter() + .find(|policy| policy.name() == value) + .ok_or_else(|| PyValueError::new_err(format!("unknown secret policy '{value}'"))) + } +} + +/// The context manager that makes one snapshot active for a project until it exits. +#[pyclass(module = "sqlbuild._native")] +#[derive(Debug)] +pub struct NativeDirectorySnapshotScope { + pub project_dir: pyo3::Py, + /// The context-variable token of the snapshot this scope activated, if it activated one. + pub token: Option>, +} diff --git a/crates/sqlbuild-python-front/src/lib.rs b/crates/sqlbuild-python-front/src/lib.rs new file mode 100644 index 0000000000..b0070dbde8 --- /dev/null +++ b/crates/sqlbuild-python-front/src/lib.rs @@ -0,0 +1,21 @@ +//! The front layer of the `sqlbuild._native` bindings: discovery, model configuration, scopes, rendering and SQL text. + +#![forbid(unsafe_code)] + +pub mod attachments; +pub mod authored_values; +pub mod command_runtime; +pub mod compile_attachment; +pub mod compile_driver; +pub mod contracts; +pub mod cursor; +pub mod discovery; +pub mod macro_bridge; +pub mod model_config; +pub mod native_host; +pub mod refactor; +pub mod render; +pub mod scopes; +pub mod sql_test_glue; +pub mod sqltext; +pub mod state_rows; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/first_compile.rs b/crates/sqlbuild-python-front/src/macro_bridge/_helpers/first_compile.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/first_compile.rs rename to crates/sqlbuild-python-front/src/macro_bridge/_helpers/first_compile.rs diff --git a/crates/sqlbuild-python-front/src/macro_bridge/_helpers/mod.rs b/crates/sqlbuild-python-front/src/macro_bridge/_helpers/mod.rs new file mode 100644 index 0000000000..45adffdb4c --- /dev/null +++ b/crates/sqlbuild-python-front/src/macro_bridge/_helpers/mod.rs @@ -0,0 +1,3 @@ +pub(crate) mod first_compile; +pub(crate) mod module_digests; +pub(crate) mod store_keys; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/module_digests.rs b/crates/sqlbuild-python-front/src/macro_bridge/_helpers/module_digests.rs similarity index 98% rename from crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/module_digests.rs rename to crates/sqlbuild-python-front/src/macro_bridge/_helpers/module_digests.rs index dd34d77fae..45cc26a97a 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/module_digests.rs +++ b/crates/sqlbuild-python-front/src/macro_bridge/_helpers/module_digests.rs @@ -10,7 +10,7 @@ use pyo3::{pyfunction, wrap_pyfunction}; use sqlbuild_cache::module_digests::main::module_digests_metadata::module_digests_metadata as metadata_text; use sqlbuild_core::json::models::JsonValue; -use crate::bindings::_helpers::macro_bridge::store_keys::text; +use crate::macro_bridge::_helpers::store_keys::text; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::cache::main::digest_files::digest_files; use sqlbuild_python_base::frontier::main::emit_error::emit_error; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/store_keys.rs b/crates/sqlbuild-python-front/src/macro_bridge/_helpers/store_keys.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/store_keys.rs rename to crates/sqlbuild-python-front/src/macro_bridge/_helpers/store_keys.rs diff --git a/crates/sqlbuild-python-front/src/macro_bridge/main/context_store_token.rs b/crates/sqlbuild-python-front/src/macro_bridge/main/context_store_token.rs new file mode 100644 index 0000000000..be5b01f271 --- /dev/null +++ b/crates/sqlbuild-python-front/src/macro_bridge/main/context_store_token.rs @@ -0,0 +1,16 @@ +//! Digest the whole context a macro may read, or None when a value has no stable text. + +use crate::macro_bridge::_helpers::store_keys; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::types::PyDict; + +/// Digest the whole context a macro may read, or None when a value has no stable text. +#[inline] +pub fn context_store_token<'py>( + py: Python<'py>, + options: Option>, +) -> PyResult> { + store_keys::context_store_token(py, options) +} diff --git a/crates/sqlbuild-python-front/src/macro_bridge/main/keep_delta_claim.rs b/crates/sqlbuild-python-front/src/macro_bridge/main/keep_delta_claim.rs new file mode 100644 index 0000000000..f2e88dec30 --- /dev/null +++ b/crates/sqlbuild-python-front/src/macro_bridge/main/keep_delta_claim.rs @@ -0,0 +1,9 @@ +//! Keep the delta compile's claim: it finished, so no full compile of this invocation follows. + +use crate::macro_bridge::_helpers::first_compile; + +/// Keep the delta compile's claim: it finished, so no full compile of this invocation follows. +#[inline] +pub fn keep_delta_claim() { + first_compile::keep_delta_claim() +} diff --git a/crates/sqlbuild-python-front/src/macro_bridge/main/macro_store_token.rs b/crates/sqlbuild-python-front/src/macro_bridge/main/macro_store_token.rs new file mode 100644 index 0000000000..1219b76282 --- /dev/null +++ b/crates/sqlbuild-python-front/src/macro_bridge/main/macro_store_token.rs @@ -0,0 +1,16 @@ +//! Name a macro by its name, file, identity and exact source, or None when it has no key. + +use crate::macro_bridge::_helpers::store_keys; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::types::PyDict; + +/// Name a macro by its name, file, identity and exact source, or None when it has no key. +#[inline] +pub fn macro_store_token<'py>( + py: Python<'py>, + options: Option>, +) -> PyResult> { + store_keys::macro_store_token(py, options) +} diff --git a/crates/sqlbuild-python-front/src/macro_bridge/main/mod.rs b/crates/sqlbuild-python-front/src/macro_bridge/main/mod.rs new file mode 100644 index 0000000000..b4f017fd06 --- /dev/null +++ b/crates/sqlbuild-python-front/src/macro_bridge/main/mod.rs @@ -0,0 +1,7 @@ +pub mod context_store_token; +pub mod keep_delta_claim; +pub mod macro_store_token; +pub mod register_first_compile; +pub mod register_module_digests; +pub mod register_store_keys; +pub mod text; diff --git a/crates/sqlbuild-python-front/src/macro_bridge/main/register_first_compile.rs b/crates/sqlbuild-python-front/src/macro_bridge/main/register_first_compile.rs new file mode 100644 index 0000000000..d255b60486 --- /dev/null +++ b/crates/sqlbuild-python-front/src/macro_bridge/main/register_first_compile.rs @@ -0,0 +1,12 @@ +//! Register the first compile functions and classes. + +use crate::macro_bridge::_helpers::first_compile; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the first compile functions and classes. +#[inline] +pub fn register_first_compile(module: &Bound<'_, PyModule>) -> PyResult<()> { + first_compile::register(module) +} diff --git a/crates/sqlbuild-python-front/src/macro_bridge/main/register_module_digests.rs b/crates/sqlbuild-python-front/src/macro_bridge/main/register_module_digests.rs new file mode 100644 index 0000000000..5c4403757a --- /dev/null +++ b/crates/sqlbuild-python-front/src/macro_bridge/main/register_module_digests.rs @@ -0,0 +1,12 @@ +//! Register the module digests functions and classes. + +use crate::macro_bridge::_helpers::module_digests; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the module digests functions and classes. +#[inline] +pub fn register_module_digests(module: &Bound<'_, PyModule>) -> PyResult<()> { + module_digests::register(module) +} diff --git a/crates/sqlbuild-python-front/src/macro_bridge/main/register_store_keys.rs b/crates/sqlbuild-python-front/src/macro_bridge/main/register_store_keys.rs new file mode 100644 index 0000000000..8ec80a3394 --- /dev/null +++ b/crates/sqlbuild-python-front/src/macro_bridge/main/register_store_keys.rs @@ -0,0 +1,12 @@ +//! Register the store keys functions and classes. + +use crate::macro_bridge::_helpers::store_keys; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the store keys functions and classes. +#[inline] +pub fn register_store_keys(module: &Bound<'_, PyModule>) -> PyResult<()> { + store_keys::register(module) +} diff --git a/crates/sqlbuild-python-front/src/macro_bridge/main/text.rs b/crates/sqlbuild-python-front/src/macro_bridge/main/text.rs new file mode 100644 index 0000000000..4a1a649ee5 --- /dev/null +++ b/crates/sqlbuild-python-front/src/macro_bridge/main/text.rs @@ -0,0 +1,13 @@ +//! A Python `str` as JSON text; one holding a lone surrogate as UTF-16 code units. + +use crate::macro_bridge::_helpers::store_keys; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::types::PyString; +use sqlbuild_core::json::models::JsonValue; + +/// A Python `str` as JSON text; one holding a lone surrogate as UTF-16 code units. +#[inline] +pub fn text(value: &Bound<'_, PyString>) -> PyResult { + store_keys::text(value) +} diff --git a/crates/sqlbuild-python-front/src/macro_bridge/mod.rs b/crates/sqlbuild-python-front/src/macro_bridge/mod.rs new file mode 100644 index 0000000000..53d5f87ee2 --- /dev/null +++ b/crates/sqlbuild-python-front/src/macro_bridge/mod.rs @@ -0,0 +1,4 @@ +//! Keys and digests the macro bridge uses to reuse first-compile macro results. + +pub(crate) mod _helpers; +pub mod main; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/config_classes.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/config/config_classes.rs similarity index 80% rename from crates/sqlbuild-python/src/bindings/_helpers/model_config/config_classes.rs rename to crates/sqlbuild-python-front/src/model_config/_helpers/config/config_classes.rs index a869bc2bcd..94efd6949a 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/model_config/config_classes.rs +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/config/config_classes.rs @@ -1,38 +1,20 @@ //! The Python classes a model's `CompileModelConfig` is built from, and building one from a native build. +use crate::model_config::models::ConfigClasses; +use pyo3::IntoPyObject; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; use pyo3::types::{PyDict, PyDictMethods, PyString, PyStringMethods, PyTuple}; -use pyo3::{FromPyObject, IntoPyObject}; use sqlbuild_model_config::model_validation::models::{RetentionOverride, TableTypeOverride}; -use crate::bindings::_helpers::model_config::model_config_builder::{ - BuiltConfig, NativeModelConfigBuilder, -}; -use crate::bindings::_helpers::model_config::typed_config::{BuiltConfigValues, retain_values}; +use crate::model_config::_helpers::config::typed_config::retain_values; +use crate::model_config::models::BuiltConfig; +use crate::model_config::types::BuiltConfigValues; const MATERIALIZED_KEY: &str = "materialized"; const VALUES_FIELD: &str = "values"; const PERMANENT_TABLE_TYPE: &str = "permanent"; const TRANSIENT_TABLE_TYPE: &str = "transient"; -/// The builder, storage defaults and Python classes a model's `CompileModelConfig` is made of. -#[derive(FromPyObject)] -#[pyo3(from_item_all)] -pub(crate) struct ConfigClasses<'py> { - pub(crate) builder: Bound<'py, NativeModelConfigBuilder>, - /// Inherited `(retention, table type)` by table-backed materialization, or `None`. - pub(crate) inherited_storage: Bound<'py, PyDict>, - pub(crate) table_backed: Vec, - pub(crate) compile_model_config: Bound<'py, PyAny>, - pub(crate) resolved_retention: Bound<'py, PyAny>, - pub(crate) retention_source: Bound<'py, PyAny>, - pub(crate) resolved_table_type: Bound<'py, PyAny>, - pub(crate) table_type: Bound<'py, PyAny>, - pub(crate) table_type_source: Bound<'py, PyAny>, - /// `record_template_reads`, the compile-reuse sink of template reads. - pub(crate) record_template_reads: Bound<'py, PyAny>, -} - /// The model's `CompileModelConfig`, once its template reads are recorded. pub(crate) fn built_config<'py>( classes: &ConfigClasses<'py>, @@ -112,7 +94,7 @@ fn storage_key<'py>( Ok(py.None().into_bound(py)) } -fn resolved_retention<'py>( +pub(crate) fn resolved_retention<'py>( classes: &ConfigClasses<'py>, desired_days: Bound<'py, PyAny>, unmanaged: bool, @@ -124,7 +106,7 @@ fn resolved_retention<'py>( classes.resolved_retention.call((), Some(&fields)) } -fn resolved_table_type<'py>( +pub(crate) fn resolved_table_type<'py>( classes: &ConfigClasses<'py>, value: &str, ) -> PyResult> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/config_errors.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/config/config_errors.rs similarity index 95% rename from crates/sqlbuild-python/src/bindings/_helpers/model_config/config_errors.rs rename to crates/sqlbuild-python-front/src/model_config/_helpers/config/config_errors.rs index 043840ee5a..1ff777cbd3 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/model_config/config_errors.rs +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/config/config_errors.rs @@ -5,8 +5,8 @@ use pyo3::types::{PyDict, PyDictMethods}; use pyo3::{Py, PyErr, pymethods}; use sqlbuild_model_config::errors::{ConfigError, ErrorClass}; -use crate::bindings::_helpers::model_config::config_values::config_value_type_error; -use crate::bindings::_helpers::model_config::errors::NativeConfigError; +use crate::model_config::_helpers::config::config_values::config_value_type_error; +use crate::model_config::errors::NativeConfigError; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::types::ErrorId; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/config_nodes.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/config/config_nodes.rs similarity index 87% rename from crates/sqlbuild-python/src/bindings/_helpers/model_config/config_nodes.rs rename to crates/sqlbuild-python-front/src/model_config/_helpers/config/config_nodes.rs index c8e79d0330..33b0181197 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/model_config/config_nodes.rs +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/config/config_nodes.rs @@ -1,10 +1,12 @@ //! Python config values converted once into `ConfigNode`s, and projected back into Python objects. +use crate::model_config::models::HostHandle; +use crate::model_config::types::PyConfigNode; use std::sync::Arc; use pyo3::IntoPyObject; use pyo3::exceptions::{PyOverflowError, PyUnicodeEncodeError}; -use pyo3::prelude::{Bound, Py, PyAny, PyAnyMethods, PyResult, Python}; +use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; use pyo3::types::{ PyBool, PyDict, PyDictMethods, PyFloat, PyInt, PyList, PyListMethods, PyString, PyStringMethods, PyTuple, PyTupleMethods, @@ -12,10 +14,9 @@ use pyo3::types::{ use sqlbuild_model_config::config_values::models::{ ConfigNode, HostChildren, HostFacts, HostValue, }; -use sqlbuild_model_config::config_values::types::HostObject; use sqlbuild_model_config::types::{AuthoredNode, NodeKind}; -use crate::bindings::_helpers::model_config::authored_nodes::PyNode; +use crate::model_config::models::PyNode; use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::types::RecordId; @@ -26,34 +27,6 @@ const HOOK_ENTRY_CLASSES: [RecordId; 3] = [ RecordId::PythonHookEntry, ]; -/// The Python object an opaque config value stands for. -#[derive(Clone, Debug)] -pub(crate) struct HostHandle(pub(crate) Arc>); - -impl HostObject for HostHandle { - fn is_date_like(&self) -> bool { - Python::attach(|py| PyNode(self.0.bind(py).clone()).is_date_like()) - } - - /// Python's text of the projected value; a `str()` or `repr()` that raises reads as empty, as `PyNode`. - fn display(node: &ConfigNode, repr: bool) -> String { - Python::attach(|py| { - config_object(py, node).map_or_else( - |_| String::new(), - |value| { - let value: PyNode<'_> = PyNode(value); - if repr { - value.python_repr() - } else { - value.python_str() - } - }, - ) - }) - } -} -/// A config value converted from Python. -pub(crate) type PyConfigNode = ConfigNode; /// A converted config mapping's entries. pub(crate) type PyConfigEntries = Vec<(PyConfigNode, PyConfigNode)>; diff --git a/crates/sqlbuild-python-front/src/model_config/_helpers/config/config_templates.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/config/config_templates.rs new file mode 100644 index 0000000000..759e89e53f --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/config/config_templates.rs @@ -0,0 +1,211 @@ +//! `${...}` templates in authored Python config values and effective vars, expanded natively. + +use crate::model_config::models::PythonHost; +use crate::model_config::models::Stop; +use crate::model_config::models::TemplateSources; +use std::cell::RefCell; + +use pyo3::prelude::{Bound, Py, PyAny, PyAnyMethods, PyModule, PyResult, Python}; +use pyo3::types::{ + PyDict, PyDictMethods, PyList, PyListMethods, PyString, PyStringMethods, PyTuple, + PyTupleMethods, +}; +use sqlbuild_model_config::errors::ConfigError; +use sqlbuild_model_config::templates::errors::TemplateError; +use sqlbuild_model_config::templates::main::expand_template_string::expand_template_string; +use sqlbuild_model_config::templates::main::template_error_message::template_error_message; +use sqlbuild_model_config::templates::models::{StringExpansion, TemplateOptions}; +use sqlbuild_model_config::templates::types::TemplateHost; + +use crate::model_config::_helpers::config::config_errors::native_config_error; +use crate::model_config::errors::NativeConfigError; + +const TEMPLATE_OPEN_TOKEN: &str = "${"; +pub(crate) const ENVIRONMENT_READ: &str = "env"; +pub(crate) const CONTEXT_READ: &str = "ctx"; +pub(crate) const EFFECTIVE_VARS_LABEL: &str = "effective vars"; +const VALUE_PATH: &str = "its value"; +const BUILTINS_MODULE: &str = "builtins"; +const ASCII_FUNCTION: &str = "ascii"; +const ENCODE: &str = "encode"; +const UTF32_LE: &str = "utf-32-le"; +const SURROGATE_PASS: &str = "surrogatepass"; + +/// Effective vars resolved on demand, as Python's `_EffectiveVarsResolver` resolves them. +#[derive(Debug)] +pub(crate) struct EffectiveVars<'py> { + pub(crate) resolved: Bound<'py, PyDict>, + pub(crate) resolving: RefCell>, +} + +/// The `CompileInputError` Python raises for a template error in the context `label`. +pub(crate) fn template_error(error: &TemplateError, label: &str) -> ConfigError { + ConfigError::compile(template_error_message(error, label)) +} + +/// The expanded value, or the native error expansion stopped at, and the reads in order. +pub(crate) type TemplateOutcome<'py> = ( + Result, Py>, + Vec<(&'static str, String)>, +); + +/// `value` with every template expanded under `options`, or the error, with its reads. +pub(crate) fn expand_config_templates<'py>( + py: Python<'py>, + value: &Bound<'py, PyAny>, + sources: TemplateSources<'py>, + (options, label): (TemplateOptions, &str), +) -> PyResult> { + let host = PythonHost::new(py, sources, label); + let result = expanded(&host, value, options); + outcome(py, host, result, label) +} + +/// The first `(var name, value path, UTF-8 byte offset)` of a lone surrogate in raw vars. +pub(crate) fn lone_surrogate_site<'py>( + raw_values: &Bound<'py, PyDict>, +) -> PyResult, String, usize)>> { + for (key, value) in raw_values.iter() { + if let Some((path, offset)) = surrogate_path(&value, VALUE_PATH.to_owned())? { + return Ok(Some((key.str()?, path, offset))); + } + } + Ok(None) +} + +/// Python's former `_reject_lone_surrogates` walk: dict keys then items, lists and tuples. +fn surrogate_path(value: &Bound<'_, PyAny>, path: String) -> PyResult> { + if let Ok(mapping) = value.downcast::() { + for (key, item) in mapping.iter() { + if let Some(site) = surrogate_path(&key, format!("{path} key"))? { + return Ok(Some(site)); + } + let key_ascii = PyModule::import(value.py(), BUILTINS_MODULE)? + .getattr(ASCII_FUNCTION)? + .call1((&key,))? + .str()? + .to_string_lossy() + .into_owned(); + if let Some(site) = surrogate_path(&item, format!("{path}[{key_ascii}]"))? { + return Ok(Some(site)); + } + } + return Ok(None); + } + if value.is_instance_of::() || value.is_instance_of::() { + for (index, item) in value.try_iter()?.enumerate() { + if let Some(site) = surrogate_path(&item?, format!("{path}[{index}]"))? { + return Ok(Some(site)); + } + } + return Ok(None); + } + let Ok(text) = value.downcast::() else { + return Ok(None); + }; + Ok(first_surrogate_offset(text)?.map(|offset| (path, offset))) +} + +/// The UTF-8 byte offset of the first lone surrogate in `text`. +fn first_surrogate_offset(text: &Bound<'_, PyString>) -> PyResult> { + let encoded = text.call_method1(ENCODE, (UTF32_LE, SURROGATE_PASS))?; + let mut offset = 0; + for unit in encoded.extract::>()?.as_chunks::<4>().0 { + let code_point = u32::from_le_bytes([unit[0], unit[1], unit[2], unit[3]]); + match char::from_u32(code_point) { + Some(character) => offset += character.len_utf8(), + None => return Ok(Some(offset)), + } + } + Ok(None) +} + +/// The resolved effective vars, or the native error resolution stopped at, with the reads. +pub(crate) fn resolve_effective_vars<'py>( + py: Python<'py>, + raw_values: &Bound<'py, PyDict>, + environment: Bound<'py, PyAny>, +) -> PyResult> { + let mut host = PythonHost::new( + py, + TemplateSources(raw_values.clone(), environment, PyDict::new(py)), + EFFECTIVE_VARS_LABEL, + ); + let resolved = PyDict::new(py); + host.effective = Some(EffectiveVars { + resolved: resolved.clone(), + resolving: RefCell::new(Vec::new()), + }); + let mut result: Result, Stop> = Ok(resolved.clone().into_any()); + for key in raw_values.keys() { + let name = key.str()?.to_str()?.to_owned(); + if let Err(failure) = host.variable(&name) { + result = Err(host.stop(failure)); + break; + } + } + outcome(py, host, result, EFFECTIVE_VARS_LABEL) +} + +fn outcome<'py>( + py: Python<'py>, + host: PythonHost<'py>, + result: Result, Stop>, + label: &str, +) -> PyResult> { + let value = match result { + Ok(value) => Ok(value), + Err(Stop::Failure(error)) => Err(native_config_error(py, template_error(&error, label))?), + Err(Stop::Python(error)) => return Err(error), + }; + Ok((value, host.into_reads())) +} + +/// Expand every template in `value` and the containers inside it. +pub(crate) fn expanded<'py>( + host: &PythonHost<'py>, + value: &Bound<'py, PyAny>, + options: TemplateOptions, +) -> Result, Stop> { + let py = host.py; + if let Ok(text) = value.downcast::() { + let text = text.to_str().map_err(Stop::Python)?; + if !text.contains(TEMPLATE_OPEN_TOKEN) { + return Ok(value.clone()); + } + return match expand_template_string(host, text, options) { + Ok(StringExpansion::Unchanged) => Ok(PyString::new(py, text).into_any()), + Ok(StringExpansion::Value(result)) => Ok(result), + Ok(StringExpansion::Text(result)) => Ok(PyString::new(py, &result).into_any()), + Err(failure) => Err(host.stop(failure)), + }; + } + if let Ok(mapping) = value.downcast::() { + let result = PyDict::new(py); + for (key, item) in mapping.iter() { + result + .set_item(key, expanded(host, &item, options)?) + .map_err(Stop::Python)?; + } + return Ok(result.into_any()); + } + if let Ok(items) = value.downcast::() { + let result = items + .iter() + .map(|item| expanded(host, &item, options)) + .collect::, _>>()?; + return PyList::new(py, result) + .map(Bound::into_any) + .map_err(Stop::Python); + } + if let Ok(items) = value.downcast::() { + let result = items + .iter() + .map(|item| expanded(host, &item, options)) + .collect::, _>>()?; + return PyTuple::new(py, result) + .map(Bound::into_any) + .map_err(Stop::Python); + } + Ok(value.clone()) +} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/config_values.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/config/config_values.rs similarity index 96% rename from crates/sqlbuild-python/src/bindings/_helpers/model_config/config_values.rs rename to crates/sqlbuild-python-front/src/model_config/_helpers/config/config_values.rs index 158d716c7e..8cf5b4efed 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/model_config/config_values.rs +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/config/config_values.rs @@ -10,8 +10,9 @@ use sqlbuild_model_config::config_values::main::checked_text::checked_text; use sqlbuild_model_config::config_values::main::checked_texts::checked_texts; use sqlbuild_model_config::config_values::models::CursorBound; -use crate::bindings::_helpers::model_config::config_nodes::{PyConfigNode, config_node}; -use crate::bindings::_helpers::model_config::typed_config::type_error; +use crate::model_config::_helpers::config::config_nodes::config_node; +use crate::model_config::_helpers::config::typed_config::type_error; +use crate::model_config::types::PyConfigNode; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/getters.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/config/getters.rs similarity index 65% rename from crates/sqlbuild-python/src/bindings/_helpers/model_config/getters.rs rename to crates/sqlbuild-python-front/src/model_config/_helpers/config/getters.rs index 4ba23b2a87..041cade44f 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/model_config/getters.rs +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/config/getters.rs @@ -3,17 +3,9 @@ use pyo3::IntoPyObjectExt; use pyo3::prelude::{Bound, PyAny, PyResult, Python}; -use crate::bindings::_helpers::model_config::errors::NativeConfigError; -use sqlbuild_python_base::records::main::registry::class_of::class_of; -use sqlbuild_python_base::records::models::GetterEntry; +use crate::model_config::errors::NativeConfigError; -/// The getter readers of this module's native pyclasses. -pub(crate) const GETTERS: &[GetterEntry] = &[GetterEntry { - class: class_of::, - read: read_native_config_error, -}]; - -fn read_native_config_error<'py>( +pub(crate) fn read_native_config_error<'py>( value: &Bound<'py, PyAny>, name: &str, ) -> Option>> { diff --git a/crates/sqlbuild-python-front/src/model_config/_helpers/config/mod.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/config/mod.rs new file mode 100644 index 0000000000..e9893f192c --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/config/mod.rs @@ -0,0 +1,8 @@ +pub(crate) mod config_classes; +pub(crate) mod config_errors; +pub(crate) mod config_nodes; +pub(crate) mod config_templates; +pub(crate) mod config_values; +pub(crate) mod getters; +pub(crate) mod template_data; +pub(crate) mod typed_config; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/template_data.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/config/template_data.rs similarity index 90% rename from crates/sqlbuild-python/src/bindings/_helpers/model_config/template_data.rs rename to crates/sqlbuild-python-front/src/model_config/_helpers/config/template_data.rs index 48273a287f..5a8c4bb375 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/model_config/template_data.rs +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/config/template_data.rs @@ -10,12 +10,13 @@ use pyo3::{pyfunction, wrap_pyfunction}; use sqlbuild_core::scenario_command::main::format_captured_at::format_captured_at; use sqlbuild_model_config::templates::models::TemplateOptions; -use crate::bindings::_helpers::model_config::config_errors::config_exception; -use crate::bindings::_helpers::model_config::config_templates::{ - TemplateOutcome, TemplateSources, expand_config_templates, lone_surrogate_site, - resolve_effective_vars, -}; -use crate::bindings::_helpers::model_config::unicode_environment::unicode_environment; +use crate::model_config::_helpers::config::config_errors::config_exception; +use crate::model_config::_helpers::config::config_templates::TemplateOutcome; +use crate::model_config::_helpers::config::config_templates::expand_config_templates; +use crate::model_config::_helpers::config::config_templates::lone_surrogate_site; +use crate::model_config::_helpers::config::config_templates::resolve_effective_vars; +use crate::model_config::_helpers::model_nodes::unicode_environment::unicode_environment; +use crate::model_config::models::TemplateSources; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::boundary::models::Request; @@ -211,3 +212,10 @@ pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { module.add_function(wrap_pyfunction!(resolve_run_id, module)?)?; Ok(()) } + +/// `record_template_reads` as a Python function. +pub(crate) fn record_template_reads_function( + py: pyo3::Python<'_>, +) -> pyo3::PyResult> { + pyo3::wrap_pyfunction!(record_template_reads, py) +} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/typed_config.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/config/typed_config.rs similarity index 92% rename from crates/sqlbuild-python/src/bindings/_helpers/model_config/typed_config.rs rename to crates/sqlbuild-python-front/src/model_config/_helpers/config/typed_config.rs index 190cb7abbf..5d628ab405 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/model_config/typed_config.rs +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/config/typed_config.rs @@ -1,11 +1,13 @@ //! Built model config trees retained natively, with Python-authored values converted on first read. +use crate::model_config::models::TypedConfigValues; +use crate::model_config::types::BuiltConfigValues; +use crate::model_config::types::ConfigValues; use std::collections::HashMap; use std::sync::{Arc, Mutex}; use pyo3::exceptions::PyRuntimeError; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult, Python}; -use pyo3::pyclass; use pyo3::types::{PyString, PyTuple}; use sqlbuild_model_config::config_values::errors::ConfigTypeError; use sqlbuild_model_config::config_values::main::checked_cursor_bound::checked_cursor_bound; @@ -15,10 +17,13 @@ use sqlbuild_model_config::config_values::main::checked_text::checked_text; use sqlbuild_model_config::config_values::main::checked_texts::checked_texts; use sqlbuild_model_config::config_values::models::{ConfigNode, CursorBound, HostChildren}; -use crate::bindings::_helpers::model_config::config_nodes::{ - HostHandle, PyConfigEntries, PyConfigNode, config_node, config_object, is_exact_container, -}; -use crate::bindings::_helpers::model_config::config_values::config_value_type_error; +use crate::model_config::_helpers::config::config_nodes::PyConfigEntries; +use crate::model_config::_helpers::config::config_nodes::config_node; +use crate::model_config::_helpers::config::config_nodes::config_object; +use crate::model_config::_helpers::config::config_nodes::is_exact_container; +use crate::model_config::_helpers::config::config_values::config_value_type_error; +use crate::model_config::models::HostHandle; +use crate::model_config::types::PyConfigNode; use sqlbuild_python_base::compile_driver::constants::TYPED_CONFIG_READS; use sqlbuild_python_base::compile_driver::main::count_stage::count_stage; use sqlbuild_python_base::records::main::fields::cached_value::cached_value; @@ -34,16 +39,6 @@ const ISOFORMAT_METHOD: &str = "isoformat"; const TYPED_VALUES_SLOT: &str = "__typed_values__"; const POISONED: &str = "typed config values cache is poisoned"; -/// A built config's string-keyed tree; values shared across reused configs stay native. -pub(crate) type BuiltConfigValues = Arc>>; - -/// The built tree and any Python-authored values opened by the record's readers. -#[pyclass(module = "sqlbuild._native", frozen)] -pub(crate) struct TypedConfigValues { - pub(crate) built: Option, - read: Mutex)>>, -} - /// Keep the builder's tree without interpreting custom Python mapping keys natively. pub(crate) fn built_values(entries: PyConfigEntries) -> Option { let mut values = HashMap::with_capacity(entries.len()); @@ -76,9 +71,6 @@ pub(crate) fn retain_values( Ok(()) } -/// A config record's values and the typed nodes read of them, each key converted on first read. -pub(crate) type ConfigValues<'py> = (Bound<'py, PyAny>, Bound<'py, TypedConfigValues>); - /// `values.get(key)` as a typed node, `None` when absent; each key is converted once. fn node(values: &ConfigValues<'_>, key: &str) -> PyResult> { let (mapping, typed) = values; diff --git a/crates/sqlbuild-python-front/src/model_config/_helpers/headers/header_audits.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/headers/header_audits.rs new file mode 100644 index 0000000000..1811576f97 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/headers/header_audits.rs @@ -0,0 +1,107 @@ +//! Retained audit contracts; Python-authored factory results remain opaque values. + +use pyo3::prelude::{PyResult, Python}; +use sqlbuild_core::json::models::{JsonInteger, JsonValue}; +use sqlbuild_discovery::model_files::main::config_value::config_value; +use sqlbuild_discovery::model_files::models::NativeAudit; +use sqlbuild_model_config::config_values::models::ConfigNode; +use sqlbuild_model_config::header_metadata::models::ParsedAudit; +use sqlbuild_sqltext::compiler::models::AuthoredValue; + +use crate::model_config::_helpers::config::config_nodes::config_node; +use crate::model_config::_helpers::config::config_nodes::config_object; +use crate::model_config::types::HeaderValue; +use crate::model_config::types::PyConfigNode; +use crate::sqltext::main::authored_value_to_python::authored_value_to_python; +use sqlbuild_python_base::result_output::main::json_value::json_value; + +/// Native discovery facts keep their authored values rather than building audit records. +pub(crate) fn authored_audit( + py: Python<'_>, + spec: &NativeAudit, +) -> PyResult> { + let value = |value: &AuthoredValue| match config_value(value) { + Some(value) => Ok(value), + None => config_node(authored_value_to_python(py, value)?.bind(py)), + }; + Ok(ParsedAudit { + definition_name: ConfigNode::Str(spec.definition_name.clone()), + arguments: spec + .arguments + .iter() + .map(|(key, item)| Ok((ConfigNode::Str(key.clone()), value(item)?))) + .collect::>()?, + name: spec.name.clone().map(ConfigNode::Str), + description: spec.description.clone().map(ConfigNode::Str), + severity: spec.severity.clone().map(ConfigNode::Str), + run_scope: spec.run_scope.clone().map(ConfigNode::Str), + always_run: spec.always_run.map(ConfigNode::Bool), + thresholds: spec.thresholds, + minimum_samples: spec.minimum_samples.as_ref().map(value).transpose()?, + evidence_limit: spec.evidence_limit.as_ref().map(value).transpose()?, + meta: spec.meta.as_ref().map(value).transpose()?, + }) +} + +/// Preserve parsed leaves without rebuilding their public argument dictionaries. +pub(crate) fn retain_audit( + py: Python<'_>, + spec: &ParsedAudit, +) -> PyResult> { + let optional = |node: &Option| node.as_ref().map(|node| node.retained(py)).transpose(); + Ok(ParsedAudit { + definition_name: spec.definition_name.retained(py)?, + arguments: spec + .arguments + .iter() + .map(|(key, value)| Ok((key.retained(py)?, value.retained(py)?))) + .collect::>()?, + name: optional(&spec.name)?, + description: optional(&spec.description)?, + severity: optional(&spec.severity)?, + run_scope: optional(&spec.run_scope)?, + always_run: optional(&spec.always_run)?, + thresholds: spec.thresholds, + minimum_samples: optional(&spec.minimum_samples)?, + evidence_limit: optional(&spec.evidence_limit)?, + meta: optional(&spec.meta)?, + }) +} + +/// Read metadata without projecting retained containers; opaque user values keep Python semantics. +pub(crate) fn config_json_value( + py: Python<'_>, + value: &PyConfigNode, +) -> PyResult> { + Ok(Some(match value { + ConfigNode::Null => JsonValue::Null, + ConfigNode::Bool(value) => JsonValue::Bool(*value), + ConfigNode::Int(value) => JsonValue::Integer(JsonInteger::from(*value)), + ConfigNode::Float(value) => JsonValue::Float(*value), + ConfigNode::Str(value) => JsonValue::String(value.clone()), + ConfigNode::List(items) | ConfigNode::Tuple(items) => { + let mut result: Vec = Vec::with_capacity(items.len()); + for item in items { + let Some(value) = config_json_value(py, item)? else { + return Ok(None); + }; + result.push(value); + } + JsonValue::Array(result) + } + ConfigNode::Map(entries) => { + let mut result: Vec<(String, JsonValue)> = Vec::with_capacity(entries.len()); + for (key, item) in entries { + let ConfigNode::Str(key) = key else { + return json_value(&config_object(py, value)?); + }; + let Some(value) = config_json_value(py, item)? else { + return Ok(None); + }; + result.push((key.clone(), value)); + } + JsonValue::Object(result) + } + ConfigNode::Host(_) => return json_value(&config_object(py, value)?), + })) +} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/header_columns.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/headers/header_columns.rs similarity index 87% rename from crates/sqlbuild-python/src/bindings/_helpers/model_config/header_columns.rs rename to crates/sqlbuild-python-front/src/model_config/_helpers/headers/header_columns.rs index 87e9ba1940..86f53dccfa 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/model_config/header_columns.rs +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/headers/header_columns.rs @@ -9,11 +9,12 @@ use sqlbuild_model_config::errors::{ConfigError, ErrorClass}; use sqlbuild_model_config::header_metadata::main::parse_schema_columns::parse_schema_columns as parse_columns; use sqlbuild_model_config::header_metadata::models::ColumnRequest; -use crate::bindings::_helpers::model_config::authored_nodes::PyNode; -use crate::bindings::_helpers::model_config::config_errors::config_exception; -use crate::bindings::_helpers::model_config::config_errors::native_config_error; -use crate::bindings::_helpers::model_config::contract_classes::contract_classes; -use crate::bindings::_helpers::model_config::header_metadata::{ContractClasses, column_tuple}; +use crate::model_config::_helpers::config::config_errors::config_exception; +use crate::model_config::_helpers::config::config_errors::native_config_error; +use crate::model_config::_helpers::headers::header_metadata::column_tuple; +use crate::model_config::_helpers::model_nodes::contract_classes::contract_classes; +use crate::model_config::models::ContractClasses; +use crate::model_config::models::PyNode; use sqlbuild_python_base::boundary::main::compiler_guard::compiler_guard; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::types::ErrorId; diff --git a/crates/sqlbuild-python-front/src/model_config/_helpers/headers/header_families.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/headers/header_families.rs new file mode 100644 index 0000000000..144dc5045a --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/headers/header_families.rs @@ -0,0 +1,24 @@ +//! Native dynamic-column contracts with a shared, lazy public projection. + +use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult}; +use sqlbuild_model_config::header_metadata::models::DynamicFamily; + +use sqlbuild_python_base::records::main::fields::field::field; + +/// A Python-authored family contract crosses into native ownership once. +pub(crate) fn family_specs(families: &Bound<'_, PyAny>) -> PyResult> { + families + .try_iter()? + .map(|family| { + let family = family?; + Ok(DynamicFamily { + name: field(&family, "name")?.extract()?, + pivot_column: field(&family, "pivot_column")?.extract()?, + value_column: field(&family, "value_column")?.extract()?, + aggregate: field(&family, "aggregate")?.extract()?, + data_type: field(&family, "type")?.extract()?, + name_pattern: field(&family, "name_pattern")?.extract()?, + }) + }) + .collect() +} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/header_metadata.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/headers/header_metadata.rs similarity index 58% rename from crates/sqlbuild-python/src/bindings/_helpers/model_config/header_metadata.rs rename to crates/sqlbuild-python-front/src/model_config/_helpers/headers/header_metadata.rs index 01f4e978fc..068e2e8701 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/model_config/header_metadata.rs +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/headers/header_metadata.rs @@ -1,40 +1,36 @@ //! Parsed MODEL header columns and audits built into the Python contract objects. +use crate::model_config::models::ContractClasses; +use crate::model_config::models::HeaderColumn; +use crate::model_config::models::NativeColumnSpec; +use crate::model_config::types::HeaderValue; use std::sync::OnceLock; use pyo3::exceptions::PyRuntimeError; use pyo3::prelude::{Bound, Py, PyAny, PyAnyMethods, PyResult, Python}; -use pyo3::sync::PyOnceLock; use pyo3::types::{PyBool, PyDict, PyDictMethods, PyTuple}; -use pyo3::{FromPyObject, IntoPyObject, IntoPyObjectExt}; +use pyo3::{IntoPyObject, IntoPyObjectExt}; use sqlbuild_discovery::model_files::models::{NativeAudit, NativeColumn}; use sqlbuild_discovery::models::LineColumnSpan; -use sqlbuild_model_config::header_metadata::constants::AUDITS_KEY; use sqlbuild_model_config::header_metadata::models::{ ParsedAudit, ParsedColumn, ParsedThresholds, ThresholdBound, }; -use sqlbuild_model_config::types::AuthoredNode; use sqlbuild_sqltext::compiler::models::AuthoredValue; -use crate::bindings::_helpers::discovery::model_file_record::NativeModelFile; -use crate::bindings::_helpers::model_config::authored_nodes::PyNode; -use crate::bindings::_helpers::model_config::config_nodes::{ - PyConfigNode, config_node, config_object, -}; -use crate::bindings::_helpers::model_config::contract_classes::contract_classes; -use crate::bindings::_helpers::model_config::header_audits::{ - AuditInstance, HeaderAudits, authored_audit, -}; -use crate::bindings::_helpers::model_config::typed_config::node_text; -use crate::bindings::_helpers::sqltext::authored_values::authored_value_to_python; +use crate::model_config::_helpers::config::config_nodes::config_object; +use crate::model_config::_helpers::config::typed_config::node_text; +use crate::model_config::_helpers::model_nodes::contract_classes::contract_classes; +use crate::model_config::models::HeaderAudits; +use crate::model_config::models::PyNode; +use crate::model_config::types::PyConfigNode; +use crate::sqltext::main::authored_value_to_python::authored_value_to_python; use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::all_specs::all_specs; -use sqlbuild_python_base::records::main::fields::field::field; use sqlbuild_python_base::records::types::RecordId; /// `SchemaColumn` fields in declaration order, the order its objects are built positionally in. -const SCHEMA_COLUMN_FIELDS: [&str; 8] = [ +pub(crate) const SCHEMA_COLUMN_FIELDS: [&str; 8] = [ "name", "type", "nullable", @@ -71,19 +67,6 @@ const POSITIONAL_RECORDS: [(&str, &[&str]); 4] = [ ("MeasurementThresholdBound", &THRESHOLD_BOUND_FIELDS), ]; -/// A parsed leaf projected only when a public contract needs its Python value. -pub(crate) trait HeaderValue: AuthoredNode { - fn object<'py>(&self, py: Python<'py>) -> PyResult>; - - fn retained(&self, py: Python<'_>) -> PyResult { - config_node(&self.object(py)?) - } - - fn exact_text(&self, py: Python<'_>) -> PyResult { - self.object(py)?.extract() - } -} - impl HeaderValue for PyNode<'_> { fn object<'py>(&self, py: Python<'py>) -> PyResult> { Ok(self.0.as_unbound().bind(py).clone()) @@ -118,16 +101,8 @@ impl HeaderValue for PyConfigNode { } } -/// Native column fields; a Python record is constructed only for public consumers. -pub(crate) struct HeaderColumn { - fields: ColumnFields, - class: Py, - audits: Option, - projection: PyOnceLock>, -} - /// What a column's Python record is built from. -enum ColumnFields { +pub(crate) enum ColumnFields { /// The record's field values, in declaration order. Python([Py; 8]), /// A header column read natively, with what its location and audits are built with. @@ -136,204 +111,6 @@ enum ColumnFields { Projected, } -/// A natively parsed header column and what its Python record is built with. -pub(crate) struct NativeColumnSpec { - pub(crate) column: NativeColumn, - /// The model file whose relative path the column's location names, and the location. - pub(crate) location: Option<(Py, LineColumnSpan)>, -} - -impl HeaderColumn { - /// Retype a builtin column without discarding its retained audit specs. - pub(crate) fn enum_type( - mut self, - py: Python<'_>, - scalar_type: Bound<'_, PyAny>, - generated: Option>, - ) -> PyResult { - if self.audits.is_none() - && let ColumnFields::Native(spec) = &self.fields - { - let audits = spec - .column - .audits - .iter() - .map(|audit| authored_audit(py, audit)) - .collect::>>()?; - let classes: ContractClasses<'_> = contract_classes(py)?.extract()?; - self.audits = Some(HeaderAudits::new( - py, - &classes, - &audits, - &native_location(py, spec)?, - )?); - } - if let Some(audits) = &mut self.audits { - if let Some(generated) = generated { - audits.push_native(generated); - } - match &mut self.fields { - ColumnFields::Native(spec) => spec.column.column_type = scalar_type.extract()?, - ColumnFields::Python(values) => values[1] = scalar_type.unbind(), - ColumnFields::Projected => { - return Err(PyRuntimeError::new_err( - "enum column has no retained fields", - )); - } - } - self.projection = PyOnceLock::new(); - return Ok(self); - } - Err(PyRuntimeError::new_err( - "enum column has no retained audits", - )) - } - - pub(crate) fn retains_audits(&self) -> bool { - self.audits.is_some() || matches!(self.fields, ColumnFields::Native(_)) - } - - pub(crate) fn audit_instances<'py>( - &self, - py: Python<'py>, - ) -> PyResult>> { - if let Some(audits) = &self.audits { - return Ok(audits.instances(py)); - } - if let ColumnFields::Native(spec) = &self.fields { - let audits = spec - .column - .audits - .iter() - .map(|audit| authored_audit(py, audit)) - .collect::>>()?; - let classes: ContractClasses<'_> = contract_classes(py)?.extract()?; - return Ok( - HeaderAudits::new(py, &classes, &audits, &native_location(py, spec)?)? - .instances(py), - ); - } - self.field(py, "audits")? - .try_iter()? - .map(|value| value.map(AuditInstance::Python)) - .collect() - } - - pub(crate) fn replaced<'py>( - class: &Bound<'py, PyAny>, - values: [Bound<'py, PyAny>; 8], - keyword_order: [usize; 8], - ) -> PyResult { - if class.is(&record_class(class.py(), RecordId::SchemaColumn)?) { - return Self::new(class, values); - } - let fields = PyDict::new(class.py()); - for index in keyword_order { - fields.set_item(SCHEMA_COLUMN_FIELDS[index], &values[index])?; - } - Self::from_python(class.call((), Some(&fields))?) - } - - pub(crate) fn field<'py>(&self, py: Python<'py>, name: &str) -> PyResult> { - let index = || { - SCHEMA_COLUMN_FIELDS - .iter() - .position(|field| *field == name) - .ok_or_else(|| PyRuntimeError::new_err("unknown column field")) - }; - if let Some(projected) = self.projection.get(py) { - return field(projected.bind(py), name); - } - if name == AUDITS_KEY - && let Some(audits) = &self.audits - { - return Ok(audits.project(py)?.into_any()); - } - match &self.fields { - ColumnFields::Python(values) => Ok(values[index()?].bind(py).clone()), - ColumnFields::Native(spec) => native_value(py, spec, index()?), - ColumnFields::Projected => field(&self.project(py)?, name), - } - } - - pub(crate) fn project<'py>(&self, py: Python<'py>) -> PyResult> { - self.projection - .get_or_try_init(py, || { - let mut values: [Bound<'py, PyAny>; 8] = match &self.fields { - ColumnFields::Python(values) => { - values.each_ref().map(|value| value.bind(py).clone()) - } - ColumnFields::Native(spec) => native_values(py, spec)?, - ColumnFields::Projected => { - return Err(PyRuntimeError::new_err("missing column projection")); - } - }; - if let Some(audits) = &self.audits { - values[5] = audits.project(py)?.into_any(); - } - contract_object(self.class.bind(py), values).map(Bound::unbind) - }) - .map(|value| value.bind(py).clone()) - } - - pub(crate) fn from_python(value: Bound<'_, PyAny>) -> PyResult { - let py = value.py(); - let projection = PyOnceLock::new(); - let class = value.get_type().into_any().unbind(); - let _ = projection.set(py, value.unbind()); - Ok(Self { - fields: ColumnFields::Projected, - class, - audits: None, - projection, - }) - } - - pub(crate) fn new<'py>( - class: &Bound<'py, PyAny>, - values: [Bound<'py, PyAny>; 8], - ) -> PyResult { - if !class.is(&record_class(class.py(), RecordId::SchemaColumn)?) { - return Self::from_python(contract_object(class, values)?); - } - checked_field_orders()?; - Ok(Self { - fields: ColumnFields::Python(values.map(Bound::unbind)), - class: class.clone().unbind(), - audits: None, - projection: PyOnceLock::new(), - }) - } - - /// A natively parsed column, whose Python record is built only when Python reads it. - pub(crate) fn native(class: &Bound<'_, PyAny>, spec: NativeColumnSpec) -> PyResult { - let py: Python<'_> = class.py(); - if !class.is(&record_class(py, RecordId::SchemaColumn)?) { - return Self::from_python(contract_object(class, native_values(py, &spec)?)?); - } - checked_field_orders()?; - Ok(Self { - fields: ColumnFields::Native(Box::new(spec)), - class: class.clone().unbind(), - audits: None, - projection: PyOnceLock::new(), - }) - } -} - -impl HeaderColumn { - /// The original native column, if no retained audit edits changed its public contract. - pub(crate) fn native_spec(&self) -> Option<&NativeColumnSpec> { - if self.audits.is_some() { - return None; - } - match &self.fields { - ColumnFields::Native(spec) => Some(spec), - ColumnFields::Python(_) | ColumnFields::Projected => None, - } - } -} - /// The `SchemaColumn` a native column projects to when its location names `location`'s path. pub(crate) fn native_column_record<'py>( py: Python<'py>, @@ -351,7 +128,7 @@ pub(crate) fn native_column_record<'py>( } /// A native column's record fields, in declaration order. -fn native_values<'py>( +pub(crate) fn native_values<'py>( py: Python<'py>, spec: &NativeColumnSpec, ) -> PyResult<[Bound<'py, PyAny>; 8]> { @@ -378,7 +155,7 @@ fn column_values<'py>( } /// The native column's record field at `index` of `SCHEMA_COLUMN_FIELDS`. -fn native_value<'py>( +pub(crate) fn native_value<'py>( py: Python<'py>, spec: &NativeColumnSpec, index: usize, @@ -397,7 +174,10 @@ fn native_value<'py>( } /// The column's `SourceLocation`, or `None`. -fn native_location<'py>(py: Python<'py>, spec: &NativeColumnSpec) -> PyResult> { +pub(crate) fn native_location<'py>( + py: Python<'py>, + spec: &NativeColumnSpec, +) -> PyResult> { match &spec.location { Some((model_file, span)) => { location_record(py, model_file.get().path_objects(py)?.1, *span) @@ -478,69 +258,6 @@ fn native_audit_instance<'py>( ) } -/// Retained native columns and their shared, lazy public tuple. -pub(crate) struct HeaderColumns { - pub(crate) specs: Vec, - projection: PyOnceLock>, -} - -impl HeaderColumns { - pub(crate) fn new(specs: Vec) -> Self { - Self { - specs, - projection: PyOnceLock::new(), - } - } - - pub(crate) fn project<'py>(&self, py: Python<'py>) -> PyResult> { - self.projection - .get_or_try_init(py, || { - let columns = self - .specs - .iter() - .map(|column| column.project(py)) - .collect::>>()?; - PyTuple::new(py, columns).map(Bound::unbind) - }) - .map(|value| value.bind(py).clone()) - } -} - -/// The Python classes the parsed metadata becomes, read from a Python mapping. -#[derive(FromPyObject)] -#[pyo3(from_item_all)] -pub(crate) struct ContractClasses<'py> { - pub(crate) schema_column: Bound<'py, PyAny>, - pub(crate) schema_audit_instance: Bound<'py, PyAny>, - pub(crate) schema_dynamic_column_family: Bound<'py, PyAny>, - pub(crate) source_location: Bound<'py, PyAny>, - measurement_thresholds: Bound<'py, PyAny>, - measurement_threshold_bound: Bound<'py, PyAny>, - pub(crate) severities: Bound<'py, PyDict>, - threshold_operators: Bound<'py, PyDict>, -} - -impl ContractClasses<'_> { - /// Whether these are the classes native header parsing builds by default. - pub(crate) fn uses_default_classes(&self) -> PyResult { - let py: Python<'_> = self.schema_column.py(); - let default: ContractClasses<'_> = contract_classes(py)?.extract()?; - Ok(self.schema_column.is(&default.schema_column) - && self - .schema_audit_instance - .is(&default.schema_audit_instance) - && self.source_location.is(&default.source_location) - && self - .measurement_thresholds - .is(&default.measurement_thresholds) - && self - .measurement_threshold_bound - .is(&default.measurement_threshold_bound) - && self.severities.is(&default.severities) - && self.threshold_operators.is(&default.threshold_operators)) - } -} - pub(crate) fn column_tuple<'py>( py: Python<'py>, classes: &ContractClasses<'py>, @@ -600,7 +317,7 @@ pub(crate) fn parsed_audit_identity( } /// `class(*values)`: the same record as keywords bind, given in `POSITIONAL_RECORDS` order. -fn contract_object<'py, const N: usize>( +pub(crate) fn contract_object<'py, const N: usize>( class: &Bound<'py, PyAny>, values: [Bound<'py, PyAny>; N], ) -> PyResult> { @@ -609,7 +326,7 @@ fn contract_object<'py, const N: usize>( } /// Fail when a positionally built record no longer declares its fields in the expected order. -fn checked_field_orders() -> PyResult<()> { +pub(crate) fn checked_field_orders() -> PyResult<()> { static MISMATCH: OnceLock> = OnceLock::new(); match MISMATCH.get_or_init(mismatched_record) { Some(record) => Err(PyRuntimeError::new_err(format!( @@ -651,7 +368,7 @@ fn optional<'py, N: HeaderValue>( .unwrap_or_else(|| py.None().into_bound(py))) } -fn schema_column<'py>( +pub(crate) fn schema_column<'py>( py: Python<'py>, classes: &ContractClasses<'py>, column: &ParsedColumn>, diff --git a/crates/sqlbuild-python-front/src/model_config/_helpers/headers/mod.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/headers/mod.rs new file mode 100644 index 0000000000..cf1bbd1e20 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/headers/mod.rs @@ -0,0 +1,4 @@ +pub(crate) mod header_audits; +pub(crate) mod header_columns; +pub(crate) mod header_families; +pub(crate) mod header_metadata; diff --git a/crates/sqlbuild-python-front/src/model_config/_helpers/mod.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/mod.rs new file mode 100644 index 0000000000..d496976569 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/mod.rs @@ -0,0 +1,3 @@ +pub(crate) mod config; +pub(crate) mod headers; +pub(crate) mod model_nodes; diff --git a/crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/authored_nodes.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/authored_nodes.rs new file mode 100644 index 0000000000..1229cfc2f6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/authored_nodes.rs @@ -0,0 +1,10 @@ +//! Python objects read in place as authored header values. + +use crate::model_config::models::PyNode; +use pyo3::prelude::{Bound, PyAny}; + +pub(crate) fn entry_nodes<'py>( + (key, value): (Bound<'py, PyAny>, Bound<'py, PyAny>), +) -> (PyNode<'py>, PyNode<'py>) { + (PyNode(key), PyNode(value)) +} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/column_migrations.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/column_migrations.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/model_config/column_migrations.rs rename to crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/column_migrations.rs diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/contract_classes.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/contract_classes.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/model_config/contract_classes.rs rename to crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/contract_classes.rs diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/described_models.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/described_models.rs similarity index 87% rename from crates/sqlbuild-python/src/bindings/_helpers/model_config/described_models.rs rename to crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/described_models.rs index c810a1a13a..4a1a1ef509 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/model_config/described_models.rs +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/described_models.rs @@ -11,11 +11,14 @@ use sqlbuild_model_config::path_defaults::main::select_path_default::select_path use sqlbuild_model_config::path_defaults::models::PathDefaultChoice; use sqlbuild_model_config::types::AuthoredNode; -use crate::bindings::_helpers::model_config::config_nodes::{ - PyConfigEntries, PyConfigNode, config_entries, config_node, config_object, is_text_node, -}; -use crate::bindings::_helpers::model_config::model_config_builder::raised_config_error; -use crate::bindings::_helpers::model_config::project_defaults::project_defaults_mapping; +use crate::model_config::_helpers::config::config_nodes::PyConfigEntries; +use crate::model_config::_helpers::config::config_nodes::config_entries; +use crate::model_config::_helpers::config::config_nodes::config_node; +use crate::model_config::_helpers::config::config_nodes::config_object; +use crate::model_config::_helpers::config::config_nodes::is_text_node; +use crate::model_config::_helpers::model_nodes::model_config_builder::raised_config_error; +use crate::model_config::_helpers::model_nodes::project_defaults::project_defaults_mapping; +use crate::model_config::types::PyConfigNode; use sqlbuild_python_base::records::main::fields::field::field as native_field; const DESCRIPTION_KEY: &str = "description"; diff --git a/crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/mod.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/mod.rs new file mode 100644 index 0000000000..6c3ecc0b48 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/mod.rs @@ -0,0 +1,8 @@ +pub(crate) mod authored_nodes; +pub(crate) mod column_migrations; +pub(crate) mod contract_classes; +pub(crate) mod described_models; +pub(crate) mod model_config_builder; +pub(crate) mod model_validator; +pub(crate) mod project_defaults; +pub(crate) mod unicode_environment; diff --git a/crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/model_config_builder.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/model_config_builder.rs new file mode 100644 index 0000000000..bbf87cae21 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/model_config_builder.rs @@ -0,0 +1,275 @@ +//! The native model config build handed Python inputs once, and its results projected for Python. + +use crate::model_config::models::BuiltConfig; +use crate::model_config::models::NativeModelConfigBuilder; +use std::collections::HashMap; + +use pyo3::PyErr; +use pyo3::exceptions::{PyKeyError, PyRuntimeError, PyValueError}; +use pyo3::prelude::{Bound, Py, PyAny, PyAnyMethods, PyModule, PyModuleMethods, PyResult, Python}; +use pyo3::types::{PyDict, PyDictMethods, PyString, PyStringMethods}; +use sqlbuild_discovery::model_files::main::config_value::config_value; +use sqlbuild_discovery::model_files::models::{EntryFacts, HeaderFacts}; +use sqlbuild_model_config::config_presence::models::MacroPath; +use sqlbuild_model_config::config_values::models::ConfigNode; +use sqlbuild_model_config::errors::ConfigError; +use sqlbuild_model_config::model_config_build::models::{ + BuiltModelConfig, ConfigBuildHalt, HeaderEntryFacts, +}; +use sqlbuild_model_config::model_config_build::types::ConfigBuildHost; +use sqlbuild_sqltext::compiler::models::AuthoredValue; + +use crate::authored_values::main::project_var_text::project_var_text; +use crate::model_config::_helpers::config::config_errors::config_exception; +use crate::model_config::_helpers::config::config_errors::native_config_error; +use crate::model_config::_helpers::config::config_nodes::PyConfigEntries; +use crate::model_config::_helpers::config::config_nodes::carried_node; +use crate::model_config::_helpers::config::config_nodes::config_node; +use crate::model_config::_helpers::config::config_nodes::config_object; +use crate::model_config::_helpers::config::config_nodes::hook_entry; +use crate::model_config::_helpers::config::config_nodes::is_exact_container; +use crate::model_config::_helpers::config::typed_config::built_values; +use crate::model_config::errors::NativeConfigError; +use crate::model_config::models::HostHandle; +use crate::model_config::types::PyConfigNode; + +/// The config keys a model's context values read. +pub(crate) const CONTEXT_KEYS: [&str; 3] = ["database", "schema", "alias"]; +const BUILD_STOPPED: &str = "a config value read as text without an error"; + +/// A header's public mapping, parsed facts and native authored values. +pub(crate) type HeaderBuildInputs<'a, 'py> = ( + &'a Bound<'py, PyDict>, + Option<&'a HeaderFacts>, + Option<&'a [(String, AuthoredValue)]>, +); + +/// `((target name, run id), (database, schema) or None)` of the active target. +pub(crate) type TargetInputs<'py> = ( + (Bound<'py, PyAny>, Bound<'py, PyAny>), + Option<(Bound<'py, PyAny>, Bound<'py, PyAny>)>, +); + +/// The process environment and project-var rendering, read through Python. +pub(crate) struct PythonConfigHost<'py> { + pub(crate) environment: Bound<'py, PyAny>, +} + +impl ConfigBuildHost for PythonConfigHost<'_> { + type Handle = HostHandle; + type Error = PyErr; + + fn environment(&self, name: &str) -> PyResult> { + if !self.environment.contains(name)? { + return Ok(None); + } + Ok(Some(config_node(&self.environment.get_item(name)?)?)) + } + + fn render(&self, value: &PyConfigNode, label: &str) -> PyResult> { + let py: Python<'_> = self.environment.py(); + let object: Bound<'_, PyAny> = config_object(py, value)?; + if let Ok(text) = object.downcast_exact::() { + return Ok(Ok(text.to_str()?.to_owned())); + } + match project_var_text(&object, label) { + Ok(text) => Ok(Ok(text)), + Err(error) if error.is_instance_of::(py) => { + Ok(Err(error.value(py).to_string())) + } + Err(error) => Err(error), + } + } + + fn text_error(&self, value: &PyConfigNode) -> PyErr { + let py: Python<'_> = self.environment.py(); + let read = || -> PyResult<()> { + let object: Bound<'_, PyAny> = config_object(py, value)?; + let text: Bound<'_, PyString> = match object.downcast::() { + Ok(text) => text.clone(), + Err(_) => object.str()?, + }; + let _ = text.to_str()?; + Ok(()) + }; + match read() { + Ok(()) => PyRuntimeError::new_err(BUILD_STOPPED), + Err(error) => error, + } + } + + fn python_str(&self, value: &PyConfigNode, exact: bool) -> PyResult { + let text: Bound<'_, PyString> = config_object(self.environment.py(), value)?.str()?; + if exact { + return Ok(text.to_str()?.to_owned()); + } + Ok(text.to_string_lossy().into_owned()) + } + + fn typed_hook_entry(&self, value: &PyConfigNode) -> PyResult { + hook_entry(&config_object(self.environment.py(), value)?) + } +} + +/// Header keys whose values the build reads item by item, which are always converted. +const INSPECTED_KEYS: [&str; 7] = [ + "tags", + "row_diff_exclude_columns", + "row_diff_tolerances", + "pre_hooks", + "post_hooks", + "time_travel_retention", + "table_type", +]; + +/// Whether `key`'s container may be carried whole: no template or macro in it, items never read. +fn carried_whole(key: &str, facts: Option<&[(String, HeaderEntryFacts)]>) -> bool { + !INSPECTED_KEYS.contains(&key) + && facts + .and_then(|facts| facts.iter().find(|(name, _)| name == key)) + .is_some_and(|(_, facts)| !facts.template && facts.macro_path == MacroPath::Absent) +} + +/// A header's entries as config nodes; containers the build never looks into stay opaque. +pub(crate) fn header_entries( + header: &Bound<'_, PyDict>, + facts: Option<&[(String, HeaderEntryFacts)]>, + authored: Option<&[(String, AuthoredValue)]>, +) -> PyResult { + let authored: HashMap<&str, &AuthoredValue> = authored + .into_iter() + .flatten() + .map(|(key, value)| (key.as_str(), value)) + .collect(); + let mut entries: PyConfigEntries = Vec::with_capacity(header.len()); + for (key, value) in header.iter() { + let native: Option = match key.downcast_exact::() { + Ok(key) => match key.to_str() { + Ok(key) => authored.get(key).and_then(|value| config_value(value)), + Err(_) => None, + }, + Err(_) => None, + }; + if let Some(native) = native { + entries.push((config_node(&key)?, native)); + continue; + } + let whole: bool = is_exact_container(&value) + && key + .downcast_exact::() + .is_ok_and(|key| key.to_str().is_ok_and(|key| carried_whole(key, facts))); + let node: PyConfigNode = if whole { + carried_node(&value)? + } else { + config_node(&value)? + }; + entries.push((config_node(&key)?, node)); + } + Ok(entries) +} + +/// One header entry's parsed facts as the build reads them. +pub(crate) fn entry_facts((key, entry): &(String, EntryFacts)) -> (String, HeaderEntryFacts) { + let facts: HeaderEntryFacts = HeaderEntryFacts { + template: entry.template, + macro_path: entry.macro_path.clone(), + }; + (key.clone(), facts) +} + +pub(crate) fn optional_node(value: Bound<'_, PyAny>) -> PyResult> { + if value.is_none() { + return Ok(None); + } + config_node(&value).map(Some) +} + +/// The Python error a halt raises, or the config error it is rejected with. +pub(crate) fn halted<'py>( + py: Python<'py>, + halt: ConfigBuildHalt, +) -> PyResult> { + Ok(match halt { + ConfigBuildHalt::Config(error) => Ok(error), + ConfigBuildHalt::Host(error) => Err(error), + ConfigBuildHalt::MissingPathDefault(key) => Err(PyKeyError::new_err(key)), + ConfigBuildHalt::KeyNotText(key) => { + Err(match config_object(py, &key)?.downcast::() { + Ok(_) => PyRuntimeError::new_err(BUILD_STOPPED), + Err(error) => error.into(), + }) + } + }) +} + +/// The built values as a new `dict`; entries still the header's own keep the header's objects. +fn own_values_dict<'py>( + header: &Bound<'py, PyDict>, + built: &BuiltModelConfig, +) -> PyResult> { + let py: Python<'py> = header.py(); + let mapping: Bound<'py, PyDict> = PyDict::new(py); + for (key, value) in &built.values { + let own: bool = own_key(key, &built.own_header_keys); + let key: Bound<'py, PyAny> = config_object(py, key)?; + let value: Bound<'py, PyAny> = match own.then(|| header.get_item(&key)).transpose()? { + Some(Some(value)) => value, + _ => config_object(py, value)?, + }; + mapping.set_item(key, value)?; + } + Ok(mapping) +} + +/// Whether `key` is a string key named among the header's own keys. +fn own_key(key: &PyConfigNode, own: &[String]) -> bool { + let text: Option<&str> = match key { + ConfigNode::Str(text) => Some(text), + ConfigNode::Host(host) if host.facts.strict_text => host.facts.text.as_deref(), + _ => None, + }; + text.is_some_and(|text| own.iter().any(|name| name == text)) +} + +/// One model's build projected for Python. +pub(crate) fn projected_build<'py>( + header: &Bound<'py, PyDict>, + built: BuiltModelConfig, +) -> PyResult> { + let py: Python<'py> = header.py(); + Ok(BuiltConfig { + values: own_values_dict(header, &built)?, + nodes: built_values(built.values), + header_keys: built.header_keys, + logical_schema: projected(py, built.logical_schema)?, + layer_schema_configured: built.layer_schema_configured, + logical_database: projected(py, built.logical_database)?, + retention: built.retention, + table_type: built.table_type, + reads: built.reads, + }) +} + +fn projected<'py>( + py: Python<'py>, + value: Option, +) -> PyResult>> { + value.map(|value| config_object(py, &value)).transpose() +} + +/// The Python exception a native config error raises as. +pub(crate) fn raised_config_error(py: Python<'_>, error: ConfigError) -> PyErr { + let raised = || -> PyResult { + let error: Py = native_config_error(py, error)?; + Ok(PyErr::from_value(config_exception( + error.bind(py).as_any(), + None, + )?)) + }; + raised().unwrap_or_else(|error| error) +} + +pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { + module.add_class::()?; + Ok(()) +} diff --git a/crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/model_validator.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/model_validator.rs new file mode 100644 index 0000000000..d90bce6055 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/model_validator.rs @@ -0,0 +1,107 @@ +//! The Python model validators, run natively up to the first error they raise. + +use crate::model_config::models::NativeModelValidator; +use sqlbuild_python_base::positional_record; +use std::collections::HashSet; + +use pyo3::IntoPyObject; +use pyo3::prelude::{Bound, Py, PyAny, PyAnyMethods, PyModule, PyModuleMethods, PyResult, Python}; +use pyo3::types::{PyDict, PyDictMethods}; +use sqlbuild_model_config::model_validation::models::ValidationStop; + +use crate::discovery::main::project::column_name::column_name; +use crate::discovery::main::project::each::each; +use crate::discovery::main::project::stem::stem; +use crate::model_config::_helpers::config::config_errors::native_config_error; +use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; + +const FILE_PATH_ATTRIBUTE: &str = "file_path"; +const RETURNS_KEY: &str = "returns"; +/// The only key of a table function's `returns` mapping. +const TABLE_RETURNS_KEY: &str = "table"; + +positional_record! { + extract; + /// Model, seed, source, function and table function names. + pub(crate) struct ResourceNames { + pub(crate) models: HashSet, + pub(crate) seeds: HashSet, + pub(crate) sources: HashSet, + pub(crate) functions: HashSet, + pub(crate) table_functions: HashSet, + } +} + +positional_record! { + extract; + /// References `(kind, name, rejected)`, schema columns, unmanaged retention and table type. + pub(crate) struct ModelFacts { + pub(crate) references: Vec<(String, String, bool)>, + pub(crate) declared_columns: Option>, + pub(crate) retention_unmanaged: bool, + pub(crate) table_type_declared: bool, + } +} + +/// Model, seed, source, function and table function names discovered in `inputs`. +pub(crate) fn discovered_names(inputs: &Bound<'_, PyAny>) -> PyResult { + let model_stem = |file: &Bound<'_, PyAny>| stem(file, FILE_PATH_ATTRIBUTE); + let mut models: HashSet = each(inputs, "model_files", model_stem)? + .into_iter() + .collect(); + if let Some(injection) = + sqlbuild_python_base::compile_context::main::delta::injection::injection() + { + models.extend(injection.model_names.iter().cloned()); + } + let mut seeds: HashSet = HashSet::new(); + for schema in native_field(inputs, "schema_files")?.try_iter()? { + seeds.extend(each(&schema?, "seed_entries", column_name)?); + } + let mut sources: HashSet = HashSet::new(); + for file in native_field(inputs, "source_files")?.try_iter()? { + sources.extend(each(&file?, "source_entries", column_name)?); + } + let mut functions: HashSet = HashSet::new(); + let mut table_functions: HashSet = HashSet::new(); + for file in native_field(inputs, "sql_function_files")?.try_iter()? { + let file: Bound<'_, PyAny> = file?; + let name: String = model_stem(&file)?; + if returns_table(&file)? { + table_functions.insert(name.clone()); + } + functions.insert(name); + } + functions.extend(each(inputs, "python_function_files", model_stem)?); + Ok(ResourceNames { + models, + seeds, + sources, + functions, + table_functions, + }) +} + +/// Whether a SQL function's header `returns` is a mapping whose only key is `table`. +fn returns_table(file: &Bound<'_, PyAny>) -> PyResult { + let headers: Bound<'_, PyAny> = native_field(file, "header_values")?; + let returns: Bound<'_, PyAny> = mapping_get(&headers, RETURNS_KEY)?; + let Ok(returns) = returns.downcast::() else { + return Ok(false); + }; + let keys: Vec> = returns.keys().into_iter().collect(); + Ok(keys.len() == 1 && keys[0].eq(TABLE_RETURNS_KEY)?) +} + +pub(crate) fn stop_object(py: Python<'_>, stop: ValidationStop) -> PyResult> { + match stop.into_error() { + Err(index) => Ok(index.into_pyobject(py)?.into_any().unbind()), + Ok(error) => Ok(native_config_error(py, error)?.into_any()), + } +} + +pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { + module.add_class::()?; + Ok(()) +} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/project_defaults.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/project_defaults.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/model_config/project_defaults.rs rename to crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/project_defaults.rs diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/unicode_environment.rs b/crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/unicode_environment.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/model_config/unicode_environment.rs rename to crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/unicode_environment.rs diff --git a/crates/sqlbuild-python-front/src/model_config/constants.rs b/crates/sqlbuild-python-front/src/model_config/constants.rs new file mode 100644 index 0000000000..b171bb61ae --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/constants.rs @@ -0,0 +1,12 @@ +//! Public constants of model config. + +use crate::model_config::_helpers::config::getters::read_native_config_error; +use crate::model_config::errors::NativeConfigError; +use sqlbuild_python_base::records::main::registry::class_of::class_of; +use sqlbuild_python_base::records::models::GetterEntry; + +/// The getter readers of this module's native pyclasses. +pub const GETTERS: &[GetterEntry] = &[GetterEntry { + class: class_of::, + read: read_native_config_error, +}]; diff --git a/crates/sqlbuild-python-front/src/model_config/errors.rs b/crates/sqlbuild-python-front/src/model_config/errors.rs new file mode 100644 index 0000000000..8f4c0257b4 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/errors.rs @@ -0,0 +1,14 @@ +//! Errors model configuration reports to Python. + +use pyo3::pyclass; + +/// One exact error: the Python class to raise, its message, code, help and named config key. +#[pyclass(module = "sqlbuild._native", frozen, get_all)] +#[derive(Debug)] +pub struct NativeConfigError { + pub class_name: &'static str, + pub message: String, + pub code: Option<&'static str>, + pub help: Option, + pub key: Option, +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/carried_node.rs b/crates/sqlbuild-python-front/src/model_config/main/config/carried_node.rs new file mode 100644 index 0000000000..4c32af982e --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/carried_node.rs @@ -0,0 +1,13 @@ +//! Carry an uninspected value: exact containers keep their own objects without opening items. + +use crate::model_config::_helpers::config::config_nodes; +use crate::model_config::types::PyConfigNode; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Carry an uninspected value: exact containers keep their own objects without opening items. +#[inline] +pub fn carried_node(value: &Bound<'_, PyAny>) -> PyResult { + config_nodes::carried_node(value) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/config_cursor_bound.rs b/crates/sqlbuild-python-front/src/model_config/main/config/config_cursor_bound.rs new file mode 100644 index 0000000000..d018ca76ee --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/config_cursor_bound.rs @@ -0,0 +1,18 @@ +//! `key`'s cursor bound as text, or `None` when absent or `None`. + +use crate::model_config::_helpers::config::typed_config; +use crate::model_config::types::ConfigValues; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// `key`'s cursor bound as text, or `None` when absent or `None`. +#[inline] +pub fn config_cursor_bound<'py>( + py: Python<'py>, + values: &ConfigValues<'_>, + key: &str, +) -> PyResult>> { + typed_config::config_cursor_bound(py, values, key) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/config_fields.rs b/crates/sqlbuild-python-front/src/model_config/main/config/config_fields.rs new file mode 100644 index 0000000000..385beff58a --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/config_fields.rs @@ -0,0 +1,18 @@ +//! Every `CompileModelConfig` field but `values`, recording the build's template reads first. + +use crate::model_config::_helpers::config::config_classes; +use crate::model_config::models::BuiltConfig; +use crate::model_config::models::ConfigClasses; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::types::PyDict; + +/// Every `CompileModelConfig` field but `values`, recording the build's template reads first. +#[inline] +pub fn config_fields<'py>( + classes: &ConfigClasses<'py>, + built: &BuiltConfig<'py>, + matched: Option<&str>, +) -> PyResult> { + config_classes::config_fields(classes, built, matched) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/config_flag.rs b/crates/sqlbuild-python-front/src/model_config/main/config/config_flag.rs new file mode 100644 index 0000000000..6ae5cde364 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/config_flag.rs @@ -0,0 +1,12 @@ +//! `key`'s boolean value, or `None` when absent or `None`. + +use crate::model_config::_helpers::config::typed_config; +use crate::model_config::types::ConfigValues; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// `key`'s boolean value, or `None` when absent or `None`. +#[inline] +pub fn config_flag(py: Python<'_>, values: &ConfigValues<'_>, key: &str) -> PyResult> { + typed_config::config_flag(py, values, key) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/config_integer_object.rs b/crates/sqlbuild-python-front/src/model_config/main/config/config_integer_object.rs new file mode 100644 index 0000000000..a6ad072d82 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/config_integer_object.rs @@ -0,0 +1,18 @@ +//! `key`'s integer value as its Python object, or `None` when absent or `None`. + +use crate::model_config::_helpers::config::typed_config; +use crate::model_config::types::ConfigValues; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// `key`'s integer value as its Python object, or `None` when absent or `None`. +#[inline] +pub fn config_integer_object<'py>( + py: Python<'py>, + values: &ConfigValues<'_>, + key: &str, +) -> PyResult>> { + typed_config::config_integer_object(py, values, key) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/config_node.rs b/crates/sqlbuild-python-front/src/model_config/main/config/config_node.rs new file mode 100644 index 0000000000..cfa8c0e2fd --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/config_node.rs @@ -0,0 +1,13 @@ +//! One Python config value as a `ConfigNode`; a value that holds itself stays opaque whole. + +use crate::model_config::_helpers::config::config_nodes; +use crate::model_config::types::PyConfigNode; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// One Python config value as a `ConfigNode`; a value that holds itself stays opaque whole. +#[inline] +pub fn config_node(value: &Bound<'_, PyAny>) -> PyResult { + config_nodes::config_node(value) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/config_node_of.rs b/crates/sqlbuild-python-front/src/model_config/main/config/config_node_of.rs new file mode 100644 index 0000000000..8fa7b8d8f3 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/config_node_of.rs @@ -0,0 +1,13 @@ +//! `values.get(key)` as its typed node, `None` (null) when absent. + +use crate::model_config::_helpers::config::typed_config; +use crate::model_config::types::ConfigValues; +use crate::model_config::types::PyConfigNode; +use pyo3::prelude::PyResult; +use std::sync::Arc; + +/// `values.get(key)` as its typed node, `None` (null) when absent. +#[inline] +pub fn config_node_of(values: &ConfigValues<'_>, key: &str) -> PyResult> { + typed_config::config_node_of(values, key) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/config_object.rs b/crates/sqlbuild-python-front/src/model_config/main/config/config_object.rs new file mode 100644 index 0000000000..dbe0dcfb9c --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/config_object.rs @@ -0,0 +1,14 @@ +//! The Python object of one config value: new builtins, and opaque values as themselves. + +use crate::model_config::_helpers::config::config_nodes; +use crate::model_config::types::PyConfigNode; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// The Python object of one config value: new builtins, and opaque values as themselves. +#[inline] +pub fn config_object<'py>(py: Python<'py>, node: &PyConfigNode) -> PyResult> { + config_nodes::config_object(py, node) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/config_str.rs b/crates/sqlbuild-python-front/src/model_config/main/config/config_str.rs new file mode 100644 index 0000000000..2e2bf43ad3 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/config_str.rs @@ -0,0 +1,15 @@ +//! An authored string, preserving a present empty string. + +use crate::model_config::_helpers::config::config_values; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// An authored string, preserving a present empty string. +#[inline] +pub fn config_str<'py>( + values: &Bound<'py, PyAny>, + key: &str, +) -> PyResult>> { + config_values::config_str(values, key) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/config_text.rs b/crates/sqlbuild-python-front/src/model_config/main/config/config_text.rs new file mode 100644 index 0000000000..50d70bbe63 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/config_text.rs @@ -0,0 +1,16 @@ +//! `key`'s string value, or `None` when absent or `None`. + +use crate::model_config::_helpers::config::typed_config; +use crate::model_config::types::ConfigValues; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// `key`'s string value, or `None` when absent or `None`. +#[inline] +pub fn config_text( + py: Python<'_>, + values: &ConfigValues<'_>, + key: &str, +) -> PyResult> { + typed_config::config_text(py, values, key) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/config_text_is.rs b/crates/sqlbuild-python-front/src/model_config/main/config/config_text_is.rs new file mode 100644 index 0000000000..44ca9d53fe --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/config_text_is.rs @@ -0,0 +1,17 @@ +//! Whether `key` holds a string equal to `expected`, as Python's `==` compares them. + +use crate::model_config::_helpers::config::typed_config; +use crate::model_config::types::ConfigValues; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// Whether `key` holds a string equal to `expected`, as Python's `==` compares them. +#[inline] +pub fn config_text_is( + py: Python<'_>, + values: &ConfigValues<'_>, + key: &str, + expected: &str, +) -> PyResult { + typed_config::config_text_is(py, values, key, expected) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/config_text_object.rs b/crates/sqlbuild-python-front/src/model_config/main/config/config_text_object.rs new file mode 100644 index 0000000000..21b9eb3c03 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/config_text_object.rs @@ -0,0 +1,18 @@ +//! `key`'s string value as its Python object, or `None` when absent or `None`. + +use crate::model_config::_helpers::config::typed_config; +use crate::model_config::types::ConfigValues; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// `key`'s string value as its Python object, or `None` when absent or `None`. +#[inline] +pub fn config_text_object<'py>( + py: Python<'py>, + values: &ConfigValues<'_>, + key: &str, +) -> PyResult>> { + typed_config::config_text_object(py, values, key) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/config_text_tuple.rs b/crates/sqlbuild-python-front/src/model_config/main/config/config_text_tuple.rs new file mode 100644 index 0000000000..97dfd82467 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/config_text_tuple.rs @@ -0,0 +1,18 @@ +//! `key`'s strings as a tuple, or `None` when absent or `None`. + +use crate::model_config::_helpers::config::typed_config; +use crate::model_config::types::ConfigValues; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::types::PyTuple; + +/// `key`'s strings as a tuple, or `None` when absent or `None`. +#[inline] +pub fn config_text_tuple<'py>( + py: Python<'py>, + values: &ConfigValues<'_>, + key: &str, +) -> PyResult>> { + typed_config::config_text_tuple(py, values, key) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/config_value.rs b/crates/sqlbuild-python-front/src/model_config/main/config/config_value.rs new file mode 100644 index 0000000000..dac00dad84 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/config_value.rs @@ -0,0 +1,18 @@ +//! `values.get(key)` as its Python object, `None` when absent. + +use crate::model_config::_helpers::config::typed_config; +use crate::model_config::types::ConfigValues; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// `values.get(key)` as its Python object, `None` when absent. +#[inline] +pub fn config_value<'py>( + py: Python<'py>, + values: &ConfigValues<'_>, + key: &str, +) -> PyResult> { + typed_config::config_value(py, values, key) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/early_model_templates.rs b/crates/sqlbuild-python-front/src/model_config/main/config/early_model_templates.rs new file mode 100644 index 0000000000..aa4ac4f1f3 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/early_model_templates.rs @@ -0,0 +1,16 @@ +//! Model header `values` with `${name}`, `${ENV:...}` and early `run.*` templates resolved. + +use crate::model_config::_helpers::config::template_data; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Model header `values` with `${name}`, `${ENV:...}` and early `run.*` templates resolved. +#[inline] +pub fn early_model_templates<'py>( + values: &Bound<'py, PyAny>, + effective_vars: &Bound<'py, PyAny>, + (target_name, run_id): (&Bound<'py, PyAny>, &Bound<'py, PyAny>), +) -> PyResult> { + template_data::early_model_templates(values, effective_vars, (target_name, run_id)) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/expanded.rs b/crates/sqlbuild-python-front/src/model_config/main/config/expanded.rs new file mode 100644 index 0000000000..77bd879839 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/expanded.rs @@ -0,0 +1,18 @@ +//! Expand every template in `value` and the containers inside it. + +use crate::model_config::_helpers::config::config_templates; +use crate::model_config::models::PythonHost; +use crate::model_config::models::Stop; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use sqlbuild_model_config::templates::models::TemplateOptions; + +/// Expand every template in `value` and the containers inside it. +#[inline] +pub fn expanded<'py>( + host: &PythonHost<'py>, + value: &Bound<'py, PyAny>, + options: TemplateOptions, +) -> Result, Stop> { + config_templates::expanded(host, value, options) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/expanded_effective_vars.rs b/crates/sqlbuild-python-front/src/model_config/main/config/expanded_effective_vars.rs new file mode 100644 index 0000000000..4ad1859ae5 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/expanded_effective_vars.rs @@ -0,0 +1,15 @@ +//! Merged effective vars with recursive `${name}` expansion. + +use crate::model_config::_helpers::config::template_data; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyDict; + +/// Merged effective vars with recursive `${name}` expansion. +#[inline] +pub fn expanded_effective_vars<'py>( + raw_values: &Bound<'py, PyDict>, +) -> PyResult> { + template_data::expanded_effective_vars(raw_values) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/expanded_template_data.rs b/crates/sqlbuild-python-front/src/model_config/main/config/expanded_template_data.rs new file mode 100644 index 0000000000..d4d335fff6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/expanded_template_data.rs @@ -0,0 +1,18 @@ +//! `value` with every `${...}` template expanded, recording the reads it made. + +use crate::model_config::_helpers::config::template_data; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyDict; +use sqlbuild_model_config::templates::models::TemplateOptions; + +/// `value` with every `${...}` template expanded, recording the reads it made. +#[inline] +pub fn expanded_template_data<'py>( + value: &Bound<'py, PyAny>, + (variables, context_values): (&Bound<'py, PyDict>, &Bound<'py, PyDict>), + (options, label): (TemplateOptions, &str), +) -> PyResult> { + template_data::expanded_template_data(value, (variables, context_values), (options, label)) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/mod.rs b/crates/sqlbuild-python-front/src/model_config/main/config/mod.rs new file mode 100644 index 0000000000..65f3e50443 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/mod.rs @@ -0,0 +1,31 @@ +pub mod carried_node; +pub mod config_cursor_bound; +pub mod config_fields; +pub mod config_flag; +pub mod config_integer_object; +pub mod config_node; +pub mod config_node_of; +pub mod config_object; +pub mod config_str; +pub mod config_text; +pub mod config_text_is; +pub mod config_text_object; +pub mod config_text_tuple; +pub mod config_value; +pub mod early_model_templates; +pub mod expanded; +pub mod expanded_effective_vars; +pub mod expanded_template_data; +pub mod model_values; +pub mod native_config_error; +pub mod raised_config_exception; +pub mod record_reads; +pub mod record_template_reads_function; +pub mod register_config_errors; +pub mod register_config_values; +pub mod register_template_data; +pub mod retain_values; +pub mod run_id; +pub mod template_error; +pub mod typed_values; +pub mod view; diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/model_values.rs b/crates/sqlbuild-python-front/src/model_config/main/config/model_values.rs new file mode 100644 index 0000000000..f8a5513f46 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/model_values.rs @@ -0,0 +1,13 @@ +//! A model's config values as typed nodes, read key by key. + +use crate::model_config::_helpers::config::typed_config; +use crate::model_config::types::ConfigValues; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// A model's config values as typed nodes, read key by key. +#[inline] +pub fn model_values<'py>(model: &Bound<'py, PyAny>) -> PyResult> { + typed_config::model_values(model) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/native_config_error.rs b/crates/sqlbuild-python-front/src/model_config/main/config/native_config_error.rs new file mode 100644 index 0000000000..ecd8bf24c2 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/native_config_error.rs @@ -0,0 +1,14 @@ +//! Wrap `error` for Python. + +use crate::model_config::_helpers::config::config_errors; +use crate::model_config::errors::NativeConfigError; +use pyo3::Py; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use sqlbuild_model_config::errors::ConfigError; + +/// Wrap `error` for Python. +#[inline] +pub fn native_config_error(py: Python<'_>, error: ConfigError) -> PyResult> { + config_errors::native_config_error(py, error) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/raised_config_exception.rs b/crates/sqlbuild-python-front/src/model_config/main/config/raised_config_exception.rs new file mode 100644 index 0000000000..a9c52c7bc0 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/raised_config_exception.rs @@ -0,0 +1,15 @@ +//! `config_exception` as the raised error, or the failure building it. + +use crate::model_config::_helpers::config::config_errors; +use pyo3::PyErr; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; + +/// `config_exception` as the raised error, or the failure building it. +#[inline] +pub fn raised_config_exception( + error: &Bound<'_, PyAny>, + values: Option<&Bound<'_, PyAny>>, +) -> PyErr { + config_errors::raised_config_exception(error, values) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/record_reads.rs b/crates/sqlbuild-python-front/src/model_config/main/config/record_reads.rs new file mode 100644 index 0000000000..b45e88ec17 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/record_reads.rs @@ -0,0 +1,14 @@ +//! Record native template environment and context reads for project reuse, in order. + +use crate::model_config::_helpers::config::template_data; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// Record native template environment and context reads for project reuse, in order. +#[inline] +pub fn record_reads<'a>( + py: Python<'_>, + reads: impl IntoIterator, +) -> PyResult<()> { + template_data::record_reads(py, reads) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/record_template_reads_function.rs b/crates/sqlbuild-python-front/src/model_config/main/config/record_template_reads_function.rs new file mode 100644 index 0000000000..975be395fa --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/record_template_reads_function.rs @@ -0,0 +1,11 @@ +//! `record_template_reads` as a Python function. + +use crate::model_config::_helpers::config::template_data; + +/// `record_template_reads` as a Python function. +#[inline] +pub fn record_template_reads_function( + py: pyo3::Python<'_>, +) -> pyo3::PyResult> { + template_data::record_template_reads_function(py) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/register_config_errors.rs b/crates/sqlbuild-python-front/src/model_config/main/config/register_config_errors.rs new file mode 100644 index 0000000000..bfb2b4dff2 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/register_config_errors.rs @@ -0,0 +1,12 @@ +//! Register the config errors functions and classes. + +use crate::model_config::_helpers::config::config_errors; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the config errors functions and classes. +#[inline] +pub fn register_config_errors(module: &Bound<'_, PyModule>) -> PyResult<()> { + config_errors::register(module) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/register_config_values.rs b/crates/sqlbuild-python-front/src/model_config/main/config/register_config_values.rs new file mode 100644 index 0000000000..209cb3c148 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/register_config_values.rs @@ -0,0 +1,12 @@ +//! Register the config values functions and classes. + +use crate::model_config::_helpers::config::config_values; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the config values functions and classes. +#[inline] +pub fn register_config_values(module: &Bound<'_, PyModule>) -> PyResult<()> { + config_values::register(module) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/register_template_data.rs b/crates/sqlbuild-python-front/src/model_config/main/config/register_template_data.rs new file mode 100644 index 0000000000..916f95a334 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/register_template_data.rs @@ -0,0 +1,12 @@ +//! Register the template data functions and classes. + +use crate::model_config::_helpers::config::template_data; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the template data functions and classes. +#[inline] +pub fn register_template_data(module: &Bound<'_, PyModule>) -> PyResult<()> { + template_data::register(module) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/retain_values.rs b/crates/sqlbuild-python-front/src/model_config/main/config/retain_values.rs new file mode 100644 index 0000000000..22552f8b28 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/retain_values.rs @@ -0,0 +1,13 @@ +//! Attach the built tree to its public record, rather than reconstructing it from that view. + +use crate::model_config::_helpers::config::typed_config; +use crate::model_config::types::BuiltConfigValues; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Attach the built tree to its public record, rather than reconstructing it from that view. +#[inline] +pub fn retain_values(config: &Bound<'_, PyAny>, built: Option<&BuiltConfigValues>) -> PyResult<()> { + typed_config::retain_values(config, built) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/run_id.rs b/crates/sqlbuild-python-front/src/model_config/main/config/run_id.rs new file mode 100644 index 0000000000..c10fda69f6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/run_id.rs @@ -0,0 +1,12 @@ +//! The selected run id, or a new `YYYYMMDDTHHMMSSZ_<12 hex>` compile invocation id. + +use crate::model_config::_helpers::config::template_data; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// The selected run id, or a new `YYYYMMDDTHHMMSSZ_<12 hex>` compile invocation id. +#[inline] +pub fn run_id<'py>(selected_run_id: &Bound<'py, PyAny>) -> PyResult> { + template_data::run_id(selected_run_id) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/template_error.rs b/crates/sqlbuild-python-front/src/model_config/main/config/template_error.rs new file mode 100644 index 0000000000..edc8f6f2a5 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/template_error.rs @@ -0,0 +1,11 @@ +//! The `CompileInputError` Python raises for a template error in the context `label`. + +use crate::model_config::_helpers::config::config_templates; +use sqlbuild_model_config::errors::ConfigError; +use sqlbuild_model_config::templates::errors::TemplateError; + +/// The `CompileInputError` Python raises for a template error in the context `label`. +#[inline] +pub fn template_error(error: &TemplateError, label: &str) -> ConfigError { + config_templates::template_error(error, label) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/typed_values.rs b/crates/sqlbuild-python-front/src/model_config/main/config/typed_values.rs new file mode 100644 index 0000000000..ca4d969669 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/typed_values.rs @@ -0,0 +1,13 @@ +//! A config record's values, their typed nodes kept on the record so each key converts once. + +use crate::model_config::_helpers::config::typed_config; +use crate::model_config::types::ConfigValues; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// A config record's values, their typed nodes kept on the record so each key converts once. +#[inline] +pub fn typed_values<'py>(config: &Bound<'py, PyAny>) -> PyResult> { + typed_config::typed_values(config) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/config/view.rs b/crates/sqlbuild-python-front/src/model_config/main/config/view.rs new file mode 100644 index 0000000000..2f6ed7ebdd --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/config/view.rs @@ -0,0 +1,20 @@ +//! A `CompileModelConfig` of `values` and the other `fields`. + +use crate::model_config::_helpers::config::config_classes; +use crate::model_config::models::ConfigClasses; +use crate::model_config::types::BuiltConfigValues; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyDict; + +/// A `CompileModelConfig` of `values` and the other `fields`. +#[inline] +pub fn view<'py>( + classes: &ConfigClasses<'py>, + values: &Bound<'py, PyDict>, + fields: &Bound<'py, PyDict>, + nodes: Option<&BuiltConfigValues>, +) -> PyResult> { + config_classes::view(classes, values, fields, nodes) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/headers/audit_tuple.rs b/crates/sqlbuild-python-front/src/model_config/main/headers/audit_tuple.rs new file mode 100644 index 0000000000..b933a5c862 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/headers/audit_tuple.rs @@ -0,0 +1,20 @@ +//! Audit tuple. + +use crate::model_config::_helpers::headers::header_metadata; +use crate::model_config::models::ContractClasses; +use crate::model_config::models::PyNode; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::types::PyTuple; +use sqlbuild_model_config::header_metadata::models::ParsedAudit; + +/// Audit tuple. +#[inline] +pub fn audit_tuple<'py>( + py: Python<'py>, + classes: &ContractClasses<'py>, + parsed: &[ParsedAudit>], +) -> PyResult> { + header_metadata::audit_tuple(py, classes, parsed) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/headers/family_specs.rs b/crates/sqlbuild-python-front/src/model_config/main/headers/family_specs.rs new file mode 100644 index 0000000000..040da859c0 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/headers/family_specs.rs @@ -0,0 +1,13 @@ +//! A Python-authored family contract crosses into native ownership once. + +use crate::model_config::_helpers::headers::header_families; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_model_config::header_metadata::models::DynamicFamily; + +/// A Python-authored family contract crosses into native ownership once. +#[inline] +pub fn family_specs(families: &Bound<'_, PyAny>) -> PyResult> { + header_families::family_specs(families) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/headers/mod.rs b/crates/sqlbuild-python-front/src/model_config/main/headers/mod.rs new file mode 100644 index 0000000000..9db9082d83 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/headers/mod.rs @@ -0,0 +1,8 @@ +pub mod audit_tuple; +pub mod family_specs; +pub mod native_column_record; +pub mod native_schema_column; +pub mod parsed_audit_identity; +pub mod register_header_columns; +pub mod schema_columns; +pub mod thresholds; diff --git a/crates/sqlbuild-python-front/src/model_config/main/headers/native_column_record.rs b/crates/sqlbuild-python-front/src/model_config/main/headers/native_column_record.rs new file mode 100644 index 0000000000..78e06cd911 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/headers/native_column_record.rs @@ -0,0 +1,19 @@ +//! The `SchemaColumn` a native column projects to when its location names `location`'s path. + +use crate::model_config::_helpers::headers::header_metadata; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use sqlbuild_discovery::model_files::models::NativeColumn; +use sqlbuild_discovery::models::LineColumnSpan; + +/// The `SchemaColumn` a native column projects to when its location names `location`'s path. +#[inline] +pub fn native_column_record<'py>( + py: Python<'py>, + column: &NativeColumn, + location: Option<(Bound<'py, PyAny>, LineColumnSpan)>, +) -> PyResult> { + header_metadata::native_column_record(py, column, location) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/headers/native_schema_column.rs b/crates/sqlbuild-python-front/src/model_config/main/headers/native_schema_column.rs new file mode 100644 index 0000000000..5fe9654ff2 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/headers/native_schema_column.rs @@ -0,0 +1,22 @@ +//! Native schema column. + +use crate::model_config::_helpers::headers::header_metadata; +use crate::model_config::models::ContractClasses; +use crate::model_config::models::HeaderColumn; +use crate::model_config::types::HeaderValue; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::types::PyDict; +use sqlbuild_model_config::header_metadata::models::ParsedColumn; + +/// Native schema column. +#[inline] +pub fn native_schema_column<'py, N: HeaderValue>( + py: Python<'py>, + classes: &ContractClasses<'py>, + column: &ParsedColumn, + locations: &Bound<'py, PyDict>, +) -> PyResult { + header_metadata::native_schema_column(py, classes, column, locations) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/headers/parsed_audit_identity.rs b/crates/sqlbuild-python-front/src/model_config/main/headers/parsed_audit_identity.rs new file mode 100644 index 0000000000..aa2fc6838a --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/headers/parsed_audit_identity.rs @@ -0,0 +1,16 @@ +//! `audit.name or audit.definition_name` of the instance `audit` builds. + +use crate::model_config::_helpers::headers::header_metadata; +use crate::model_config::types::HeaderValue; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use sqlbuild_model_config::header_metadata::models::ParsedAudit; + +/// `audit.name or audit.definition_name` of the instance `audit` builds. +#[inline] +pub fn parsed_audit_identity( + py: Python<'_>, + audit: &ParsedAudit, +) -> PyResult { + header_metadata::parsed_audit_identity(py, audit) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/headers/register_header_columns.rs b/crates/sqlbuild-python-front/src/model_config/main/headers/register_header_columns.rs new file mode 100644 index 0000000000..398b17e024 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/headers/register_header_columns.rs @@ -0,0 +1,12 @@ +//! Register the header columns functions and classes. + +use crate::model_config::_helpers::headers::header_columns; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the header columns functions and classes. +#[inline] +pub fn register_header_columns(module: &Bound<'_, PyModule>) -> PyResult<()> { + header_columns::register(module) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/headers/schema_columns.rs b/crates/sqlbuild-python-front/src/model_config/main/headers/schema_columns.rs new file mode 100644 index 0000000000..6c5318feff --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/headers/schema_columns.rs @@ -0,0 +1,21 @@ +//! The `SchemaColumn` tuple of one authored columns mapping, raising Python's error for it. + +use crate::model_config::_helpers::headers::header_columns; +use crate::model_config::_helpers::headers::header_columns::ColumnOptions; +use crate::model_config::_helpers::headers::header_columns::ColumnSite; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyDict; +use pyo3::types::PyTuple; + +/// The `SchemaColumn` tuple of one authored columns mapping, raising Python's error for it. +#[inline] +pub fn schema_columns<'py>( + raw_columns: &Bound<'py, PyAny>, + site: ColumnSite<'_>, + options: ColumnOptions, + column_locations: &Bound<'py, PyDict>, +) -> PyResult> { + header_columns::schema_columns(raw_columns, site, options, column_locations) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/headers/thresholds.rs b/crates/sqlbuild-python-front/src/model_config/main/headers/thresholds.rs new file mode 100644 index 0000000000..74ba4ef14c --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/headers/thresholds.rs @@ -0,0 +1,19 @@ +//! `MeasurementThresholds` of `parsed`, or `None`. + +use crate::model_config::_helpers::headers::header_metadata; +use crate::model_config::models::ContractClasses; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use sqlbuild_model_config::header_metadata::models::ParsedThresholds; + +/// `MeasurementThresholds` of `parsed`, or `None`. +#[inline] +pub fn thresholds<'py>( + py: Python<'py>, + classes: &ContractClasses<'py>, + parsed: Option<&ParsedThresholds>, +) -> PyResult> { + header_metadata::thresholds(py, classes, parsed) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/mod.rs b/crates/sqlbuild-python-front/src/model_config/main/mod.rs new file mode 100644 index 0000000000..54261f6e8c --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/mod.rs @@ -0,0 +1,3 @@ +pub mod config; +pub mod headers; +pub mod model_nodes; diff --git a/crates/sqlbuild-python-front/src/model_config/main/model_nodes/column_migration_error.rs b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/column_migration_error.rs new file mode 100644 index 0000000000..583bffaebc --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/column_migration_error.rs @@ -0,0 +1,18 @@ +//! The first column-rename problem for a model with these config values, if any. + +use crate::model_config::_helpers::model_nodes::column_migrations; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::types::PyDict; +use sqlbuild_model_config::errors::ConfigError; +use sqlbuild_model_config::model_validation::models::ColumnMigration; + +/// The first column-rename problem for a model with these config values, if any. +#[inline] +pub fn column_migration_error( + model_name: &str, + values: &Bound<'_, PyDict>, + columns: &[ColumnMigration], +) -> PyResult> { + column_migrations::column_migration_error(model_name, values, columns) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/model_nodes/contract_classes.rs b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/contract_classes.rs new file mode 100644 index 0000000000..47eaec549e --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/contract_classes.rs @@ -0,0 +1,13 @@ +//! The contract classes native header parsing builds columns and audits as. + +use crate::model_config::_helpers::model_nodes::contract_classes; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::types::PyDict; + +/// The contract classes native header parsing builds columns and audits as. +#[inline] +pub fn contract_classes(py: Python<'_>) -> PyResult> { + contract_classes::contract_classes(py) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/model_nodes/externally_described_models.rs b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/externally_described_models.rs new file mode 100644 index 0000000000..699db0625e --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/externally_described_models.rs @@ -0,0 +1,16 @@ +//! The file path of each model whose layered config or model schema gives it a description. + +use crate::model_config::_helpers::model_nodes::described_models; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyDict; + +/// The file path of each model whose layered config or model schema gives it a description. +#[inline] +pub fn externally_described_models<'py>( + inputs: Bound<'py, PyAny>, + model_schemas: Bound<'py, PyDict>, +) -> PyResult>> { + described_models::externally_described_models(inputs, model_schemas) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/model_nodes/mod.rs b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/mod.rs new file mode 100644 index 0000000000..2a26dde974 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/mod.rs @@ -0,0 +1,9 @@ +pub mod column_migration_error; +pub mod contract_classes; +pub mod externally_described_models; +pub mod raised_config_error; +pub mod register_model_config_builder; +pub mod register_model_validator; +pub mod register_unicode_environment; +pub mod unicode_environment; +pub mod yaml_entry_classes; diff --git a/crates/sqlbuild-python-front/src/model_config/main/model_nodes/raised_config_error.rs b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/raised_config_error.rs new file mode 100644 index 0000000000..62a6e2593b --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/raised_config_error.rs @@ -0,0 +1,12 @@ +//! The Python exception a native config error raises as. + +use crate::model_config::_helpers::model_nodes::model_config_builder; +use pyo3::PyErr; +use pyo3::prelude::Python; +use sqlbuild_model_config::errors::ConfigError; + +/// The Python exception a native config error raises as. +#[inline] +pub fn raised_config_error(py: Python<'_>, error: ConfigError) -> PyErr { + model_config_builder::raised_config_error(py, error) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/model_nodes/register_model_config_builder.rs b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/register_model_config_builder.rs new file mode 100644 index 0000000000..c191e8b135 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/register_model_config_builder.rs @@ -0,0 +1,12 @@ +//! Register the model config builder functions and classes. + +use crate::model_config::_helpers::model_nodes::model_config_builder; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the model config builder functions and classes. +#[inline] +pub fn register_model_config_builder(module: &Bound<'_, PyModule>) -> PyResult<()> { + model_config_builder::register(module) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/model_nodes/register_model_validator.rs b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/register_model_validator.rs new file mode 100644 index 0000000000..bd5ccb345e --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/register_model_validator.rs @@ -0,0 +1,12 @@ +//! Register the model validator functions and classes. + +use crate::model_config::_helpers::model_nodes::model_validator; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the model validator functions and classes. +#[inline] +pub fn register_model_validator(module: &Bound<'_, PyModule>) -> PyResult<()> { + model_validator::register(module) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/model_nodes/register_unicode_environment.rs b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/register_unicode_environment.rs new file mode 100644 index 0000000000..6399b67927 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/register_unicode_environment.rs @@ -0,0 +1,12 @@ +//! Register the unicode environment functions and classes. + +use crate::model_config::_helpers::model_nodes::unicode_environment; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the unicode environment functions and classes. +#[inline] +pub fn register_unicode_environment(module: &Bound<'_, PyModule>) -> PyResult<()> { + unicode_environment::register(module) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/model_nodes/unicode_environment.rs b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/unicode_environment.rs new file mode 100644 index 0000000000..59c24504a6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/unicode_environment.rs @@ -0,0 +1,13 @@ +//! A new view of the process environment as compile text reads it. + +use crate::model_config::_helpers::model_nodes::unicode_environment; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// A new view of the process environment as compile text reads it. +#[inline] +pub fn unicode_environment(py: Python<'_>) -> PyResult> { + unicode_environment::unicode_environment(py) +} diff --git a/crates/sqlbuild-python-front/src/model_config/main/model_nodes/yaml_entry_classes.rs b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/yaml_entry_classes.rs new file mode 100644 index 0000000000..bc68a1655a --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/main/model_nodes/yaml_entry_classes.rs @@ -0,0 +1,13 @@ +//! The classes parsed seed and source declarations become. + +use crate::model_config::_helpers::model_nodes::contract_classes; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::types::PyDict; + +/// The classes parsed seed and source declarations become. +#[inline] +pub fn yaml_entry_classes(py: Python<'_>) -> PyResult> { + contract_classes::yaml_entry_classes(py) +} diff --git a/crates/sqlbuild-python-front/src/model_config/mod.rs b/crates/sqlbuild-python-front/src/model_config/mod.rs new file mode 100644 index 0000000000..ada7d471cf --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/mod.rs @@ -0,0 +1,8 @@ +//! Model configuration: authored nodes, config classes, templates, header metadata and validation. + +pub(crate) mod _helpers; +pub mod constants; +pub mod errors; +pub mod main; +pub mod models; +pub mod types; diff --git a/crates/sqlbuild-python-front/src/model_config/models.rs b/crates/sqlbuild-python-front/src/model_config/models.rs new file mode 100644 index 0000000000..2b2d80cc80 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/models.rs @@ -0,0 +1,1477 @@ +//! Public records of model config. + +use crate::attachments::main::argument_pairs::argument_pairs; +use crate::attachments::main::config_argument_value::config_argument_value; +use crate::authored_values::main::project_var_text::project_var_text; +use crate::discovery::main::project::each::each; +use crate::discovery::models::NativeModelFile; +use crate::model_config::_helpers::config::config_classes::built_config; +use crate::model_config::_helpers::config::config_errors::native_config_error; +use crate::model_config::_helpers::config::config_nodes::PyConfigEntries; +use crate::model_config::_helpers::config::config_nodes::config_dict; +use crate::model_config::_helpers::config::config_nodes::config_entries; +use crate::model_config::_helpers::config::config_nodes::config_node; +use crate::model_config::_helpers::config::config_nodes::config_object; +use crate::model_config::_helpers::config::config_templates::CONTEXT_READ; +use crate::model_config::_helpers::config::config_templates::EFFECTIVE_VARS_LABEL; +use crate::model_config::_helpers::config::config_templates::ENVIRONMENT_READ; +use crate::model_config::_helpers::config::config_templates::EffectiveVars; +use crate::model_config::_helpers::headers::header_audits::authored_audit; +use crate::model_config::_helpers::headers::header_audits::config_json_value; +use crate::model_config::_helpers::headers::header_audits::retain_audit; +use crate::model_config::_helpers::headers::header_families::family_specs; +use crate::model_config::_helpers::headers::header_metadata::ColumnFields; +use crate::model_config::_helpers::headers::header_metadata::SCHEMA_COLUMN_FIELDS; +use crate::model_config::_helpers::headers::header_metadata::audit_instance; +use crate::model_config::_helpers::headers::header_metadata::checked_field_orders; +use crate::model_config::_helpers::headers::header_metadata::contract_object; +use crate::model_config::_helpers::headers::header_metadata::native_location; +use crate::model_config::_helpers::headers::header_metadata::native_value; +use crate::model_config::_helpers::headers::header_metadata::native_values; +use crate::model_config::_helpers::headers::header_metadata::thresholds; +use crate::model_config::_helpers::model_nodes::authored_nodes::entry_nodes; +use crate::model_config::_helpers::model_nodes::contract_classes::contract_classes; +use crate::model_config::_helpers::model_nodes::model_config_builder::CONTEXT_KEYS; +use crate::model_config::_helpers::model_nodes::model_config_builder::HeaderBuildInputs; +use crate::model_config::_helpers::model_nodes::model_config_builder::PythonConfigHost; +use crate::model_config::_helpers::model_nodes::model_config_builder::TargetInputs; +use crate::model_config::_helpers::model_nodes::model_config_builder::entry_facts; +use crate::model_config::_helpers::model_nodes::model_config_builder::halted; +use crate::model_config::_helpers::model_nodes::model_config_builder::header_entries; +use crate::model_config::_helpers::model_nodes::model_config_builder::optional_node; +use crate::model_config::_helpers::model_nodes::model_config_builder::projected_build; +use crate::model_config::_helpers::model_nodes::model_validator::ModelFacts; +use crate::model_config::_helpers::model_nodes::model_validator::ResourceNames; +use crate::model_config::_helpers::model_nodes::model_validator::discovered_names; +use crate::model_config::_helpers::model_nodes::model_validator::stop_object; +use crate::model_config::_helpers::model_nodes::project_defaults::project_defaults_mapping; +use crate::model_config::errors::NativeConfigError; +use crate::model_config::types::BuiltConfigValues; +use crate::model_config::types::HeaderValue; +use crate::model_config::types::PyConfigNode; +use pyo3::FromPyObject; +use pyo3::IntoPyObjectExt; +use pyo3::exceptions::PyRuntimeError; +use pyo3::exceptions::PyValueError; +use pyo3::prelude::Bound; +use pyo3::prelude::Py; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyAnyMethods; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::pyclass; +use pyo3::pymethods; +use pyo3::sync::PyOnceLock; +use pyo3::types::PyBool; +use pyo3::types::PyBoolMethods; +use pyo3::types::PyDict; +use pyo3::types::PyDictMethods; +use pyo3::types::PyFloat; +use pyo3::types::PyInt; +use pyo3::types::PyList; +use pyo3::types::PyListMethods; +use pyo3::types::PyString; +use pyo3::types::PyStringMethods; +use pyo3::types::PyTuple; +use pyo3::types::PyTupleMethods; +use sqlbuild_attachments::audits::models::ArgumentValue; +use sqlbuild_attachments::functions::models::KnownResources; +use sqlbuild_core::json::models::JsonValue; +use sqlbuild_discovery::model_files::models::NativeColumn; +use sqlbuild_discovery::models::LineColumnSpan; +use sqlbuild_model_config::config_values::models::ConfigNode; +use sqlbuild_model_config::config_values::types::HostObject; +use sqlbuild_model_config::header_metadata::constants::ACCEPTED_VALUES_ARGUMENT; +use sqlbuild_model_config::header_metadata::constants::ACCEPTED_VALUES_AUDIT; +use sqlbuild_model_config::header_metadata::constants::AUDITS_KEY; +use sqlbuild_model_config::header_metadata::models::DynamicFamily; +use sqlbuild_model_config::header_metadata::models::ParsedAudit; +use sqlbuild_model_config::model_config_build::main::build_model_config::build_model_config; +use sqlbuild_model_config::model_config_build::main::inherited_config::inherited_config; +use sqlbuild_model_config::model_config_build::main::model_context_values::model_context_values; +use sqlbuild_model_config::model_config_build::models::ConfigBuildInputs; +use sqlbuild_model_config::model_config_build::models::HeaderEntryFacts; +use sqlbuild_model_config::model_config_build::models::ModelHeader; +use sqlbuild_model_config::model_validation::main::validate_model_config::validate_model_config; +use sqlbuild_model_config::model_validation::main::validate_model_references::validate_model_references; +use sqlbuild_model_config::model_validation::models::ModelReference; +use sqlbuild_model_config::model_validation::models::ModelValidationFacts; +use sqlbuild_model_config::model_validation::models::ProjectValidationFacts; +use sqlbuild_model_config::model_validation::models::RetentionOverride; +use sqlbuild_model_config::model_validation::models::TableTypeOverride; +use sqlbuild_model_config::path_defaults::main::select_path_default::select_path_default; +use sqlbuild_model_config::path_defaults::models::PathDefaultChoice; +use sqlbuild_model_config::templates::errors::TemplateError; +use sqlbuild_model_config::templates::main::expand_template_text::expand_template_text; +use sqlbuild_model_config::templates::models::ContextValue; +use sqlbuild_model_config::templates::models::Scalar; +use sqlbuild_model_config::templates::models::TemplateFailure; +use sqlbuild_model_config::templates::models::TemplateOptions; +use sqlbuild_model_config::templates::types::TemplateHost; +use sqlbuild_model_config::types::AuthoredNode; +use sqlbuild_model_config::types::NodeKind; +use sqlbuild_python_base::boundary::main::compiler_guard::compiler_guard; +use sqlbuild_python_base::native_host::models::AuditProjection; +use sqlbuild_python_base::native_host::models::FamilyProjection; +use sqlbuild_python_base::records::main::construct::record_class::record_class; +use sqlbuild_python_base::records::main::fields::field::field; +use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_base::result_output::main::json_value::json_value; +use std::cell::RefCell; +use std::collections::HashSet; +use std::sync::Arc; +use std::sync::Mutex; + +/// One Python object viewed as an authored value; parsed results keep the object itself. +#[derive(Clone, Debug)] +pub struct PyNode<'py>(pub Bound<'py, PyAny>); + +impl AuthoredNode for PyNode<'_> { + fn kind(&self) -> NodeKind { + let value = &self.0; + if value.is_none() { + NodeKind::Null + } else if let Ok(flag) = value.downcast::() { + NodeKind::Bool(flag.is_true()) + } else if value.is_instance_of::() { + value + .lt(0) + .map_or(NodeKind::Other, |negative| NodeKind::Int { negative }) + } else if value.is_instance_of::() { + NodeKind::Str + } else if value.is_instance_of::() { + NodeKind::List + } else if value.is_instance_of::() { + NodeKind::Tuple + } else if value.is_instance_of::() { + NodeKind::Map + } else { + NodeKind::Other + } + } + + fn integer(&self) -> Option { + if !self.0.is_instance_of::() + && self.0.is_instance_of::() + && let Ok(number) = self.0.extract::() + { + Some(number) + } else { + None + } + } + + fn number(&self) -> Option { + let value = &self.0; + let is_number: bool = value.is_instance_of::() + || (value.is_instance_of::() && !value.is_instance_of::()); + if !is_number { + return None; + } + if let Ok(number) = value.extract::() { + return Some(number); + } + let Ok(number) = self.python_str().parse::() else { + return None; + }; + Some(number) + } + + fn text(&self) -> Option { + self.with_text(str::to_owned) + } + + /// Read a string's text; lone surrogates, rejected where text enters a compile, read as U+FFFD. + fn with_text(&self, read: impl FnOnce(&str) -> R) -> Option { + match self.0.downcast::() { + Ok(value) => Some(read(&value.to_string_lossy())), + Err(_) => None, + } + } + + fn is_text(&self, text: &str) -> bool { + self.with_text(|value| value == text).unwrap_or(false) + } + + fn items(&self) -> Vec { + if let Ok(items) = self.0.downcast::() { + items.iter().map(PyNode).collect() + } else if let Ok(items) = self.0.downcast::() { + items.iter().map(PyNode).collect() + } else { + Vec::new() + } + } + + fn entries(&self) -> Vec<(Self, Self)> { + if let Ok(entries) = self.0.downcast::() { + entries.iter().map(entry_nodes).collect() + } else { + Vec::new() + } + } + + fn python_str(&self) -> String { + self.0 + .str() + .map(|text| text.to_string_lossy().into_owned()) + .unwrap_or_default() + } + + fn python_repr(&self) -> String { + self.0 + .repr() + .map(|text| text.to_string_lossy().into_owned()) + .unwrap_or_default() + } + + fn is_date_like(&self) -> bool { + let py = self.0.py(); + py.import("datetime") + .and_then(|module| native_field(&module, "date")) + .and_then(|date| self.0.is_instance(&date)) + .unwrap_or(false) + } +} + +/// The builder, storage defaults and Python classes a model's `CompileModelConfig` is made of. +#[derive(Debug, FromPyObject)] +#[pyo3(from_item_all)] +pub struct ConfigClasses<'py> { + pub builder: Bound<'py, NativeModelConfigBuilder>, + /// Inherited `(retention, table type)` by table-backed materialization, or `None`. + pub inherited_storage: Bound<'py, PyDict>, + pub table_backed: Vec, + pub compile_model_config: Bound<'py, PyAny>, + pub resolved_retention: Bound<'py, PyAny>, + pub retention_source: Bound<'py, PyAny>, + pub resolved_table_type: Bound<'py, PyAny>, + pub table_type: Bound<'py, PyAny>, + pub table_type_source: Bound<'py, PyAny>, + /// `record_template_reads`, the compile-reuse sink of template reads. + pub record_template_reads: Bound<'py, PyAny>, +} + +/// The Python object an opaque config value stands for. +#[derive(Clone, Debug)] +pub struct HostHandle(pub Arc>); + +impl HostObject for HostHandle { + fn is_date_like(&self) -> bool { + Python::attach(|py| PyNode(self.0.bind(py).clone()).is_date_like()) + } + + /// Python's text of the projected value; a `str()` or `repr()` that raises reads as empty, as `PyNode`. + fn display(node: &ConfigNode, repr: bool) -> String { + Python::attach(|py| { + config_object(py, node).map_or_else( + |_| String::new(), + |value| { + let value: PyNode<'_> = PyNode(value); + if repr { + value.python_repr() + } else { + value.python_str() + } + }, + ) + }) + } +} + +/// Variables, the process environment and context values, all read through Python. +pub struct PythonHost<'py> { + pub(crate) py: Python<'py>, + pub(crate) sources: TemplateSources<'py>, + pub(crate) label: String, + pub(crate) effective: Option>, + pub(crate) reads: RefCell>, + pub(crate) raised: RefCell>, +} + +impl std::fmt::Debug for PythonHost<'_> { + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + formatter.debug_struct("PythonHost").finish_non_exhaustive() + } +} + +impl<'py> PythonHost<'py> { + /// Read variables, the environment and context values from these Python objects. + pub fn new(py: Python<'py>, sources: TemplateSources<'py>, label: &str) -> Self { + Self { + py, + sources, + label: label.to_owned(), + effective: None, + reads: RefCell::new(Vec::new()), + raised: RefCell::new(None), + } + } + + /// Return the `(kind, name)` reads in order. + pub fn into_reads(self) -> Vec<(&'static str, String)> { + self.reads.into_inner() + } + + /// Hold a Python error until the expansion returns, and stop evaluation. + pub(crate) fn hold(&self, error: pyo3::PyErr) -> TemplateFailure { + self.raised.borrow_mut().get_or_insert(error); + TemplateFailure::Host + } + + /// The stop for `failure`, taking the held Python error of a host failure. + pub fn stop(&self, failure: TemplateFailure) -> Stop { + match failure { + TemplateFailure::Missing(error) | TemplateFailure::Invalid(error) => { + Stop::Failure(error) + } + TemplateFailure::Host => { + Stop::Python(self.raised.borrow_mut().take().unwrap_or_else(|| { + PyRuntimeError::new_err("template expansion stopped without an error") + })) + } + } + } + + pub(crate) fn text_of(&self, value: &Bound<'py, PyAny>) -> Result { + value + .downcast::() + .map_err(|error| self.hold(error.into()))? + .to_str() + .map(str::to_owned) + .map_err(|error| self.hold(error)) + } + + /// Resolve effective var `name`, keeping Python's resolving stack on errors. + pub(crate) fn resolve( + &self, + effective: &EffectiveVars<'py>, + name: &str, + ) -> Result>, TemplateFailure> { + let Some(raw) = self + .sources + .0 + .get_item(name) + .map_err(|error| self.hold(error))? + else { + return Ok(None); + }; + if let Some(value) = effective + .resolved + .get_item(name) + .map_err(|error| self.hold(error))? + { + return Ok(Some(value)); + } + if effective.resolving.borrow().iter().any(|key| key == name) { + let mut cycle = effective.resolving.borrow().clone(); + cycle.push(name.to_owned()); + return Err(TemplateFailure::Invalid(TemplateError::Message(format!( + "{EFFECTIVE_VARS_LABEL} contain a cyclic reference: {}", + cycle.join(" -> ") + )))); + } + effective.resolving.borrow_mut().push(name.to_owned()); + let value = if raw.is_instance_of::() { + let text = self.text_of(&raw)?; + let options = TemplateOptions { + allow_context: false, + preserve_context_tokens: false, + preserve_unknown_context: false, + }; + PyString::new(self.py, &expand_template_text(self, &text, options)?).into_any() + } else { + raw + }; + effective.resolving.borrow_mut().pop(); + effective + .resolved + .set_item(name, &value) + .map_err(|error| self.hold(error))?; + Ok(Some(value)) + } +} + +/// The variables, the `os.environ` mapping and the context values one expansion reads. +#[derive(Debug, FromPyObject)] +pub struct TemplateSources<'py>( + pub Bound<'py, PyDict>, + pub Bound<'py, PyAny>, + pub Bound<'py, PyDict>, +); + +/// A template error, or a Python error raised while reading values or building containers. +#[derive(Debug)] +pub enum Stop { + Failure(TemplateError), + Python(pyo3::PyErr), +} + +impl<'py> TemplateHost for PythonHost<'py> { + type Value = Bound<'py, PyAny>; + + fn variable(&self, name: &str) -> Result, TemplateFailure> { + if let Some(effective) = &self.effective { + return self.resolve(effective, name); + } + self.sources + .0 + .get_item(name) + .map_err(|error| self.hold(error)) + } + + fn environment(&self, name: &str) -> Result, TemplateFailure> { + self.reads + .borrow_mut() + .push((ENVIRONMENT_READ, name.to_owned())); + let environment: &Bound<'py, PyAny> = &self.sources.1; + if environment + .contains(name) + .map_err(|error| self.hold(error))? + { + environment + .get_item(name) + .map(Some) + .map_err(|error| self.hold(error)) + } else { + Ok(None) + } + } + + fn context(&self, name: &str) -> Result, TemplateFailure> { + self.reads + .borrow_mut() + .push((CONTEXT_READ, name.to_owned())); + match self + .sources + .2 + .get_item(name) + .map_err(|error| self.hold(error))? + { + None => Ok(ContextValue::Unknown), + Some(value) if value.is_none() => Ok(ContextValue::Unavailable), + Some(value) => Ok(ContextValue::Value(value)), + } + } + + fn text(&self, text: &str) -> Result { + Ok(PyString::new(self.py, text).into_any()) + } + + fn boolean(&self, flag: bool) -> Result { + Ok(PyBool::new(self.py, flag).to_owned().into_any()) + } + + fn null(&self) -> Self::Value { + self.py.None().into_bound(self.py) + } + + fn scalar(&self, value: &Self::Value) -> Result { + if value.is_none() { + return Ok(Scalar::Null); + } + if let Ok(flag) = value.downcast_exact::() { + return Ok(Scalar::Bool(flag.is_true())); + } + let text = value.str().map_err(|error| self.hold(error))?; + self.text_of(text.as_any()).map(Scalar::Text) + } + + fn render(&self, value: &Self::Value, label: &str) -> Result { + if value.is_exact_instance_of::() { + return self.text_of(value); + } + match project_var_text(value, label) { + Ok(text) => Ok(text), + Err(error) if error.is_instance_of::(self.py) => Err( + TemplateFailure::Invalid(TemplateError::Message(error.value(self.py).to_string())), + ), + Err(error) => Err(self.hold(error)), + } + } + + fn label(&self) -> &str { + &self.label + } +} + +/// Native-built specs never become Python audit records just to be read by attachment. +#[derive(Debug)] +pub enum AuditInstance<'py> { + Native(Arc>, Bound<'py, PyAny>), + Python(Bound<'py, PyAny>), +} + +impl<'py> AuditInstance<'py> { + /// Equality with the builtin generated enum audit, without constructing argument containers. + pub fn accepts_enum(&self, values: &[PyConfigNode]) -> PyResult { + let Self::Native(spec, location) = self else { + return Ok(false); + }; + let py = location.py(); + if spec.definition_name.exact_text(py)? != ACCEPTED_VALUES_AUDIT + || spec.thresholds.is_some() + { + return Ok(false); + } + for name in [ + "name", + "description", + "severity", + "run_scope", + "minimum_samples", + "evidence_limit", + "meta", + ] { + if !self.field(name)?.is_none() { + return Ok(false); + } + } + if !self.field("always_run")?.eq(false)? || spec.arguments.len() != 1 { + return Ok(false); + } + let (key, authored) = &spec.arguments[0]; + let matches = match key { + ConfigNode::Str(key) => key == ACCEPTED_VALUES_ARGUMENT, + ConfigNode::Host(_) => { + let key = key.object(py)?; + key.is_instance_of::() && key.eq(ACCEPTED_VALUES_ARGUMENT)? + } + _ => false, + }; + if !matches { + return Ok(false); + } + let ConfigNode::Tuple(authored) = authored else { + return Ok(false); + }; + if authored.len() != values.len() { + return Ok(false); + } + for (left, right) in authored.iter().zip(values) { + if !left.object(py)?.eq(right.object(py)?)? { + return Ok(false); + } + } + Ok(true) + } + + pub fn meta_present(&self) -> PyResult { + match self { + Self::Native(spec, _) => Ok(spec + .meta + .as_ref() + .is_some_and(|value| !matches!(value, ConfigNode::Null))), + Self::Python(value) => Ok(!field(value, "meta")?.is_none()), + } + } + + pub fn threshold_policy(&self) -> PyResult<(bool, bool)> { + match self { + Self::Native(spec, _) => Ok(( + spec.thresholds.is_some(), + spec.thresholds.is_some_and(|value| value.error.is_some()), + )), + Self::Python(value) => { + let thresholds = field(value, "thresholds")?; + Ok(( + !thresholds.is_none(), + !thresholds.is_none() && !field(&thresholds, "error")?.is_none(), + )) + } + } + } + + pub fn field(&self, name: &str) -> PyResult> { + let (spec, location) = match self { + Self::Native(spec, location) => (spec, location), + Self::Python(value) => return field(value, name), + }; + let py = location.py(); + let value = match name { + "definition_name" => return spec.definition_name.object(py), + "name" => &spec.name, + "description" => &spec.description, + "run_scope" => &spec.run_scope, + "minimum_samples" => &spec.minimum_samples, + "evidence_limit" => &spec.evidence_limit, + "meta" => &spec.meta, + "always_run" => { + return match &spec.always_run { + Some(value) => value.object(py), + None => false.into_bound_py_any(py), + }; + } + "severity" => { + let classes = contract_classes(py)?; + let classes: ContractClasses<'_> = classes.extract()?; + return match &spec.severity { + Some(value) => Ok(classes + .severities + .get_item(value.object(py)?)? + .unwrap_or_else(|| py.None().into_bound(py))), + None => Ok(py.None().into_bound(py)), + }; + } + "thresholds" => { + let classes: ContractClasses<'_> = contract_classes(py)?.extract()?; + return thresholds(py, &classes, spec.thresholds.as_ref()); + } + "location" => return Ok(location.clone()), + _ => return Err(pyo3::exceptions::PyAttributeError::new_err(name.to_owned())), + }; + value + .as_ref() + .map(|value| value.object(py)) + .transpose() + .map(|value| value.unwrap_or_else(|| py.None().into_bound(py))) + } + + pub fn argument(&self, name: &str) -> PyResult>> { + match self { + Self::Native(spec, location) => { + for (key, value) in &spec.arguments { + let matches = match key { + ConfigNode::Str(key) => key == name, + ConfigNode::Host(_) => { + let key = key.object(location.py())?; + key.is_instance_of::() && key.eq(name)? + } + _ => false, + }; + if matches { + return value.object(location.py()).map(Some); + } + } + Ok(None) + } + Self::Python(value) => field(value, "arguments")?.cast::()?.get_item(name), + } + } + + pub fn arguments(&self) -> PyResult> { + match self { + Self::Native(spec, location) => { + let mut arguments = Vec::with_capacity(spec.arguments.len()); + for (key, value) in &spec.arguments { + let key = match key { + ConfigNode::Str(key) => key.clone(), + ConfigNode::Host(_) => { + let key = key.object(location.py())?; + let Ok(key) = key.cast::() else { + continue; + }; + key.to_string_lossy().into_owned() + } + _ => continue, + }; + arguments.push((key, config_argument_value(location.py(), value)?)); + } + Ok(arguments) + } + Self::Python(value) => argument_pairs(field(value, "arguments")?.cast()?), + } + } + + pub fn meta(&self) -> PyResult> { + match self { + Self::Native(spec, location) => spec + .meta + .as_ref() + .map(|value| config_json_value(location.py(), value)) + .transpose() + .map(Option::flatten), + Self::Python(value) => { + let meta = field(value, "meta")?; + if meta.is_none() { + Ok(None) + } else { + json_value(&meta) + } + } + } + } +} + +/// The parsed specs and genuine Python audit objects of one model or column. +#[derive(Debug)] +pub struct HeaderAudits { + pub(crate) specs: Vec>, + pub(crate) native_generated: Vec>, + pub(crate) public: AuditProjection, +} + +impl HeaderAudits { + pub fn new( + py: Python<'_>, + classes: &ContractClasses<'_>, + specs: &[ParsedAudit], + location: &Bound<'_, PyAny>, + ) -> PyResult { + let custom = if classes.uses_default_classes()? { + None + } else { + Some( + specs + .iter() + .map(|spec| audit_instance(py, classes, spec, location).map(Bound::unbind)) + .collect::>()?, + ) + }; + Ok(Self { + specs: specs + .iter() + .map(|spec| retain_audit(py, spec)) + .collect::>()?, + native_generated: Vec::new(), + public: AuditProjection { + custom, + generated: Vec::new(), + location: location.clone().unbind(), + records: PyOnceLock::new(), + }, + }) + } + + pub fn extend(&mut self, generated: Vec>) { + self.public + .generated + .extend(generated.into_iter().map(Bound::unbind)); + } + + pub fn push_native(&mut self, spec: ParsedAudit) { + self.native_generated.push(spec); + } + + /// The number of audits the header declares, generated ones included. + pub fn count(&self) -> usize { + self.specs.len() + self.public.generated.len() + self.native_generated.len() + } + + pub fn native_specs(&self) -> &[ParsedAudit] { + if self.public.custom.is_some() { + &[] + } else { + &self.specs + } + } + + pub fn python_specs<'py>(&self, py: Python<'py>) -> Vec> { + self.public + .custom + .iter() + .flatten() + .chain(&self.public.generated) + .map(|spec| spec.bind(py).clone()) + .collect() + } + + pub fn instances<'py>(&self, py: Python<'py>) -> Vec> { + self.native_specs() + .iter() + .map(|spec| { + AuditInstance::Native( + Arc::new(spec.clone()), + self.public.location.bind(py).clone(), + ) + }) + .chain(self.python_specs(py).into_iter().map(AuditInstance::Python)) + .chain(self.native_generated.iter().map(|spec| { + AuditInstance::Native(Arc::new(spec.clone()), py.None().into_bound(py)) + })) + .collect() + } + + pub fn project<'py>(&self, py: Python<'py>) -> PyResult> { + self.public + .records + .get_or_try_init(py, || { + let classes: ContractClasses<'_> = contract_classes(py)?.extract()?; + let mut audits = self + .native_specs() + .iter() + .map(|spec| audit_instance(py, &classes, spec, self.public.location.bind(py))) + .collect::>>()?; + audits.extend(self.python_specs(py)); + for spec in &self.native_generated { + audits.push(audit_instance( + py, + &classes, + spec, + &py.None().into_bound(py), + )?); + } + PyTuple::new(py, audits).map(Bound::unbind) + }) + .map(|value| value.bind(py).clone()) + } + + pub fn key_rows(&self, py: Python<'_>) -> PyResult)>> { + let mut rows = Vec::with_capacity(self.count()); + for spec in self.instances(py) { + let column = spec.argument("column")?; + rows.push(( + spec.field("definition_name")?.extract()?, + column + .filter(|value| value.is_instance_of::()) + .map(|value| value.extract()) + .transpose()?, + )); + } + Ok(rows) + } +} + +/// Parsed family specs stay native until a public schema attribute needs records. +#[derive(Debug)] +pub struct HeaderFamilies { + pub specs: Vec, + pub(crate) public: FamilyProjection, +} + +impl HeaderFamilies { + pub fn new(class: &Bound<'_, PyAny>, specs: Vec) -> PyResult { + let result = Self { + specs, + public: FamilyProjection::new( + class, + !class.is(&record_class( + class.py(), + RecordId::SchemaDynamicColumnFamily, + )?), + ), + }; + if result.public.custom { + let _ = result.project(class.py())?; + } + Ok(result) + } + + pub fn read(&self, py: Python<'_>) -> PyResult> { + if self.public.custom { + family_specs(self.project(py)?.as_any()) + } else { + Ok(self.specs.clone()) + } + } + + pub fn project<'py>(&self, py: Python<'py>) -> PyResult> { + self.public.project(py, &self.specs) + } +} + +/// Native column fields; a Python record is constructed only for public consumers. +pub struct HeaderColumn { + pub(crate) fields: ColumnFields, + pub(crate) class: Py, + pub(crate) audits: Option, + pub(crate) projection: PyOnceLock>, +} + +impl std::fmt::Debug for HeaderColumn { + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + formatter + .debug_struct("HeaderColumn") + .finish_non_exhaustive() + } +} + +/// A natively parsed header column and what its Python record is built with. +#[derive(Debug)] +pub struct NativeColumnSpec { + pub column: NativeColumn, + /// The model file whose relative path the column's location names, and the location. + pub location: Option<(Py, LineColumnSpan)>, +} + +impl HeaderColumn { + /// Retype a builtin column without discarding its retained audit specs. + pub fn enum_type( + mut self, + py: Python<'_>, + scalar_type: Bound<'_, PyAny>, + generated: Option>, + ) -> PyResult { + if self.audits.is_none() + && let ColumnFields::Native(spec) = &self.fields + { + let audits = spec + .column + .audits + .iter() + .map(|audit| authored_audit(py, audit)) + .collect::>>()?; + let classes: ContractClasses<'_> = contract_classes(py)?.extract()?; + self.audits = Some(HeaderAudits::new( + py, + &classes, + &audits, + &native_location(py, spec)?, + )?); + } + if let Some(audits) = &mut self.audits { + if let Some(generated) = generated { + audits.push_native(generated); + } + match &mut self.fields { + ColumnFields::Native(spec) => spec.column.column_type = scalar_type.extract()?, + ColumnFields::Python(values) => values[1] = scalar_type.unbind(), + ColumnFields::Projected => { + return Err(PyRuntimeError::new_err( + "enum column has no retained fields", + )); + } + } + self.projection = PyOnceLock::new(); + return Ok(self); + } + Err(PyRuntimeError::new_err( + "enum column has no retained audits", + )) + } + + pub fn retains_audits(&self) -> bool { + self.audits.is_some() || matches!(self.fields, ColumnFields::Native(_)) + } + + pub fn audit_instances<'py>(&self, py: Python<'py>) -> PyResult>> { + if let Some(audits) = &self.audits { + return Ok(audits.instances(py)); + } + if let ColumnFields::Native(spec) = &self.fields { + let audits = spec + .column + .audits + .iter() + .map(|audit| authored_audit(py, audit)) + .collect::>>()?; + let classes: ContractClasses<'_> = contract_classes(py)?.extract()?; + return Ok( + HeaderAudits::new(py, &classes, &audits, &native_location(py, spec)?)? + .instances(py), + ); + } + self.field(py, "audits")? + .try_iter()? + .map(|value| value.map(AuditInstance::Python)) + .collect() + } + + pub fn replaced<'py>( + class: &Bound<'py, PyAny>, + values: [Bound<'py, PyAny>; 8], + keyword_order: [usize; 8], + ) -> PyResult { + if class.is(&record_class(class.py(), RecordId::SchemaColumn)?) { + return Self::new(class, values); + } + let fields = PyDict::new(class.py()); + for index in keyword_order { + fields.set_item(SCHEMA_COLUMN_FIELDS[index], &values[index])?; + } + Self::from_python(class.call((), Some(&fields))?) + } + + pub fn field<'py>(&self, py: Python<'py>, name: &str) -> PyResult> { + let index = || { + SCHEMA_COLUMN_FIELDS + .iter() + .position(|field| *field == name) + .ok_or_else(|| PyRuntimeError::new_err("unknown column field")) + }; + if let Some(projected) = self.projection.get(py) { + return field(projected.bind(py), name); + } + if name == AUDITS_KEY + && let Some(audits) = &self.audits + { + return Ok(audits.project(py)?.into_any()); + } + match &self.fields { + ColumnFields::Python(values) => Ok(values[index()?].bind(py).clone()), + ColumnFields::Native(spec) => native_value(py, spec, index()?), + ColumnFields::Projected => field(&self.project(py)?, name), + } + } + + pub fn project<'py>(&self, py: Python<'py>) -> PyResult> { + self.projection + .get_or_try_init(py, || { + let mut values: [Bound<'py, PyAny>; 8] = match &self.fields { + ColumnFields::Python(values) => { + values.each_ref().map(|value| value.bind(py).clone()) + } + ColumnFields::Native(spec) => native_values(py, spec)?, + ColumnFields::Projected => { + return Err(PyRuntimeError::new_err("missing column projection")); + } + }; + if let Some(audits) = &self.audits { + values[5] = audits.project(py)?.into_any(); + } + contract_object(self.class.bind(py), values).map(Bound::unbind) + }) + .map(|value| value.bind(py).clone()) + } + + pub fn from_python(value: Bound<'_, PyAny>) -> PyResult { + let py = value.py(); + let projection = PyOnceLock::new(); + let class = value.get_type().into_any().unbind(); + let _ = projection.set(py, value.unbind()); + Ok(Self { + fields: ColumnFields::Projected, + class, + audits: None, + projection, + }) + } + + pub fn new<'py>(class: &Bound<'py, PyAny>, values: [Bound<'py, PyAny>; 8]) -> PyResult { + if !class.is(&record_class(class.py(), RecordId::SchemaColumn)?) { + return Self::from_python(contract_object(class, values)?); + } + checked_field_orders()?; + Ok(Self { + fields: ColumnFields::Python(values.map(Bound::unbind)), + class: class.clone().unbind(), + audits: None, + projection: PyOnceLock::new(), + }) + } + + /// A natively parsed column, whose Python record is built only when Python reads it. + pub fn native(class: &Bound<'_, PyAny>, spec: NativeColumnSpec) -> PyResult { + let py: Python<'_> = class.py(); + if !class.is(&record_class(py, RecordId::SchemaColumn)?) { + return Self::from_python(contract_object(class, native_values(py, &spec)?)?); + } + checked_field_orders()?; + Ok(Self { + fields: ColumnFields::Native(Box::new(spec)), + class: class.clone().unbind(), + audits: None, + projection: PyOnceLock::new(), + }) + } +} + +impl HeaderColumn { + /// The original native column, if no retained audit edits changed its public contract. + pub fn native_spec(&self) -> Option<&NativeColumnSpec> { + if self.audits.is_some() { + return None; + } + match &self.fields { + ColumnFields::Native(spec) => Some(spec), + ColumnFields::Python(_) | ColumnFields::Projected => None, + } + } +} + +/// Retained native columns and their shared, lazy public tuple. +pub struct HeaderColumns { + pub specs: Vec, + pub(crate) projection: PyOnceLock>, +} + +impl std::fmt::Debug for HeaderColumns { + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + formatter + .debug_struct("HeaderColumns") + .finish_non_exhaustive() + } +} + +impl HeaderColumns { + pub fn new(specs: Vec) -> Self { + Self { + specs, + projection: PyOnceLock::new(), + } + } + + pub fn project<'py>(&self, py: Python<'py>) -> PyResult> { + self.projection + .get_or_try_init(py, || { + let columns = self + .specs + .iter() + .map(|column| column.project(py)) + .collect::>>()?; + PyTuple::new(py, columns).map(Bound::unbind) + }) + .map(|value| value.bind(py).clone()) + } +} + +/// The Python classes the parsed metadata becomes, read from a Python mapping. +#[derive(Debug, FromPyObject)] +#[pyo3(from_item_all)] +pub struct ContractClasses<'py> { + pub schema_column: Bound<'py, PyAny>, + pub schema_audit_instance: Bound<'py, PyAny>, + pub schema_dynamic_column_family: Bound<'py, PyAny>, + pub source_location: Bound<'py, PyAny>, + pub(crate) measurement_thresholds: Bound<'py, PyAny>, + pub(crate) measurement_threshold_bound: Bound<'py, PyAny>, + pub severities: Bound<'py, PyDict>, + pub(crate) threshold_operators: Bound<'py, PyDict>, +} + +impl ContractClasses<'_> { + /// Whether these are the classes native header parsing builds by default. + pub fn uses_default_classes(&self) -> PyResult { + let py: Python<'_> = self.schema_column.py(); + let default: ContractClasses<'_> = contract_classes(py)?.extract()?; + Ok(self.schema_column.is(&default.schema_column) + && self + .schema_audit_instance + .is(&default.schema_audit_instance) + && self.source_location.is(&default.source_location) + && self + .measurement_thresholds + .is(&default.measurement_thresholds) + && self + .measurement_threshold_bound + .is(&default.measurement_threshold_bound) + && self.severities.is(&default.severities) + && self.threshold_operators.is(&default.threshold_operators)) + } +} + +/// The project-wide inputs every model's config build reads, converted once per compile. +#[pyclass(module = "sqlbuild._native", frozen)] +#[derive(Debug)] +pub struct NativeModelConfigBuilder { + pub(crate) inputs: ConfigBuildInputs, + pub(crate) path_keys: Vec, + pub(crate) environment: Py, +} + +/// One model's built config before Python wraps it in `CompileModelConfig`. +#[derive(Debug)] +pub struct BuiltConfig<'py> { + pub values: Bound<'py, PyDict>, + pub nodes: Option, + pub header_keys: Vec, + pub logical_schema: Option>, + pub layer_schema_configured: bool, + pub logical_database: Option>, + pub retention: RetentionOverride, + pub table_type: TableTypeOverride, + pub reads: Vec<(&'static str, String)>, +} + +/// A native build's outcome: the built config, or the config error it raises. +#[derive(Debug)] +pub enum ConfigBuild<'py> { + Built(BuiltConfig<'py>), + Rejected(Py), +} + +#[pymethods] +impl NativeModelConfigBuilder { + #[new] + pub fn new( + layers: (Bound<'_, PyAny>, Bound<'_, PyDict>, Bound<'_, PyTuple>), + sources: (Bound<'_, PyDict>, Bound<'_, PyAny>), + target: TargetInputs<'_>, + ) -> PyResult { + let (run, target_namespace) = target; + let (defaults, path_defaults, _hook_entry_types) = layers; + let mut path_keys: Vec = Vec::with_capacity(path_defaults.len()); + let mut path_values: Vec<(String, PyConfigEntries)> = + Vec::with_capacity(path_defaults.len()); + for (key, values) in path_defaults.iter() { + let key: String = key.extract()?; + path_values.push((key.clone(), config_entries(values.downcast::()?)?)); + path_keys.push(key); + } + let (target_name, run_id) = run; + Ok(Self { + inputs: ConfigBuildInputs { + defaults: config_entries(&project_defaults_mapping(&defaults)?)?, + path_defaults: path_values, + variables: config_entries(&sources.0)?, + run_id: config_node(&run_id)?, + target_name: optional_node(target_name)?.unwrap_or(ConfigNode::Null), + target_namespace: target_namespace + .map(|(database, schema)| -> PyResult<_> { + Ok((config_node(&database)?, config_node(&schema)?)) + }) + .transpose()?, + }, + path_keys, + environment: sources.1.unbind(), + }) + } + + /// Return the model's `CompileModelConfig` or the first config error. + pub(crate) fn model_config<'py>( + &self, + py: Python<'py>, + header: Bound<'py, PyDict>, + model: (Option, String), + classes: ConfigClasses<'py>, + ) -> PyResult> { + let (matched_path_default, model_name) = model; + let matched_path_default: Option<&str> = matched_path_default.as_deref(); + compiler_guard(|| { + match self.built(py, (&header, None, None), matched_path_default, &model_name)? { + ConfigBuild::Built(built) => { + Ok(built_config(&classes, &built, matched_path_default)?.unbind()) + } + ConfigBuild::Rejected(error) => Ok(error.into_any()), + } + }) + } +} + +impl NativeModelConfigBuilder { + pub(crate) fn host<'py>(&self, py: Python<'py>) -> PythonConfigHost<'py> { + PythonConfigHost { + environment: self.environment.bind(py).clone(), + } + } + + /// The selected path-default key, or the conflict error Python raises. + pub fn selected_path_default( + &self, + py: Python<'_>, + model_path: &str, + ) -> PyResult, Py>> { + Ok(match select_path_default(model_path, &self.path_keys) { + PathDefaultChoice::Selected(key) => Ok(key), + PathDefaultChoice::Conflict(error) => Err(native_config_error(py, error)?), + }) + } + + /// Build one model's config natively. + pub fn built<'py>( + &self, + py: Python<'py>, + (header, facts, authored): HeaderBuildInputs<'_, 'py>, + matched_path_default: Option<&str>, + model_name: &str, + ) -> PyResult> { + let facts: Option> = + facts.map(|facts| facts.entries.iter().map(entry_facts).collect()); + let entries: PyConfigEntries = header_entries(header, facts.as_deref(), authored)?; + let model_header = ModelHeader { + entries: &entries, + facts: facts.as_deref(), + }; + let host: PythonConfigHost<'py> = self.host(py); + match build_model_config( + (&host, &self.inputs), + model_header, + matched_path_default, + model_name, + ) { + Ok(built) => Ok(ConfigBuild::Built(projected_build(header, built)?)), + Err(halt) => match halted(py, halt)? { + Ok(error) => Ok(ConfigBuild::Rejected(native_config_error(py, error)?)), + Err(error) => Err(error), + }, + } + } + + /// `build_layered_model_values` with an empty header: what a path default's models inherit. + pub fn inherited_values<'py>( + &self, + py: Python<'py>, + matched_path_default: Option<&str>, + ) -> PyResult, Py>> { + let host: PythonConfigHost<'py> = self.host(py); + match inherited_config((&host, &self.inputs), matched_path_default) { + Ok(values) => Ok(Ok(config_dict(py, &values)?)), + Err(halt) => match halted(py, halt)? { + Ok(error) => Ok(Err(native_config_error(py, error)?)), + Err(error) => Err(error), + }, + } + } + + /// `build_model_context_values` for a model's config values. + pub fn model_context_values<'py>( + &self, + values: &Bound<'py, PyDict>, + model_name: &str, + include_target_values: bool, + ) -> PyResult> { + let mut read: PyConfigEntries = Vec::with_capacity(CONTEXT_KEYS.len()); + for key in CONTEXT_KEYS { + if let Some(value) = values.get_item(key)? { + read.push((ConfigNode::Str(key.to_owned()), config_node(&value)?)); + } + } + let context: PyConfigEntries = + model_context_values(&self.inputs, &read, model_name, include_target_values); + config_dict(values.py(), &context) + } + + /// The active target's `(database, schema)`, or `(None, None)` without a target. + pub fn target_namespace<'py>(&self, py: Python<'py>) -> PyResult> { + match &self.inputs.target_namespace { + Some((database, schema)) => PyTuple::new( + py, + [config_object(py, database)?, config_object(py, schema)?], + ), + None => PyTuple::new(py, [py.None(), py.None()]), + } + } +} + +/// The project facts every model's validation reads, captured once per compile. +#[pyclass(module = "sqlbuild._native", frozen)] +#[derive(Debug)] +pub struct NativeModelValidator { + pub(crate) project: ProjectValidationFacts, +} + +impl NativeModelValidator { + /// The project's discovered resource names, which every reference resolves against. + pub fn known_resources(&self) -> KnownResources<'_> { + KnownResources { + models: &self.project.models, + seeds: &self.project.seeds, + sources: &self.project.sources, + functions: &self.project.functions, + table_functions: &self.project.table_functions, + } + } +} + +#[pymethods] +impl NativeModelValidator { + /// The validator for the resources and materializations `inputs` discovered. + #[staticmethod] + pub fn from_inputs(inputs: Bound<'_, PyAny>, microbatch_concurrency: bool) -> PyResult { + let names: ResourceNames = discovered_names(&inputs)?; + let custom_materializations: HashSet = + each(&inputs, "materialization_files", |file| { + native_field(file, "name")?.extract() + })? + .into_iter() + .collect(); + Self::new(names, custom_materializations, microbatch_concurrency) + } + + /// The discovered model names references resolve against. + pub(crate) fn model_names(&self) -> HashSet { + self.project.models.clone() + } + + #[new] + pub(crate) fn new( + names: ResourceNames, + custom_materializations: HashSet, + microbatch_concurrency: bool, + ) -> PyResult { + let ResourceNames { + models, + seeds, + sources, + functions, + table_functions, + } = names; + Ok(Self { + project: ProjectValidationFacts { + custom_materializations, + microbatch_concurrency, + models, + seeds, + sources, + functions, + table_functions, + }, + }) + } + + /// `None` when accepted, the first error, or the first externally rejected reference. + pub(crate) fn validate( + &self, + py: Python<'_>, + values: Bound<'_, PyDict>, + model: (String, String, String), + facts: ModelFacts, + ) -> PyResult> { + compiler_guard(|| { + let (model_name, query_sql, relative_path) = model; + let ModelFacts { + references, + declared_columns, + retention_unmanaged, + table_type_declared, + } = facts; + let references: Vec = references + .into_iter() + .map(|(kind, name, externally_rejected)| ModelReference { + kind, + name, + externally_rejected, + }) + .collect(); + let entries: Vec<(PyNode<'_>, PyNode<'_>)> = values + .iter() + .map(|(key, value)| (PyNode(key), PyNode(value))) + .collect(); + let facts = ModelValidationFacts { + model_name: &model_name, + relative_path: &relative_path, + references: &references, + declared_columns: declared_columns.as_deref(), + query_sql: &query_sql, + retention_unmanaged, + table_type_declared, + }; + match validate_model_config(entries, &self.project, &facts) { + Ok(()) => Ok(py.None()), + Err(stop) => stop_object(py, stop), + } + }) + } + + /// Check references alone: `None`, the first error, or a rejected dbt reference's index. + pub(crate) fn references( + &self, + py: Python<'_>, + model: (String, String), + references: Vec<(String, String, bool)>, + ) -> PyResult> { + compiler_guard(|| { + let (model_name, relative_path) = model; + let references: Vec = references + .into_iter() + .map(|(kind, name, externally_rejected)| ModelReference { + kind, + name, + externally_rejected, + }) + .collect(); + let facts = ModelValidationFacts { + model_name: &model_name, + relative_path: &relative_path, + references: &references, + declared_columns: None, + query_sql: "", + retention_unmanaged: false, + table_type_declared: false, + }; + match validate_model_references(&self.project, &facts) { + Ok(()) => Ok(py.None()), + Err(stop) => stop_object(py, stop), + } + }) + } +} + +/// The built tree and any Python-authored values opened by the record's readers. +#[pyclass(module = "sqlbuild._native", frozen)] +#[derive(Debug)] +pub struct TypedConfigValues { + pub built: Option, + pub(crate) read: Mutex)>>, +} diff --git a/crates/sqlbuild-python-front/src/model_config/types.rs b/crates/sqlbuild-python-front/src/model_config/types.rs new file mode 100644 index 0000000000..bf2205a325 --- /dev/null +++ b/crates/sqlbuild-python-front/src/model_config/types.rs @@ -0,0 +1,36 @@ +//! Public traits and type aliases of model config. + +use crate::model_config::_helpers::config::config_nodes::config_node; +use crate::model_config::models::HostHandle; +use crate::model_config::models::TypedConfigValues; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyAnyMethods; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use sqlbuild_model_config::config_values::models::ConfigNode; +use sqlbuild_model_config::types::AuthoredNode; +use std::collections::HashMap; +use std::sync::Arc; + +/// A config value converted from Python. +pub type PyConfigNode = ConfigNode; + +/// A parsed leaf projected only when a public contract needs its Python value. +pub trait HeaderValue: AuthoredNode { + fn object<'py>(&self, py: Python<'py>) -> PyResult>; + + fn retained(&self, py: Python<'_>) -> PyResult { + config_node(&self.object(py)?) + } + + fn exact_text(&self, py: Python<'_>) -> PyResult { + self.object(py)?.extract() + } +} + +/// A built config's string-keyed tree; values shared across reused configs stay native. +pub type BuiltConfigValues = Arc>>; + +/// A config record's values and the typed nodes read of them, each key converted on first read. +pub type ConfigValues<'py> = (Bound<'py, PyAny>, Bound<'py, TypedConfigValues>); diff --git a/crates/sqlbuild-python/src/bindings/_helpers/native_host/audit_results_state.rs b/crates/sqlbuild-python-front/src/native_host/_helpers/audit_results_state.rs similarity index 93% rename from crates/sqlbuild-python/src/bindings/_helpers/native_host/audit_results_state.rs rename to crates/sqlbuild-python-front/src/native_host/_helpers/audit_results_state.rs index dbb1234c40..2a2ecb2147 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/native_host/audit_results_state.rs +++ b/crates/sqlbuild-python-front/src/native_host/_helpers/audit_results_state.rs @@ -5,7 +5,7 @@ use pyo3::{pyfunction, wrap_pyfunction}; use sqlbuild_core::constants::AUDIT_RESULTS_TABLE_NAME; use sqlbuild_state::audit_results::main::prune_audit_results_sql::prune_audit_results_sql; -use crate::bindings::_helpers::native_host::consumption_state::state_table_name; +use crate::native_host::_helpers::consumption_state::state_table_name; /// SQL deleting audit results beyond the newest `retain_versions` per audit binding. #[pyfunction] diff --git a/crates/sqlbuild-python/src/bindings/_helpers/native_host/consumption_state.rs b/crates/sqlbuild-python-front/src/native_host/_helpers/consumption_state.rs similarity index 73% rename from crates/sqlbuild-python/src/bindings/_helpers/native_host/consumption_state.rs rename to crates/sqlbuild-python-front/src/native_host/_helpers/consumption_state.rs index 363921da4b..59e36ee016 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/native_host/consumption_state.rs +++ b/crates/sqlbuild-python-front/src/native_host/_helpers/consumption_state.rs @@ -1,10 +1,11 @@ //! The consumption table through the adapter, and the connection and callbacks a recording build holds. +use crate::native_host::constants::ROWS_PER_STATEMENT; +use crate::native_host::models::Location; use chrono::{DateTime, NaiveDateTime, Utc}; -use std::sync::Mutex; -use pyo3::exceptions::{PyRuntimeError, PyValueError}; -use pyo3::prelude::{Bound, Py, PyAny, PyAnyMethods, PyModule, PyModuleMethods, PyResult, Python}; +use pyo3::exceptions::PyValueError; +use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyModule, PyModuleMethods, PyResult, Python}; use pyo3::types::{PyDict, PyFrozenSet, PyInt, PyString, PyTuple}; use pyo3::{pyfunction, wrap_pyfunction}; use sqlbuild_core::constants::CONSUMPTION_TABLE_NAME; @@ -13,7 +14,6 @@ use sqlbuild_state::consumption::constants::{ }; use sqlbuild_state::consumption::main::executions_by_id_sql::executions_by_id_sql; use sqlbuild_state::consumption::main::prune_executions_sql::prune_executions_sql; -use sqlbuild_state::consumption::main::recent_executions::recent_executions; use sqlbuild_state::consumption::main::recent_executions_sql::recent_executions_sql; use sqlbuild_state::consumption::models::{ ConsumedInput, ConsumptionAppend, ConsumptionRow, NodeKey, RelationKey, @@ -21,14 +21,11 @@ use sqlbuild_state::consumption::models::{ use sqlbuild_state::freshness::constants::STRING_STATE_VALUE_TYPE; use sqlbuild_state::state_tables::main::values_insert_sql::values_insert_sql; -use crate::bindings::_helpers::state_rows::state_tables::state_table_create_sql; +use crate::state_rows::main::tables::state_table_create_sql::state_table_create_sql; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::contracts::main::render_state_sql_literal::render_state_sql_literal; use sqlbuild_python_base::records::main::fields::field::field as native_field; -use sqlbuild_python_base::warehouse_access::models::SyncedCopyAdapter; -/// Rows per `INSERT`; SQL Server accepts at most 1,000 rows in one `VALUES` list. -pub(crate) const ROWS_PER_STATEMENT: usize = 500; /// Execution IDs per `IN` list when reading executions back by ID. const EXECUTION_ID_BATCH: usize = 500; /// Warehouse timestamp texts with a UTC offset, as drivers render aware values. @@ -36,35 +33,7 @@ const OFFSET_TIME_FORMATS: [&str; 2] = ["%Y-%m-%dT%H:%M:%S%.f%:z", "%Y-%m-%d %H: /// Warehouse timestamp texts without an offset, which the consumption table stores as UTC. const NAIVE_TIME_FORMATS: [&str; 2] = ["%Y-%m-%dT%H:%M:%S%.f", "%Y-%m-%d %H:%M:%S%.f"]; -/// One destination schema of the consumption table. -#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] -pub(crate) struct Location { - pub(crate) database: Option, - pub(crate) schema: String, -} - -impl Location { - pub(crate) fn of(relation: &RelationKey) -> Self { - Self { - database: relation.database.clone(), - schema: relation.schema.clone(), - } - } - - pub(crate) fn keywords<'py>(&self, py: Python<'py>) -> Vec<(&'static str, Bound<'py, PyAny>)> { - vec![ - ( - "database", - self.database - .as_deref() - .map_or_else(|| py.None().into_bound(py), |database| text(py, database)), - ), - ("schema", text(py, &self.schema)), - ] - } -} - -fn text<'py>(py: Python<'py>, value: &str) -> Bound<'py, PyAny> { +pub(crate) fn text<'py>(py: Python<'py>, value: &str) -> Bound<'py, PyAny> { PyString::new(py, value).into_any() } @@ -188,7 +157,7 @@ pub(crate) fn execute<'py>( } /// Create the schema, table and indexes in `location`; `started` rows precede schema preparation. -fn ensure_table( +pub(crate) fn ensure_table( adapter: &Bound<'_, PyAny>, connection: &Bound<'_, PyAny>, location: &Location, @@ -233,7 +202,7 @@ fn table_exists( } /// Rows of the newest executions per relation in `location`; none when the table is missing. -fn read_recent( +pub(crate) fn read_recent( adapter: &Bound<'_, PyAny>, connection: &Bound<'_, PyAny>, location: &Location, @@ -256,7 +225,7 @@ fn read_recent( } /// Rows of the named executions in `location`, read in batches; none when the table is missing. -fn read_executions( +pub(crate) fn read_executions( adapter: &Bound<'_, PyAny>, connection: &Bound<'_, PyAny>, location: &Location, @@ -400,7 +369,7 @@ fn row_cells(py: Python<'_>, row: &ConsumptionAppend, recorded_at: &str) -> PyRe } /// Append `rows` to `location`'s table, in statements no longer than every warehouse accepts. -fn append( +pub(crate) fn append( adapter: &Bound<'_, PyAny>, connection: &Bound<'_, PyAny>, location: &Location, @@ -430,114 +399,6 @@ fn append( Ok(()) } -/// One build's consumption I/O, connected only per phase so loaders can lock file warehouses. -pub(crate) struct ConsumptionConnection { - adapter: Py, - connection_config: Py, - connection: Mutex>>, -} - -impl ConsumptionConnection { - pub(crate) fn new(adapter: &Bound<'_, PyAny>, connection_config: &Bound<'_, PyAny>) -> Self { - Self { - adapter: adapter.clone().unbind(), - connection_config: connection_config.clone().unbind(), - connection: Mutex::new(None), - } - } - - pub(crate) fn connected<'py>(&self, py: Python<'py>) -> PyResult> { - let mut open = self - .connection - .lock() - .map_err(|_| PyRuntimeError::new_err("consumption connection lock poisoned"))?; - if let Some(connection) = open.as_ref() { - return Ok(connection.bind(py).clone()); - } - let connection: Bound<'py, PyAny> = native_field(self.adapter.bind(py), "connect")? - .call1((self.connection_config.bind(py),))?; - *open = Some(connection.clone().unbind()); - Ok(connection) - } - - pub(crate) fn ensure_table(&self, py: Python<'_>, location: &Location) -> PyResult<()> { - ensure_table(self.adapter.bind(py), &self.connected(py)?, location) - } - - pub(crate) fn read_recent( - &self, - py: Python<'_>, - location: &Location, - ) -> PyResult> { - if let Ok(copy) = self.adapter.bind(py).downcast::() { - return Ok(recent_executions( - © - .get() - .consumption((location.database.as_deref(), &location.schema)), - RECENT_EXECUTIONS, - )); - } - read_recent(self.adapter.bind(py), &self.connected(py)?, location) - } - - pub(crate) fn read_executions( - &self, - py: Python<'_>, - location: &Location, - execution_ids: &[&str], - ) -> PyResult> { - if let Ok(copy) = self.adapter.bind(py).downcast::() { - let mut rows: Vec = copy - .get() - .consumption((location.database.as_deref(), &location.schema)); - rows.retain(|row| execution_ids.contains(&row.row.execution_id.as_str())); - return Ok(rows); - } - read_executions( - self.adapter.bind(py), - &self.connected(py)?, - location, - execution_ids, - ) - } - - pub(crate) fn append( - &self, - py: Python<'_>, - location: &Location, - rows: &[ConsumptionAppend], - ) -> PyResult<()> { - append(self.adapter.bind(py), &self.connected(py)?, location, rows) - } - - /// Close the connection if one is open; the next operation connects again. - pub(crate) fn close(&self, py: Python<'_>) -> PyResult<()> { - let open: Option> = self - .connection - .lock() - .map_err(|_| PyRuntimeError::new_err("consumption connection lock poisoned"))? - .take(); - if let Some(connection) = open { - native_field(self.adapter.bind(py), "close")?.call1((connection.bind(py),))?; - } - Ok(()) - } -} - -/// The build's own node-completion callback, which the recorder forwards every result to. -pub(crate) struct NodeCompleteHook(Py); - -impl NodeCompleteHook { - pub(crate) fn new(callback: &Bound<'_, PyAny>) -> Self { - Self(callback.clone().unbind()) - } - - pub(crate) fn forward(&self, result: &Bound<'_, PyAny>) -> PyResult<()> { - self.0.bind(result.py()).call1((result,))?; - Ok(()) - } -} - /// The recorder's `on_node_complete` and `before_node_write` methods, as build callbacks. pub(crate) fn recorder_callbacks<'py>( recorder: &Bound<'py, PyAny>, diff --git a/crates/sqlbuild-python-front/src/native_host/_helpers/mod.rs b/crates/sqlbuild-python-front/src/native_host/_helpers/mod.rs new file mode 100644 index 0000000000..378e185cd4 --- /dev/null +++ b/crates/sqlbuild-python-front/src/native_host/_helpers/mod.rs @@ -0,0 +1,3 @@ +pub(crate) mod audit_results_state; +pub(crate) mod consumption_state; +pub(crate) mod observations_state; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/native_host/observations_state.rs b/crates/sqlbuild-python-front/src/native_host/_helpers/observations_state.rs similarity index 90% rename from crates/sqlbuild-python/src/bindings/_helpers/native_host/observations_state.rs rename to crates/sqlbuild-python-front/src/native_host/_helpers/observations_state.rs index c1c06cbf59..bb8276aadc 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/native_host/observations_state.rs +++ b/crates/sqlbuild-python-front/src/native_host/_helpers/observations_state.rs @@ -1,5 +1,6 @@ //! DDL and pruning of the display-only observations table through the adapter. +use crate::native_host::models::ObservationAppend; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyModule, PyModuleMethods, PyResult, Python}; use pyo3::{pyfunction, wrap_pyfunction}; use sqlbuild_core::constants::OBSERVATIONS_TABLE_NAME; @@ -10,9 +11,12 @@ use sqlbuild_state::observations::main::prune_observations_sql::prune_observatio use sqlbuild_state::state_tables::main::values_insert_sql::values_insert_sql; use uuid::Uuid; -use crate::bindings::_helpers::native_host::consumption_state::{ - Location, ROWS_PER_STATEMENT, execute, fixed_state_table_sql, literal, state_table_name, -}; +use crate::native_host::_helpers::consumption_state::execute; +use crate::native_host::_helpers::consumption_state::fixed_state_table_sql; +use crate::native_host::_helpers::consumption_state::literal; +use crate::native_host::_helpers::consumption_state::state_table_name; +use crate::native_host::constants::ROWS_PER_STATEMENT; +use crate::native_host::models::Location; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; @@ -54,15 +58,6 @@ fn build_observations_prune_sql( .unwrap_or_default()) } -/// One observation to append; the warehouse clock fills `observed_at`. -pub(crate) struct ObservationAppend { - pub(crate) kind: &'static str, - pub(crate) node: String, - pub(crate) cursor_type: Option, - pub(crate) value: String, - pub(crate) run_id: String, -} - /// Create the schema and observations table in `location` if missing, then append `rows`. pub(crate) fn append_observations( adapter: &Bound<'_, PyAny>, diff --git a/crates/sqlbuild-python-front/src/native_host/constants.rs b/crates/sqlbuild-python-front/src/native_host/constants.rs new file mode 100644 index 0000000000..7c8c29b580 --- /dev/null +++ b/crates/sqlbuild-python-front/src/native_host/constants.rs @@ -0,0 +1,4 @@ +//! Public constants of native host. + +/// Rows per `INSERT`; SQL Server accepts at most 1,000 rows in one `VALUES` list. +pub const ROWS_PER_STATEMENT: usize = 500; diff --git a/crates/sqlbuild-python-front/src/native_host/main/append_observations.rs b/crates/sqlbuild-python-front/src/native_host/main/append_observations.rs new file mode 100644 index 0000000000..5d63443aa6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/native_host/main/append_observations.rs @@ -0,0 +1,19 @@ +//! Create the schema and observations table in `location` if missing, then append `rows`. + +use crate::native_host::_helpers::observations_state; +use crate::native_host::models::Location; +use crate::native_host::models::ObservationAppend; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Create the schema and observations table in `location` if missing, then append `rows`. +#[inline] +pub fn append_observations( + adapter: &Bound<'_, PyAny>, + connection: &Bound<'_, PyAny>, + location: &Location, + rows: &[ObservationAppend], +) -> PyResult<()> { + observations_state::append_observations(adapter, connection, location, rows) +} diff --git a/crates/sqlbuild-python-front/src/native_host/main/execute.rs b/crates/sqlbuild-python-front/src/native_host/main/execute.rs new file mode 100644 index 0000000000..1c9e3b6ff0 --- /dev/null +++ b/crates/sqlbuild-python-front/src/native_host/main/execute.rs @@ -0,0 +1,16 @@ +//! Execute. + +use crate::native_host::_helpers::consumption_state; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Execute. +#[inline] +pub fn execute<'py>( + adapter: &Bound<'py, PyAny>, + connection: &Bound<'py, PyAny>, + sql: &str, +) -> PyResult> { + consumption_state::execute(adapter, connection, sql) +} diff --git a/crates/sqlbuild-python-front/src/native_host/main/fixed_state_table_sql.rs b/crates/sqlbuild-python-front/src/native_host/main/fixed_state_table_sql.rs new file mode 100644 index 0000000000..91cfd5cb21 --- /dev/null +++ b/crates/sqlbuild-python-front/src/native_host/main/fixed_state_table_sql.rs @@ -0,0 +1,20 @@ +//! Create-if-missing DDL for a state table with fixed columns, typed by the adapter. + +use crate::native_host::_helpers::consumption_state; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Create-if-missing DDL for a state table with fixed columns, typed by the adapter. +#[inline] +pub fn fixed_state_table_sql( + (database, schema): (&Bound<'_, PyAny>, &Bound<'_, PyAny>), + (render_qualified_name, render_framework_type): (&Bound<'_, PyAny>, &Bound<'_, PyAny>), + (table_name, column_types, nullable): (&str, &[(&str, &str)], &[&str]), +) -> PyResult { + consumption_state::fixed_state_table_sql( + (database, schema), + (render_qualified_name, render_framework_type), + (table_name, column_types, nullable), + ) +} diff --git a/crates/sqlbuild-python-front/src/native_host/main/integer_literal.rs b/crates/sqlbuild-python-front/src/native_host/main/integer_literal.rs new file mode 100644 index 0000000000..290ad1dd2a --- /dev/null +++ b/crates/sqlbuild-python-front/src/native_host/main/integer_literal.rs @@ -0,0 +1,11 @@ +//! Integer literal. + +use crate::native_host::_helpers::consumption_state; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// Integer literal. +#[inline] +pub fn integer_literal(py: Python<'_>, value: Option) -> PyResult { + consumption_state::integer_literal(py, value) +} diff --git a/crates/sqlbuild-python-front/src/native_host/main/literal.rs b/crates/sqlbuild-python-front/src/native_host/main/literal.rs new file mode 100644 index 0000000000..5a274ff9fb --- /dev/null +++ b/crates/sqlbuild-python-front/src/native_host/main/literal.rs @@ -0,0 +1,11 @@ +//! Literal. + +use crate::native_host::_helpers::consumption_state; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// Literal. +#[inline] +pub fn literal(py: Python<'_>, value: Option<&str>) -> PyResult { + consumption_state::literal(py, value) +} diff --git a/crates/sqlbuild-python-front/src/native_host/main/mod.rs b/crates/sqlbuild-python-front/src/native_host/main/mod.rs new file mode 100644 index 0000000000..effd6e652f --- /dev/null +++ b/crates/sqlbuild-python-front/src/native_host/main/mod.rs @@ -0,0 +1,11 @@ +pub mod append_observations; +pub mod execute; +pub mod fixed_state_table_sql; +pub mod integer_literal; +pub mod literal; +pub mod optional_text; +pub mod recorder_callbacks; +pub mod register_audit_results_state; +pub mod register_consumption_state; +pub mod register_observations_state; +pub mod state_table_name; diff --git a/crates/sqlbuild-python-front/src/native_host/main/optional_text.rs b/crates/sqlbuild-python-front/src/native_host/main/optional_text.rs new file mode 100644 index 0000000000..1babb19549 --- /dev/null +++ b/crates/sqlbuild-python-front/src/native_host/main/optional_text.rs @@ -0,0 +1,12 @@ +//! Optional text. + +use crate::native_host::_helpers::consumption_state; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Optional text. +#[inline] +pub fn optional_text(value: &Bound<'_, PyAny>) -> PyResult> { + consumption_state::optional_text(value) +} diff --git a/crates/sqlbuild-python-front/src/native_host/main/recorder_callbacks.rs b/crates/sqlbuild-python-front/src/native_host/main/recorder_callbacks.rs new file mode 100644 index 0000000000..3a3544c506 --- /dev/null +++ b/crates/sqlbuild-python-front/src/native_host/main/recorder_callbacks.rs @@ -0,0 +1,14 @@ +//! The recorder's `on_node_complete` and `before_node_write` methods, as build callbacks. + +use crate::native_host::_helpers::consumption_state; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// The recorder's `on_node_complete` and `before_node_write` methods, as build callbacks. +#[inline] +pub fn recorder_callbacks<'py>( + recorder: &Bound<'py, PyAny>, +) -> PyResult<(Bound<'py, PyAny>, Bound<'py, PyAny>)> { + consumption_state::recorder_callbacks(recorder) +} diff --git a/crates/sqlbuild-python-front/src/native_host/main/register_audit_results_state.rs b/crates/sqlbuild-python-front/src/native_host/main/register_audit_results_state.rs new file mode 100644 index 0000000000..d7cdba3673 --- /dev/null +++ b/crates/sqlbuild-python-front/src/native_host/main/register_audit_results_state.rs @@ -0,0 +1,12 @@ +//! Register the audit results state functions and classes. + +use crate::native_host::_helpers::audit_results_state; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the audit results state functions and classes. +#[inline] +pub fn register_audit_results_state(module: &Bound<'_, PyModule>) -> PyResult<()> { + audit_results_state::register(module) +} diff --git a/crates/sqlbuild-python-front/src/native_host/main/register_consumption_state.rs b/crates/sqlbuild-python-front/src/native_host/main/register_consumption_state.rs new file mode 100644 index 0000000000..84da4f5782 --- /dev/null +++ b/crates/sqlbuild-python-front/src/native_host/main/register_consumption_state.rs @@ -0,0 +1,12 @@ +//! Register the consumption state functions and classes. + +use crate::native_host::_helpers::consumption_state; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the consumption state functions and classes. +#[inline] +pub fn register_consumption_state(module: &Bound<'_, PyModule>) -> PyResult<()> { + consumption_state::register(module) +} diff --git a/crates/sqlbuild-python-front/src/native_host/main/register_observations_state.rs b/crates/sqlbuild-python-front/src/native_host/main/register_observations_state.rs new file mode 100644 index 0000000000..97ab0d3395 --- /dev/null +++ b/crates/sqlbuild-python-front/src/native_host/main/register_observations_state.rs @@ -0,0 +1,12 @@ +//! Register the observations state functions and classes. + +use crate::native_host::_helpers::observations_state; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the observations state functions and classes. +#[inline] +pub fn register_observations_state(module: &Bound<'_, PyModule>) -> PyResult<()> { + observations_state::register(module) +} diff --git a/crates/sqlbuild-python-front/src/native_host/main/state_table_name.rs b/crates/sqlbuild-python-front/src/native_host/main/state_table_name.rs new file mode 100644 index 0000000000..5d1c8fd59c --- /dev/null +++ b/crates/sqlbuild-python-front/src/native_host/main/state_table_name.rs @@ -0,0 +1,16 @@ +//! The adapter's qualified name of a state table in `(database, schema)`, if it has one. + +use crate::native_host::_helpers::consumption_state; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// The adapter's qualified name of a state table in `(database, schema)`, if it has one. +#[inline] +pub fn state_table_name( + render_qualified_name: &Bound<'_, PyAny>, + (database, schema): (&Bound<'_, PyAny>, &Bound<'_, PyAny>), + table: &str, +) -> PyResult> { + consumption_state::state_table_name(render_qualified_name, (database, schema), table) +} diff --git a/crates/sqlbuild-python-front/src/native_host/mod.rs b/crates/sqlbuild-python-front/src/native_host/mod.rs new file mode 100644 index 0000000000..d3f58713b5 --- /dev/null +++ b/crates/sqlbuild-python-front/src/native_host/mod.rs @@ -0,0 +1,6 @@ +//! Warehouse state tables for audit results, consumption and observations. + +pub(crate) mod _helpers; +pub mod constants; +pub mod main; +pub mod models; diff --git a/crates/sqlbuild-python-front/src/native_host/models.rs b/crates/sqlbuild-python-front/src/native_host/models.rs new file mode 100644 index 0000000000..d4fb5a61ea --- /dev/null +++ b/crates/sqlbuild-python-front/src/native_host/models.rs @@ -0,0 +1,170 @@ +//! Public records of native host. + +use crate::native_host::_helpers::consumption_state::append; +use crate::native_host::_helpers::consumption_state::ensure_table; +use crate::native_host::_helpers::consumption_state::read_executions; +use crate::native_host::_helpers::consumption_state::read_recent; +use crate::native_host::_helpers::consumption_state::text; +use pyo3::exceptions::PyRuntimeError; +use pyo3::prelude::Bound; +use pyo3::prelude::Py; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyAnyMethods; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_base::warehouse_access::models::SyncedCopyAdapter; +use sqlbuild_state::consumption::constants::RECENT_EXECUTIONS; +use sqlbuild_state::consumption::main::recent_executions::recent_executions; +use sqlbuild_state::consumption::models::ConsumptionAppend; +use sqlbuild_state::consumption::models::ConsumptionRow; +use sqlbuild_state::consumption::models::RelationKey; +use std::sync::Mutex; + +/// One destination schema of the consumption table. +#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub struct Location { + pub database: Option, + pub schema: String, +} + +impl Location { + pub fn of(relation: &RelationKey) -> Self { + Self { + database: relation.database.clone(), + schema: relation.schema.clone(), + } + } + + pub fn keywords<'py>(&self, py: Python<'py>) -> Vec<(&'static str, Bound<'py, PyAny>)> { + vec![ + ( + "database", + self.database + .as_deref() + .map_or_else(|| py.None().into_bound(py), |database| text(py, database)), + ), + ("schema", text(py, &self.schema)), + ] + } +} + +/// One build's consumption I/O, connected only per phase so loaders can lock file warehouses. +#[derive(Debug)] +pub struct ConsumptionConnection { + pub(crate) adapter: Py, + pub(crate) connection_config: Py, + pub(crate) connection: Mutex>>, +} + +impl ConsumptionConnection { + pub fn new(adapter: &Bound<'_, PyAny>, connection_config: &Bound<'_, PyAny>) -> Self { + Self { + adapter: adapter.clone().unbind(), + connection_config: connection_config.clone().unbind(), + connection: Mutex::new(None), + } + } + + pub fn connected<'py>(&self, py: Python<'py>) -> PyResult> { + let mut open = self + .connection + .lock() + .map_err(|_| PyRuntimeError::new_err("consumption connection lock poisoned"))?; + if let Some(connection) = open.as_ref() { + return Ok(connection.bind(py).clone()); + } + let connection: Bound<'py, PyAny> = native_field(self.adapter.bind(py), "connect")? + .call1((self.connection_config.bind(py),))?; + *open = Some(connection.clone().unbind()); + Ok(connection) + } + + pub fn ensure_table(&self, py: Python<'_>, location: &Location) -> PyResult<()> { + ensure_table(self.adapter.bind(py), &self.connected(py)?, location) + } + + pub fn read_recent( + &self, + py: Python<'_>, + location: &Location, + ) -> PyResult> { + if let Ok(copy) = self.adapter.bind(py).downcast::() { + return Ok(recent_executions( + © + .get() + .consumption((location.database.as_deref(), &location.schema)), + RECENT_EXECUTIONS, + )); + } + read_recent(self.adapter.bind(py), &self.connected(py)?, location) + } + + pub fn read_executions( + &self, + py: Python<'_>, + location: &Location, + execution_ids: &[&str], + ) -> PyResult> { + if let Ok(copy) = self.adapter.bind(py).downcast::() { + let mut rows: Vec = copy + .get() + .consumption((location.database.as_deref(), &location.schema)); + rows.retain(|row| execution_ids.contains(&row.row.execution_id.as_str())); + return Ok(rows); + } + read_executions( + self.adapter.bind(py), + &self.connected(py)?, + location, + execution_ids, + ) + } + + pub fn append( + &self, + py: Python<'_>, + location: &Location, + rows: &[ConsumptionAppend], + ) -> PyResult<()> { + append(self.adapter.bind(py), &self.connected(py)?, location, rows) + } + + /// Close the connection if one is open; the next operation connects again. + pub fn close(&self, py: Python<'_>) -> PyResult<()> { + let open: Option> = self + .connection + .lock() + .map_err(|_| PyRuntimeError::new_err("consumption connection lock poisoned"))? + .take(); + if let Some(connection) = open { + native_field(self.adapter.bind(py), "close")?.call1((connection.bind(py),))?; + } + Ok(()) + } +} + +/// The build's own node-completion callback, which the recorder forwards every result to. +#[derive(Debug)] +pub struct NodeCompleteHook(Py); + +impl NodeCompleteHook { + pub fn new(callback: &Bound<'_, PyAny>) -> Self { + Self(callback.clone().unbind()) + } + + pub fn forward(&self, result: &Bound<'_, PyAny>) -> PyResult<()> { + self.0.bind(result.py()).call1((result,))?; + Ok(()) + } +} + +/// One observation to append; the warehouse clock fills `observed_at`. +#[derive(Debug)] +pub struct ObservationAppend { + pub kind: &'static str, + pub node: String, + pub cursor_type: Option, + pub value: String, + pub run_id: String, +} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/refactor/contract_compare.rs b/crates/sqlbuild-python-front/src/refactor/_helpers/contract_compare.rs similarity index 99% rename from crates/sqlbuild-python/src/bindings/_helpers/refactor/contract_compare.rs rename to crates/sqlbuild-python-front/src/refactor/_helpers/contract_compare.rs index 248b4cdcd0..374c433043 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/refactor/contract_compare.rs +++ b/crates/sqlbuild-python-front/src/refactor/_helpers/contract_compare.rs @@ -7,7 +7,7 @@ use pyo3::{pyfunction, wrap_pyfunction}; use sqlbuild_core::text::main::python_casefold::python_casefold; use sqlbuild_host::entries::models::AdapterHost; -use crate::bindings::_helpers::contracts::spec_resolution::matching_dynamic_families; +use crate::contracts::main::matching_dynamic_families::matching_dynamic_families; use sqlbuild_python_base::boundary::models::Request; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::construct::enum_from_value::enum_from_value; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/refactor/contract_edits.rs b/crates/sqlbuild-python-front/src/refactor/_helpers/contract_edits.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/refactor/contract_edits.rs rename to crates/sqlbuild-python-front/src/refactor/_helpers/contract_edits.rs diff --git a/crates/sqlbuild-python-front/src/refactor/_helpers/mod.rs b/crates/sqlbuild-python-front/src/refactor/_helpers/mod.rs new file mode 100644 index 0000000000..eaa35e18a1 --- /dev/null +++ b/crates/sqlbuild-python-front/src/refactor/_helpers/mod.rs @@ -0,0 +1,4 @@ +pub(crate) mod contract_compare; +pub(crate) mod contract_edits; +pub(crate) mod python_strings; +pub(crate) mod refactor_facts; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/refactor/python_strings.rs b/crates/sqlbuild-python-front/src/refactor/_helpers/python_strings.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/refactor/python_strings.rs rename to crates/sqlbuild-python-front/src/refactor/_helpers/python_strings.rs diff --git a/crates/sqlbuild-python/src/bindings/_helpers/refactor/refactor_facts.rs b/crates/sqlbuild-python-front/src/refactor/_helpers/refactor_facts.rs similarity index 97% rename from crates/sqlbuild-python/src/bindings/_helpers/refactor/refactor_facts.rs rename to crates/sqlbuild-python-front/src/refactor/_helpers/refactor_facts.rs index 3bfea8498c..bdee9fe23e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/refactor/refactor_facts.rs +++ b/crates/sqlbuild-python-front/src/refactor/_helpers/refactor_facts.rs @@ -12,11 +12,12 @@ use sqlbuild_refactor::refactoring::models::{ }; use sqlbuild_scopes::scope_index::models::{ResourceIdentity, ResourceKind}; -use crate::bindings::_helpers::model_config::config_values::config_str; -use crate::bindings::_helpers::refactor::python_strings::find_python_string_locations; -use crate::bindings::_helpers::scopes::scope_lookup::build_scope_lookup; -use crate::bindings::_helpers::scopes::scope_reports::{scope_move_preview, scope_rebound_usages}; -use crate::bindings::_helpers::scopes::scope_validation::relocated_declarations; +use crate::model_config::main::config::config_str::config_str; +use crate::refactor::_helpers::python_strings::find_python_string_locations; +use crate::scopes::main::checks::relocated_declarations::relocated_declarations; +use crate::scopes::main::index::build_scope_lookup::build_scope_lookup; +use crate::scopes::main::reports::scope_move_preview::scope_move_preview; +use crate::scopes::main::reports::scope_rebound_usages::scope_rebound_usages; use sqlbuild_python_base::records::main::fields::field::field as native_field; const SQL_SUFFIX: &str = ".sql"; diff --git a/crates/sqlbuild-python-front/src/refactor/main/compare_contracts.rs b/crates/sqlbuild-python-front/src/refactor/main/compare_contracts.rs new file mode 100644 index 0000000000..ef10768f9f --- /dev/null +++ b/crates/sqlbuild-python-front/src/refactor/main/compare_contracts.rs @@ -0,0 +1,15 @@ +//! Selected declarations compared with one bulk read of physical columns. + +use crate::refactor::_helpers::contract_compare; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::types::PyDict; +use pyo3::types::PyTuple; + +/// Selected declarations compared with one bulk read of physical columns. +#[inline] +pub fn compare_contracts<'py>( + request: Option<&Bound<'py, PyDict>>, +) -> PyResult> { + contract_compare::compare_contracts(request) +} diff --git a/crates/sqlbuild-python-front/src/refactor/main/declaration_placement.rs b/crates/sqlbuild-python-front/src/refactor/main/declaration_placement.rs new file mode 100644 index 0000000000..14ff083598 --- /dev/null +++ b/crates/sqlbuild-python-front/src/refactor/main/declaration_placement.rs @@ -0,0 +1,18 @@ +//! Where scope placement puts declarations once every `(model, destination)` moves together. + +use crate::refactor::_helpers::refactor_facts; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_refactor::refactoring::models::DeclarationPlacement; +use std::collections::BTreeSet; + +/// Where scope placement puts declarations once every `(model, destination)` moves together. +#[inline] +pub fn declaration_placement( + project: &Bound<'_, PyAny>, + moves: &[(String, String)], + vacated: &BTreeSet, +) -> PyResult { + refactor_facts::declaration_placement(project, moves, vacated) +} diff --git a/crates/sqlbuild-python-front/src/refactor/main/edit_contract_model.rs b/crates/sqlbuild-python-front/src/refactor/main/edit_contract_model.rs new file mode 100644 index 0000000000..c924eea433 --- /dev/null +++ b/crates/sqlbuild-python-front/src/refactor/main/edit_contract_model.rs @@ -0,0 +1,18 @@ +//! The model's MODEL header with physical columns adopted, or the ownership conflict. + +use crate::refactor::_helpers::contract_edits; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// The model's MODEL header with physical columns adopted, or the ownership conflict. +#[inline] +pub fn edit_contract_model( + py: Python<'_>, + model: &Bound<'_, PyAny>, + physical_columns: &Bound<'_, PyAny>, + overwrite: bool, +) -> PyResult<(Option, Option)> { + contract_edits::edit_contract_model(py, model, physical_columns, overwrite) +} diff --git a/crates/sqlbuild-python-front/src/refactor/main/edit_contract_source.rs b/crates/sqlbuild-python-front/src/refactor/main/edit_contract_source.rs new file mode 100644 index 0000000000..ca1b85b4d6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/refactor/main/edit_contract_source.rs @@ -0,0 +1,17 @@ +//! The source's YAML declaration with physical columns adopted, or the ownership conflict. + +use crate::refactor::_helpers::contract_edits; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// The source's YAML declaration with physical columns adopted, or the ownership conflict. +#[inline] +pub fn edit_contract_source( + source: &Bound<'_, PyAny>, + physical_columns: &Bound<'_, PyAny>, + overwrite: bool, + contents: Option, +) -> PyResult<(Option, Option)> { + contract_edits::edit_contract_source(source, physical_columns, overwrite, contents) +} diff --git a/crates/sqlbuild-python-front/src/refactor/main/mod.rs b/crates/sqlbuild-python-front/src/refactor/main/mod.rs new file mode 100644 index 0000000000..7a22599a8d --- /dev/null +++ b/crates/sqlbuild-python-front/src/refactor/main/mod.rs @@ -0,0 +1,11 @@ +pub mod compare_contracts; +pub mod declaration_placement; +pub mod edit_contract_model; +pub mod edit_contract_source; +pub mod model_facts; +pub mod refactor_facts; +pub mod register_contract_compare; +pub mod register_contract_edits; +pub mod register_python_strings; +pub mod remaining_contract_findings; +pub mod unit_test_rebindings; diff --git a/crates/sqlbuild-python-front/src/refactor/main/model_facts.rs b/crates/sqlbuild-python-front/src/refactor/main/model_facts.rs new file mode 100644 index 0000000000..315bfc6065 --- /dev/null +++ b/crates/sqlbuild-python-front/src/refactor/main/model_facts.rs @@ -0,0 +1,13 @@ +//! Every compiled model's refactoring facts, or none without a project. + +use crate::refactor::_helpers::refactor_facts; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_refactor::refactoring::models::ModelFacts; + +/// Every compiled model's refactoring facts, or none without a project. +#[inline] +pub fn model_facts(refactor_project: &Bound<'_, PyAny>) -> PyResult>> { + refactor_facts::model_facts(refactor_project) +} diff --git a/crates/sqlbuild-python-front/src/refactor/main/refactor_facts.rs b/crates/sqlbuild-python-front/src/refactor/main/refactor_facts.rs new file mode 100644 index 0000000000..dc984f9324 --- /dev/null +++ b/crates/sqlbuild-python-front/src/refactor/main/refactor_facts.rs @@ -0,0 +1,17 @@ +//! The facts one refactoring plan of `requests` reads. + +use crate::refactor::_helpers::refactor_facts; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_refactor::refactoring::models::RefactorFacts; +use sqlbuild_refactor::refactoring::models::RefactorRequest; + +/// The facts one refactoring plan of `requests` reads. +#[inline] +pub fn refactor_facts( + project: &Bound<'_, PyAny>, + requests: &[RefactorRequest], +) -> PyResult { + refactor_facts::refactor_facts(project, requests) +} diff --git a/crates/sqlbuild-python-front/src/refactor/main/register_contract_compare.rs b/crates/sqlbuild-python-front/src/refactor/main/register_contract_compare.rs new file mode 100644 index 0000000000..bdf7573d6a --- /dev/null +++ b/crates/sqlbuild-python-front/src/refactor/main/register_contract_compare.rs @@ -0,0 +1,12 @@ +//! Register the contract compare functions and classes. + +use crate::refactor::_helpers::contract_compare; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the contract compare functions and classes. +#[inline] +pub fn register_contract_compare(module: &Bound<'_, PyModule>) -> PyResult<()> { + contract_compare::register(module) +} diff --git a/crates/sqlbuild-python-front/src/refactor/main/register_contract_edits.rs b/crates/sqlbuild-python-front/src/refactor/main/register_contract_edits.rs new file mode 100644 index 0000000000..0b3046740f --- /dev/null +++ b/crates/sqlbuild-python-front/src/refactor/main/register_contract_edits.rs @@ -0,0 +1,12 @@ +//! Register the contract edits functions and classes. + +use crate::refactor::_helpers::contract_edits; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the contract edits functions and classes. +#[inline] +pub fn register_contract_edits(module: &Bound<'_, PyModule>) -> PyResult<()> { + contract_edits::register(module) +} diff --git a/crates/sqlbuild-python-front/src/refactor/main/register_python_strings.rs b/crates/sqlbuild-python-front/src/refactor/main/register_python_strings.rs new file mode 100644 index 0000000000..e5f93791ba --- /dev/null +++ b/crates/sqlbuild-python-front/src/refactor/main/register_python_strings.rs @@ -0,0 +1,12 @@ +//! Register the python strings functions and classes. + +use crate::refactor::_helpers::python_strings; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the python strings functions and classes. +#[inline] +pub fn register_python_strings(module: &Bound<'_, PyModule>) -> PyResult<()> { + python_strings::register(module) +} diff --git a/crates/sqlbuild-python-front/src/refactor/main/remaining_contract_findings.rs b/crates/sqlbuild-python-front/src/refactor/main/remaining_contract_findings.rs new file mode 100644 index 0000000000..f8ef7ff7d7 --- /dev/null +++ b/crates/sqlbuild-python-front/src/refactor/main/remaining_contract_findings.rs @@ -0,0 +1,19 @@ +//! The findings an edit leaves, plus an ownership-conflict finding when the edit was refused. + +use crate::refactor::_helpers::contract_edits; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::types::PyTuple; + +/// The findings an edit leaves, plus an ownership-conflict finding when the edit was refused. +#[inline] +pub fn remaining_contract_findings<'py>( + py: Python<'py>, + findings: &Bound<'py, PyAny>, + overwrite: bool, + conflict: Option, +) -> PyResult> { + contract_edits::remaining_contract_findings(py, findings, overwrite, conflict) +} diff --git a/crates/sqlbuild-python-front/src/refactor/main/unit_test_rebindings.rs b/crates/sqlbuild-python-front/src/refactor/main/unit_test_rebindings.rs new file mode 100644 index 0000000000..9b31ee349d --- /dev/null +++ b/crates/sqlbuild-python-front/src/refactor/main/unit_test_rebindings.rs @@ -0,0 +1,15 @@ +//! Scoped declarations the test file at `path` uses that resolve differently from `destination`. + +use crate::refactor::_helpers::refactor_facts; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Scoped declarations the test file at `path` uses that resolve differently from `destination`. +#[inline] +pub fn unit_test_rebindings( + project: &Bound<'_, PyAny>, + paths: (&str, &str), +) -> PyResult>> { + refactor_facts::unit_test_rebindings(project, paths) +} diff --git a/crates/sqlbuild-python-front/src/refactor/mod.rs b/crates/sqlbuild-python-front/src/refactor/mod.rs new file mode 100644 index 0000000000..5911569de6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/refactor/mod.rs @@ -0,0 +1,4 @@ +//! Contract comparison and edits, Python string literals and refactor facts. + +pub(crate) mod _helpers; +pub mod main; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_arguments.rs b/crates/sqlbuild-python-front/src/render/_helpers/calls/macro_arguments.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/render/macro_arguments.rs rename to crates/sqlbuild-python-front/src/render/_helpers/calls/macro_arguments.rs diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_call_classes.rs b/crates/sqlbuild-python-front/src/render/_helpers/calls/macro_call_classes.rs similarity index 97% rename from crates/sqlbuild-python/src/bindings/_helpers/render/macro_call_classes.rs rename to crates/sqlbuild-python-front/src/render/_helpers/calls/macro_call_classes.rs index fa114160c3..c46dd48fb7 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_call_classes.rs +++ b/crates/sqlbuild-python-front/src/render/_helpers/calls/macro_call_classes.rs @@ -7,8 +7,9 @@ use pyo3::types::{PyDict, PyDictMethods}; use sqlbuild_render::macro_calls::main::call_class_store_text::call_class_store_text; -use crate::bindings::_helpers::macro_bridge::store_keys::{context_store_token, macro_store_token}; -use crate::bindings::_helpers::render::macro_expansion_facts::ResourceRef; +use crate::macro_bridge::main::context_store_token::context_store_token; +use crate::macro_bridge::main::macro_store_token::macro_store_token; +use crate::render::_helpers::expansion::macro_expansion_facts::ResourceRef; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_call_memo.rs b/crates/sqlbuild-python-front/src/render/_helpers/calls/macro_call_memo.rs similarity index 98% rename from crates/sqlbuild-python/src/bindings/_helpers/render/macro_call_memo.rs rename to crates/sqlbuild-python-front/src/render/_helpers/calls/macro_call_memo.rs index 8ad46bdaf7..f95c22d737 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_call_memo.rs +++ b/crates/sqlbuild-python-front/src/render/_helpers/calls/macro_call_memo.rs @@ -10,7 +10,7 @@ use std::sync::Mutex; use sqlbuild_python_base::cache::main::open_store::open_store; use sqlbuild_python_base::cache::main::save_store::save_store; -use crate::bindings::_helpers::render::macro_call_classes::CallClassState; +use crate::render::_helpers::calls::macro_call_classes::CallClassState; /// The native store kind holding recorded macro calls. const MACRO_CALL_STORE_KIND: &str = "macro-calls"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_call_rows.rs b/crates/sqlbuild-python-front/src/render/_helpers/calls/macro_call_rows.rs similarity index 79% rename from crates/sqlbuild-python/src/bindings/_helpers/render/macro_call_rows.rs rename to crates/sqlbuild-python-front/src/render/_helpers/calls/macro_call_rows.rs index a693d6aee9..6d5b316bd9 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_call_rows.rs +++ b/crates/sqlbuild-python-front/src/render/_helpers/calls/macro_call_rows.rs @@ -1,9 +1,10 @@ //! Python rows of macro call sites and splice spans. +use crate::render::models::SpanTuple; +use crate::render::types::SpanRow; use sqlbuild_analysis::semantic_validation::models::Expansion; use sqlbuild_python_base::positional_record; use sqlbuild_render::macro_calls::models::{MacroCallSite, MacroSpliceSpan}; -use sqlbuild_sqltext::compiler::models::CharSpan; positional_record! { into; @@ -17,19 +18,6 @@ positional_record! { typed_reference_text: bool, } } -/// One substitution span: source start and end, output start and end. -pub(crate) type SpanRow = CharSpan; - -positional_record! { - into; - /// A span as the tuple Python reads: source start and end, output start and end. - pub(crate) struct SpanTuple { - source_start: usize, - source_end: usize, - output_start: usize, - output_end: usize, - } -} /// A span as the tuple Python reads. pub(crate) fn span_tuple(span: &SpanRow) -> SpanTuple { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_calls.rs b/crates/sqlbuild-python-front/src/render/_helpers/calls/macro_calls.rs similarity index 90% rename from crates/sqlbuild-python/src/bindings/_helpers/render/macro_calls.rs rename to crates/sqlbuild-python-front/src/render/_helpers/calls/macro_calls.rs index 5c8d4f0f10..3a574a0d63 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_calls.rs +++ b/crates/sqlbuild-python-front/src/render/_helpers/calls/macro_calls.rs @@ -9,11 +9,13 @@ use sqlbuild_render::macro_calls::main::scan_macro_call_sites::scan_macro_call_s use sqlbuild_render::macro_calls::main::splice_macro_calls::splice_macro_calls as splice_calls; use sqlbuild_render::macro_calls::models::{MacroCallScan, MacroScanFailure}; -use crate::bindings::_helpers::render::macro_call_memo::MacroCallMemo; -use crate::bindings::_helpers::render::macro_call_rows::{ - SiteRow, SpanTuple, site_row, span_row, span_tuple, -}; -use crate::bindings::_helpers::render::macro_expansion::raised; +use crate::render::_helpers::calls::macro_call_memo::MacroCallMemo; +use crate::render::_helpers::calls::macro_call_rows::SiteRow; +use crate::render::_helpers::calls::macro_call_rows::site_row; +use crate::render::_helpers::calls::macro_call_rows::span_row; +use crate::render::_helpers::calls::macro_call_rows::span_tuple; +use crate::render::_helpers::expansion::macro_expansion::raised; +use crate::render::models::SpanTuple; use sqlbuild_python_base::boundary::main::compiler_error::compiler_error; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::types::ErrorId; diff --git a/crates/sqlbuild-python-front/src/render/_helpers/calls/mod.rs b/crates/sqlbuild-python-front/src/render/_helpers/calls/mod.rs new file mode 100644 index 0000000000..9897c241f9 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/_helpers/calls/mod.rs @@ -0,0 +1,5 @@ +pub(crate) mod macro_arguments; +pub(crate) mod macro_call_classes; +pub(crate) mod macro_call_memo; +pub(crate) mod macro_call_rows; +pub(crate) mod macro_calls; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/authored_sql.rs b/crates/sqlbuild-python-front/src/render/_helpers/declarations/authored_sql.rs similarity index 77% rename from crates/sqlbuild-python/src/bindings/_helpers/render/authored_sql.rs rename to crates/sqlbuild-python-front/src/render/_helpers/declarations/authored_sql.rs index 58280d96e9..386a946494 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/render/authored_sql.rs +++ b/crates/sqlbuild-python-front/src/render/_helpers/declarations/authored_sql.rs @@ -1,6 +1,7 @@ //! Authored SQL expanded through project vars, declarations and macros, with each pass's spans. -use pyo3::prelude::Py; +use crate::render::models::AuthoredExpansion; +use crate::render::models::SqlExpansionInputs; use pyo3::prelude::{ Bound, IntoPyObject, PyAny, PyAnyMethods, PyErr, PyModule, PyModuleMethods, PyResult, Python, }; @@ -8,23 +9,27 @@ use pyo3::types::{PyDict, PyDictMethods, PyString, PyTuple}; use pyo3::{pyfunction, wrap_pyfunction}; use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; -use crate::bindings::_helpers::model_config::template_data::record_reads; -use crate::bindings::_helpers::model_config::unicode_environment::unicode_environment; -use crate::bindings::_helpers::render::declaration_expansion::{ - DeclarationExpansion, ExpandedDeclarations, ExpansionClasses, ExpansionConsumer, - expand_declarations, span_rows, -}; -use crate::bindings::_helpers::render::declaration_values::ConstantRendering; -use crate::bindings::_helpers::render::declaration_values::resolved_declaration_context; -use crate::bindings::_helpers::render::macro_call_rows::SpanRow; -use crate::bindings::_helpers::render::macro_call_rows::{span_row, span_tuple}; -use crate::bindings::_helpers::render::macro_expansion_result::{ExpansionRequest, macro_output}; -use crate::bindings::_helpers::render::sql_macro_host::SqlMacroSource; -use crate::bindings::_helpers::sqltext::declaration_references::declaration_scan; -use crate::bindings::_helpers::sqltext::lexical_syntax::optional_record_syntax; -use crate::bindings::_helpers::sqltext::static_sql::{ - InterpolationRow, InterpolationSources, interpolation_batch, -}; +use crate::model_config::main::config::record_reads::record_reads; +use crate::model_config::main::model_nodes::unicode_environment::unicode_environment; +use crate::render::_helpers::calls::macro_call_rows::span_row; +use crate::render::_helpers::calls::macro_call_rows::span_tuple; +use crate::render::_helpers::declarations::declaration_expansion::expand_declarations; +use crate::render::_helpers::declarations::declaration_expansion::span_rows; +use crate::render::_helpers::declarations::declaration_values::resolved_declaration_context; +use crate::render::_helpers::expansion::macro_expansion_result::macro_output; +use crate::render::models::ConstantRendering; +use crate::render::models::DeclarationExpansion; +use crate::render::models::DeclarationExpansionClasses; +use crate::render::models::ExpandedDeclarations; +use crate::render::models::ExpansionConsumer; +use crate::render::models::ExpansionRequest; +use crate::render::models::SqlMacroSource; +use crate::render::types::SpanRow; +use crate::sqltext::main::declaration_scan::declaration_scan; +use crate::sqltext::main::interpolation_batch::interpolation_batch; +use crate::sqltext::main::optional_record_syntax::optional_record_syntax; +use crate::sqltext::models::InterpolationRow; +use crate::sqltext::models::InterpolationSources; use sqlbuild_python_base::boundary::models::Request; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::construct::new_record::new_record; @@ -151,7 +156,7 @@ fn declarations_expanded<'py>( value_renderer.clone().unbind(), collection_rendering.clone().unbind(), ); - let classes = ExpansionClasses { + let classes = DeclarationExpansionClasses { usage_record: record_class(py, RecordId::UsageRecord)?, compile_error: error_class(py, ErrorId::CompileInput)?, }; @@ -179,13 +184,6 @@ fn declarations_expanded<'py>( Ok((expanded.spliced.sql, spans)) } -/// Authored SQL expanded through vars, declarations and macros, with each pass's spans. -pub(crate) struct AuthoredExpansion { - pub(crate) sql: String, - /// Interpolation, declaration and macro spans, in pass order. - pub(crate) passes: [Vec; 3], -} - /// What one authored SQL expansion reads. struct AuthoredSources<'a, 'py> { sql: &'a Bound<'py, PyAny>, @@ -400,66 +398,3 @@ pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { module.add_function(wrap_pyfunction!(substitute_sql_vars_with_spans, module)?)?; Ok(()) } - -/// The inputs authored SQL is expanded with outside a compile; the handles carry user values. -pub(crate) struct SqlExpansionInputs { - pub(crate) effective_vars: Py, - pub(crate) loaded_macros: Py, - pub(crate) macro_context: Py, - pub(crate) enums: Py, - pub(crate) constants: Py, - pub(crate) value_renderer: Py, - pub(crate) collection_rendering: Py, - /// Each model file's own declarations, by file path. - pub(crate) local_declarations: Py, - pub(crate) declaration_resolver: Py, -} - -impl SqlExpansionInputs { - /// The inputs a `SqlExpansionContext` record holds. - pub(crate) fn from_record(record: &Bound<'_, PyAny>) -> PyResult { - let field = - |name: &str| -> PyResult> { Ok(native_field(record, name)?.unbind()) }; - Ok(Self { - effective_vars: field("effective_vars")?, - loaded_macros: field("loaded_macros")?, - macro_context: field("macro_context")?, - enums: field("enums")?, - constants: field("constants")?, - value_renderer: field("value_renderer")?, - collection_rendering: field("collection_rendering")?, - local_declarations: native_field(record, "local_declarations")? - .downcast_into::()? - .unbind(), - declaration_resolver: field("declaration_resolver")?, - }) - } - - /// These inputs as a `SqlExpansionContext` record. - pub(crate) fn record<'py>(&self, py: Python<'py>) -> PyResult> { - new_record_with( - py, - RecordId::SqlExpansionContext, - &[ - ("effective_vars", self.effective_vars.bind(py).clone()), - ("loaded_macros", self.loaded_macros.bind(py).clone()), - ("macro_context", self.macro_context.bind(py).clone()), - ("enums", self.enums.bind(py).clone()), - ("constants", self.constants.bind(py).clone()), - ("value_renderer", self.value_renderer.bind(py).clone()), - ( - "collection_rendering", - self.collection_rendering.bind(py).clone(), - ), - ( - "local_declarations", - self.local_declarations.bind(py).clone().into_any(), - ), - ( - "declaration_resolver", - self.declaration_resolver.bind(py).clone(), - ), - ], - ) - } -} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/declaration_expansion.rs b/crates/sqlbuild-python-front/src/render/_helpers/declarations/declaration_expansion.rs similarity index 82% rename from crates/sqlbuild-python/src/bindings/_helpers/render/declaration_expansion.rs rename to crates/sqlbuild-python-front/src/render/_helpers/declarations/declaration_expansion.rs index 5428788f91..a641972038 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/render/declaration_expansion.rs +++ b/crates/sqlbuild-python-front/src/render/_helpers/declarations/declaration_expansion.rs @@ -1,7 +1,9 @@ //! Enum and constant references expanded natively, for model queries and every other caller. -use crate::bindings::_helpers::render::macro_call_rows::SpanRow; -use pyo3::FromPyObject; +use crate::render::models::DeclarationExpansion; +use crate::render::models::DeclarationExpansionClasses; +use crate::render::models::ExpandedDeclarations; +use crate::render::types::SpanRow; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult}; use pyo3::types::{PyDict, PyDictMethods, PyInt, PyTuple}; use sqlbuild_analysis::compiled_project::errors::DeclarationError; @@ -11,13 +13,12 @@ use sqlbuild_analysis::compiled_project::main::splice_declarations::splice_decla use sqlbuild_analysis::compiled_project::models::{ DeclarationSplice, InaccessibleDeclaration, SplicedSql, }; -use sqlbuild_analysis::sql_macros::models::{ExpandedText, SqlMacroCheck, TypedCall}; +use sqlbuild_analysis::sql_macros::models::{ExpandedText, TypedCall}; -use crate::bindings::_helpers::render::declaration_values::ConstantRendering; -use crate::bindings::_helpers::render::sql_macro_host::{ - SqlMacroSource, expanded_sql_macro_calls, is_sql_macro_reference, reject_bare_macro_calls, -}; -use crate::bindings::_helpers::sqltext::declaration_references::ScannedReference; +use crate::render::_helpers::sql_macros::sql_macro_host::expanded_sql_macro_calls; +use crate::render::_helpers::sql_macros::sql_macro_host::is_sql_macro_reference; +use crate::render::_helpers::sql_macros::sql_macro_host::reject_bare_macro_calls; +use crate::sqltext::models::ScannedReference; const ENUM_REFERENCE_KIND: u8 = 0; const ENUM_KIND: &str = "enum"; @@ -45,47 +46,6 @@ const THROUGH: &str = "through"; const CONSUMER: &str = "consumer"; const ENUM_MEMBER: &str = "enum_member"; -/// The Python classes expansion builds usages and errors from. -#[derive(FromPyObject)] -#[pyo3(from_item_all)] -pub(crate) struct ExpansionClasses<'py> { - pub(crate) usage_record: Bound<'py, PyAny>, - pub(crate) compile_error: Bound<'py, PyAny>, -} - -/// Who reads the declarations, whether it prefers relationship visibility, and its error path. -#[derive(Clone)] -pub(crate) struct ExpansionConsumer<'a, 'py> { - pub(crate) identity: Option>, - pub(crate) relationship_visibility: bool, - pub(crate) path: &'a str, -} - -/// One expansion: the SQL, its scan, the visible declarations and the adapter's constant rendering. -pub(crate) struct DeclarationExpansion<'a, 'py> { - pub(crate) sql: &'a str, - pub(crate) references: &'a [ScannedReference], - pub(crate) stop: Option, - pub(crate) context: &'a Bound<'py, PyAny>, - pub(crate) consumer: ExpansionConsumer<'a, 'py>, - pub(crate) rendering: &'a ConstantRendering, - pub(crate) classes: &'a ExpansionClasses<'py>, - /// What SQL macro calls read beyond the context; `None` where SQL macros are not expanded. - pub(crate) sql_macros: Option>, -} - -/// The expanded SQL with its spans, and the usage records it adds in reference order. -pub(crate) struct ExpandedDeclarations<'py> { - pub(crate) spliced: SplicedSql, - pub(crate) usages: Vec>, - /// The SQL macros the SQL called, top-level and nested, once each. - pub(crate) sql_macros: Vec, - /// What the analysed SQL must show for each top-level call's arguments to fit. - pub(crate) sql_macro_checks: Vec, - /// Each expression macro call in the spliced SQL, by byte range. - pub(crate) typed_calls: Vec, -} - /// Splice each reference in order, raising the attachment's error for the first bad one. pub(crate) fn expand_declarations<'py>( request: &DeclarationExpansion<'_, 'py>, @@ -314,7 +274,7 @@ fn inaccessible_record(record: &Bound<'_, PyAny>) -> PyResult( +pub(crate) fn visibility<'py>( request: &DeclarationExpansion<'_, 'py>, attribute: &str, name: &str, @@ -345,8 +305,8 @@ pub(crate) fn usage_visibility<'py>( Ok(if related.is_empty() { records } else { related }) } -fn usage<'py>( - classes: &ExpansionClasses<'py>, +pub(crate) fn usage<'py>( + classes: &DeclarationExpansionClasses<'py>, consumer: &Bound<'py, PyAny>, record: &Bound<'py, PyAny>, member: Option<&str>, @@ -359,7 +319,10 @@ fn usage<'py>( classes.usage_record.call((), Some(&fields)) } -fn compile_error(request: &DeclarationExpansion<'_, '_>, error: &DeclarationError) -> PyErr { +pub(crate) fn compile_error( + request: &DeclarationExpansion<'_, '_>, + error: &DeclarationError, +) -> PyErr { let message: String = declaration_error_message(error, request.consumer.path); match request.classes.compile_error.call1((message,)) { Ok(instance) => PyErr::from_value(instance), diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/declaration_indexes.rs b/crates/sqlbuild-python-front/src/render/_helpers/declarations/declaration_indexes.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/render/declaration_indexes.rs rename to crates/sqlbuild-python-front/src/render/_helpers/declarations/declaration_indexes.rs diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/declaration_values.rs b/crates/sqlbuild-python-front/src/render/_helpers/declarations/declaration_values.rs similarity index 90% rename from crates/sqlbuild-python/src/bindings/_helpers/render/declaration_values.rs rename to crates/sqlbuild-python-front/src/render/_helpers/declarations/declaration_values.rs index 886cf48f92..73f68d7474 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/render/declaration_values.rs +++ b/crates/sqlbuild-python-front/src/render/_helpers/declarations/declaration_values.rs @@ -1,14 +1,14 @@ //! Declaration scope resolvers, per-path declaration contexts and adapter-rendered constants. use pyo3::prelude::{ - Bound, Py, PyAny, PyAnyMethods, PyErr, PyModule, PyModuleMethods, PyResult, Python, + Bound, PyAny, PyAnyMethods, PyErr, PyModule, PyModuleMethods, PyResult, Python, }; use pyo3::types::{PyDict, PyDictMethods, PyFrozenSet, PyInt, PyList, PyString, PyTuple}; -use pyo3::{IntoPyObject, pyclass, pyfunction, wrap_pyfunction}; +use pyo3::{IntoPyObject, pyfunction, wrap_pyfunction}; use sqlbuild_host::entries::models::ExecutorHost; -use crate::bindings::_helpers::scopes::declaration_contexts::NativeDeclarationContexts; -use crate::bindings::_helpers::scopes::scope_lookup::build_scope_lookup; +use crate::scopes::main::index::build_scope_lookup::build_scope_lookup; +use crate::scopes::models::NativeDeclarationContexts; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::native_host::main::host_entry::host_entry; @@ -432,49 +432,6 @@ pub(crate) fn constant_declaration_sql<'py>( Err(PyErr::from_value(compile_error)) } -/// The adapter's constant rendering a compile's declaration expansions share. -#[pyclass(module = "sqlbuild._native", frozen)] -pub(crate) struct ConstantRendering { - value_renderer: Py, - collection_rendering: Py, -} - -impl ConstantRendering { - /// Rendering with the adapter's value renderer and the project's collection rendering. - pub(crate) fn new(value_renderer: Py, collection_rendering: Py) -> Self { - Self { - value_renderer, - collection_rendering, - } - } - - /// The adapter name the value renderer renders for, empty when it names none. - pub(crate) fn adapter_name(&self, py: Python<'_>) -> String { - native_field(self.value_renderer.bind(py), "adapter_name") - .and_then(|name| name.extract::()) - .unwrap_or_default() - } - - /// The SQL analysis dialect of the adapter the value renderer renders for, if it has one. - pub(crate) fn analysis_dialect(&self, py: Python<'_>) -> PyResult> { - native_field(self.value_renderer.bind(py), "sql_analysis_dialect_name")?.extract() - } - - /// One visible constant as SQL, its failures located at `file_path`. - pub(crate) fn render( - &self, - declaration: &Bound<'_, PyAny>, - file_path: &str, - ) -> PyResult { - let py: Python<'_> = declaration.py(); - constant_declaration_sql( - declaration, - self.value_renderer.bind(py), - (self.collection_rendering.bind(py), Some(file_path)), - ) - } -} - /// One enum member value as a SQL scalar literal. #[pyfunction] #[pyo3(signature = (*, value))] diff --git a/crates/sqlbuild-python-front/src/render/_helpers/declarations/mod.rs b/crates/sqlbuild-python-front/src/render/_helpers/declarations/mod.rs new file mode 100644 index 0000000000..ab58ada601 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/_helpers/declarations/mod.rs @@ -0,0 +1,4 @@ +pub(crate) mod authored_sql; +pub(crate) mod declaration_expansion; +pub(crate) mod declaration_indexes; +pub(crate) mod declaration_values; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_evaluation.rs b/crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_evaluation.rs similarity index 98% rename from crates/sqlbuild-python/src/bindings/_helpers/render/macro_evaluation.rs rename to crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_evaluation.rs index b657179e1a..ce9fa04516 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_evaluation.rs +++ b/crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_evaluation.rs @@ -14,11 +14,11 @@ use sqlbuild_render::macro_calls::main::macro_call_names::macro_call_names as sc use sqlbuild_render::macro_calls::main::scan_macro_call_sites::scan_macro_call_sites as scan_sites; use sqlbuild_render::macro_calls::models::{MacroCallScan, MacroCallSite}; -use crate::bindings::_helpers::render::macro_arguments::parsed_arguments; -use crate::bindings::_helpers::render::macro_expansion::{ - ExpansionClasses, NativeMacroExpansion, raised, -}; -use crate::bindings::_helpers::render::macro_expansion_facts::ResourceRef; +use crate::render::_helpers::calls::macro_arguments::parsed_arguments; +use crate::render::_helpers::expansion::macro_expansion::ExpansionClasses; +use crate::render::_helpers::expansion::macro_expansion::raised; +use crate::render::_helpers::expansion::macro_expansion_facts::ResourceRef; +use crate::render::models::NativeMacroExpansion; use sqlbuild_python_base::records::main::fields::field::field as native_field; const CONTEXT_PARAMETER: &str = "ctx"; diff --git a/crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_expansion.rs b/crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_expansion.rs new file mode 100644 index 0000000000..9c23011592 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_expansion.rs @@ -0,0 +1,282 @@ +//! One authored string's macro expansion: scanned, memoised, evaluated and spliced natively. + +use crate::render::models::ExpansionOutput; +use crate::render::models::NativeMacroExpansion; +use sqlbuild_python_base::positional_record; + +use pyo3::FromPyObject; +use pyo3::exceptions::PyValueError; +use pyo3::prelude::{ + Bound, Py, PyAny, PyAnyMethods, PyErr, PyModule, PyModuleMethods, PyRef, PyResult, Python, +}; +use pyo3::types::{PyDict, PyDictMethods, PyList}; +use sqlbuild_render::macro_calls::errors::ScanError; +use sqlbuild_render::macro_calls::main::scan_macro_call_sites::scan_macro_call_sites as scan_sites; +use sqlbuild_render::macro_calls::main::splice_macro_calls::splice_macro_calls as splice_calls; +use sqlbuild_render::macro_calls::models::{MacroCallScan, MacroCallSite}; + +use crate::render::_helpers::calls::macro_call_classes::CallClass; +use crate::render::_helpers::calls::macro_call_memo::MacroCallMemo; +use crate::render::_helpers::calls::macro_call_memo::poisoned; +use crate::render::_helpers::expansion::macro_evaluation::CallText; +use crate::render::_helpers::expansion::macro_evaluation::Evaluation; +use crate::render::_helpers::expansion::macro_evaluation::evaluate_call; +use crate::render::_helpers::expansion::macro_expansion_facts::ResourceRef; +use crate::render::_helpers::expansion::macro_generated_references::GeneratedReferenceClasses; +use crate::render::models::SpanTuple; +use sqlbuild_python_base::records::main::construct::new_helped_error::new_helped_error; +use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_base::records::types::ErrorId; + +pub(crate) const RELATION_PREFIX: &str = "__sqlbuild_relation_"; +const MEMO_ATTRIBUTE: &str = "memo"; +pub(crate) const LEXICAL_SYNTAX_ATTRIBUTE: &str = "_lexical_syntax"; +const OBSERVE_MODULES_METHOD: &str = "observe_modules"; +pub(crate) const RELATION_SUFFIX: &str = "__"; +pub(crate) const CONSTANT_KIND: &str = "constant"; +const RELATIONSHIP_CONSUMER_KINDS: [&str; 2] = ["test", "scenario"]; +pub(crate) const SQL_LANGUAGE: &str = "sql"; +pub(crate) const DECLARATION_FORMS: [&str; 3] = ["const", "enum", "param"]; +pub(crate) const UNREAD_CALL_HELP: &str = "Close every quote, block comment and parenthesis in the macro \ + call, and follow its name with its opening parenthesis"; + +/// Why the scan could not read the call `@{called}`, if the scan stopped inside a call. +pub(crate) fn unread_call_detail(error: ScanError, called: &str) -> Option { + let reason: String = match error { + ScanError::UnclosedQuote => format!("a quoted string in {called} is not closed"), + ScanError::UnclosedComment => format!("a block comment in {called} is not closed"), + ScanError::UnclosedParenthesis => format!("{called} is not closed with ')'"), + ScanError::MissingParenthesis => { + format!("{called} is not followed by its opening parenthesis") + } + ScanError::BareCall | ScanError::SqlCall => return None, + }; + Some(format!("could not be read: {reason}")) +} + +/// How a scanned call is written: `@py.name`, or `@const` and the other declaration forms. +pub(crate) fn written_call(name: &str) -> String { + if DECLARATION_FORMS.contains(&name) { + format!("@{name}") + } else { + format!("@py.{name}") + } +} + +positional_record! { + into; + /// `(sql, spans, argument references, dependencies, usages)` of one expansion. + pub(crate) struct ExpansionRow { + pub(crate) sql: String, + pub(crate) spans: Vec, + pub(crate) argument_references: Vec, + pub(crate) dependencies: Vec>, + pub(crate) usages: Vec>, + } +} + +/// The Python classes, enums and helpers an expansion builds facts, errors and contexts from. +#[derive(FromPyObject)] +#[pyo3(from_item_all)] +pub(crate) struct ExpansionClasses<'py> { + pub(crate) compile_error: Bound<'py, PyAny>, + pub(crate) macro_argument_error: Bound<'py, PyAny>, + pub(crate) mismatch_error: Bound<'py, PyAny>, + pub(crate) declaration_identity: Bound<'py, PyAny>, + pub(crate) declaration_kind: Bound<'py, PyAny>, + pub(crate) macro_kind: Bound<'py, PyAny>, + pub(crate) usage_record: Bound<'py, PyAny>, + pub(crate) runtime_usage: Bound<'py, PyAny>, + pub(crate) resource_identity: Bound<'py, PyAny>, + pub(crate) model_kind: Bound<'py, PyAny>, + pub(crate) resource_ref: Bound<'py, PyAny>, + /// `SqlResourceRefKind` member by typed reference function, such as `__ref`. + pub(crate) ref_kinds: Bound<'py, PyDict>, + /// Typed reference function by `SqlResourceRefKind` value. + pub(crate) ref_functions: Bound<'py, PyDict>, + pub(crate) relation_renderer: Bound<'py, PyAny>, + /// Builds the `MacroContext` a macro is called with from the visible declarations. + pub(crate) invocation_context: Bound<'py, PyAny>, + /// What reference calls a macro returned are reported with. + pub(crate) generated: GeneratedReferenceClasses<'py>, + pub(crate) int_type: Bound<'py, PyAny>, + pub(crate) float_type: Bound<'py, PyAny>, +} + +/// Expand `sql` with the expansion's inputs, through the bridge's memo when one is active. +pub(crate) fn expanded<'py>( + expansion: &Bound<'py, NativeMacroExpansion>, + sql: &str, + bridge: &Bound<'py, PyAny>, +) -> PyResult { + let py: Python<'py> = expansion.py(); + let this: PyRef<'py, NativeMacroExpansion> = expansion.borrow(); + let classes: ExpansionClasses<'py> = this.classes.bind(py).extract()?; + let handle: Bound<'py, PyAny> = expansion.as_any().clone(); + let run: Evaluation<'_, 'py> = Evaluation { + expansion: &this, + handle: &handle, + classes: &classes, + }; + let text: CallText<'_> = CallText::new(sql); + let scan: MacroCallScan = scan_sites(text.text, this.syntax.as_ref()); + let memo: Option> = if bridge.is_none() { + None + } else { + Some(bridge.getattr(MEMO_ATTRIBUTE)?.downcast_into()?) + }; + let call_classes: Option> = match &memo { + Some(memo) => this.call_classes(&classes, memo.get(), &scan)?, + None => None, + }; + let outputs: Vec = match (call_classes, &memo) { + (Some(call_classes), Some(memo)) => { + let mut outputs: Vec = Vec::with_capacity(scan.sites.len()); + for (site, call_class) in scan.sites.iter().zip(call_classes) { + outputs.push(this.bridged_output( + &run, + (bridge, memo.get()), + (&text, site), + &call_class, + )?); + } + outputs + } + _ => this.unmemoised_outputs(&run, &text, &scan)?, + }; + let bounds: Vec<(usize, usize)> = scan + .sites + .iter() + .map(|site| (site.start, site.end)) + .collect(); + let (rendered, spans) = splice_calls(text.text, &bounds, &outputs) + .ok_or_else(|| PyValueError::new_err("macro call sites do not fit the SQL"))?; + let facts = this.facts.borrow(); + Ok(ExpansionOutput { + sql: rendered, + spans, + argument_references: facts.argument_references.clone(), + dependencies: facts + .dependencies + .iter() + .map(|item| item.clone_ref(py)) + .collect(), + usages: facts.usages.iter().map(|item| item.clone_ref(py)).collect(), + }) +} + +/// One top-level call's SQL. +pub(crate) fn top_level_output( + run: &Evaluation<'_, '_>, + call: (&CallText<'_>, &MacroCallSite), +) -> PyResult { + evaluate_call(run, call, true)?.extract() +} + +/// A `SqlResourceRef`'s kind value and name. +pub(crate) fn resource_key(reference: &Bound<'_, PyAny>) -> PyResult { + Ok(( + native_field(&native_field(reference, "kind")?, "value")?.extract()?, + native_field(reference, "name")?.extract()?, + )) +} + +/// `reference_call_text`: the reference call naming `reference`, such as `__ref("orders")`. +pub(crate) fn reference_call_text( + classes: &ExpansionClasses<'_>, + reference: &ResourceRef, +) -> PyResult { + let (kind, name) = reference; + let function: String = classes + .ref_functions + .get_item(kind)? + .ok_or_else(|| PyErr::new::(kind.clone()))? + .extract()?; + Ok(format!("{function}(\"{name}\")")) +} + +/// Whether the consumer is a test or scenario, which records relationship visibility. +pub(crate) fn relationship_consumer( + classes: &ExpansionClasses<'_>, + consumer: &Bound<'_, PyAny>, +) -> PyResult { + if !consumer.is_instance(&classes.resource_identity)? { + return Ok(false); + } + let kind: String = native_field(&native_field(consumer, "kind")?, "value")?.extract()?; + Ok(RELATIONSHIP_CONSUMER_KINDS.contains(&kind.as_str())) +} + +/// A runtime `UsageRecord` of `declaration` by `consumer`, through a relationship if any. +pub(crate) fn usage<'py>( + classes: &ExpansionClasses<'py>, + usage: (&Bound<'py, PyAny>, &Bound<'py, PyAny>), + through: Option<&Bound<'py, PyAny>>, +) -> PyResult> { + let (consumer, declaration) = usage; + let keywords: Bound<'py, PyDict> = PyDict::new(consumer.py()); + if let Some(through) = through { + keywords.set_item("through", through)?; + } + classes.usage_record.call( + (consumer, declaration, &classes.runtime_usage), + Some(&keywords), + ) +} + +/// `", ".join(sorted(names)) or "none"`. +pub(crate) fn sorted_names(names: &Bound<'_, PyAny>) -> PyResult { + let mut sorted: Vec = + PyList::new(names.py(), names.try_iter()?.collect::>>()?)?.extract()?; + sorted.sort_unstable(); + Ok(if sorted.is_empty() { + "none".to_owned() + } else { + sorted.join(", ") + }) +} + +/// The `CompileInputError(message, code=code, help=help)` the classes' compile error builds. +pub(crate) fn coded(class: &Bound<'_, PyAny>, message: &str, (code, help): (&str, &str)) -> PyErr { + new_helped_error( + class.py(), + ErrorId::CompileInput, + (message.to_owned(), code), + Some(help), + ) +} + +/// The exception `class(message)` builds. +pub(crate) fn raised(class: &Bound<'_, PyAny>, message: &str) -> PyErr { + match class.call1((message,)) { + Ok(instance) => PyErr::from_value(instance), + Err(error) => error, + } +} + +pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { + module.add_class::()?; + Ok(()) +} + +/// Whether a macro's result calls any reference function. +pub(crate) fn result_has_markers(classes: &ExpansionClasses<'_>, result: &str) -> bool { + classes + .generated + .markers() + .any(|marker| result.contains(marker)) +} + +/// Observe modules a recorded call imported, so the store is not saved over changed code. +pub(crate) fn observe_new_modules(bridge: &Bound<'_, PyAny>, memo: &MacroCallMemo) -> PyResult<()> { + let Some(observed) = *memo.observed_modules.lock().map_err(poisoned)? else { + return Ok(()); + }; + let loaded: usize = PyModule::import(bridge.py(), "sys")? + .getattr("modules")? + .len()?; + if loaded != observed { + let _ = bridge.call_method0(OBSERVE_MODULES_METHOD)?; + } + Ok(()) +} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_expansion_facts.rs b/crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_expansion_facts.rs similarity index 99% rename from crates/sqlbuild-python/src/bindings/_helpers/render/macro_expansion_facts.rs rename to crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_expansion_facts.rs index 0748b6edf3..2e753aaf5f 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_expansion_facts.rs +++ b/crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_expansion_facts.rs @@ -9,7 +9,7 @@ use sqlbuild_render::macro_calls::models::MacroCallEvent; pub(crate) type ResourceRef = (String, String); /// `MacroExpansionFacts`: dependencies, usages, relations, call-site references and the event log. -#[derive(Default)] +#[derive(Debug, Default)] pub(crate) struct ExpansionFacts { pub(crate) dependencies: Vec>, pub(crate) usages: Vec>, diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_expansion_result.rs b/crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_expansion_result.rs similarity index 91% rename from crates/sqlbuild-python/src/bindings/_helpers/render/macro_expansion_result.rs rename to crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_expansion_result.rs index 5b9ee096d4..83221cb5ba 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_expansion_result.rs +++ b/crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_expansion_result.rs @@ -1,5 +1,6 @@ //! Expand one authored SQL string's macros into a `MacroExpansionResult`. +use crate::render::models::ExpansionRequest; use pyo3::IntoPyObject; use pyo3::prelude::{Bound, Py, PyAny, PyAnyMethods, PyModule, PyModuleMethods, PyResult, Python}; use pyo3::sync::PyOnceLock; @@ -7,13 +8,15 @@ use pyo3::types::{PyDict, PyDictMethods, PyList, PyString, PyStringMethods, PyTu use pyo3::{pyfunction, wrap_pyfunction}; use sqlbuild_host::entries::models::UserCodeHost; -use crate::bindings::_helpers::discovery::guidance::explicit_references_help; -use crate::bindings::_helpers::render::declaration_values::resolved_declaration_context; -use crate::bindings::_helpers::render::macro_call_rows::{SpanRow, span_row}; -use crate::bindings::_helpers::render::macro_expansion::{ - ExpansionOutput, NativeMacroExpansion, StateInput, expanded, -}; -use crate::bindings::_helpers::sqltext::sql_references::extract_references; +use crate::discovery::main::failures::explicit_references_help::explicit_references_help; +use crate::render::_helpers::calls::macro_call_rows::span_row; +use crate::render::_helpers::declarations::declaration_values::resolved_declaration_context; +use crate::render::_helpers::expansion::macro_expansion::expanded; +use crate::render::models::ExpansionOutput; +use crate::render::models::NativeMacroExpansion; +use crate::render::models::StateInput; +use crate::render::types::SpanRow; +use crate::sqltext::main::extract_references::extract_references; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::boundary::models::KeywordArguments; @@ -47,18 +50,6 @@ const GENERATED_ALLOWED: &str = "macro-generated references"; static EXPANSION_CLASSES: PyOnceLock> = PyOnceLock::new(); -/// One expansion's inputs, as Python's `expand_sql_macros_result` takes them. -pub(crate) struct ExpansionRequest<'py> { - pub(crate) sql: Bound<'py, PyString>, - pub(crate) file_path: Bound<'py, PyAny>, - pub(crate) loaded_macros: Bound<'py, PyDict>, - pub(crate) macro_overrides: Option>, - pub(crate) macro_context: Bound<'py, PyAny>, - pub(crate) declaration_resolver: Option>, - pub(crate) declarations: Option>, - pub(crate) consumer: Option>, -} - fn generated_classes(py: Python<'_>) -> PyResult> { let help: Bound<'_, PyAny> = PyString::new(py, &explicit_references_help(GENERATED_ALLOWED)).into_any(); diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_generated_references.rs b/crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_generated_references.rs similarity index 99% rename from crates/sqlbuild-python/src/bindings/_helpers/render/macro_generated_references.rs rename to crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_generated_references.rs index 720656612e..f8f58cfc9c 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_generated_references.rs +++ b/crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_generated_references.rs @@ -11,7 +11,7 @@ use sqlbuild_sqltext::sql_references::models::{ }; use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; -use crate::bindings::_helpers::sqltext::lexical_syntax::LexicalSyntaxInput; +use crate::sqltext::models::LexicalSyntaxInput; use sqlbuild_python_base::compile_context::main::diagnostic_collector::report_compile_diagnostic::report_compile_diagnostic; use sqlbuild_python_base::records::main::fields::field::field as native_field; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_modules.rs b/crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_modules.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/render/macro_modules.rs rename to crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_modules.rs diff --git a/crates/sqlbuild-python-front/src/render/_helpers/expansion/mod.rs b/crates/sqlbuild-python-front/src/render/_helpers/expansion/mod.rs new file mode 100644 index 0000000000..f51bfd0ca3 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/_helpers/expansion/mod.rs @@ -0,0 +1,6 @@ +pub(crate) mod macro_evaluation; +pub(crate) mod macro_expansion; +pub(crate) mod macro_expansion_facts; +pub(crate) mod macro_expansion_result; +pub(crate) mod macro_generated_references; +pub(crate) mod macro_modules; diff --git a/crates/sqlbuild-python-front/src/render/_helpers/mod.rs b/crates/sqlbuild-python-front/src/render/_helpers/mod.rs new file mode 100644 index 0000000000..39cd0dcc0f --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/_helpers/mod.rs @@ -0,0 +1,4 @@ +pub(crate) mod calls; +pub(crate) mod declarations; +pub(crate) mod expansion; +pub(crate) mod sql_macros; diff --git a/crates/sqlbuild-python-front/src/render/_helpers/sql_macros/mod.rs b/crates/sqlbuild-python-front/src/render/_helpers/sql_macros/mod.rs new file mode 100644 index 0000000000..aeb781ae2e --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/_helpers/sql_macros/mod.rs @@ -0,0 +1,4 @@ +pub(crate) mod sql_macro_host; +pub(crate) mod sql_macro_inventory; +pub(crate) mod sql_macro_mocks; +pub(crate) mod sql_macro_tests; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/sql_macro_host.rs b/crates/sqlbuild-python-front/src/render/_helpers/sql_macros/sql_macro_host.rs similarity index 94% rename from crates/sqlbuild-python/src/bindings/_helpers/render/sql_macro_host.rs rename to crates/sqlbuild-python-front/src/render/_helpers/sql_macros/sql_macro_host.rs index afb0f41812..1d2445ca42 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/render/sql_macro_host.rs +++ b/crates/sqlbuild-python-front/src/render/_helpers/sql_macros/sql_macro_host.rs @@ -1,5 +1,7 @@ //! SQL macro calls expanded in the declaration pass, reading the caller's visible declarations. +use crate::render::models::SqlCallOrigin; +use crate::render::models::SqlMacroSource; use std::cell::RefCell; use std::collections::HashMap; use std::sync::Arc; @@ -26,10 +28,11 @@ use sqlbuild_analysis::sql_macros::models::{ use sqlbuild_analysis::sql_macros::types::{ConstantShape, SqlMacroHost, SqlMacroScope}; use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; -use crate::bindings::_helpers::render::declaration_expansion::{ - DeclarationExpansion, ExpandedDeclarations, expand_declarations, usage_visibility, -}; -use crate::bindings::_helpers::sqltext::declaration_references::declaration_scan; +use crate::render::_helpers::declarations::declaration_expansion::expand_declarations; +use crate::render::_helpers::declarations::declaration_expansion::usage_visibility; +use crate::render::models::DeclarationExpansion; +use crate::render::models::ExpandedDeclarations; +use crate::sqltext::main::declaration_scan::declaration_scan; use sqlbuild_python_base::records::main::construct::enum_member::enum_member; use sqlbuild_python_base::records::main::construct::new_helped_error::new_helped_error; use sqlbuild_python_base::records::main::construct::new_record::new_record; @@ -51,35 +54,6 @@ const MODEL_KIND: &str = "model"; /// A macro the caller sees, and one it cannot see, by name. type LoadedMacro<'py> = (Option>, Option>); -/// Where the caller's text came from, to locate calls in its authored file. -#[derive(Clone, Copy)] -pub(crate) struct SqlCallOrigin<'a> { - /// The authored file's project-relative path. - pub(crate) relative_path: &'a str, - /// The authored file's contents. - pub(crate) contents: &'a str, - /// The authored query the expanded text came from, within `contents`. - pub(crate) query: &'a str, -} - -/// What SQL macro calls in one declaration pass read beyond the declaration context. -#[derive(Clone, Copy)] -pub(crate) struct SqlMacroSource<'a, 'py> { - /// Every loaded macro by name, for unscoped compiles whose context holds none. - pub(crate) loaded_macros: Option<&'a Bound<'py, PyAny>>, - pub(crate) origin: Option>, - /// Where macro bodies resolve their declarations; `None` outside the input loops. - pub(crate) scopes: Option<&'a dyn MacroScopes<'py>>, - /// The lexical rules the authored SQL is written in; `None` reads it under the generic rules. - pub(crate) syntax: Option<&'a LexicalSyntax>, -} - -/// The declaration contexts of macro files in a scoped compile. -pub(crate) trait MacroScopes<'py> { - /// The context the file at `path` sees, or `None` when the compile is unscoped. - fn file_context(&self, path: &str) -> PyResult>>; -} - /// The facts a declaration pass's SQL macro calls recorded. #[derive(Default)] pub(crate) struct SqlMacroFacts<'py> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/sql_macro_inventory.rs b/crates/sqlbuild-python-front/src/render/_helpers/sql_macros/sql_macro_inventory.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/render/sql_macro_inventory.rs rename to crates/sqlbuild-python-front/src/render/_helpers/sql_macros/sql_macro_inventory.rs diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/sql_macro_mocks.rs b/crates/sqlbuild-python-front/src/render/_helpers/sql_macros/sql_macro_mocks.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/render/sql_macro_mocks.rs rename to crates/sqlbuild-python-front/src/render/_helpers/sql_macros/sql_macro_mocks.rs diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/sql_macro_tests.rs b/crates/sqlbuild-python-front/src/render/_helpers/sql_macros/sql_macro_tests.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/render/sql_macro_tests.rs rename to crates/sqlbuild-python-front/src/render/_helpers/sql_macros/sql_macro_tests.rs diff --git a/crates/sqlbuild-python-front/src/render/main/calls/mod.rs b/crates/sqlbuild-python-front/src/render/main/calls/mod.rs new file mode 100644 index 0000000000..2447c45aa4 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/calls/mod.rs @@ -0,0 +1,6 @@ +pub mod register_macro_arguments; +pub mod register_macro_calls; +pub mod span_expansion; +pub mod span_row; +pub mod span_tuple; +pub mod top_level_macro_call_names; diff --git a/crates/sqlbuild-python-front/src/render/main/calls/register_macro_arguments.rs b/crates/sqlbuild-python-front/src/render/main/calls/register_macro_arguments.rs new file mode 100644 index 0000000000..1f7be17726 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/calls/register_macro_arguments.rs @@ -0,0 +1,12 @@ +//! Register the macro arguments functions and classes. + +use crate::render::_helpers::calls::macro_arguments; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the macro arguments functions and classes. +#[inline] +pub fn register_macro_arguments(module: &Bound<'_, PyModule>) -> PyResult<()> { + macro_arguments::register(module) +} diff --git a/crates/sqlbuild-python-front/src/render/main/calls/register_macro_calls.rs b/crates/sqlbuild-python-front/src/render/main/calls/register_macro_calls.rs new file mode 100644 index 0000000000..d44a654e62 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/calls/register_macro_calls.rs @@ -0,0 +1,12 @@ +//! Register the macro calls functions and classes. + +use crate::render::_helpers::calls::macro_calls; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the macro calls functions and classes. +#[inline] +pub fn register_macro_calls(module: &Bound<'_, PyModule>) -> PyResult<()> { + macro_calls::register(module) +} diff --git a/crates/sqlbuild-python-front/src/render/main/calls/span_expansion.rs b/crates/sqlbuild-python-front/src/render/main/calls/span_expansion.rs new file mode 100644 index 0000000000..e30ecf2a63 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/calls/span_expansion.rs @@ -0,0 +1,11 @@ +//! A span as the expansion semantic validation maps offsets through. + +use crate::render::_helpers::calls::macro_call_rows; +use crate::render::types::SpanRow; +use sqlbuild_analysis::semantic_validation::models::Expansion; + +/// A span as the expansion semantic validation maps offsets through. +#[inline] +pub fn span_expansion(span: SpanRow) -> Expansion { + macro_call_rows::span_expansion(span) +} diff --git a/crates/sqlbuild-python-front/src/render/main/calls/span_row.rs b/crates/sqlbuild-python-front/src/render/main/calls/span_row.rs new file mode 100644 index 0000000000..5a2e19132f --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/calls/span_row.rs @@ -0,0 +1,11 @@ +//! Span row. + +use crate::render::_helpers::calls::macro_call_rows; +use crate::render::types::SpanRow; +use sqlbuild_render::macro_calls::models::MacroSpliceSpan; + +/// Span row. +#[inline] +pub fn span_row(span: MacroSpliceSpan) -> SpanRow { + macro_call_rows::span_row(span) +} diff --git a/crates/sqlbuild-python-front/src/render/main/calls/span_tuple.rs b/crates/sqlbuild-python-front/src/render/main/calls/span_tuple.rs new file mode 100644 index 0000000000..d1c2173566 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/calls/span_tuple.rs @@ -0,0 +1,11 @@ +//! A span as the tuple Python reads. + +use crate::render::_helpers::calls::macro_call_rows; +use crate::render::models::SpanTuple; +use crate::render::types::SpanRow; + +/// A span as the tuple Python reads. +#[inline] +pub fn span_tuple(span: &SpanRow) -> SpanTuple { + macro_call_rows::span_tuple(span) +} diff --git a/crates/sqlbuild-python-front/src/render/main/calls/top_level_macro_call_names.rs b/crates/sqlbuild-python-front/src/render/main/calls/top_level_macro_call_names.rs new file mode 100644 index 0000000000..f740688342 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/calls/top_level_macro_call_names.rs @@ -0,0 +1,18 @@ +//! Python's `find_macro_call_names`: top-level call names in encounter order, declarations excluded. + +use crate::render::_helpers::calls::macro_calls; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::types::PyTuple; +use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; + +/// Python's `find_macro_call_names`: top-level call names in encounter order, declarations excluded. +#[inline] +pub fn top_level_macro_call_names<'py>( + py: Python<'py>, + sql: &str, + syntax: Option<&LexicalSyntax>, +) -> PyResult> { + macro_calls::top_level_macro_call_names(py, sql, syntax) +} diff --git a/crates/sqlbuild-python-front/src/render/main/declarations/constant_declaration_sql.rs b/crates/sqlbuild-python-front/src/render/main/declarations/constant_declaration_sql.rs new file mode 100644 index 0000000000..98c8ffe2cd --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/declarations/constant_declaration_sql.rs @@ -0,0 +1,20 @@ +//! Render one validated constant with the active adapter's typed-value contract. + +use crate::render::_helpers::declarations::declaration_values; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Render one validated constant with the active adapter's typed-value contract. +#[inline] +pub fn constant_declaration_sql<'py>( + declaration: &Bound<'py, PyAny>, + value_renderer: &Bound<'py, PyAny>, + (collection_rendering, file_path): (&Bound<'py, PyAny>, Option<&str>), +) -> PyResult { + declaration_values::constant_declaration_sql( + declaration, + value_renderer, + (collection_rendering, file_path), + ) +} diff --git a/crates/sqlbuild-python-front/src/render/main/declarations/declaration_scope_resolver.rs b/crates/sqlbuild-python-front/src/render/main/declarations/declaration_scope_resolver.rs new file mode 100644 index 0000000000..0f8d8e6cbd --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/declarations/declaration_scope_resolver.rs @@ -0,0 +1,16 @@ +//! Pair the serializable static index with original process-local declaration values. + +use crate::render::_helpers::declarations::declaration_values; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Pair the serializable static index with original process-local declaration values. +#[inline] +pub fn declaration_scope_resolver<'py>( + discovered: &Bound<'py, PyAny>, + scope_index: &Bound<'py, PyAny>, + (loaded_macros, lookup): (&Bound<'py, PyAny>, &Bound<'py, PyAny>), +) -> PyResult> { + declaration_values::declaration_scope_resolver(discovered, scope_index, (loaded_macros, lookup)) +} diff --git a/crates/sqlbuild-python-front/src/render/main/declarations/expand_declarations.rs b/crates/sqlbuild-python-front/src/render/main/declarations/expand_declarations.rs new file mode 100644 index 0000000000..f0bfbf7df2 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/declarations/expand_declarations.rs @@ -0,0 +1,14 @@ +//! Splice each reference in order, raising the attachment's error for the first bad one. + +use crate::render::_helpers::declarations::declaration_expansion; +use crate::render::models::DeclarationExpansion; +use crate::render::models::ExpandedDeclarations; +use pyo3::prelude::PyResult; + +/// Splice each reference in order, raising the attachment's error for the first bad one. +#[inline] +pub fn expand_declarations<'py>( + request: &DeclarationExpansion<'_, 'py>, +) -> PyResult> { + declaration_expansion::expand_declarations(request) +} diff --git a/crates/sqlbuild-python-front/src/render/main/declarations/expand_with_inputs.rs b/crates/sqlbuild-python-front/src/render/main/declarations/expand_with_inputs.rs new file mode 100644 index 0000000000..4b1bac8d3d --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/declarations/expand_with_inputs.rs @@ -0,0 +1,18 @@ +//! `sql` expanded with lint's expansion inputs, as `file_path`'s declarations see them. + +use crate::render::_helpers::declarations::authored_sql; +use crate::render::models::AuthoredExpansion; +use crate::render::models::SqlExpansionInputs; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// `sql` expanded with lint's expansion inputs, as `file_path`'s declarations see them. +#[inline] +pub fn expand_with_inputs( + inputs: &SqlExpansionInputs, + sql: &str, + file_path: &Bound<'_, PyAny>, +) -> PyResult { + authored_sql::expand_with_inputs(inputs, sql, file_path) +} diff --git a/crates/sqlbuild-python-front/src/render/main/declarations/mod.rs b/crates/sqlbuild-python-front/src/render/main/declarations/mod.rs new file mode 100644 index 0000000000..709e78359a --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/declarations/mod.rs @@ -0,0 +1,11 @@ +pub mod constant_declaration_sql; +pub mod declaration_scope_resolver; +pub mod expand_declarations; +pub mod expand_with_inputs; +pub mod public_declaration_indexes; +pub mod public_model_schema_index; +pub mod register_authored_sql; +pub mod register_declaration_indexes; +pub mod register_declaration_values; +pub mod render_enum_member_value; +pub mod span_rows; diff --git a/crates/sqlbuild-python-front/src/render/main/declarations/public_declaration_indexes.rs b/crates/sqlbuild-python-front/src/render/main/declarations/public_declaration_indexes.rs new file mode 100644 index 0000000000..aada555fa0 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/declarations/public_declaration_indexes.rs @@ -0,0 +1,15 @@ +//! Every public enum and constant by name, collision-checked. + +use crate::render::_helpers::declarations::declaration_indexes; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyDict; + +/// Every public enum and constant by name, collision-checked. +#[inline] +pub fn public_declaration_indexes<'py>( + inputs: Bound<'py, PyAny>, +) -> PyResult<(Bound<'py, PyDict>, Bound<'py, PyDict>)> { + declaration_indexes::public_declaration_indexes(inputs) +} diff --git a/crates/sqlbuild-python-front/src/render/main/declarations/public_model_schema_index.rs b/crates/sqlbuild-python-front/src/render/main/declarations/public_model_schema_index.rs new file mode 100644 index 0000000000..1c1d35991e --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/declarations/public_model_schema_index.rs @@ -0,0 +1,13 @@ +//! Every public model schema by name, with its inherited columns first, collision-checked. + +use crate::render::_helpers::declarations::declaration_indexes; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyDict; + +/// Every public model schema by name, with its inherited columns first, collision-checked. +#[inline] +pub fn public_model_schema_index<'py>(inputs: Bound<'py, PyAny>) -> PyResult> { + declaration_indexes::public_model_schema_index(inputs) +} diff --git a/crates/sqlbuild-python-front/src/render/main/declarations/register_authored_sql.rs b/crates/sqlbuild-python-front/src/render/main/declarations/register_authored_sql.rs new file mode 100644 index 0000000000..1a77c6da6c --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/declarations/register_authored_sql.rs @@ -0,0 +1,12 @@ +//! Register the authored sql functions and classes. + +use crate::render::_helpers::declarations::authored_sql; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the authored sql functions and classes. +#[inline] +pub fn register_authored_sql(module: &Bound<'_, PyModule>) -> PyResult<()> { + authored_sql::register(module) +} diff --git a/crates/sqlbuild-python-front/src/render/main/declarations/register_declaration_indexes.rs b/crates/sqlbuild-python-front/src/render/main/declarations/register_declaration_indexes.rs new file mode 100644 index 0000000000..dab0eed265 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/declarations/register_declaration_indexes.rs @@ -0,0 +1,12 @@ +//! Register the declaration indexes functions and classes. + +use crate::render::_helpers::declarations::declaration_indexes; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the declaration indexes functions and classes. +#[inline] +pub fn register_declaration_indexes(module: &Bound<'_, PyModule>) -> PyResult<()> { + declaration_indexes::register(module) +} diff --git a/crates/sqlbuild-python-front/src/render/main/declarations/register_declaration_values.rs b/crates/sqlbuild-python-front/src/render/main/declarations/register_declaration_values.rs new file mode 100644 index 0000000000..92d91956ef --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/declarations/register_declaration_values.rs @@ -0,0 +1,12 @@ +//! Register the declaration values functions and classes. + +use crate::render::_helpers::declarations::declaration_values; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the declaration values functions and classes. +#[inline] +pub fn register_declaration_values(module: &Bound<'_, PyModule>) -> PyResult<()> { + declaration_values::register(module) +} diff --git a/crates/sqlbuild-python-front/src/render/main/declarations/render_enum_member_value.rs b/crates/sqlbuild-python-front/src/render/main/declarations/render_enum_member_value.rs new file mode 100644 index 0000000000..18b3148a1e --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/declarations/render_enum_member_value.rs @@ -0,0 +1,12 @@ +//! One enum member value as a SQL scalar literal. + +use crate::render::_helpers::declarations::declaration_values; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// One enum member value as a SQL scalar literal. +#[inline] +pub fn render_enum_member_value(value: &Bound<'_, PyAny>) -> PyResult { + declaration_values::render_enum_member_value(value) +} diff --git a/crates/sqlbuild-python-front/src/render/main/declarations/span_rows.rs b/crates/sqlbuild-python-front/src/render/main/declarations/span_rows.rs new file mode 100644 index 0000000000..69f717b456 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/declarations/span_rows.rs @@ -0,0 +1,11 @@ +//! Span rows. + +use crate::render::_helpers::declarations::declaration_expansion; +use crate::render::types::SpanRow; +use sqlbuild_analysis::compiled_project::models::SplicedSql; + +/// Span rows. +#[inline] +pub fn span_rows(spliced: &SplicedSql) -> Vec { + declaration_expansion::span_rows(spliced) +} diff --git a/crates/sqlbuild-python-front/src/render/main/expansion/expanded.rs b/crates/sqlbuild-python-front/src/render/main/expansion/expanded.rs new file mode 100644 index 0000000000..f3493f3740 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/expansion/expanded.rs @@ -0,0 +1,18 @@ +//! Expand `sql` with the expansion's inputs, through the bridge's memo when one is active. + +use crate::render::_helpers::expansion::macro_expansion; +use crate::render::models::ExpansionOutput; +use crate::render::models::NativeMacroExpansion; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Expand `sql` with the expansion's inputs, through the bridge's memo when one is active. +#[inline] +pub fn expanded<'py>( + expansion: &Bound<'py, NativeMacroExpansion>, + sql: &str, + bridge: &Bound<'py, PyAny>, +) -> PyResult { + macro_expansion::expanded(expansion, sql, bridge) +} diff --git a/crates/sqlbuild-python-front/src/render/main/expansion/expansion_result.rs b/crates/sqlbuild-python-front/src/render/main/expansion/expansion_result.rs new file mode 100644 index 0000000000..3cc313db31 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/expansion/expansion_result.rs @@ -0,0 +1,13 @@ +//! Expansion result. + +use crate::render::_helpers::expansion::macro_expansion_result; +use crate::render::models::ExpansionRequest; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Expansion result. +#[inline] +pub fn expansion_result<'py>(request: ExpansionRequest<'py>) -> PyResult> { + macro_expansion_result::expansion_result(request) +} diff --git a/crates/sqlbuild-python-front/src/render/main/expansion/macro_expansion_classes.rs b/crates/sqlbuild-python-front/src/render/main/expansion/macro_expansion_classes.rs new file mode 100644 index 0000000000..ceebea1865 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/expansion/macro_expansion_classes.rs @@ -0,0 +1,13 @@ +//! The classes, enums and helpers the native expansion builds facts and errors from, built once. + +use crate::render::_helpers::expansion::macro_expansion_result; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::types::PyDict; + +/// The classes, enums and helpers the native expansion builds facts and errors from, built once. +#[inline] +pub fn macro_expansion_classes(py: Python<'_>) -> PyResult> { + macro_expansion_result::macro_expansion_classes(py) +} diff --git a/crates/sqlbuild-python-front/src/render/main/expansion/mod.rs b/crates/sqlbuild-python-front/src/render/main/expansion/mod.rs new file mode 100644 index 0000000000..e4c870bc17 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/expansion/mod.rs @@ -0,0 +1,6 @@ +pub mod expanded; +pub mod expansion_result; +pub mod macro_expansion_classes; +pub mod register_macro_expansion; +pub mod register_macro_expansion_result; +pub mod register_macro_modules; diff --git a/crates/sqlbuild-python-front/src/render/main/expansion/register_macro_expansion.rs b/crates/sqlbuild-python-front/src/render/main/expansion/register_macro_expansion.rs new file mode 100644 index 0000000000..14a84995b5 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/expansion/register_macro_expansion.rs @@ -0,0 +1,12 @@ +//! Register the macro expansion functions and classes. + +use crate::render::_helpers::expansion::macro_expansion; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the macro expansion functions and classes. +#[inline] +pub fn register_macro_expansion(module: &Bound<'_, PyModule>) -> PyResult<()> { + macro_expansion::register(module) +} diff --git a/crates/sqlbuild-python-front/src/render/main/expansion/register_macro_expansion_result.rs b/crates/sqlbuild-python-front/src/render/main/expansion/register_macro_expansion_result.rs new file mode 100644 index 0000000000..bd34acc97d --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/expansion/register_macro_expansion_result.rs @@ -0,0 +1,12 @@ +//! Register the macro expansion result functions and classes. + +use crate::render::_helpers::expansion::macro_expansion_result; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the macro expansion result functions and classes. +#[inline] +pub fn register_macro_expansion_result(module: &Bound<'_, PyModule>) -> PyResult<()> { + macro_expansion_result::register(module) +} diff --git a/crates/sqlbuild-python-front/src/render/main/expansion/register_macro_modules.rs b/crates/sqlbuild-python-front/src/render/main/expansion/register_macro_modules.rs new file mode 100644 index 0000000000..abe97ff144 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/expansion/register_macro_modules.rs @@ -0,0 +1,12 @@ +//! Register the macro modules functions and classes. + +use crate::render::_helpers::expansion::macro_modules; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the macro modules functions and classes. +#[inline] +pub fn register_macro_modules(module: &Bound<'_, PyModule>) -> PyResult<()> { + macro_modules::register(module) +} diff --git a/crates/sqlbuild-python-front/src/render/main/mod.rs b/crates/sqlbuild-python-front/src/render/main/mod.rs new file mode 100644 index 0000000000..0a859610d2 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/mod.rs @@ -0,0 +1,4 @@ +pub mod calls; +pub mod declarations; +pub mod expansion; +pub mod sql_macros; diff --git a/crates/sqlbuild-python-front/src/render/main/sql_macros/mod.rs b/crates/sqlbuild-python-front/src/render/main/sql_macros/mod.rs new file mode 100644 index 0000000000..93d5f7aeb5 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/sql_macros/mod.rs @@ -0,0 +1,3 @@ +pub mod register_sql_macro_inventory; +pub mod with_sql_macro_mocks; +pub mod without_with_list_calls; diff --git a/crates/sqlbuild-python-front/src/render/main/sql_macros/register_sql_macro_inventory.rs b/crates/sqlbuild-python-front/src/render/main/sql_macros/register_sql_macro_inventory.rs new file mode 100644 index 0000000000..2242424725 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/sql_macros/register_sql_macro_inventory.rs @@ -0,0 +1,12 @@ +//! Register the sql macro inventory functions and classes. + +use crate::render::_helpers::sql_macros::sql_macro_inventory; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the sql macro inventory functions and classes. +#[inline] +pub fn register_sql_macro_inventory(module: &Bound<'_, PyModule>) -> PyResult<()> { + sql_macro_inventory::register(module) +} diff --git a/crates/sqlbuild-python-front/src/render/main/sql_macros/with_sql_macro_mocks.rs b/crates/sqlbuild-python-front/src/render/main/sql_macros/with_sql_macro_mocks.rs new file mode 100644 index 0000000000..951d255eb0 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/sql_macros/with_sql_macro_mocks.rs @@ -0,0 +1,17 @@ +//! `macro_source_sql` with each call of a mocked SQL macro the model makes replaced by its mock. + +use crate::render::_helpers::sql_macros::sql_macro_mocks; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyDict; + +/// `macro_source_sql` with each call of a mocked SQL macro the model makes replaced by its mock. +#[inline] +pub fn with_sql_macro_mocks( + model_input: &Bound<'_, PyAny>, + macro_source_sql: String, + (mocks, loaded_macros): (&Bound<'_, PyDict>, &Bound<'_, PyAny>), +) -> PyResult { + sql_macro_mocks::with_sql_macro_mocks(model_input, macro_source_sql, (mocks, loaded_macros)) +} diff --git a/crates/sqlbuild-python-front/src/render/main/sql_macros/without_with_list_calls.rs b/crates/sqlbuild-python-front/src/render/main/sql_macros/without_with_list_calls.rs new file mode 100644 index 0000000000..4f4d902195 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/main/sql_macros/without_with_list_calls.rs @@ -0,0 +1,9 @@ +//! The test's SQL with each `WITH`-list SQL macro call blanked, and the macros those calls name. + +use crate::render::_helpers::sql_macros::sql_macro_tests; + +/// The test's SQL with each `WITH`-list SQL macro call blanked, and the macros those calls name. +#[inline] +pub fn without_with_list_calls(sql: &str) -> (String, Vec) { + sql_macro_tests::without_with_list_calls(sql) +} diff --git a/crates/sqlbuild-python-front/src/render/mod.rs b/crates/sqlbuild-python-front/src/render/mod.rs new file mode 100644 index 0000000000..04e542ab75 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/mod.rs @@ -0,0 +1,6 @@ +//! SQL rendering: authored SQL, declaration expansion, macro calls and expansion, and SQL macros. + +pub(crate) mod _helpers; +pub mod main; +pub mod models; +pub mod types; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_expansion.rs b/crates/sqlbuild-python-front/src/render/models.rs similarity index 59% rename from crates/sqlbuild-python/src/bindings/_helpers/render/macro_expansion.rs rename to crates/sqlbuild-python-front/src/render/models.rs index 2a38d11899..a350fc00b4 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/render/macro_expansion.rs +++ b/crates/sqlbuild-python-front/src/render/models.rs @@ -1,151 +1,312 @@ -//! One authored string's macro expansion: scanned, memoised, evaluated and spliced natively. - -use sqlbuild_python_base::positional_record; -use std::cell::RefCell; - -use pyo3::exceptions::{PyIndexError, PyValueError}; -use pyo3::prelude::{ - Bound, Py, PyAny, PyAnyMethods, PyErr, PyModule, PyModuleMethods, PyRef, PyResult, Python, -}; -use pyo3::types::{PyDict, PyDictMethods, PyList, PyString, PyStringMethods, PyTuple}; -use pyo3::{FromPyObject, pyclass, pymethods}; -use sqlbuild_analysis::sql_macros::constants::{BARE_MACRO_CALL_CODE, MIXED_KIND_CODE}; +//! Public records of render. + +use crate::render::_helpers::calls::macro_call_classes::CallClass; +use crate::render::_helpers::calls::macro_call_classes::ClassInputs; +use crate::render::_helpers::calls::macro_call_memo::MacroCallMemo; +use crate::render::_helpers::calls::macro_call_memo::poisoned; +use crate::render::_helpers::calls::macro_call_rows::span_row; +use crate::render::_helpers::calls::macro_call_rows::span_tuple; +use crate::render::_helpers::declarations::declaration_expansion::usage_visibility; +use crate::render::_helpers::declarations::declaration_values::constant_declaration_sql; +use crate::render::_helpers::expansion::macro_evaluation::CallText; +use crate::render::_helpers::expansion::macro_evaluation::Evaluation; +use crate::render::_helpers::expansion::macro_evaluation::macro_argument_error; +use crate::render::_helpers::expansion::macro_expansion::CONSTANT_KIND; +use crate::render::_helpers::expansion::macro_expansion::DECLARATION_FORMS; +use crate::render::_helpers::expansion::macro_expansion::ExpansionClasses; +use crate::render::_helpers::expansion::macro_expansion::ExpansionRow; +use crate::render::_helpers::expansion::macro_expansion::LEXICAL_SYNTAX_ATTRIBUTE; +use crate::render::_helpers::expansion::macro_expansion::RELATION_PREFIX; +use crate::render::_helpers::expansion::macro_expansion::RELATION_SUFFIX; +use crate::render::_helpers::expansion::macro_expansion::SQL_LANGUAGE; +use crate::render::_helpers::expansion::macro_expansion::UNREAD_CALL_HELP; +use crate::render::_helpers::expansion::macro_expansion::coded; +use crate::render::_helpers::expansion::macro_expansion::expanded; +use crate::render::_helpers::expansion::macro_expansion::observe_new_modules; +use crate::render::_helpers::expansion::macro_expansion::raised; +use crate::render::_helpers::expansion::macro_expansion::reference_call_text; +use crate::render::_helpers::expansion::macro_expansion::relationship_consumer; +use crate::render::_helpers::expansion::macro_expansion::resource_key; +use crate::render::_helpers::expansion::macro_expansion::result_has_markers; +use crate::render::_helpers::expansion::macro_expansion::sorted_names; +use crate::render::_helpers::expansion::macro_expansion::top_level_output; +use crate::render::_helpers::expansion::macro_expansion::unread_call_detail; +use crate::render::_helpers::expansion::macro_expansion::written_call; +use crate::render::_helpers::expansion::macro_expansion_facts::ExpansionFacts; +use crate::render::_helpers::expansion::macro_expansion_facts::ResourceRef; +use crate::render::_helpers::expansion::macro_generated_references::GeneratedOrigin; +use crate::render::_helpers::expansion::macro_generated_references::report_generated_references; +use crate::render::types::MacroScopes; +use crate::render::types::SpanRow; +use crate::render::types::StateTuple; +use crate::sqltext::main::optional_record_syntax::optional_record_syntax; +use crate::sqltext::models::ScannedReference; +use pyo3::FromPyObject; +use pyo3::exceptions::PyIndexError; +use pyo3::prelude::Bound; +use pyo3::prelude::Py; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyAnyMethods; +use pyo3::prelude::PyErr; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::pyclass; +use pyo3::pymethods; +use pyo3::types::PyDict; +use pyo3::types::PyDictMethods; +use pyo3::types::PyString; +use pyo3::types::PyStringMethods; +use pyo3::types::PyTuple; +use sqlbuild_analysis::compiled_project::models::SplicedSql; +use sqlbuild_analysis::sql_macros::constants::BARE_MACRO_CALL_CODE; +use sqlbuild_analysis::sql_macros::constants::MIXED_KIND_CODE; +use sqlbuild_analysis::sql_macros::models::SqlMacroCheck; +use sqlbuild_analysis::sql_macros::models::TypedCall; use sqlbuild_core::text::main::is_decimal_digit::is_decimal_digit; +use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; +use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_base::records::main::fields::field_text::field_text; +use sqlbuild_python_base::records::types::RecordId; use sqlbuild_render::macro_calls::errors::ScanError; -use sqlbuild_render::macro_calls::main::scan_macro_call_sites::scan_macro_call_sites as scan_sites; -use sqlbuild_render::macro_calls::main::splice_macro_calls::splice_macro_calls as splice_calls; -use sqlbuild_render::macro_calls::models::{ - MacroCallEntry, MacroCallEvent, MacroCallScan, MacroCallSite, MacroScanFailure, MacroSpliceSpan, -}; +use sqlbuild_render::macro_calls::models::MacroCallEntry; +use sqlbuild_render::macro_calls::models::MacroCallEvent; +use sqlbuild_render::macro_calls::models::MacroCallScan; +use sqlbuild_render::macro_calls::models::MacroCallSite; +use sqlbuild_render::macro_calls::models::MacroScanFailure; +use sqlbuild_render::macro_calls::models::MacroSpliceSpan; use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; +use std::cell::RefCell; -use crate::bindings::_helpers::render::declaration_expansion::usage_visibility; -use crate::bindings::_helpers::render::macro_call_classes::{CallClass, ClassInputs}; -use crate::bindings::_helpers::render::macro_call_memo::{MacroCallMemo, poisoned}; -use crate::bindings::_helpers::render::macro_call_rows::{SpanTuple, span_row, span_tuple}; -use crate::bindings::_helpers::render::macro_evaluation::{ - CallText, Evaluation, evaluate_call, macro_argument_error, -}; -use crate::bindings::_helpers::render::macro_expansion_facts::{ExpansionFacts, ResourceRef}; -use crate::bindings::_helpers::render::macro_generated_references::{ - GeneratedOrigin, GeneratedReferenceClasses, report_generated_references, -}; -use crate::bindings::_helpers::sqltext::lexical_syntax::optional_record_syntax; -use sqlbuild_python_base::records::main::construct::new_helped_error::new_helped_error; -use sqlbuild_python_base::records::main::fields::field::field as native_field; -use sqlbuild_python_base::records::main::fields::field_text::field_text; -use sqlbuild_python_base::records::types::ErrorId; - -const RELATION_PREFIX: &str = "__sqlbuild_relation_"; -const MEMO_ATTRIBUTE: &str = "memo"; -const LEXICAL_SYNTAX_ATTRIBUTE: &str = "_lexical_syntax"; -const OBSERVE_MODULES_METHOD: &str = "observe_modules"; -const RELATION_SUFFIX: &str = "__"; -const CONSTANT_KIND: &str = "constant"; -const RELATIONSHIP_CONSUMER_KINDS: [&str; 2] = ["test", "scenario"]; -const SQL_LANGUAGE: &str = "sql"; -const DECLARATION_FORMS: [&str; 3] = ["const", "enum", "param"]; -const UNREAD_CALL_HELP: &str = "Close every quote, block comment and parenthesis in the macro \ - call, and follow its name with its opening parenthesis"; - -/// Why the scan could not read the call `@{called}`, if the scan stopped inside a call. -fn unread_call_detail(error: ScanError, called: &str) -> Option { - let reason: String = match error { - ScanError::UnclosedQuote => format!("a quoted string in {called} is not closed"), - ScanError::UnclosedComment => format!("a block comment in {called} is not closed"), - ScanError::UnclosedParenthesis => format!("{called} is not closed with ')'"), - ScanError::MissingParenthesis => { - format!("{called} is not followed by its opening parenthesis") - } - ScanError::BareCall | ScanError::SqlCall => return None, - }; - Some(format!("could not be read: {reason}")) +/// Authored SQL expanded through vars, declarations and macros, with each pass's spans. +#[derive(Debug)] +pub struct AuthoredExpansion { + pub sql: String, + /// Interpolation, declaration and macro spans, in pass order. + pub passes: [Vec; 3], } -/// How a scanned call is written: `@py.name`, or `@const` and the other declaration forms. -fn written_call(name: &str) -> String { - if DECLARATION_FORMS.contains(&name) { - format!("@{name}") - } else { - format!("@py.{name}") - } +/// The inputs authored SQL is expanded with outside a compile; the handles carry user values. +#[derive(Debug)] +pub struct SqlExpansionInputs { + pub effective_vars: Py, + pub loaded_macros: Py, + pub macro_context: Py, + pub enums: Py, + pub constants: Py, + pub value_renderer: Py, + pub collection_rendering: Py, + /// Each model file's own declarations, by file path. + pub local_declarations: Py, + pub declaration_resolver: Py, } -positional_record! { - into; - /// `(sql, spans, argument references, dependencies, usages)` of one expansion. - struct ExpansionRow { - sql: String, - spans: Vec, - argument_references: Vec, - dependencies: Vec>, - usages: Vec>, +impl SqlExpansionInputs { + /// The inputs a `SqlExpansionContext` record holds. + pub fn from_record(record: &Bound<'_, PyAny>) -> PyResult { + let field = + |name: &str| -> PyResult> { Ok(native_field(record, name)?.unbind()) }; + Ok(Self { + effective_vars: field("effective_vars")?, + loaded_macros: field("loaded_macros")?, + macro_context: field("macro_context")?, + enums: field("enums")?, + constants: field("constants")?, + value_renderer: field("value_renderer")?, + collection_rendering: field("collection_rendering")?, + local_declarations: native_field(record, "local_declarations")? + .downcast_into::()? + .unbind(), + declaration_resolver: field("declaration_resolver")?, + }) + } + + /// These inputs as a `SqlExpansionContext` record. + pub fn record<'py>(&self, py: Python<'py>) -> PyResult> { + new_record_with( + py, + RecordId::SqlExpansionContext, + &[ + ("effective_vars", self.effective_vars.bind(py).clone()), + ("loaded_macros", self.loaded_macros.bind(py).clone()), + ("macro_context", self.macro_context.bind(py).clone()), + ("enums", self.enums.bind(py).clone()), + ("constants", self.constants.bind(py).clone()), + ("value_renderer", self.value_renderer.bind(py).clone()), + ( + "collection_rendering", + self.collection_rendering.bind(py).clone(), + ), + ( + "local_declarations", + self.local_declarations.bind(py).clone().into_any(), + ), + ( + "declaration_resolver", + self.declaration_resolver.bind(py).clone(), + ), + ], + ) } } -/// The Python classes, enums and helpers an expansion builds facts, errors and contexts from. -#[derive(FromPyObject)] +/// The Python classes expansion builds usages and errors from. +#[derive(Debug, FromPyObject)] #[pyo3(from_item_all)] -pub(crate) struct ExpansionClasses<'py> { - pub(crate) compile_error: Bound<'py, PyAny>, - pub(crate) macro_argument_error: Bound<'py, PyAny>, - mismatch_error: Bound<'py, PyAny>, - declaration_identity: Bound<'py, PyAny>, - declaration_kind: Bound<'py, PyAny>, - macro_kind: Bound<'py, PyAny>, - usage_record: Bound<'py, PyAny>, - runtime_usage: Bound<'py, PyAny>, - resource_identity: Bound<'py, PyAny>, - model_kind: Bound<'py, PyAny>, - pub(crate) resource_ref: Bound<'py, PyAny>, - /// `SqlResourceRefKind` member by typed reference function, such as `__ref`. - pub(crate) ref_kinds: Bound<'py, PyDict>, - /// Typed reference function by `SqlResourceRefKind` value. - ref_functions: Bound<'py, PyDict>, - pub(crate) relation_renderer: Bound<'py, PyAny>, - /// Builds the `MacroContext` a macro is called with from the visible declarations. - pub(crate) invocation_context: Bound<'py, PyAny>, - /// What reference calls a macro returned are reported with. - generated: GeneratedReferenceClasses<'py>, - pub(crate) int_type: Bound<'py, PyAny>, - pub(crate) float_type: Bound<'py, PyAny>, +pub struct DeclarationExpansionClasses<'py> { + pub usage_record: Bound<'py, PyAny>, + pub compile_error: Bound<'py, PyAny>, +} + +/// Who reads the declarations, whether it prefers relationship visibility, and its error path. +#[derive(Debug, Clone)] +pub struct ExpansionConsumer<'a, 'py> { + pub identity: Option>, + pub relationship_visibility: bool, + pub path: &'a str, +} + +/// One expansion: the SQL, its scan, the visible declarations and the adapter's constant rendering. +#[derive(Debug)] +pub struct DeclarationExpansion<'a, 'py> { + pub sql: &'a str, + pub references: &'a [ScannedReference], + pub stop: Option, + pub context: &'a Bound<'py, PyAny>, + pub consumer: ExpansionConsumer<'a, 'py>, + pub rendering: &'a ConstantRendering, + pub classes: &'a DeclarationExpansionClasses<'py>, + /// What SQL macro calls read beyond the context; `None` where SQL macros are not expanded. + pub sql_macros: Option>, +} + +/// The expanded SQL with its spans, and the crate::render::_helpers::declarations::declaration_expansion::usage records it adds in reference order. +#[derive(Debug)] +pub struct ExpandedDeclarations<'py> { + pub spliced: SplicedSql, + pub usages: Vec>, + /// The SQL macros the SQL called, top-level and nested, once each. + pub sql_macros: Vec, + /// What the analysed SQL must show for each top-level call's arguments to fit. + pub sql_macro_checks: Vec, + /// Each expression macro call in the spliced SQL, by byte range. + pub typed_calls: Vec, +} + +/// The adapter's constant rendering a compile's declaration expansions share. +#[pyclass(module = "sqlbuild._native", frozen)] +#[derive(Debug)] +pub struct ConstantRendering { + pub(crate) value_renderer: Py, + pub(crate) collection_rendering: Py, +} + +impl ConstantRendering { + /// Rendering with the adapter's value renderer and the project's collection rendering. + pub fn new(value_renderer: Py, collection_rendering: Py) -> Self { + Self { + value_renderer, + collection_rendering, + } + } + + /// The adapter name the value renderer renders for, empty when it names none. + pub fn adapter_name(&self, py: Python<'_>) -> String { + native_field(self.value_renderer.bind(py), "adapter_name") + .and_then(|name| name.extract::()) + .unwrap_or_default() + } + + /// The SQL analysis dialect of the adapter the value renderer renders for, if it has one. + pub fn analysis_dialect(&self, py: Python<'_>) -> PyResult> { + native_field(self.value_renderer.bind(py), "sql_analysis_dialect_name")?.extract() + } + + /// One visible constant as SQL, its failures located at `file_path`. + pub fn render(&self, declaration: &Bound<'_, PyAny>, file_path: &str) -> PyResult { + let py: Python<'_> = declaration.py(); + constant_declaration_sql( + declaration, + self.value_renderer.bind(py), + (self.collection_rendering.bind(py), Some(file_path)), + ) + } +} + +/// A span as the tuple Python reads: source start and end, output start and end. +#[derive(Debug)] +pub struct SpanTuple { + pub source_start: usize, + pub source_end: usize, + pub output_start: usize, + pub output_end: usize, +} + +impl<'py> pyo3::IntoPyObject<'py> for SpanTuple { + type Target = pyo3::types::PyTuple; + type Output = pyo3::Bound<'py, pyo3::types::PyTuple>; + type Error = pyo3::PyErr; + + fn into_pyobject(self, py: pyo3::Python<'py>) -> Result { + pyo3::IntoPyObject::into_pyobject( + ( + self.source_start, + self.source_end, + self.output_start, + self.output_end, + ), + py, + ) + } } /// One authored string's expansion inputs and the facts it records. #[pyclass(module = "sqlbuild._native", unsendable)] -pub(crate) struct NativeMacroExpansion { - pub(crate) file_path: Py, - pub(crate) file_label: String, - pub(crate) loaded_macros: Py, - pub(crate) overrides: Py, - pub(crate) macro_context: Py, +#[derive(Debug)] +pub struct NativeMacroExpansion { + pub file_path: Py, + pub file_label: String, + pub loaded_macros: Py, + pub overrides: Py, + pub macro_context: Py, /// The visible `DeclarationResolutionContext`, or `None`. - pub(crate) declarations: Py, + pub declarations: Py, /// The consumer usages are recorded for, or `None`. - pub(crate) consumer: Py, - enforce_explicit: bool, - classes: Py, + pub consumer: Py, + pub(crate) enforce_explicit: bool, + pub(crate) classes: Py, pub(crate) facts: RefCell, /// The lexical rules the authored SQL is written in, from the macro context, if it has them. - pub(crate) syntax: Option, + pub syntax: Option, } -positional_record! { - extract; - /// The `(macros, overrides, context, declarations, consumer)` one expansion reads. - pub(crate) struct StateInput { - pub(crate) loaded_macros: Py, - pub(crate) overrides: Py, - pub(crate) macro_context: Py, - pub(crate) declarations: Py, - pub(crate) consumer: Py, +/// The `(macros, overrides, context, declarations, consumer)` one expansion reads. +#[derive(Debug)] +pub struct StateInput { + pub loaded_macros: Py, + pub overrides: Py, + pub macro_context: Py, + pub declarations: Py, + pub consumer: Py, +} + +impl<'py> pyo3::FromPyObject<'py> for StateInput { + fn extract_bound(value: &pyo3::Bound<'py, pyo3::PyAny>) -> pyo3::PyResult { + let (loaded_macros, overrides, macro_context, declarations, consumer): StateTuple = + pyo3::types::PyAnyMethods::extract(value)?; + Ok(Self { + loaded_macros, + overrides, + macro_context, + declarations, + consumer, + }) } } #[pymethods] impl NativeMacroExpansion { #[new] - pub(crate) fn new( + pub fn new( file_path: &Bound<'_, PyAny>, state: StateInput, enforce_explicit: bool, @@ -180,7 +341,7 @@ impl NativeMacroExpansion { } /// Expand `sql`, through the bridge's memo when one is active. - fn expand<'py>( + pub(crate) fn expand<'py>( slf: &Bound<'py, Self>, sql: &Bound<'py, PyString>, bridge: &Bound<'py, PyAny>, @@ -200,7 +361,7 @@ impl NativeMacroExpansion { } /// `render_relation`: an approved call-site reference's placeholder, else its reference call. - fn render_relation(&self, reference: &Bound<'_, PyAny>) -> PyResult { + pub(crate) fn render_relation(&self, reference: &Bound<'_, PyAny>) -> PyResult { let py: Python<'_> = reference.py(); let classes: ExpansionClasses<'_> = self.classes.bind(py).extract()?; if !reference.is_instance(&classes.resource_ref)? { @@ -218,20 +379,20 @@ impl NativeMacroExpansion { } /// `_record_macro_declaration_usage`: a macro read a constant or enum through its context. - fn declaration_read(&self, kind: &str, name: &str, py: Python<'_>) -> PyResult<()> { + pub(crate) fn declaration_read(&self, kind: &str, name: &str, py: Python<'_>) -> PyResult<()> { let classes: ExpansionClasses<'_> = self.classes.bind(py).extract()?; self.record_declaration_read(&classes, kind, name) } /// Mark the executing call as dependent on its consumer, so it is never replayed. - fn block_memo(&self) { + pub(crate) fn block_memo(&self) { self.facts.borrow_mut().block_memo(); } } impl NativeMacroExpansion { /// Each site's call class, or `None` when the scan failed or a tree name is unresolvable. - fn call_classes<'py>( + pub(crate) fn call_classes<'py>( &self, classes: &ExpansionClasses<'py>, memo: &MacroCallMemo, @@ -261,7 +422,7 @@ impl NativeMacroExpansion { } /// `_bridged_call_output`: a recorded call replayed, or the call evaluated and recorded. - fn bridged_output<'py>( + pub(crate) fn bridged_output<'py>( &self, run: &Evaluation<'_, 'py>, bridge: (&Bound<'py, PyAny>, &MacroCallMemo), @@ -324,7 +485,7 @@ impl NativeMacroExpansion { } /// `_unmemoised_sql_macros`: every call evaluated in order, then the scan's failure raised. - fn unmemoised_outputs( + pub(crate) fn unmemoised_outputs( &self, run: &Evaluation<'_, '_>, text: &CallText<'_>, @@ -340,7 +501,7 @@ impl NativeMacroExpansion { Ok(outputs) } - fn evaluated_output( + pub(crate) fn evaluated_output( &self, run: &Evaluation<'_, '_>, call: (&CallText<'_>, &MacroCallSite), @@ -350,7 +511,7 @@ impl NativeMacroExpansion { } /// Whether a test overrides any macro in the call's tree. - fn mocked(&self, site: &MacroCallSite, py: Python<'_>) -> PyResult { + pub(crate) fn mocked(&self, site: &MacroCallSite, py: Python<'_>) -> PyResult { let overrides: &Bound<'_, PyDict> = self.overrides.bind(py); for name in site.tree_names.iter().flatten() { if overrides.contains(name)? { @@ -478,7 +639,7 @@ impl NativeMacroExpansion { Err(raised(&classes.compile_error, &message)) } - /// `_record_macro_use`: the macro's dependency and its runtime usage by the consumer. + /// `_record_macro_use`: the macro's dependency and its runtime crate::render::_helpers::expansion::macro_expansion::usage by the consumer. pub(crate) fn record_macro_use<'py>( &self, classes: &ExpansionClasses<'py>, @@ -508,7 +669,7 @@ impl NativeMacroExpansion { let mut usages: Vec> = Vec::new(); for visible in usage_visibility(&visibility, relationship_consumer(classes, consumer)?)? { - usages.push(usage( + usages.push(crate::render::_helpers::expansion::macro_expansion::usage( classes, (consumer, identity), Some(&native_field(&visible, "through")?), @@ -516,7 +677,11 @@ impl NativeMacroExpansion { } usages } else { - vec![usage(classes, (consumer, identity), None)?] + vec![crate::render::_helpers::expansion::macro_expansion::usage( + classes, + (consumer, identity), + None, + )?] }; self.facts .borrow_mut() @@ -526,7 +691,7 @@ impl NativeMacroExpansion { } /// `_record_macro_declaration_usage` for a constant or enum the macro read. - fn record_declaration_read( + pub(crate) fn record_declaration_read( &self, classes: &ExpansionClasses<'_>, kind: &str, @@ -562,7 +727,7 @@ impl NativeMacroExpansion { for visible in usage_visibility(&visibility, relationship_consumer(classes, &consumer)?)? { - usages.push(usage( + usages.push(crate::render::_helpers::expansion::macro_expansion::usage( classes, (&consumer, &native_field(&visible, "declaration")?), Some(&native_field(&visible, "through")?), @@ -587,7 +752,11 @@ impl NativeMacroExpansion { fields.set_item("owner", owner)?; let identity: Bound<'_, PyAny> = classes.declaration_identity.call((), Some(&fields))?; - usages.push(usage(classes, (&consumer, &identity), None)?); + usages.push(crate::render::_helpers::expansion::macro_expansion::usage( + classes, + (&consumer, &identity), + None, + )?); } self.facts .borrow_mut() @@ -622,7 +791,11 @@ impl NativeMacroExpansion { } /// `_replay_macro_call_event`: one recorded fact, recorded again for this consumer. - fn replay(&self, classes: &ExpansionClasses<'_>, event: MacroCallEvent) -> PyResult<()> { + pub(crate) fn replay( + &self, + classes: &ExpansionClasses<'_>, + event: MacroCallEvent, + ) -> PyResult<()> { let py: Python<'_> = classes.compile_error.py(); match event { MacroCallEvent::MacroUse { name } => { @@ -681,7 +854,11 @@ impl NativeMacroExpansion { } /// `render_relation_placeholders`: each placeholder as the reference call it stands for. - fn render_placeholders(&self, classes: &ExpansionClasses<'_>, sql: &str) -> PyResult { + pub(crate) fn render_placeholders( + &self, + classes: &ExpansionClasses<'_>, + sql: &str, + ) -> PyResult { let relations: Vec = self.facts.borrow().relations.clone(); if relations.is_empty() || !sql.contains(RELATION_PREFIX) { return Ok(sql.to_owned()); @@ -718,188 +895,55 @@ impl NativeMacroExpansion { } /// One expansion's SQL, substitution spans, call-site references, dependencies and usages. -pub(crate) struct ExpansionOutput { - pub(crate) sql: String, - pub(crate) spans: Vec, - pub(crate) argument_references: Vec, - pub(crate) dependencies: Vec>, - pub(crate) usages: Vec>, +#[derive(Debug)] +pub struct ExpansionOutput { + pub sql: String, + pub spans: Vec, + pub argument_references: Vec, + pub dependencies: Vec>, + pub usages: Vec>, } -/// Expand `sql` with the expansion's inputs, through the bridge's memo when one is active. -pub(crate) fn expanded<'py>( - expansion: &Bound<'py, NativeMacroExpansion>, - sql: &str, - bridge: &Bound<'py, PyAny>, -) -> PyResult { - let py: Python<'py> = expansion.py(); - let this: PyRef<'py, NativeMacroExpansion> = expansion.borrow(); - let classes: ExpansionClasses<'py> = this.classes.bind(py).extract()?; - let handle: Bound<'py, PyAny> = expansion.as_any().clone(); - let run: Evaluation<'_, 'py> = Evaluation { - expansion: &this, - handle: &handle, - classes: &classes, - }; - let text: CallText<'_> = CallText::new(sql); - let scan: MacroCallScan = scan_sites(text.text, this.syntax.as_ref()); - let memo: Option> = if bridge.is_none() { - None - } else { - Some(bridge.getattr(MEMO_ATTRIBUTE)?.downcast_into()?) - }; - let call_classes: Option> = match &memo { - Some(memo) => this.call_classes(&classes, memo.get(), &scan)?, - None => None, - }; - let outputs: Vec = match (call_classes, &memo) { - (Some(call_classes), Some(memo)) => { - let mut outputs: Vec = Vec::with_capacity(scan.sites.len()); - for (site, call_class) in scan.sites.iter().zip(call_classes) { - outputs.push(this.bridged_output( - &run, - (bridge, memo.get()), - (&text, site), - &call_class, - )?); - } - outputs - } - _ => this.unmemoised_outputs(&run, &text, &scan)?, - }; - let bounds: Vec<(usize, usize)> = scan - .sites - .iter() - .map(|site| (site.start, site.end)) - .collect(); - let (rendered, spans) = splice_calls(text.text, &bounds, &outputs) - .ok_or_else(|| PyValueError::new_err("macro call sites do not fit the SQL"))?; - let facts = this.facts.borrow(); - Ok(ExpansionOutput { - sql: rendered, - spans, - argument_references: facts.argument_references.clone(), - dependencies: facts - .dependencies - .iter() - .map(|item| item.clone_ref(py)) - .collect(), - usages: facts.usages.iter().map(|item| item.clone_ref(py)).collect(), - }) -} - -/// One top-level call's SQL. -fn top_level_output( - run: &Evaluation<'_, '_>, - call: (&CallText<'_>, &MacroCallSite), -) -> PyResult { - evaluate_call(run, call, true)?.extract() -} - -/// A `SqlResourceRef`'s kind value and name. -pub(crate) fn resource_key(reference: &Bound<'_, PyAny>) -> PyResult { - Ok(( - native_field(&native_field(reference, "kind")?, "value")?.extract()?, - native_field(reference, "name")?.extract()?, - )) -} - -/// `reference_call_text`: the reference call naming `reference`, such as `__ref("orders")`. -fn reference_call_text( - classes: &ExpansionClasses<'_>, - reference: &ResourceRef, -) -> PyResult { - let (kind, name) = reference; - let function: String = classes - .ref_functions - .get_item(kind)? - .ok_or_else(|| PyErr::new::(kind.clone()))? - .extract()?; - Ok(format!("{function}(\"{name}\")")) -} - -/// Whether the consumer is a test or scenario, which records relationship visibility. -fn relationship_consumer( - classes: &ExpansionClasses<'_>, - consumer: &Bound<'_, PyAny>, -) -> PyResult { - if !consumer.is_instance(&classes.resource_identity)? { - return Ok(false); - } - let kind: String = native_field(&native_field(consumer, "kind")?, "value")?.extract()?; - Ok(RELATIONSHIP_CONSUMER_KINDS.contains(&kind.as_str())) -} - -/// A runtime `UsageRecord` of `declaration` by `consumer`, through a relationship if any. -fn usage<'py>( - classes: &ExpansionClasses<'py>, - usage: (&Bound<'py, PyAny>, &Bound<'py, PyAny>), - through: Option<&Bound<'py, PyAny>>, -) -> PyResult> { - let (consumer, declaration) = usage; - let keywords: Bound<'py, PyDict> = PyDict::new(consumer.py()); - if let Some(through) = through { - keywords.set_item("through", through)?; - } - classes.usage_record.call( - (consumer, declaration, &classes.runtime_usage), - Some(&keywords), - ) -} - -/// `", ".join(sorted(names)) or "none"`. -fn sorted_names(names: &Bound<'_, PyAny>) -> PyResult { - let mut sorted: Vec = - PyList::new(names.py(), names.try_iter()?.collect::>>()?)?.extract()?; - sorted.sort_unstable(); - Ok(if sorted.is_empty() { - "none".to_owned() - } else { - sorted.join(", ") - }) -} - -/// The `CompileInputError(message, code=code, help=help)` the classes' compile error builds. -fn coded(class: &Bound<'_, PyAny>, message: &str, (code, help): (&str, &str)) -> PyErr { - new_helped_error( - class.py(), - ErrorId::CompileInput, - (message.to_owned(), code), - Some(help), - ) -} - -/// The exception `class(message)` builds. -pub(crate) fn raised(class: &Bound<'_, PyAny>, message: &str) -> PyErr { - match class.call1((message,)) { - Ok(instance) => PyErr::from_value(instance), - Err(error) => error, - } +/// One expansion's inputs, as Python's `expand_sql_macros_result` takes them. +#[derive(Debug)] +pub struct ExpansionRequest<'py> { + pub sql: Bound<'py, PyString>, + pub file_path: Bound<'py, PyAny>, + pub loaded_macros: Bound<'py, PyDict>, + pub macro_overrides: Option>, + pub macro_context: Bound<'py, PyAny>, + pub declaration_resolver: Option>, + pub declarations: Option>, + pub consumer: Option>, } -pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { - module.add_class::()?; - Ok(()) +/// Where the caller's text came from, to locate calls in its authored file. +#[derive(Debug, Clone, Copy)] +pub struct SqlCallOrigin<'a> { + /// The authored file's project-relative path. + pub relative_path: &'a str, + /// The authored file's contents. + pub contents: &'a str, + /// The authored query the expanded text came from, within `contents`. + pub query: &'a str, } -/// Whether a macro's result calls any reference function. -fn result_has_markers(classes: &ExpansionClasses<'_>, result: &str) -> bool { - classes - .generated - .markers() - .any(|marker| result.contains(marker)) +/// What SQL macro calls in one declaration pass read beyond the declaration context. +#[derive(Clone, Copy)] +pub struct SqlMacroSource<'a, 'py> { + /// Every loaded macro by name, for unscoped compiles whose context holds none. + pub loaded_macros: Option<&'a Bound<'py, PyAny>>, + pub origin: Option>, + /// Where macro bodies resolve their declarations; `None` outside the input loops. + pub scopes: Option<&'a dyn MacroScopes<'py>>, + /// The lexical rules the authored SQL is written in; `None` reads it under the generic rules. + pub syntax: Option<&'a LexicalSyntax>, } -/// Observe modules a recorded call imported, so the store is not saved over changed code. -fn observe_new_modules(bridge: &Bound<'_, PyAny>, memo: &MacroCallMemo) -> PyResult<()> { - let Some(observed) = *memo.observed_modules.lock().map_err(poisoned)? else { - return Ok(()); - }; - let loaded: usize = PyModule::import(bridge.py(), "sys")? - .getattr("modules")? - .len()?; - if loaded != observed { - let _ = bridge.call_method0(OBSERVE_MODULES_METHOD)?; +impl std::fmt::Debug for SqlMacroSource<'_, '_> { + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + formatter + .debug_struct("SqlMacroSource") + .finish_non_exhaustive() } - Ok(()) } diff --git a/crates/sqlbuild-python-front/src/render/types.rs b/crates/sqlbuild-python-front/src/render/types.rs new file mode 100644 index 0000000000..d56caa2878 --- /dev/null +++ b/crates/sqlbuild-python-front/src/render/types.rs @@ -0,0 +1,20 @@ +//! Public traits and type aliases of render. + +use pyo3::prelude::Bound; +use pyo3::prelude::Py; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyDict; +use sqlbuild_sqltext::compiler::models::CharSpan; + +/// One substitution span: source start and end, output start and end. +pub type SpanRow = CharSpan; + +/// The `(macros, overrides, context, declarations, consumer)` tuple Python passes one expansion. +pub type StateTuple = (Py, Py, Py, Py, Py); + +/// The declaration contexts of macro files in a scoped compile. +pub trait MacroScopes<'py> { + /// The context the file at `path` sees, or `None` when the compile is unscoped. + fn file_context(&self, path: &str) -> PyResult>>; +} diff --git a/crates/sqlbuild-python-front/src/scopes/_helpers/checks/mod.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/checks/mod.rs new file mode 100644 index 0000000000..62be446495 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/checks/mod.rs @@ -0,0 +1,3 @@ +pub(crate) mod scope_tolerant; +pub(crate) mod scope_validation; +pub(crate) mod scope_visibility; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_tolerant.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/checks/scope_tolerant.rs similarity index 94% rename from crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_tolerant.rs rename to crates/sqlbuild-python-front/src/scopes/_helpers/checks/scope_tolerant.rs index 97f2dde9f2..6f05103216 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_tolerant.rs +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/checks/scope_tolerant.rs @@ -8,10 +8,14 @@ use sqlbuild_scopes::scope_index::models::{ OwnershipRoot, OwnershipRootKind, ResourceIdentity, ResourceKind, ResourceRecord, }; -use crate::bindings::_helpers::scopes::scope_objects::{ - ScopeClasses, enum_text, field, optional_item, read_resource, root_object, tuple_attribute, -}; -use crate::bindings::_helpers::scopes::scope_validation::replace; +use crate::scopes::_helpers::checks::scope_validation::replace; +use crate::scopes::_helpers::index::scope_objects::enum_text; +use crate::scopes::_helpers::index::scope_objects::field; +use crate::scopes::_helpers::index::scope_objects::optional_item; +use crate::scopes::_helpers::index::scope_objects::read_resource; +use crate::scopes::_helpers::index::scope_objects::root_object; +use crate::scopes::_helpers::index::scope_objects::tuple_attribute; +use crate::scopes::models::ScopeClasses; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_validation.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/checks/scope_validation.rs similarity index 93% rename from crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_validation.rs rename to crates/sqlbuild-python-front/src/scopes/_helpers/checks/scope_validation.rs index dbbc0fd927..ab84f15f4d 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_validation.rs +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/checks/scope_validation.rs @@ -14,14 +14,23 @@ use sqlbuild_scopes::placement::models::{ }; use sqlbuild_scopes::scope_index::models::ResourceIdentity; -use crate::bindings::_helpers::scopes::compile_usages::{ - MergeRows, SourceRow, merged_usage_rows, model_schema_scope_usages, -}; -use crate::bindings::_helpers::scopes::placement::{QualifiedRow, resource_identity}; -use crate::bindings::_helpers::scopes::scope_objects::{ - ScopeClasses, enum_text, field, identity_row, optional_item, qualified_row, read_completeness, - read_placement_index, root_object, tuple_attribute, value_of, -}; +use crate::scopes::_helpers::declarations::placement::QualifiedRow; +use crate::scopes::_helpers::declarations::placement::resource_identity; +use crate::scopes::_helpers::index::scope_objects::enum_text; +use crate::scopes::_helpers::index::scope_objects::field; +use crate::scopes::_helpers::index::scope_objects::identity_row; +use crate::scopes::_helpers::index::scope_objects::optional_item; +use crate::scopes::_helpers::index::scope_objects::qualified_row; +use crate::scopes::_helpers::index::scope_objects::read_completeness; +use crate::scopes::_helpers::index::scope_objects::read_placement_index; +use crate::scopes::_helpers::index::scope_objects::root_object; +use crate::scopes::_helpers::index::scope_objects::tuple_attribute; +use crate::scopes::_helpers::index::scope_objects::value_of; +use crate::scopes::_helpers::relationships::compile_usages::MergeRows; +use crate::scopes::_helpers::relationships::compile_usages::SourceRow; +use crate::scopes::_helpers::relationships::compile_usages::merged_usage_rows; +use crate::scopes::_helpers::relationships::compile_usages::model_schema_scope_usages; +use crate::scopes::models::ScopeClasses; use sqlbuild_python_base::boundary::main::compiler_error::compiler_error; use sqlbuild_python_base::records::main::construct::enum_member::enum_member; use sqlbuild_python_base::records::main::construct::error_class::error_class; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_visibility.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/checks/scope_visibility.rs similarity index 94% rename from crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_visibility.rs rename to crates/sqlbuild-python-front/src/scopes/_helpers/checks/scope_visibility.rs index 417516cccb..ba33e6ec00 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_visibility.rs +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/checks/scope_visibility.rs @@ -11,12 +11,14 @@ use sqlbuild_scopes::scope_index::models::{ OwnershipRoot, OwnershipRootKind, RejectedPath, ResourceIdentity, ResourceKind, ResourceRecord, }; -use crate::bindings::_helpers::scopes::scope_lookup::{ - NativeScopeLookup, ResolvedRows, TargetRows, scope_path_error, -}; -use crate::bindings::_helpers::scopes::scope_objects::{ - ScopeClasses, qualified_row, read_resource, tuple_attribute, -}; +use crate::scopes::_helpers::index::scope_lookup::NativeScopeLookup; +use crate::scopes::_helpers::index::scope_lookup::ResolvedRows; +use crate::scopes::_helpers::index::scope_lookup::TargetRows; +use crate::scopes::_helpers::index::scope_lookup::scope_path_error; +use crate::scopes::_helpers::index::scope_objects::qualified_row; +use crate::scopes::_helpers::index::scope_objects::read_resource; +use crate::scopes::_helpers::index::scope_objects::tuple_attribute; +use crate::scopes::models::ScopeClasses; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; diff --git a/crates/sqlbuild-python-front/src/scopes/_helpers/declarations/declaration_contexts.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/declarations/declaration_contexts.rs new file mode 100644 index 0000000000..fafbf520b4 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/declarations/declaration_contexts.rs @@ -0,0 +1,66 @@ +//! Declaration resolution contexts built natively from a Python scope lookup's positions. + +use crate::scopes::models::NativeDeclarationContexts; +use std::collections::HashMap; + +use pyo3::FromPyObject; +use pyo3::prelude::{Bound, Py, PyAny, PyModule, PyModuleMethods, PyResult}; +use pyo3::types::PyDict; + +use sqlbuild_scopes::scope_index::models::VisibleEntry; + +pub(crate) const ENUM_KIND: u8 = 0; +pub(crate) const CONSTANT_KIND: u8 = 1; +pub(crate) const MACRO_KIND: u8 = 2; + +pub(crate) type TableRow = ( + Vec, + HashMap>, + HashMap>, +); +pub(crate) type VisibleRow<'py> = (Bound<'py, PyAny>, VisibleEntry, Option>); + +/// One declaration position: identity, first record, name, kinds, runtime value and key. +#[derive(Debug, FromPyObject)] +pub(crate) struct PositionRow( + pub(crate) Py, + pub(crate) Py, + pub(crate) Py, + pub(crate) u8, + pub(crate) Py, + pub(crate) u8, + pub(crate) u32, +); + +/// The Python classes and enum members the contexts are built from. +#[derive(Debug, FromPyObject)] +#[pyo3(from_item_all)] +pub(crate) struct ContextClasses { + pub(crate) visibility_record: Py, + pub(crate) resolution_context: Py, + pub(crate) reasons: Py, +} + +/// The Python lookup mappings a matching resource's private positions and grants come from. +#[derive(Debug, FromPyObject)] +#[pyo3(from_item_all)] +pub(crate) struct LookupMappings { + pub(crate) identity_keys: Py, + pub(crate) private_positions: Py, + pub(crate) grants_by_resource: Py, +} + +/// Dictionaries one context is assembled into, in Python's insertion order. +pub(crate) struct ContextParts<'py> { + pub(crate) enums: Bound<'py, PyDict>, + pub(crate) constants: Bound<'py, PyDict>, + pub(crate) macros: Bound<'py, PyDict>, + pub(crate) macro_records: Bound<'py, PyDict>, + pub(crate) inaccessible: [Bound<'py, PyDict>; 3], + pub(crate) visibility: [Bound<'py, PyDict>; 3], +} + +pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { + module.add_class::()?; + Ok(()) +} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/declaration_resolution.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/declarations/declaration_resolution.rs similarity index 98% rename from crates/sqlbuild-python/src/bindings/_helpers/scopes/declaration_resolution.rs rename to crates/sqlbuild-python-front/src/scopes/_helpers/declarations/declaration_resolution.rs index 0915a43d9a..30e3caf6b2 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scopes/declaration_resolution.rs +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/declarations/declaration_resolution.rs @@ -13,7 +13,7 @@ use sqlbuild_scopes::scope_index::models::{ DeclarationIdentity, IdentityFailure, QualifiedIdentity, ResourceIdentity, ScopePathFailure, }; -use crate::bindings::_helpers::scopes::declaration_contexts::NativeDeclarationContexts; +use crate::scopes::models::NativeDeclarationContexts; use sqlbuild_python_base::records::main::fields::field::field as native_field; const PATH_CACHE_PREFIX: &str = ""; @@ -26,7 +26,7 @@ const PATH_RESOURCE_SUFFIX: &str = ">"; const MODEL_KIND: &str = "model"; /// The lookup mappings and classes resolution reads beyond the classifier's own. -#[derive(FromPyObject)] +#[derive(Debug, FromPyObject)] #[pyo3(from_item_all)] pub(crate) struct ResolutionInputs { resources_by_path: Py, @@ -49,7 +49,7 @@ type Matches<'py> = (Vec>, Bound<'py, PyAny>); impl NativeDeclarationContexts { /// The context of `file_path` or `resource`, and whether it was projected rather than cached. - pub(crate) fn resolved_context<'py>( + pub fn resolved_context<'py>( &self, resolver: &Bound<'py, PyAny>, file_path: &str, @@ -271,7 +271,7 @@ impl NativeDeclarationContexts { } /// `_rebind_declaration_context`: fresh mappings, visibility rebound to `consumer`. - pub(crate) fn rebound_context<'py>( + pub fn rebound_context<'py>( &self, context: &Bound<'py, PyAny>, consumer: &Bound<'py, PyAny>, @@ -294,7 +294,7 @@ impl NativeDeclarationContexts { } /// `_rebind_visibility`: each record with `consumer` as its resource. - pub(crate) fn rebound_visibility<'py>( + pub fn rebound_visibility<'py>( &self, records_by_name: &Bound<'py, PyDict>, consumer: &Bound<'py, PyAny>, diff --git a/crates/sqlbuild-python-front/src/scopes/_helpers/declarations/mod.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/declarations/mod.rs new file mode 100644 index 0000000000..d8ddc87120 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/declarations/mod.rs @@ -0,0 +1,3 @@ +pub(crate) mod declaration_contexts; +pub(crate) mod declaration_resolution; +pub(crate) mod placement; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/placement.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/declarations/placement.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/scopes/placement.rs rename to crates/sqlbuild-python-front/src/scopes/_helpers/declarations/placement.rs diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/getters.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/index/getters.rs similarity index 62% rename from crates/sqlbuild-python/src/bindings/_helpers/scopes/getters.rs rename to crates/sqlbuild-python-front/src/scopes/_helpers/index/getters.rs index 7e5c5fbda2..78500096a1 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scopes/getters.rs +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/index/getters.rs @@ -3,17 +3,9 @@ use pyo3::IntoPyObjectExt; use pyo3::prelude::{Bound, PyAny, PyResult, Python}; -use crate::bindings::_helpers::scopes::scope_index::NativeScopeIndex; -use sqlbuild_python_base::records::main::registry::class_of::class_of; -use sqlbuild_python_base::records::models::GetterEntry; +use crate::scopes::models::NativeScopeIndex; -/// The getter readers of this module's native pyclasses. -pub(crate) const GETTERS: &[GetterEntry] = &[GetterEntry { - class: class_of::, - read: read_native_scope_index, -}]; - -fn read_native_scope_index<'py>( +pub(crate) fn read_native_scope_index<'py>( value: &Bound<'py, PyAny>, name: &str, ) -> Option>> { diff --git a/crates/sqlbuild-python-front/src/scopes/_helpers/index/mod.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/index/mod.rs new file mode 100644 index 0000000000..6b74563908 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/index/mod.rs @@ -0,0 +1,5 @@ +pub(crate) mod getters; +pub(crate) mod scope_cache; +pub(crate) mod scope_index; +pub(crate) mod scope_lookup; +pub(crate) mod scope_objects; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_cache.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_cache.rs similarity index 94% rename from crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_cache.rs rename to crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_cache.rs index 548b55dc52..83357b83b3 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_cache.rs +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_cache.rs @@ -12,9 +12,10 @@ use sqlbuild_scopes::scope_cache::main::scope_fingerprint::scope_fingerprint; use sqlbuild_scopes::scope_cache::main::write_scope_cache::write_scope_cache; use sqlbuild_scopes::scope_cache::models::{CachedIndex, Fingerprint, FingerprintInputs}; -use crate::bindings::_helpers::scopes::scope_objects::{ - ScopeClasses, index_object, read_completeness, read_index, -}; +use crate::scopes::_helpers::index::scope_objects::index_object; +use crate::scopes::_helpers::index::scope_objects::read_completeness; +use crate::scopes::_helpers::index::scope_objects::read_index; +use crate::scopes::models::ScopeClasses; use sqlbuild_python_base::boundary::main::compiler_error::compiler_error; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::types::CompilerDetach; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_index.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_index.rs similarity index 85% rename from crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_index.rs rename to crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_index.rs index 77138e1ed1..1716405bb2 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_index.rs +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_index.rs @@ -1,5 +1,6 @@ //! The static scope index built natively from discovered inputs, as the Python scope models. +use crate::scopes::models::NativeScopeIndex; use std::collections::HashMap; use pyo3::exceptions::PyKeyError; @@ -7,28 +8,26 @@ use pyo3::prelude::{ Bound, Py, PyAny, PyAnyMethods, PyErr, PyModule, PyModuleMethods, PyResult, Python, }; use pyo3::types::{PyDict, PyDictMethods, PyTuple}; -use pyo3::{IntoPyObjectExt, pyclass, pyfunction, pymethods, wrap_pyfunction}; -use sqlbuild_scopes::relationship_names::models::RelationshipScan; +use pyo3::{IntoPyObjectExt, pyfunction, wrap_pyfunction}; use sqlbuild_scopes::scope_index::main::build_scope_index::build_scope_index; use sqlbuild_scopes::scope_index::main::macro_source_digest::macro_source_digest; use sqlbuild_scopes::scope_index::main::normalize_scope_path::normalize_scope_path; use sqlbuild_scopes::scope_index::main::rejected_path_message::rejected_path_message; -use sqlbuild_scopes::scope_index::main::relationship_grants::relationship_grants; use sqlbuild_scopes::scope_index::models::{ - DeclarationIdentity, DeclarationInput, DeclarationKind, GrantRecord, GrantThrough, - RejectedPath, RelationshipFact, ResourceIdentity, ResourceInput, ResourceKind, ResourceRoot, - ScopeDeferral, ScopeIndex, ScopeInputs, ScopeKind, + DeclarationIdentity, DeclarationInput, DeclarationKind, RejectedPath, ResourceIdentity, + ResourceInput, ResourceKind, ResourceRoot, ScopeDeferral, ScopeIndex, ScopeInputs, ScopeKind, }; -use crate::bindings::_helpers::discovery::model_file_record::{ModelFileTexts, NativeModelFile}; -use crate::bindings::_helpers::scopes::relationship_scan::{ - RelationshipScanSettings, ScenarioRow, TestFileRow, scanned_relationships, -}; -use crate::bindings::_helpers::scopes::scope_lookup::scope_path_error; -use crate::bindings::_helpers::scopes::scope_objects::{ - ScopeClasses, field, optional_item, root_object, value_of, -}; -use crate::bindings::_helpers::scopes::scope_validation::replace; +use crate::discovery::models::ModelFileTexts; +use crate::discovery::models::NativeModelFile; +use crate::scopes::_helpers::index::scope_lookup::scope_path_error; +use crate::scopes::_helpers::index::scope_objects::field; +use crate::scopes::_helpers::index::scope_objects::optional_item; +use crate::scopes::_helpers::index::scope_objects::root_object; +use crate::scopes::_helpers::index::scope_objects::value_of; +use crate::scopes::_helpers::relationships::relationship_scan::ScenarioRow; +use crate::scopes::_helpers::relationships::relationship_scan::TestFileRow; +use crate::scopes::models::ScopeClasses; use sqlbuild_python_base::boundary::main::compiler_error::compiler_error; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; @@ -42,7 +41,7 @@ use sqlbuild_python_base::types::CompilerDetach; const UNINDEXABLE_SCOPE_MESSAGE: &str = "Native scope indexing could not place a discovered path or resource kind. Discovery always yields normalized project-relative paths, so this is a SQLBuild bug; please file an issue with the project layout"; const INSPECT_MODULE: &str = "inspect"; const CODE_TYPE_MODULE: &str = "types"; -const PATHLIB_MODULE: &str = "pathlib"; +pub(crate) const PATHLIB_MODULE: &str = "pathlib"; const PRIVATE_ROOT: &str = "models"; const MACRO_FALLBACK: &str = "macros"; const ENUM_FALLBACK: &str = "enums"; @@ -135,12 +134,12 @@ fn header_name<'py>(file: &Bound<'py, PyAny>) -> PyResult> { native_field(file, "header_values")?.call_method1("get", ("name",)) } -fn items<'py>(item: &Bound<'py, PyAny>, name: &str) -> PyResult>> { +pub(crate) fn items<'py>(item: &Bound<'py, PyAny>, name: &str) -> PyResult>> { native_field(item, name)?.try_iter()?.collect() } impl<'py> Walk<'py> { - fn new(py: Python<'py>) -> PyResult { + pub(crate) fn new(py: Python<'py>) -> PyResult { Ok(Self { classes: ScopeClasses::new(py)?, inputs: ScopeInputs::default(), @@ -670,22 +669,12 @@ fn normalized(py: Python<'_>, path: &Bound<'_, PyAny>) -> PyResult { }) } -fn unindexable(py: Python<'_>) -> PyResult { +pub(crate) fn unindexable(py: Python<'_>) -> PyResult { Ok(PyErr::from_value( error_class(py, ErrorId::UnindexableScope)?.call1((UNINDEXABLE_SCOPE_MESSAGE,))?, )) } -/// A built scope index and the Python records materialised from it. -#[pyclass(module = "sqlbuild._native")] -pub(crate) struct NativeScopeIndex { - native: ScopeIndex, - /// Each declaration record in input order. - declarations: Vec>, - index: Py, - grants: Py, -} - fn resource_root<'py>( classes: &ScopeClasses<'py>, kind: ResourceKind, @@ -840,7 +829,7 @@ fn materialise<'py>(walk: Walk<'py>, native: ScopeIndex) -> PyResult) -> PyResult { +pub(crate) fn test_file_row(test_file: &Bound<'_, PyAny>) -> PyResult { let path: Bound<'_, PyAny> = native_field(test_file, "relative_path")?; let mut blocks: Vec<(String, String, String)> = Vec::new(); for block in items(test_file, "blocks")? { @@ -856,7 +845,7 @@ fn test_file_row(test_file: &Bound<'_, PyAny>) -> PyResult { Ok((text(&path)?, blocks)) } -fn scenario_row(scenario: &Bound<'_, PyAny>) -> PyResult { +pub(crate) fn scenario_row(scenario: &Bound<'_, PyAny>) -> PyResult { Ok(( field(scenario, "name")?, text(&native_field(scenario, "relative_path")?)?, @@ -864,112 +853,6 @@ fn scenario_row(scenario: &Bound<'_, PyAny>) -> PyResult { )) } -#[pymethods] -impl NativeScopeIndex { - /// The static index, without grants. - #[getter] - pub(crate) fn index(&self, py: Python<'_>) -> Py { - self.index.clone_ref(py) - } - - /// Whether any macro, enum or constant is scoped, which makes relationship grants matter. - #[getter] - pub(crate) fn has_scoped_relationship_declarations(&self) -> bool { - self.native.has_scoped_relationship_declarations - } - - /// Grant every test's and scenario's relationships; return each extraction fault. - #[pyo3(signature = (*, discovered_inputs, syntax, scan_store))] - fn grant_relationships( - &mut self, - py: Python<'_>, - discovered_inputs: &Bound<'_, PyAny>, - syntax: &Bound<'_, PyAny>, - scan_store: (Bound<'_, PyAny>, String), - ) -> PyResult> { - let files: Vec = items(discovered_inputs, "test_files")? - .iter() - .map(test_file_row) - .collect::>()?; - let scenarios: Vec = items(discovered_inputs, "scenario_files")? - .iter() - .map(scenario_row) - .collect::>()?; - let (store, algorithm) = scan_store; - let settings: Bound<'_, PyDict> = PyDict::new(py); - settings.set_item("syntax", native_field(syntax, "native_mapping")?)?; - settings.set_item("store", store)?; - settings.set_item("scan_key", (algorithm, native_field(syntax, "cache_key")?))?; - let settings: RelationshipScanSettings = settings.extract()?; - let scan: RelationshipScan = scanned_relationships(py, &files, &scenarios, settings)?; - let index: &ScopeIndex = &self.native; - let facts: &[RelationshipFact] = &scan.facts; - let grants: Result, ScopeDeferral> = py - .compiler_detach(|| Ok(relationship_grants(index, facts))) - .map_err(compiler_error)?; - let Ok(grants) = grants else { - return Err(unindexable(py)?); - }; - let classes: ScopeClasses<'_> = ScopeClasses::new(py)?; - let mut records: Vec> = Vec::with_capacity(grants.len()); - for grant in &grants { - let through: Bound<'_, PyAny> = match &grant.through { - GrantThrough::Model(name) => classes.model(RecordId::ResourceIdentity)?.call1(( - classes.member(RecordId::ResourceKind, ResourceKind::Model.as_str())?, - name.as_str(), - ))?, - GrantThrough::Declaration(position) => { - self.declarations[*position].bind(py).getattr("identity")? - } - }; - records.push( - classes.model(RecordId::GrantRecord)?.call1(( - classes.model(RecordId::ResourceIdentity)?.call1(( - classes.member(RecordId::ResourceKind, grant.resource.kind.as_str())?, - grant.resource.name.as_str(), - ))?, - self.declarations[grant.declaration] - .bind(py) - .getattr("identity")?, - through, - classes.member(RecordId::GrantKind, grant.kind.as_str())?, - ))?, - ); - } - self.grants = PyTuple::new(py, records)?.unbind(); - let path_class: Bound<'_, PyAny> = py.import(PATHLIB_MODULE)?.getattr("Path")?; - let faults: Vec> = scan - .faults - .into_iter() - .map(|(path, message)| { - Ok(PyTuple::new( - py, - [path_class.call1((path,))?, message.into_bound_py_any(py)?], - )? - .into_any()) - }) - .collect::>()?; - Ok(PyTuple::new(py, faults)?.unbind()) - } - - /// The index with its grants attached and relationships complete. - fn index_with_relationships(&self, py: Python<'_>) -> PyResult> { - let index: &Bound<'_, PyAny> = self.index.bind(py); - let completeness: Bound<'_, PyAny> = replace( - &native_field(index, "completeness")?, - &[("relationships", true.into_bound_py_any(py)?)], - )?; - Ok(replace( - index, - &[ - ("grants", self.grants.bind(py).clone().into_any()), - ("completeness", completeness), - ], - )? - .unbind()) - } -} - /// Python's `open_native_scope_index`: the natively built index of discovered inputs. #[pyfunction] #[pyo3(signature = (*, discovered_inputs, loaded_macros, static_macros = None))] diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_lookup.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_lookup.rs similarity index 97% rename from crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_lookup.rs rename to crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_lookup.rs index 4956b5a323..e0ea677f39 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_lookup.rs +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_lookup.rs @@ -18,10 +18,12 @@ use sqlbuild_scopes::scope_index::models::{ }; use sqlbuild_scopes::scope_report::main::cached_report_records::cached_report_records; -use crate::bindings::_helpers::scopes::placement::{QualifiedRow, qualified_identity}; -use crate::bindings::_helpers::scopes::scope_objects::{ - ScopeClasses, read_index, resource_identity_object, tuple_attribute, -}; +use crate::scopes::_helpers::declarations::placement::QualifiedRow; +use crate::scopes::_helpers::declarations::placement::qualified_identity; +use crate::scopes::_helpers::index::scope_objects::read_index; +use crate::scopes::_helpers::index::scope_objects::resource_identity_object; +use crate::scopes::_helpers::index::scope_objects::tuple_attribute; +use crate::scopes::models::ScopeClasses; use sqlbuild_python_base::boundary::main::compiler_error::compiler_error; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_objects.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_objects.rs similarity index 94% rename from crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_objects.rs rename to crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_objects.rs index 1e69c3b012..016b1beb3e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_objects.rs +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_objects.rs @@ -1,5 +1,6 @@ //! Python `ScopeIndex` models read into the native full index, and built back from it. +use crate::scopes::models::ScopeClasses; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; use pyo3::types::PyTuple; use sqlbuild_scopes::placement::models::{PlacementIndex, PlacementUsage}; @@ -12,45 +13,21 @@ use sqlbuild_scopes::scope_index::models::{ ResourceKind, ResourceRecord, }; -use crate::bindings::_helpers::scopes::placement::{ - DeclarationRow, IdentityRow, QualifiedRow, RootRow, declaration_identity, declaration_record, - ownership_root, qualified_identity, resource_identity, -}; -use crate::bindings::_helpers::scopes::scope_lookup::grant_kind; -use sqlbuild_python_base::records::main::construct::new_record::new_record; -use sqlbuild_python_base::records::main::construct::record_class::record_class; +use crate::scopes::_helpers::declarations::placement::DeclarationRow; +use crate::scopes::_helpers::declarations::placement::IdentityRow; +use crate::scopes::_helpers::declarations::placement::QualifiedRow; +use crate::scopes::_helpers::declarations::placement::RootRow; +use crate::scopes::_helpers::declarations::placement::declaration_identity; +use crate::scopes::_helpers::declarations::placement::declaration_record; +use crate::scopes::_helpers::declarations::placement::ownership_root; +use crate::scopes::_helpers::declarations::placement::qualified_identity; +use crate::scopes::_helpers::declarations::placement::resource_identity; +use crate::scopes::_helpers::index::scope_lookup::grant_kind; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; const ENUM_MODULE: &str = "enum"; -/// The native scope model and enum classes every built object comes from. -pub(crate) struct ScopeClasses<'py> { - py: Python<'py>, -} - -impl<'py> ScopeClasses<'py> { - /// The scope classes of `py`. - pub(crate) fn new(py: Python<'py>) -> PyResult { - Ok(Self { py }) - } - - /// One scope model class. - pub(crate) fn model(&self, name: RecordId) -> PyResult> { - record_class(self.py, name) - } - - /// The member of scope enum `name` with `value`; an unknown value raises `ValueError`. - pub(crate) fn member(&self, name: RecordId, value: &str) -> PyResult> { - new_record(self.py, name, (value,), None) - } - - /// The interpreter the classes belong to. - pub(crate) fn py(&self) -> Python<'py> { - self.py - } -} - /// `str(value.value)` of an enum, else `str(value)`. pub(crate) fn enum_text(value: &Bound<'_, PyAny>) -> PyResult { let enum_type = value.py().import(ENUM_MODULE)?.getattr("Enum")?; diff --git a/crates/sqlbuild-python-front/src/scopes/_helpers/mod.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/mod.rs new file mode 100644 index 0000000000..dd95c3c9ea --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/mod.rs @@ -0,0 +1,5 @@ +pub(crate) mod checks; +pub(crate) mod declarations; +pub(crate) mod index; +pub(crate) mod relationships; +pub(crate) mod reports; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/compile_usages.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/relationships/compile_usages.rs similarity index 98% rename from crates/sqlbuild-python/src/bindings/_helpers/scopes/compile_usages.rs rename to crates/sqlbuild-python-front/src/scopes/_helpers/relationships/compile_usages.rs index 35ed2fce64..b84011d0f1 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scopes/compile_usages.rs +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/relationships/compile_usages.rs @@ -27,8 +27,6 @@ use sqlbuild_python_base::records::main::fields::mapping_items::mapping_items; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; -/// The folder a scope path is relative to when its owner names none. -pub(crate) const CURRENT_FOLDER: &str = "."; const INACCESSIBLE_DECLARATION_CODE: &str = "S006"; const SCHEMA_USAGE_KINDS: [&str; 2] = ["schema", "enum"]; diff --git a/crates/sqlbuild-python-front/src/scopes/_helpers/relationships/mod.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/relationships/mod.rs new file mode 100644 index 0000000000..8959f14da6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/relationships/mod.rs @@ -0,0 +1,3 @@ +pub(crate) mod compile_usages; +pub(crate) mod relationship_names; +pub(crate) mod relationship_scan; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/relationship_names.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/relationships/relationship_names.rs similarity index 97% rename from crates/sqlbuild-python/src/bindings/_helpers/scopes/relationship_names.rs rename to crates/sqlbuild-python-front/src/scopes/_helpers/relationships/relationship_names.rs index 15b2e43d85..eb801aa90f 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scopes/relationship_names.rs +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/relationships/relationship_names.rs @@ -9,7 +9,7 @@ use sqlbuild_scopes::relationship_names::models::{ }; use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; -use crate::bindings::_helpers::sqltext::lexical_syntax::LexicalSyntaxInput; +use crate::sqltext::models::LexicalSyntaxInput; use sqlbuild_python_base::boundary::main::compiler_error::compiler_error; use sqlbuild_python_base::types::CompilerDetach; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/relationship_scan.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/relationships/relationship_scan.rs similarity index 98% rename from crates/sqlbuild-python/src/bindings/_helpers/scopes/relationship_scan.rs rename to crates/sqlbuild-python-front/src/scopes/_helpers/relationships/relationship_scan.rs index 7f8cd890c6..f9bf1a70e6 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scopes/relationship_scan.rs +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/relationships/relationship_scan.rs @@ -9,7 +9,7 @@ use sqlbuild_scopes::relationship_names::models::{ }; use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; -use crate::bindings::_helpers::sqltext::lexical_syntax::LexicalSyntaxInput; +use crate::sqltext::models::LexicalSyntaxInput; use sqlbuild_python_base::boundary::main::compiler_error::compiler_error; use sqlbuild_python_base::cache::models::SqlTestScanStore; use sqlbuild_python_base::types::CompilerDetach; diff --git a/crates/sqlbuild-python-front/src/scopes/_helpers/reports/mod.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/reports/mod.rs new file mode 100644 index 0000000000..13d2d9a90a --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/reports/mod.rs @@ -0,0 +1,3 @@ +pub(crate) mod scope_errors; +pub(crate) mod scope_report_objects; +pub(crate) mod scope_reports; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_errors.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/reports/scope_errors.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_errors.rs rename to crates/sqlbuild-python-front/src/scopes/_helpers/reports/scope_errors.rs diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_report_objects.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/reports/scope_report_objects.rs similarity index 98% rename from crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_report_objects.rs rename to crates/sqlbuild-python-front/src/scopes/_helpers/reports/scope_report_objects.rs index e50f0edd1b..396b548083 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_report_objects.rs +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/reports/scope_report_objects.rs @@ -15,13 +15,16 @@ use sqlbuild_scopes::scope_report::models::{ ScopeFolder, ScopeReport, ScopeResult, ScopeSection, SourceLocation, }; -use crate::bindings::_helpers::scopes::scope_objects::{ - ScopeClasses, field, optional_item, read_declaration_identity, read_diagnostic, read_qualified, -}; +use crate::scopes::_helpers::index::scope_objects::field; +use crate::scopes::_helpers::index::scope_objects::optional_item; +use crate::scopes::_helpers::index::scope_objects::read_declaration_identity; +use crate::scopes::_helpers::index::scope_objects::read_diagnostic; +use crate::scopes::_helpers::index::scope_objects::read_qualified; +use crate::scopes::models::ScopeClasses; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; -type PyObject = Py; +pub(crate) type PyObject = Py; const PATHLIB_MODULE: &str = "pathlib"; /// The error `plain_value` raises for an integer outside 64 bits. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_reports.rs b/crates/sqlbuild-python-front/src/scopes/_helpers/reports/scope_reports.rs similarity index 92% rename from crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_reports.rs rename to crates/sqlbuild-python-front/src/scopes/_helpers/reports/scope_reports.rs index d183c49625..cfb49a189b 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_reports.rs +++ b/crates/sqlbuild-python-front/src/scopes/_helpers/reports/scope_reports.rs @@ -1,5 +1,8 @@ //! `sqb scope` reports over a `ScopeLookup`, their serialization and the metadata projection. +use crate::scopes::models::ExplainArguments; +use crate::scopes::models::ListArguments; +use crate::scopes::models::ReportArguments; use pyo3::exceptions::{PyIndexError, PyValueError}; use pyo3::prelude::{ Bound, Py, PyAny, PyAnyMethods, PyErr, PyModule, PyModuleMethods, PyResult, Python, @@ -26,44 +29,31 @@ use sqlbuild_scopes::scope_report::models::{ ScopeResult, }; -use crate::bindings::_helpers::scopes::scope_lookup::NativeScopeLookup; -use crate::bindings::_helpers::scopes::scope_objects::{ - ScopeClasses, read_completeness, read_declaration, read_index, -}; -use crate::bindings::_helpers::scopes::scope_report_objects::{ - browse_object, diagnostics_object, explanation_object, json_to_plain, json_to_python, - list_object, move_object, read_declaration_target, read_filters, read_optional_target, - read_result, read_target, report_object, -}; +use crate::scopes::_helpers::index::scope_lookup::NativeScopeLookup; +use crate::scopes::_helpers::index::scope_objects::read_completeness; +use crate::scopes::_helpers::index::scope_objects::read_declaration; +use crate::scopes::_helpers::index::scope_objects::read_index; +use crate::scopes::_helpers::reports::scope_report_objects::browse_object; +use crate::scopes::_helpers::reports::scope_report_objects::diagnostics_object; +use crate::scopes::_helpers::reports::scope_report_objects::explanation_object; +use crate::scopes::_helpers::reports::scope_report_objects::json_to_plain; +use crate::scopes::_helpers::reports::scope_report_objects::json_to_python; +use crate::scopes::_helpers::reports::scope_report_objects::list_object; +use crate::scopes::_helpers::reports::scope_report_objects::move_object; +use crate::scopes::_helpers::reports::scope_report_objects::read_declaration_target; +use crate::scopes::_helpers::reports::scope_report_objects::read_filters; +use crate::scopes::_helpers::reports::scope_report_objects::read_optional_target; +use crate::scopes::_helpers::reports::scope_report_objects::read_result; +use crate::scopes::_helpers::reports::scope_report_objects::read_target; +use crate::scopes::_helpers::reports::scope_report_objects::report_object; +use crate::scopes::models::ScopeClasses; use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; -type PyObject = Py; - -/// Target, location, whether it is a directory, and the filters. -pub(crate) struct ReportArguments<'py> { - pub(crate) target: Option>, - pub(crate) at: Option>, - pub(crate) directory: bool, - pub(crate) filters: Option>, -} -/// Declaration, target, location and whether it is a directory. -pub(crate) struct ExplainArguments<'py> { - pub(crate) declaration: Bound<'py, PyAny>, - pub(crate) target: Option>, - pub(crate) at: Option>, - pub(crate) directory: bool, -} -/// Folder, filters, target and whether the target is prospective. -pub(crate) struct ListArguments<'py> { - pub(crate) folder: String, - pub(crate) filters: Option>, - pub(crate) target: Option>, - pub(crate) target_is_prospective: bool, -} +pub(crate) type PyObject = Py; const CURRENT_FOLDER: &str = "."; diff --git a/crates/sqlbuild-python-front/src/scopes/constants.rs b/crates/sqlbuild-python-front/src/scopes/constants.rs new file mode 100644 index 0000000000..a17faf551a --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/constants.rs @@ -0,0 +1,15 @@ +//! Public constants of scopes. + +use crate::scopes::_helpers::index::getters::read_native_scope_index; +use crate::scopes::models::NativeScopeIndex; +use sqlbuild_python_base::records::main::registry::class_of::class_of; +use sqlbuild_python_base::records::models::GetterEntry; + +/// The folder a scope path is relative to when its owner names none. +pub const CURRENT_FOLDER: &str = "."; + +/// The getter readers of this module's native pyclasses. +pub const GETTERS: &[GetterEntry] = &[GetterEntry { + class: class_of::, + read: read_native_scope_index, +}]; diff --git a/crates/sqlbuild-python-front/src/scopes/main/checks/mod.rs b/crates/sqlbuild-python-front/src/scopes/main/checks/mod.rs new file mode 100644 index 0000000000..3045d21e05 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/checks/mod.rs @@ -0,0 +1,6 @@ +pub mod register_scope_validation; +pub mod register_scope_visibility; +pub mod relocated_declarations; +pub mod scope_index_with_compile_usages; +pub mod scope_tolerant_index; +pub mod validate_scope_index; diff --git a/crates/sqlbuild-python-front/src/scopes/main/checks/register_scope_validation.rs b/crates/sqlbuild-python-front/src/scopes/main/checks/register_scope_validation.rs new file mode 100644 index 0000000000..59bb9c9aa3 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/checks/register_scope_validation.rs @@ -0,0 +1,12 @@ +//! Register the scope validation functions and classes. + +use crate::scopes::_helpers::checks::scope_validation; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the scope validation functions and classes. +#[inline] +pub fn register_scope_validation(module: &Bound<'_, PyModule>) -> PyResult<()> { + scope_validation::register(module) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/checks/register_scope_visibility.rs b/crates/sqlbuild-python-front/src/scopes/main/checks/register_scope_visibility.rs new file mode 100644 index 0000000000..03b3da25b7 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/checks/register_scope_visibility.rs @@ -0,0 +1,12 @@ +//! Register the scope visibility functions and classes. + +use crate::scopes::_helpers::checks::scope_visibility; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the scope visibility functions and classes. +#[inline] +pub fn register_scope_visibility(module: &Bound<'_, PyModule>) -> PyResult<()> { + scope_visibility::register(module) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/checks/relocated_declarations.rs b/crates/sqlbuild-python-front/src/scopes/main/checks/relocated_declarations.rs new file mode 100644 index 0000000000..1f67ce386f --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/checks/relocated_declarations.rs @@ -0,0 +1,17 @@ +//! Relocated records after every move in `moves`, and per record whether it lacks a needed group. + +use crate::scopes::_helpers::checks::scope_validation; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; +use sqlbuild_scopes::scope_index::models::ResourceIdentity; + +/// Relocated records after every move in `moves`, and per record whether it lacks a needed group. +#[inline] +pub fn relocated_declarations<'py>( + index: &Bound<'py, PyAny>, + moves: &[(ResourceIdentity, String)], +) -> PyResult, Vec)>> { + scope_validation::relocated_declarations(index, moves) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/checks/scope_index_with_compile_usages.rs b/crates/sqlbuild-python-front/src/scopes/main/checks/scope_index_with_compile_usages.rs new file mode 100644 index 0000000000..8eb10e7943 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/checks/scope_index_with_compile_usages.rs @@ -0,0 +1,14 @@ +//! Compile inputs' canonical index with all usage and placement facts. + +use crate::scopes::_helpers::checks::scope_validation; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Compile inputs' canonical index with all usage and placement facts. +#[inline] +pub fn scope_index_with_compile_usages<'py>( + inputs: &Bound<'py, PyAny>, +) -> PyResult> { + scope_validation::scope_index_with_compile_usages(inputs) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/checks/scope_tolerant_index.rs b/crates/sqlbuild-python-front/src/scopes/main/checks/scope_tolerant_index.rs new file mode 100644 index 0000000000..82e2186ba0 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/checks/scope_tolerant_index.rs @@ -0,0 +1,19 @@ +//! The tolerant index: fault diagnostics, prospective resources and partial completeness. + +use crate::scopes::_helpers::checks::scope_tolerant; +use pyo3::prelude::Bound; +use pyo3::prelude::Py; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// The tolerant index: fault diagnostics, prospective resources and partial completeness. +#[inline] +pub fn scope_tolerant_index( + py: Python<'_>, + index: &Bound<'_, PyAny>, + snapshot: &Bound<'_, PyAny>, + faults: (Bound<'_, PyAny>, Bound<'_, PyAny>), +) -> PyResult> { + scope_tolerant::scope_tolerant_index(py, index, snapshot, faults) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/checks/validate_scope_index.rs b/crates/sqlbuild-python-front/src/scopes/main/checks/validate_scope_index.rs new file mode 100644 index 0000000000..117154f15d --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/checks/validate_scope_index.rs @@ -0,0 +1,12 @@ +//! Python's `validate_scope_index`: raise one `ScopeValidationError` for its error diagnostics. + +use crate::scopes::_helpers::checks::scope_validation; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyErr; + +/// Python's `validate_scope_index`: raise one `ScopeValidationError` for its error diagnostics. +#[inline] +pub fn validate_scope_index(index: &Bound<'_, PyAny>) -> Result<(), PyErr> { + scope_validation::validate_scope_index(index) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/declarations/mod.rs b/crates/sqlbuild-python-front/src/scopes/main/declarations/mod.rs new file mode 100644 index 0000000000..b038a93a76 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/declarations/mod.rs @@ -0,0 +1 @@ +pub mod register_declaration_contexts; diff --git a/crates/sqlbuild-python-front/src/scopes/main/declarations/register_declaration_contexts.rs b/crates/sqlbuild-python-front/src/scopes/main/declarations/register_declaration_contexts.rs new file mode 100644 index 0000000000..b613d65b38 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/declarations/register_declaration_contexts.rs @@ -0,0 +1,12 @@ +//! Register the declaration contexts functions and classes. + +use crate::scopes::_helpers::declarations::declaration_contexts; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the declaration contexts functions and classes. +#[inline] +pub fn register_declaration_contexts(module: &Bound<'_, PyModule>) -> PyResult<()> { + declaration_contexts::register(module) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/index/build_scope_lookup.rs b/crates/sqlbuild-python-front/src/scopes/main/index/build_scope_lookup.rs new file mode 100644 index 0000000000..d9260694d9 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/index/build_scope_lookup.rs @@ -0,0 +1,14 @@ +//! Python's `build_scope_lookup`: the canonical index, its mappings and the native lookup. + +use crate::scopes::_helpers::index::scope_lookup; +use pyo3::prelude::Bound; +use pyo3::prelude::Py; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// Python's `build_scope_lookup`: the canonical index, its mappings and the native lookup. +#[inline] +pub fn build_scope_lookup(py: Python<'_>, index: &Bound<'_, PyAny>) -> PyResult> { + scope_lookup::build_scope_lookup(py, index) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/index/mod.rs b/crates/sqlbuild-python-front/src/scopes/main/index/mod.rs new file mode 100644 index 0000000000..9b4bded765 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/index/mod.rs @@ -0,0 +1,8 @@ +pub mod build_scope_lookup; +pub mod open_native_scope_index; +pub mod project_fingerprint; +pub mod read_scope_index_cache; +pub mod register_scope_cache; +pub mod register_scope_index; +pub mod register_scope_lookup; +pub mod write_scope_index_cache; diff --git a/crates/sqlbuild-python-front/src/scopes/main/index/open_native_scope_index.rs b/crates/sqlbuild-python-front/src/scopes/main/index/open_native_scope_index.rs new file mode 100644 index 0000000000..2196717847 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/index/open_native_scope_index.rs @@ -0,0 +1,19 @@ +//! Python's `open_native_scope_index`: the natively built index of discovered inputs. + +use crate::scopes::_helpers::index::scope_index; +use crate::scopes::models::NativeScopeIndex; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// Python's `open_native_scope_index`: the natively built index of discovered inputs. +#[inline] +pub fn open_native_scope_index( + py: Python<'_>, + discovered_inputs: &Bound<'_, PyAny>, + loaded_macros: &Bound<'_, PyAny>, + static_macros: Option>, +) -> PyResult { + scope_index::open_native_scope_index(py, discovered_inputs, loaded_macros, static_macros) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/index/project_fingerprint.rs b/crates/sqlbuild-python-front/src/scopes/main/index/project_fingerprint.rs new file mode 100644 index 0000000000..ac5ddfb553 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/index/project_fingerprint.rs @@ -0,0 +1,12 @@ +//! The scope index fingerprint of `project_dir`, `None` when it cannot be read. + +use crate::scopes::_helpers::index::scope_cache; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use std::path::PathBuf; + +/// The scope index fingerprint of `project_dir`, `None` when it cannot be read. +#[inline] +pub fn project_fingerprint(py: Python<'_>, project_dir: PathBuf) -> PyResult> { + scope_cache::project_fingerprint(py, project_dir) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/index/read_scope_index_cache.rs b/crates/sqlbuild-python-front/src/scopes/main/index/read_scope_index_cache.rs new file mode 100644 index 0000000000..146846e797 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/index/read_scope_index_cache.rs @@ -0,0 +1,18 @@ +//! The verified cached `ScopeIndex` at `path` for `fingerprint`; every fault is a miss. + +use crate::scopes::_helpers::index::scope_cache; +use pyo3::prelude::Py; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use std::path::PathBuf; + +/// The verified cached `ScopeIndex` at `path` for `fingerprint`; every fault is a miss. +#[inline] +pub fn read_scope_index_cache( + py: Python<'_>, + path: PathBuf, + fingerprint: String, +) -> PyResult>> { + scope_cache::read_scope_index_cache(py, path, fingerprint) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/index/register_scope_cache.rs b/crates/sqlbuild-python-front/src/scopes/main/index/register_scope_cache.rs new file mode 100644 index 0000000000..4dcdf09e70 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/index/register_scope_cache.rs @@ -0,0 +1,12 @@ +//! Register the scope cache functions and classes. + +use crate::scopes::_helpers::index::scope_cache; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the scope cache functions and classes. +#[inline] +pub fn register_scope_cache(module: &Bound<'_, PyModule>) -> PyResult<()> { + scope_cache::register(module) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/index/register_scope_index.rs b/crates/sqlbuild-python-front/src/scopes/main/index/register_scope_index.rs new file mode 100644 index 0000000000..1194dee508 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/index/register_scope_index.rs @@ -0,0 +1,12 @@ +//! Register the scope index functions and classes. + +use crate::scopes::_helpers::index::scope_index; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the scope index functions and classes. +#[inline] +pub fn register_scope_index(module: &Bound<'_, PyModule>) -> PyResult<()> { + scope_index::register(module) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/index/register_scope_lookup.rs b/crates/sqlbuild-python-front/src/scopes/main/index/register_scope_lookup.rs new file mode 100644 index 0000000000..4c3e76c30d --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/index/register_scope_lookup.rs @@ -0,0 +1,12 @@ +//! Register the scope lookup functions and classes. + +use crate::scopes::_helpers::index::scope_lookup; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the scope lookup functions and classes. +#[inline] +pub fn register_scope_lookup(module: &Bound<'_, PyModule>) -> PyResult<()> { + scope_lookup::register(module) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/index/write_scope_index_cache.rs b/crates/sqlbuild-python-front/src/scopes/main/index/write_scope_index_cache.rs new file mode 100644 index 0000000000..1f3e8858d2 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/index/write_scope_index_cache.rs @@ -0,0 +1,19 @@ +//! Atomically write one complete `ScopeIndex` for `fingerprint`; whether the write landed. + +use crate::scopes::_helpers::index::scope_cache; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use std::path::PathBuf; + +/// Atomically write one complete `ScopeIndex` for `fingerprint`; whether the write landed. +#[inline] +pub fn write_scope_index_cache( + py: Python<'_>, + location: (PathBuf, String), + fingerprint: String, + index: &Bound<'_, PyAny>, +) -> PyResult { + scope_cache::write_scope_index_cache(py, location, fingerprint, index) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/mod.rs b/crates/sqlbuild-python-front/src/scopes/main/mod.rs new file mode 100644 index 0000000000..711007d92b --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/mod.rs @@ -0,0 +1,5 @@ +pub mod checks; +pub mod declarations; +pub mod index; +pub mod relationships; +pub mod reports; diff --git a/crates/sqlbuild-python-front/src/scopes/main/relationships/mod.rs b/crates/sqlbuild-python-front/src/scopes/main/relationships/mod.rs new file mode 100644 index 0000000000..b0b6f3c5a6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/relationships/mod.rs @@ -0,0 +1,2 @@ +pub mod register_compile_usages; +pub mod register_relationship_names; diff --git a/crates/sqlbuild-python-front/src/scopes/main/relationships/register_compile_usages.rs b/crates/sqlbuild-python-front/src/scopes/main/relationships/register_compile_usages.rs new file mode 100644 index 0000000000..2b36f57b36 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/relationships/register_compile_usages.rs @@ -0,0 +1,12 @@ +//! Register the compile usages functions and classes. + +use crate::scopes::_helpers::relationships::compile_usages; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the compile usages functions and classes. +#[inline] +pub fn register_compile_usages(module: &Bound<'_, PyModule>) -> PyResult<()> { + compile_usages::register(module) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/relationships/register_relationship_names.rs b/crates/sqlbuild-python-front/src/scopes/main/relationships/register_relationship_names.rs new file mode 100644 index 0000000000..03781fc7b2 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/relationships/register_relationship_names.rs @@ -0,0 +1,12 @@ +//! Register the relationship names functions and classes. + +use crate::scopes::_helpers::relationships::relationship_names; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the relationship names functions and classes. +#[inline] +pub fn register_relationship_names(module: &Bound<'_, PyModule>) -> PyResult<()> { + relationship_names::register(module) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/reports/json_to_python.rs b/crates/sqlbuild-python-front/src/scopes/main/reports/json_to_python.rs new file mode 100644 index 0000000000..ff32cbaeb1 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/reports/json_to_python.rs @@ -0,0 +1,13 @@ +//! A JSON value as Python builds it; arrays become tuples or lists. + +use crate::scopes::_helpers::reports::scope_report_objects; +use crate::scopes::_helpers::reports::scope_report_objects::PyObject; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use sqlbuild_core::json::models::JsonValue; + +/// A JSON value as Python builds it; arrays become tuples or lists. +#[inline] +pub fn json_to_python(py: Python<'_>, value: JsonValue, tuples: bool) -> PyResult { + scope_report_objects::json_to_python(py, value, tuples) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/reports/metadata_projection_value.rs b/crates/sqlbuild-python-front/src/scopes/main/reports/metadata_projection_value.rs new file mode 100644 index 0000000000..9ccc5d8479 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/reports/metadata_projection_value.rs @@ -0,0 +1,12 @@ +//! `plain_value` of `scope_metadata_projection(index=index)`, without a Python round trip. + +use crate::scopes::_helpers::reports::scope_reports; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// `plain_value` of `scope_metadata_projection(index=index)`, without a Python round trip. +#[inline] +pub fn metadata_projection_value(index: &Bound<'_, PyAny>) -> PyResult { + scope_reports::metadata_projection_value(index) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/reports/mod.rs b/crates/sqlbuild-python-front/src/scopes/main/reports/mod.rs new file mode 100644 index 0000000000..96240903c4 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/reports/mod.rs @@ -0,0 +1,12 @@ +pub mod json_to_python; +pub mod metadata_projection_value; +pub mod read_result; +pub mod register_scope_reports; +pub mod report_scope_index_errors; +pub mod scope_browse; +pub mod scope_explain; +pub mod scope_list; +pub mod scope_move_preview; +pub mod scope_rebound_usages; +pub mod scope_report; +pub mod serialize_scope_report; diff --git a/crates/sqlbuild-python-front/src/scopes/main/reports/read_result.rs b/crates/sqlbuild-python-front/src/scopes/main/reports/read_result.rs new file mode 100644 index 0000000000..255b493c51 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/reports/read_result.rs @@ -0,0 +1,14 @@ +//! A `ScopeReport`, `ScopeBrowseResult` or, otherwise, `ScopeListResult` as its native result. + +use crate::scopes::_helpers::reports::scope_report_objects; +use crate::scopes::models::ScopeClasses; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_scopes::scope_report::models::ScopeResult; + +/// A `ScopeReport`, `ScopeBrowseResult` or, otherwise, `ScopeListResult` as its native result. +#[inline] +pub fn read_result(classes: &ScopeClasses<'_>, result: &Bound<'_, PyAny>) -> PyResult { + scope_report_objects::read_result(classes, result) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/reports/register_scope_reports.rs b/crates/sqlbuild-python-front/src/scopes/main/reports/register_scope_reports.rs new file mode 100644 index 0000000000..fe8102070b --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/reports/register_scope_reports.rs @@ -0,0 +1,12 @@ +//! Register the scope reports functions and classes. + +use crate::scopes::_helpers::reports::scope_reports; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the scope reports functions and classes. +#[inline] +pub fn register_scope_reports(module: &Bound<'_, PyModule>) -> PyResult<()> { + scope_reports::register(module) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/reports/report_scope_index_errors.rs b/crates/sqlbuild-python-front/src/scopes/main/reports/report_scope_index_errors.rs new file mode 100644 index 0000000000..fb15112112 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/reports/report_scope_index_errors.rs @@ -0,0 +1,12 @@ +//! `report_scope_index_errors`: each error-severity finding of `index`, keyed for the collector. + +use crate::scopes::_helpers::reports::scope_errors; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// `report_scope_index_errors`: each error-severity finding of `index`, keyed for the collector. +#[inline] +pub fn report_scope_index_errors(index: &Bound<'_, PyAny>) -> PyResult<()> { + scope_errors::report_scope_index_errors(index) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/reports/scope_browse.rs b/crates/sqlbuild-python-front/src/scopes/main/reports/scope_browse.rs new file mode 100644 index 0000000000..1a134fa5a9 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/reports/scope_browse.rs @@ -0,0 +1,18 @@ +//! `browse_scope_folders`: the direct child declaration-definition folders of `folder`. + +use crate::scopes::_helpers::reports::scope_reports; +use crate::scopes::_helpers::reports::scope_reports::PyObject; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// `browse_scope_folders`: the direct child declaration-definition folders of `folder`. +#[inline] +pub fn scope_browse( + py: Python<'_>, + lookup: &Bound<'_, PyAny>, + request: (String, Option>, bool), +) -> PyResult { + scope_reports::scope_browse(py, lookup, request) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/reports/scope_explain.rs b/crates/sqlbuild-python-front/src/scopes/main/reports/scope_explain.rs new file mode 100644 index 0000000000..86db324665 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/reports/scope_explain.rs @@ -0,0 +1,19 @@ +//! `explain_scope_declaration`: one qualified declaration in an optional context. + +use crate::scopes::_helpers::reports::scope_reports; +use crate::scopes::_helpers::reports::scope_reports::PyObject; +use crate::scopes::models::ExplainArguments; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// `explain_scope_declaration`: one qualified declaration in an optional context. +#[inline] +pub fn scope_explain( + py: Python<'_>, + lookup: &Bound<'_, PyAny>, + request: ExplainArguments<'_>, +) -> PyResult<(PyObject, PyObject)> { + scope_reports::scope_explain(py, lookup, request) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/reports/scope_list.rs b/crates/sqlbuild-python-front/src/scopes/main/reports/scope_list.rs new file mode 100644 index 0000000000..7460b26b08 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/reports/scope_list.rs @@ -0,0 +1,19 @@ +//! `list_scope_declarations`: declarations recursively beneath one definition folder. + +use crate::scopes::_helpers::reports::scope_reports; +use crate::scopes::_helpers::reports::scope_reports::PyObject; +use crate::scopes::models::ListArguments; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// `list_scope_declarations`: declarations recursively beneath one definition folder. +#[inline] +pub fn scope_list( + py: Python<'_>, + lookup: &Bound<'_, PyAny>, + request: ListArguments<'_>, +) -> PyResult { + scope_reports::scope_list(py, lookup, request) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/reports/scope_move_preview.rs b/crates/sqlbuild-python-front/src/scopes/main/reports/scope_move_preview.rs new file mode 100644 index 0000000000..21dbee2b9e --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/reports/scope_move_preview.rs @@ -0,0 +1,19 @@ +//! `preview_scope_move`: visibility deltas of a resource move, without mutating the lookup. + +use crate::scopes::_helpers::reports::scope_reports; +use crate::scopes::_helpers::reports::scope_reports::PyObject; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// `preview_scope_move`: visibility deltas of a resource move, without mutating the lookup. +#[inline] +pub fn scope_move_preview( + py: Python<'_>, + lookup: &Bound<'_, PyAny>, + resource: &Bound<'_, PyAny>, + destination: &Bound<'_, PyAny>, +) -> PyResult<(Option, PyObject)> { + scope_reports::scope_move_preview(py, lookup, resource, destination) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/reports/scope_rebound_usages.rs b/crates/sqlbuild-python-front/src/scopes/main/reports/scope_rebound_usages.rs new file mode 100644 index 0000000000..ac85c5fe37 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/reports/scope_rebound_usages.rs @@ -0,0 +1,17 @@ +//! Scoped declarations the resources at `path` use that resolve differently from `destination`. + +use crate::scopes::_helpers::reports::scope_reports; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// Scoped declarations the resources at `path` use that resolve differently from `destination`. +#[inline] +pub fn scope_rebound_usages( + py: Python<'_>, + lookup: &Bound<'_, PyAny>, + paths: (&str, &str), +) -> PyResult>> { + scope_reports::scope_rebound_usages(py, lookup, paths) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/reports/scope_report.rs b/crates/sqlbuild-python-front/src/scopes/main/reports/scope_report.rs new file mode 100644 index 0000000000..5ad16340fa --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/reports/scope_report.rs @@ -0,0 +1,19 @@ +//! `query_scope_report`: one existing target or prospective path; invalid paths raise. + +use crate::scopes::_helpers::reports::scope_reports; +use crate::scopes::_helpers::reports::scope_reports::PyObject; +use crate::scopes::models::ReportArguments; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// `query_scope_report`: one existing target or prospective path; invalid paths raise. +#[inline] +pub fn scope_report( + py: Python<'_>, + lookup: &Bound<'_, PyAny>, + request: ReportArguments<'_>, +) -> PyResult { + scope_reports::scope_report(py, lookup, request) +} diff --git a/crates/sqlbuild-python-front/src/scopes/main/reports/serialize_scope_report.rs b/crates/sqlbuild-python-front/src/scopes/main/reports/serialize_scope_report.rs new file mode 100644 index 0000000000..91429ea6c6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/main/reports/serialize_scope_report.rs @@ -0,0 +1,13 @@ +//! `serialize_scope_report`: deterministic schema-version-two ASCII JSON of one result. + +use crate::scopes::_helpers::reports::scope_reports; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// `serialize_scope_report`: deterministic schema-version-two ASCII JSON of one result. +#[inline] +pub fn serialize_scope_report(py: Python<'_>, report: &Bound<'_, PyAny>) -> PyResult { + scope_reports::serialize_scope_report(py, report) +} diff --git a/crates/sqlbuild-python-front/src/scopes/mod.rs b/crates/sqlbuild-python-front/src/scopes/mod.rs new file mode 100644 index 0000000000..f5236d29bb --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/mod.rs @@ -0,0 +1,6 @@ +//! Declaration scopes: placement, resolution, visibility, relationships and scope reports. + +pub(crate) mod _helpers; +pub mod constants; +pub mod main; +pub mod models; diff --git a/crates/sqlbuild-python-front/src/scopes/models.rs b/crates/sqlbuild-python-front/src/scopes/models.rs new file mode 100644 index 0000000000..f9cdf007a1 --- /dev/null +++ b/crates/sqlbuild-python-front/src/scopes/models.rs @@ -0,0 +1,487 @@ +//! Public records of scopes. + +use crate::scopes::_helpers::checks::scope_validation::replace; +use crate::scopes::_helpers::declarations::declaration_contexts::CONSTANT_KIND; +use crate::scopes::_helpers::declarations::declaration_contexts::ContextClasses; +use crate::scopes::_helpers::declarations::declaration_contexts::ContextParts; +use crate::scopes::_helpers::declarations::declaration_contexts::ENUM_KIND; +use crate::scopes::_helpers::declarations::declaration_contexts::LookupMappings; +use crate::scopes::_helpers::declarations::declaration_contexts::MACRO_KIND; +use crate::scopes::_helpers::declarations::declaration_contexts::PositionRow; +use crate::scopes::_helpers::declarations::declaration_contexts::TableRow; +use crate::scopes::_helpers::declarations::declaration_contexts::VisibleRow; +use crate::scopes::_helpers::declarations::declaration_resolution::ResolutionInputs; +use crate::scopes::_helpers::index::scope_index::PATHLIB_MODULE; +use crate::scopes::_helpers::index::scope_index::items; +use crate::scopes::_helpers::index::scope_index::scenario_row; +use crate::scopes::_helpers::index::scope_index::test_file_row; +use crate::scopes::_helpers::index::scope_index::unindexable; +use crate::scopes::_helpers::relationships::relationship_scan::RelationshipScanSettings; +use crate::scopes::_helpers::relationships::relationship_scan::ScenarioRow; +use crate::scopes::_helpers::relationships::relationship_scan::TestFileRow; +use crate::scopes::_helpers::relationships::relationship_scan::scanned_relationships; +use pyo3::IntoPyObjectExt; +use pyo3::intern; +use pyo3::prelude::Bound; +use pyo3::prelude::Py; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyAnyMethods; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::pyclass; +use pyo3::pymethods; +use pyo3::types::PyDict; +use pyo3::types::PyDictMethods; +use pyo3::types::PyTuple; +use sqlbuild_python_base::boundary::main::compiler_error::compiler_error; +use sqlbuild_python_base::boundary::main::compiler_guard::compiler_guard; +use sqlbuild_python_base::records::main::construct::new_record::new_record; +use sqlbuild_python_base::records::main::construct::record_class::record_class; +use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_base::types::CompilerDetach; +use sqlbuild_scopes::relationship_names::models::RelationshipScan; +use sqlbuild_scopes::scope_index::main::classify_resource::classify_resource; +use sqlbuild_scopes::scope_index::main::relationship_grants::relationship_grants; +use sqlbuild_scopes::scope_index::models::ConsumerResource; +use sqlbuild_scopes::scope_index::models::GrantEntry; +use sqlbuild_scopes::scope_index::models::GrantRecord; +use sqlbuild_scopes::scope_index::models::GrantThrough; +use sqlbuild_scopes::scope_index::models::RelationshipFact; +use sqlbuild_scopes::scope_index::models::ResourceKind; +use sqlbuild_scopes::scope_index::models::ScopeDeferral; +use sqlbuild_scopes::scope_index::models::ScopeIndex; +use sqlbuild_scopes::scope_index::models::VisibilityReason; +use sqlbuild_scopes::scope_index::models::VisibilityTable; +use sqlbuild_scopes::scope_index::models::VisibleEntry; +use std::collections::HashMap; + +/// Positions, visibility table and classes of one scope lookup. +#[pyclass(frozen, module = "sqlbuild._native")] +#[derive(Debug)] +pub struct NativeDeclarationContexts { + pub(crate) positions: Vec, + pub(crate) table: VisibilityTable, + pub(crate) classes: ContextClasses, + pub(crate) lookup: LookupMappings, + pub(crate) resolution: ResolutionInputs, +} + +#[pymethods] +impl NativeDeclarationContexts { + #[new] + pub(crate) fn new( + positions: Vec, + table: TableRow, + classes: ContextClasses, + lookups: (LookupMappings, ResolutionInputs), + ) -> Self { + let (lookup, resolution) = lookups; + let (global, local, inherited) = table; + let identity_keys: Vec = positions.iter().map(|row| row.6).collect(); + Self { + table: VisibilityTable { + identity_keys, + global, + local, + inherited, + }, + positions, + classes, + lookup, + resolution, + } + } + + /// `resolve_declaration_context`: the context and whether it was projected, not cached. + #[pyo3(signature = (resolver, file_path, resource=None))] + pub(crate) fn resolve<'py>( + &self, + resolver: Bound<'py, PyAny>, + file_path: Bound<'py, PyAny>, + resource: Option>, + ) -> PyResult<(Bound<'py, PyAny>, bool)> { + compiler_guard(|| { + let path: String = file_path.str()?.to_string(); + self.resolved_context(&resolver, &path, resource.as_ref()) + }) + } +} + +impl NativeDeclarationContexts { + pub fn classified_context<'py>( + &self, + py: Python<'py>, + matches: Vec>, + consumer: Bound<'py, PyAny>, + ) -> PyResult> { + let mut visible: Vec> = Vec::new(); + let mut inaccessible: Vec = Vec::new(); + for record in matches { + let identity: Bound<'py, PyAny> = native_field(&record, "identity")?; + let path: String = native_field(&record, "path")?.extract()?; + let private: Vec = self + .lookup + .private_positions + .bind(py) + .call_method1(intern!(py, "get"), (&identity, PyTuple::empty(py)))? + .extract()?; + if private + .iter() + .any(|position| *position >= self.positions.len()) + { + return Err(compiler_error( + "private declaration outside the scope lookup", + )); + } + let (grants, throughs) = self.grants(py, &identity)?; + let classified = classify_resource( + &self.table, + &ConsumerResource { + private, + path, + grants, + }, + ) + .map_err(|deferral| compiler_error(deferral.reason))?; + for entry in classified.visible { + let through: Option> = + entry.through.map(|slot| throughs[slot].clone()); + visible.push((identity.clone(), entry, through)); + } + inaccessible.extend(classified.inaccessible); + } + self.assemble(py, &visible, &inaccessible, consumer) + } + + /// The resource's grants of indexed declarations, with each grant's `through` value. + pub(crate) fn grants<'py>( + &self, + py: Python<'py>, + identity: &Bound<'py, PyAny>, + ) -> PyResult<(Vec, Vec>)> { + let records: Bound<'py, PyAny> = self + .lookup + .grants_by_resource + .bind(py) + .call_method1(intern!(py, "get"), (identity, PyTuple::empty(py)))?; + let identity_keys: &Bound<'py, PyDict> = self.lookup.identity_keys.bind(py); + let mut grants: Vec = Vec::new(); + let mut throughs: Vec> = Vec::new(); + for grant in records.try_iter()? { + let grant: Bound<'py, PyAny> = grant?; + let Some(identity_key) = + identity_keys.get_item(native_field(&grant, "declaration")?)? + else { + continue; + }; + let kind: String = native_field(&grant, "kind")? + .getattr(intern!(py, "value"))? + .extract()?; + grants.push(GrantEntry { + identity_key: identity_key.extract()?, + reason: if kind == VisibilityReason::TestedMacro.as_str() { + VisibilityReason::TestedMacro + } else { + VisibilityReason::ExpectedModel + }, + through: throughs.len(), + }); + throughs.push(native_field(&grant, "through")?); + } + Ok((grants, throughs)) + } + + pub(crate) fn assemble<'py>( + &self, + py: Python<'py>, + visible: &[VisibleRow<'py>], + inaccessible: &[usize], + consumer: Bound<'py, PyAny>, + ) -> PyResult> { + let parts: ContextParts<'py> = ContextParts { + enums: PyDict::new(py), + constants: PyDict::new(py), + macros: PyDict::new(py), + macro_records: PyDict::new(py), + inaccessible: [PyDict::new(py), PyDict::new(py), PyDict::new(py)], + visibility: [PyDict::new(py), PyDict::new(py), PyDict::new(py)], + }; + let mut records_by_identity: HashMap>> = HashMap::new(); + for (resource, entry, through) in visible { + let record: Bound<'py, PyAny> = self.visibility_record(py, resource, entry, through)?; + records_by_identity + .entry(self.positions[entry.position].6) + .or_default() + .push(record); + } + for (_, entry, _) in visible { + self.add_visible_value(py, &parts, entry.position)?; + } + for position in inaccessible { + let row: &PositionRow = &self.positions[*position]; + if let Some(target) = parts.inaccessible.get(usize::from(row.3)) { + target.set_item(row.2.bind(py), row.1.bind(py))?; + } + } + for (_, entry, _) in visible { + let row: &PositionRow = &self.positions[entry.position]; + if let Some(target) = parts.visibility.get(usize::from(row.3)) { + let records: &[Bound<'py, PyAny>] = + records_by_identity.get(&row.6).map_or(&[], Vec::as_slice); + target.set_item(row.2.bind(py), PyTuple::new(py, records)?)?; + } + } + let fields: Bound<'py, PyDict> = PyDict::new(py); + fields.set_item("enums", &parts.enums)?; + fields.set_item("constants", &parts.constants)?; + fields.set_item("inaccessible_enums", &parts.inaccessible[0])?; + fields.set_item("inaccessible_constants", &parts.inaccessible[1])?; + fields.set_item("enum_visibility", &parts.visibility[0])?; + fields.set_item("constant_visibility", &parts.visibility[1])?; + fields.set_item("macros", &parts.macros)?; + fields.set_item("macro_records", &parts.macro_records)?; + fields.set_item("macro_visibility", &parts.visibility[2])?; + fields.set_item("inaccessible_macros", &parts.inaccessible[2])?; + fields.set_item("consumer", consumer)?; + self.classes + .resolution_context + .bind(py) + .call((), Some(&fields)) + } + + pub(crate) fn add_visible_value<'py>( + &self, + py: Python<'py>, + parts: &ContextParts<'py>, + position: usize, + ) -> PyResult<()> { + let row: &PositionRow = &self.positions[position]; + let name: &Bound<'py, PyAny> = row.2.bind(py); + let value: &Bound<'py, PyAny> = row.4.bind(py); + match row.5 { + ENUM_KIND => parts.enums.set_item(name, value), + CONSTANT_KIND => parts.constants.set_item(name, value), + MACRO_KIND => { + parts.macros.set_item(name, value)?; + parts.macro_records.set_item(name, row.1.bind(py)) + } + _ => Ok(()), + } + } + + pub(crate) fn visibility_record<'py>( + &self, + py: Python<'py>, + resource: &Bound<'py, PyAny>, + entry: &VisibleEntry, + through: &Option>, + ) -> PyResult> { + let none: Bound<'py, PyAny> = py.None().into_bound(py); + let reason: Bound<'py, PyAny> = self + .classes + .reasons + .bind(py) + .get_item(entry.reason.as_str())? + .unwrap_or_else(|| none.clone()); + self.visibility_record_for( + resource, + self.positions[entry.position].0.bind(py), + &reason, + through.as_ref().unwrap_or(&none), + ) + } + + /// A `VisibilityRecord` of `resource`, `declaration`, `reason` and `through`. + pub fn visibility_record_for<'py>( + &self, + resource: &Bound<'py, PyAny>, + declaration: &Bound<'py, PyAny>, + reason: &Bound<'py, PyAny>, + through: &Bound<'py, PyAny>, + ) -> PyResult> { + let py: Python<'py> = resource.py(); + let class: &Bound<'py, PyAny> = self.classes.visibility_record.bind(py); + let record: Bound<'py, PyAny> = class.call1((resource, declaration, reason, through))?; + Ok(record) + } +} + +/// A built scope index and the Python records materialised from it. +#[pyclass(module = "sqlbuild._native")] +#[derive(Debug)] +pub struct NativeScopeIndex { + pub(crate) native: ScopeIndex, + /// Each declaration record in input order. + pub(crate) declarations: Vec>, + pub(crate) index: Py, + pub(crate) grants: Py, +} + +#[pymethods] +impl NativeScopeIndex { + /// The static index, without grants. + #[getter] + pub fn index(&self, py: Python<'_>) -> Py { + self.index.clone_ref(py) + } + + /// Whether any macro, enum or constant is scoped, which makes relationship grants matter. + #[getter] + pub fn has_scoped_relationship_declarations(&self) -> bool { + self.native.has_scoped_relationship_declarations + } + + /// Grant every test's and scenario's relationships; return each extraction fault. + #[pyo3(signature = (*, discovered_inputs, syntax, scan_store))] + pub(crate) fn grant_relationships( + &mut self, + py: Python<'_>, + discovered_inputs: &Bound<'_, PyAny>, + syntax: &Bound<'_, PyAny>, + scan_store: (Bound<'_, PyAny>, String), + ) -> PyResult> { + let files: Vec = items(discovered_inputs, "test_files")? + .iter() + .map(test_file_row) + .collect::>()?; + let scenarios: Vec = items(discovered_inputs, "scenario_files")? + .iter() + .map(scenario_row) + .collect::>()?; + let (store, algorithm) = scan_store; + let settings: Bound<'_, PyDict> = PyDict::new(py); + settings.set_item("syntax", native_field(syntax, "native_mapping")?)?; + settings.set_item("store", store)?; + settings.set_item("scan_key", (algorithm, native_field(syntax, "cache_key")?))?; + let settings: RelationshipScanSettings = settings.extract()?; + let scan: RelationshipScan = scanned_relationships(py, &files, &scenarios, settings)?; + let index: &ScopeIndex = &self.native; + let facts: &[RelationshipFact] = &scan.facts; + let grants: Result, ScopeDeferral> = py + .compiler_detach(|| Ok(relationship_grants(index, facts))) + .map_err(compiler_error)?; + let Ok(grants) = grants else { + return Err(unindexable(py)?); + }; + let classes: ScopeClasses<'_> = ScopeClasses::new(py)?; + let mut records: Vec> = Vec::with_capacity(grants.len()); + for grant in &grants { + let through: Bound<'_, PyAny> = match &grant.through { + GrantThrough::Model(name) => classes.model(RecordId::ResourceIdentity)?.call1(( + classes.member(RecordId::ResourceKind, ResourceKind::Model.as_str())?, + name.as_str(), + ))?, + GrantThrough::Declaration(position) => { + self.declarations[*position].bind(py).getattr("identity")? + } + }; + records.push( + classes.model(RecordId::GrantRecord)?.call1(( + classes.model(RecordId::ResourceIdentity)?.call1(( + classes.member(RecordId::ResourceKind, grant.resource.kind.as_str())?, + grant.resource.name.as_str(), + ))?, + self.declarations[grant.declaration] + .bind(py) + .getattr("identity")?, + through, + classes.member(RecordId::GrantKind, grant.kind.as_str())?, + ))?, + ); + } + self.grants = PyTuple::new(py, records)?.unbind(); + let path_class: Bound<'_, PyAny> = py.import(PATHLIB_MODULE)?.getattr("Path")?; + let faults: Vec> = scan + .faults + .into_iter() + .map(|(path, message)| { + Ok(PyTuple::new( + py, + [path_class.call1((path,))?, message.into_bound_py_any(py)?], + )? + .into_any()) + }) + .collect::>()?; + Ok(PyTuple::new(py, faults)?.unbind()) + } + + /// The index with its grants attached and relationships complete. + pub(crate) fn index_with_relationships(&self, py: Python<'_>) -> PyResult> { + let index: &Bound<'_, PyAny> = self.index.bind(py); + let completeness: Bound<'_, PyAny> = replace( + &native_field(index, "completeness")?, + &[("relationships", true.into_bound_py_any(py)?)], + )?; + Ok(replace( + index, + &[ + ("grants", self.grants.bind(py).clone().into_any()), + ("completeness", completeness), + ], + )? + .unbind()) + } +} + +/// The native scope model and enum classes every built object comes from. +pub struct ScopeClasses<'py> { + pub(crate) py: Python<'py>, +} + +impl std::fmt::Debug for ScopeClasses<'_> { + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + formatter + .debug_struct("ScopeClasses") + .finish_non_exhaustive() + } +} + +impl<'py> ScopeClasses<'py> { + /// The scope classes of `py`. + pub fn new(py: Python<'py>) -> PyResult { + Ok(Self { py }) + } + + /// One scope model class. + pub fn model(&self, name: RecordId) -> PyResult> { + record_class(self.py, name) + } + + /// The member of scope enum `name` with `value`; an unknown value raises `ValueError`. + pub fn member(&self, name: RecordId, value: &str) -> PyResult> { + new_record(self.py, name, (value,), None) + } + + /// The interpreter the classes belong to. + pub fn py(&self) -> Python<'py> { + self.py + } +} + +/// Target, location, whether it is a directory, and the filters. +#[derive(Debug)] +pub struct ReportArguments<'py> { + pub target: Option>, + pub at: Option>, + pub directory: bool, + pub filters: Option>, +} + +/// Declaration, target, location and whether it is a directory. +#[derive(Debug)] +pub struct ExplainArguments<'py> { + pub declaration: Bound<'py, PyAny>, + pub target: Option>, + pub at: Option>, + pub directory: bool, +} + +/// Folder, filters, target and whether the target is prospective. +#[derive(Debug)] +pub struct ListArguments<'py> { + pub folder: String, + pub filters: Option>, + pub target: Option>, + pub target_is_prospective: bool, +} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/authored_ctes.rs b/crates/sqlbuild-python-front/src/sql_test_glue/_helpers/authored_ctes.rs similarity index 98% rename from crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/authored_ctes.rs rename to crates/sqlbuild-python-front/src/sql_test_glue/_helpers/authored_ctes.rs index b2bfd88836..e6e78be935 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/authored_ctes.rs +++ b/crates/sqlbuild-python-front/src/sql_test_glue/_helpers/authored_ctes.rs @@ -12,7 +12,7 @@ use sqlbuild_analysis::compiler::models::{SqlTestExtractionFailure, SqlTestReque use sqlbuild_analysis::sql_test_attachment::main::authored_test_offset::authored_test_offset; use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; -use crate::bindings::_helpers::sqltext::lexical_syntax::LexicalSyntaxInput; +use crate::sqltext::models::LexicalSyntaxInput; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; diff --git a/crates/sqlbuild-python-front/src/sql_test_glue/_helpers/mod.rs b/crates/sqlbuild-python-front/src/sql_test_glue/_helpers/mod.rs new file mode 100644 index 0000000000..b5cbd1d8ea --- /dev/null +++ b/crates/sqlbuild-python-front/src/sql_test_glue/_helpers/mod.rs @@ -0,0 +1 @@ +pub(crate) mod authored_ctes; diff --git a/crates/sqlbuild-python-front/src/sql_test_glue/main/mod.rs b/crates/sqlbuild-python-front/src/sql_test_glue/main/mod.rs new file mode 100644 index 0000000000..cf178c6ba0 --- /dev/null +++ b/crates/sqlbuild-python-front/src/sql_test_glue/main/mod.rs @@ -0,0 +1,3 @@ +pub mod prefixed_ctes; +pub mod register_authored_ctes; +pub mod validate_authored_sql_test_ctes; diff --git a/crates/sqlbuild-python-front/src/sql_test_glue/main/prefixed_ctes.rs b/crates/sqlbuild-python-front/src/sql_test_glue/main/prefixed_ctes.rs new file mode 100644 index 0000000000..ee70b193f8 --- /dev/null +++ b/crates/sqlbuild-python-front/src/sql_test_glue/main/prefixed_ctes.rs @@ -0,0 +1,13 @@ +//! Extract fixture bodies from authored test or scenario CTEs in authored order. + +use crate::sql_test_glue::_helpers::authored_ctes; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyDict; + +/// Extract fixture bodies from authored test or scenario CTEs in authored order. +#[inline] +pub fn prefixed_ctes<'py>(ctes: &Bound<'py, PyAny>, prefix: &str) -> PyResult> { + authored_ctes::prefixed_ctes(ctes, prefix) +} diff --git a/crates/sqlbuild-python-front/src/sql_test_glue/main/register_authored_ctes.rs b/crates/sqlbuild-python-front/src/sql_test_glue/main/register_authored_ctes.rs new file mode 100644 index 0000000000..06b795b1ca --- /dev/null +++ b/crates/sqlbuild-python-front/src/sql_test_glue/main/register_authored_ctes.rs @@ -0,0 +1,12 @@ +//! Register the authored ctes functions and classes. + +use crate::sql_test_glue::_helpers::authored_ctes; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the authored ctes functions and classes. +#[inline] +pub fn register_authored_ctes(module: &Bound<'_, PyModule>) -> PyResult<()> { + authored_ctes::register(module) +} diff --git a/crates/sqlbuild-python-front/src/sql_test_glue/main/validate_authored_sql_test_ctes.rs b/crates/sqlbuild-python-front/src/sql_test_glue/main/validate_authored_sql_test_ctes.rs new file mode 100644 index 0000000000..4fb8a7c492 --- /dev/null +++ b/crates/sqlbuild-python-front/src/sql_test_glue/main/validate_authored_sql_test_ctes.rs @@ -0,0 +1,19 @@ +//! Reject the first authored test block, then scenario, whose CTE names cannot be read. + +use crate::sql_test_glue::_helpers::authored_ctes; +use crate::sqltext::models::LexicalSyntaxInput; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyErr; +use pyo3::prelude::Python; + +/// Reject the first authored test block, then scenario, whose CTE names cannot be read. +#[inline] +pub fn validate_authored_sql_test_ctes( + py: Python<'_>, + test_files: Bound<'_, PyAny>, + scenario_files: Bound<'_, PyAny>, + syntax: LexicalSyntaxInput, +) -> Result<(), PyErr> { + authored_ctes::validate_authored_sql_test_ctes(py, test_files, scenario_files, syntax) +} diff --git a/crates/sqlbuild-python-front/src/sql_test_glue/mod.rs b/crates/sqlbuild-python-front/src/sql_test_glue/mod.rs new file mode 100644 index 0000000000..28fdd5543e --- /dev/null +++ b/crates/sqlbuild-python-front/src/sql_test_glue/mod.rs @@ -0,0 +1,4 @@ +//! Authored CTEs of SQL tests. + +pub(crate) mod _helpers; +pub mod main; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sqltext/authored_values.rs b/crates/sqlbuild-python-front/src/sqltext/_helpers/authored_values.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/sqltext/authored_values.rs rename to crates/sqlbuild-python-front/src/sqltext/_helpers/authored_values.rs diff --git a/crates/sqlbuild-python-front/src/sqltext/_helpers/code_scanner.rs b/crates/sqlbuild-python-front/src/sqltext/_helpers/code_scanner.rs new file mode 100644 index 0000000000..948a471284 --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/_helpers/code_scanner.rs @@ -0,0 +1,9 @@ +//! Comment, quoted-text and parenthesis boundaries at Python string offsets of one SQL text. + +use crate::sqltext::models::SqlCodeScanner; +use pyo3::prelude::{Bound, PyModule, PyModuleMethods, PyResult}; + +pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { + module.add_class::()?; + Ok(()) +} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sqltext/ddl_effects.rs b/crates/sqlbuild-python-front/src/sqltext/_helpers/ddl_effects.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/sqltext/ddl_effects.rs rename to crates/sqlbuild-python-front/src/sqltext/_helpers/ddl_effects.rs diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sqltext/declaration_references.rs b/crates/sqlbuild-python-front/src/sqltext/_helpers/declaration_references.rs similarity index 91% rename from crates/sqlbuild-python/src/bindings/_helpers/sqltext/declaration_references.rs rename to crates/sqlbuild-python-front/src/sqltext/_helpers/declaration_references.rs index e990f03a98..a31739eb01 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sqltext/declaration_references.rs +++ b/crates/sqlbuild-python-front/src/sqltext/_helpers/declaration_references.rs @@ -1,5 +1,6 @@ //! `@enum`/`@const` reference offsets scanned natively for the model loop. +use crate::sqltext::models::ScannedReference; use sqlbuild_analysis::sql_macros::constants::SQL_CALL_PREFIX; use sqlbuild_analysis::sql_macros::main::sql_macro_calls::sql_macro_calls; use sqlbuild_sqltext::compiler::main::declaration_references::scan_declaration_references; @@ -12,17 +13,8 @@ use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; /// The reference kind of an outer SQL macro call. const SQL_MACRO_REFERENCE_KIND: u8 = 2; -/// One natively scanned reference: kind 0 is an enum member, 1 a constant, 2 a SQL macro call. -#[derive(Clone)] -pub(crate) struct ScannedReference { - pub(crate) kind: u8, - pub(crate) name: String, - pub(crate) member: Option, - pub(crate) start: usize, - pub(crate) end: usize, -} /// References and stop code: unclosed quote 0, block comment 1, invalid enum 2, constant 3. -type ScanRow = (Vec, Option); +pub(crate) type ScanRow = (Vec, Option); /// One SQL string's references and stop code, scanned without walking past malformed ones. pub(crate) fn declaration_scan(sql: &str, syntax: Option<&LexicalSyntax>) -> ScanRow { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sqltext/lexical_syntax.rs b/crates/sqlbuild-python-front/src/sqltext/_helpers/lexical_syntax.rs similarity index 89% rename from crates/sqlbuild-python/src/bindings/_helpers/sqltext/lexical_syntax.rs rename to crates/sqlbuild-python-front/src/sqltext/_helpers/lexical_syntax.rs index 4fa4e68116..200ce9e1eb 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sqltext/lexical_syntax.rs +++ b/crates/sqlbuild-python-front/src/sqltext/_helpers/lexical_syntax.rs @@ -1,6 +1,6 @@ //! One adapter's `SqlLexicalSyntax`, read from a Python mapping. -use pyo3::FromPyObject; +use crate::sqltext::models::LexicalSyntaxInput; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; use pyo3::types::PyFrozenSet; use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; @@ -9,18 +9,6 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; -/// One adapter's `SqlLexicalSyntax`, read from a Python mapping. -#[derive(Clone, FromPyObject)] -#[pyo3(from_item_all)] -pub(crate) struct LexicalSyntaxInput { - backslash_escape_quotes: Vec, - escape_string_prefix: bool, - raw_string_prefix: bool, - triple_quoted_strings: bool, - nested_block_comments: bool, - line_comment_prefixes: Vec, -} - impl From for LexicalSyntax { fn from(input: LexicalSyntaxInput) -> Self { Self { diff --git a/crates/sqlbuild-python-front/src/sqltext/_helpers/mod.rs b/crates/sqlbuild-python-front/src/sqltext/_helpers/mod.rs new file mode 100644 index 0000000000..4a2ee8426a --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/_helpers/mod.rs @@ -0,0 +1,9 @@ +pub(crate) mod authored_values; +pub(crate) mod code_scanner; +pub(crate) mod ddl_effects; +pub(crate) mod declaration_references; +pub(crate) mod lexical_syntax; +pub(crate) mod model_headers; +pub(crate) mod placeholders; +pub(crate) mod sql_references; +pub(crate) mod static_sql; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sqltext/model_headers.rs b/crates/sqlbuild-python-front/src/sqltext/_helpers/model_headers.rs similarity index 84% rename from crates/sqlbuild-python/src/bindings/_helpers/sqltext/model_headers.rs rename to crates/sqlbuild-python-front/src/sqltext/_helpers/model_headers.rs index 0aa0183f3e..f8c8ecd8c9 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sqltext/model_headers.rs +++ b/crates/sqlbuild-python-front/src/sqltext/_helpers/model_headers.rs @@ -1,20 +1,15 @@ //! Match, tokenize and parse model headers natively. -use pyo3::prelude::{Bound, Py, PyAny, PyModule, PyModuleMethods, PyResult, Python}; +use crate::sqltext::models::ColumnLocation; +use crate::sqltext::types::ParsedModelHeader; +use pyo3::prelude::{Bound, PyModule, PyModuleMethods, PyResult, Python}; use pyo3::{pyfunction, wrap_pyfunction}; -use sqlbuild_python_base::positional_record; -use crate::bindings::_helpers::sqltext::authored_values::optional_authored_value_to_python; +use crate::sqltext::_helpers::authored_values::optional_authored_value_to_python; use sqlbuild_python_base::boundary::main::compiler_guard::compiler_guard; use sqlbuild_python_base::boundary::main::value_error::value_error; use sqlbuild_python_base::types::CompilerDetach; -pub(crate) type ParsedModelHeader = ( - Option>, - Option>, - Option, -); - #[pyfunction] pub(crate) fn parse_model_headers( py: Python<'_>, @@ -37,18 +32,6 @@ pub(crate) fn parse_model_headers( .collect() } -positional_record! { - into; - /// A column name and its authored line, column, end line and end column. - pub(crate) struct ColumnLocation { - pub(crate) name: String, - pub(crate) line: usize, - pub(crate) column: usize, - pub(crate) end_line: usize, - pub(crate) end_column: usize, - } -} - pub(crate) fn location_rows( locations: Vec<(String, sqlbuild_sqltext::compiler::models::TextLocation)>, ) -> Vec { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sqltext/placeholders.rs b/crates/sqlbuild-python-front/src/sqltext/_helpers/placeholders.rs similarity index 100% rename from crates/sqlbuild-python/src/bindings/_helpers/sqltext/placeholders.rs rename to crates/sqlbuild-python-front/src/sqltext/_helpers/placeholders.rs diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sqltext/sql_references.rs b/crates/sqlbuild-python-front/src/sqltext/_helpers/sql_references.rs similarity index 99% rename from crates/sqlbuild-python/src/bindings/_helpers/sqltext/sql_references.rs rename to crates/sqlbuild-python-front/src/sqltext/_helpers/sql_references.rs index 6e04c994fb..c45eecade0 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sqltext/sql_references.rs +++ b/crates/sqlbuild-python-front/src/sqltext/_helpers/sql_references.rs @@ -12,7 +12,7 @@ use sqlbuild_sqltext::sql_references::models::{ }; use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; -use crate::bindings::_helpers::sqltext::lexical_syntax::LexicalSyntaxInput; +use crate::sqltext::models::LexicalSyntaxInput; use sqlbuild_python_base::boundary::main::compiler_guard::compiler_guard; use sqlbuild_python_base::compile_context::main::diagnostic_collector::report_compile_diagnostic::report_compile_diagnostic; use sqlbuild_python_base::records::main::construct::enum_from_value::enum_from_value; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sqltext/static_sql.rs b/crates/sqlbuild-python-front/src/sqltext/_helpers/static_sql.rs similarity index 88% rename from crates/sqlbuild-python/src/bindings/_helpers/sqltext/static_sql.rs rename to crates/sqlbuild-python-front/src/sqltext/_helpers/static_sql.rs index a85311b919..1e37cd63c7 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sqltext/static_sql.rs +++ b/crates/sqlbuild-python-front/src/sqltext/_helpers/static_sql.rs @@ -1,5 +1,7 @@ //! Interpolate `@@` tokens in authored SQL and extract static SQL references. +use crate::sqltext::models::InterpolationRow; +use crate::sqltext::models::InterpolationSources; use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; use std::cell::RefCell; @@ -11,30 +13,9 @@ use sqlbuild_sqltext::compiler::main::sql_interpolation::interpolate_sql; use sqlbuild_sqltext::compiler::models::InterpolationRead; use sqlbuild_sqltext::compiler::types::InterpolationHost; -use crate::bindings::_helpers::render::macro_call_rows::SpanRow; - const ENVIRONMENT_READ: &str = "env"; const CONTEXT_READ: &str = "ctx"; -/// One SQL text interpolated: its SQL, substitution spans, reads and error message. -pub(crate) struct InterpolationRow { - /// The interpolated SQL, or `None` when unchanged. - pub(crate) sql: Option, - pub(crate) spans: Vec, - pub(crate) reads: Vec<(&'static str, String)>, - pub(crate) error: Option, -} - -/// Variables, environment, context values (or `None`), variable renderer and lexical rules. -pub(crate) struct InterpolationSources<'py>( - pub(crate) Bound<'py, PyDict>, - pub(crate) Bound<'py, PyAny>, - pub(crate) Option>, - pub(crate) Bound<'py, PyAny>, - /// The lexical rules the SQL is authored in; `None` reads it under the generic rules. - pub(crate) Option, -); - struct PythonInterpolationHost<'py> { sources: InterpolationSources<'py>, /// A Python exception other than a rendering `ValueError`, raised after the scan. diff --git a/crates/sqlbuild-python-front/src/sqltext/main/authored_value_to_python.rs b/crates/sqlbuild-python-front/src/sqltext/main/authored_value_to_python.rs new file mode 100644 index 0000000000..4b26dde9b3 --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/authored_value_to_python.rs @@ -0,0 +1,14 @@ +//! One authored value as the Python header object discovery hands to config builds. + +use crate::sqltext::_helpers::authored_values; +use pyo3::prelude::Py; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use sqlbuild_sqltext::compiler::models::AuthoredValue; + +/// One authored value as the Python header object discovery hands to config builds. +#[inline] +pub fn authored_value_to_python(py: Python<'_>, value: &AuthoredValue) -> PyResult> { + authored_values::authored_value_to_python(py, value) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/main/declaration_scan.rs b/crates/sqlbuild-python-front/src/sqltext/main/declaration_scan.rs new file mode 100644 index 0000000000..78b1018b7c --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/declaration_scan.rs @@ -0,0 +1,11 @@ +//! One SQL string's references and stop code, scanned without walking past malformed ones. + +use crate::sqltext::_helpers::declaration_references; +use crate::sqltext::_helpers::declaration_references::ScanRow; +use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; + +/// One SQL string's references and stop code, scanned without walking past malformed ones. +#[inline] +pub fn declaration_scan(sql: &str, syntax: Option<&LexicalSyntax>) -> ScanRow { + declaration_references::declaration_scan(sql, syntax) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/main/extract_references.rs b/crates/sqlbuild-python-front/src/sqltext/main/extract_references.rs new file mode 100644 index 0000000000..dd8e5d84b4 --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/extract_references.rs @@ -0,0 +1,16 @@ +//! Logical SQL refs outside comments and quotes, reporting rejected calls as P012. + +use crate::sqltext::_helpers::sql_references; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// Logical SQL refs outside comments and quotes, reporting rejected calls as P012. +#[inline] +pub fn extract_references<'py>( + sql: &str, + syntax: &Bound<'py, PyAny>, +) -> PyResult> { + sql_references::extract_references(sql, syntax) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/main/header_failure.rs b/crates/sqlbuild-python-front/src/sqltext/main/header_failure.rs new file mode 100644 index 0000000000..3a0a42ef4a --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/header_failure.rs @@ -0,0 +1,13 @@ +//! A header syntax error's detail, help and file line (when `header_line` is known). + +use crate::sqltext::_helpers::model_headers; + +/// A header syntax error's detail, help and file line (when `header_line` is known). +#[inline] +pub fn header_failure( + error: &str, + header: &str, + header_line: Option, +) -> (String, Option, Option) { + model_headers::header_failure(error, header, header_line) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/main/interpolated.rs b/crates/sqlbuild-python-front/src/sqltext/main/interpolated.rs new file mode 100644 index 0000000000..37f5d41c82 --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/interpolated.rs @@ -0,0 +1,16 @@ +//! One SQL text interpolated: the SQL (`None` when unchanged), its reads, and its error. + +use crate::sqltext::_helpers::static_sql; +use crate::sqltext::_helpers::static_sql::InterpolatedRow; +use crate::sqltext::models::InterpolationSources; +use pyo3::prelude::PyResult; + +/// One SQL text interpolated: the SQL (`None` when unchanged), its reads, and its error. +#[inline] +pub fn interpolated( + sources: InterpolationSources<'_>, + sql: &str, + file_path: &str, +) -> PyResult { + static_sql::interpolated(sources, sql, file_path) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/main/interpolation_batch.rs b/crates/sqlbuild-python-front/src/sqltext/main/interpolation_batch.rs new file mode 100644 index 0000000000..5c13ea9fdf --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/interpolation_batch.rs @@ -0,0 +1,15 @@ +//! Each `(sql, file path)` interpolated in order; non-rendering Python failures raise. + +use crate::sqltext::_helpers::static_sql; +use crate::sqltext::models::InterpolationRow; +use crate::sqltext::models::InterpolationSources; +use pyo3::prelude::PyResult; + +/// Each `(sql, file path)` interpolated in order; non-rendering Python failures raise. +#[inline] +pub fn interpolation_batch( + sources: InterpolationSources<'_>, + sqls: &[(String, String)], +) -> PyResult> { + static_sql::interpolation_batch(sources, sqls) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/main/location_rows.rs b/crates/sqlbuild-python-front/src/sqltext/main/location_rows.rs new file mode 100644 index 0000000000..5788549395 --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/location_rows.rs @@ -0,0 +1,12 @@ +//! Location rows. + +use crate::sqltext::_helpers::model_headers; +use crate::sqltext::models::ColumnLocation; + +/// Location rows. +#[inline] +pub fn location_rows( + locations: Vec<(String, sqlbuild_sqltext::compiler::models::TextLocation)>, +) -> Vec { + model_headers::location_rows(locations) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/main/map_to_python.rs b/crates/sqlbuild-python-front/src/sqltext/main/map_to_python.rs new file mode 100644 index 0000000000..eb9e38b163 --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/map_to_python.rs @@ -0,0 +1,14 @@ +//! Map to python. + +use crate::sqltext::_helpers::authored_values; +use pyo3::prelude::Py; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use sqlbuild_sqltext::compiler::models::AuthoredValue; + +/// Map to python. +#[inline] +pub fn map_to_python(py: Python<'_>, values: &[(String, AuthoredValue)]) -> PyResult> { + authored_values::map_to_python(py, values) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/main/mod.rs b/crates/sqlbuild-python-front/src/sqltext/main/mod.rs new file mode 100644 index 0000000000..7d472535a4 --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/mod.rs @@ -0,0 +1,20 @@ +pub mod authored_value_to_python; +pub mod declaration_scan; +pub mod extract_references; +pub mod header_failure; +pub mod interpolated; +pub mod interpolation_batch; +pub mod location_rows; +pub mod map_to_python; +pub mod model_output_columns; +pub mod optional_authored_value_to_python; +pub mod optional_record_syntax; +pub mod parse_model_headers; +pub mod record_syntax; +pub mod register_code_scanner; +pub mod register_ddl_effects; +pub mod register_model_headers; +pub mod register_placeholders; +pub mod register_sql_references; +pub mod sorted_texts; +pub mod syntax_record; diff --git a/crates/sqlbuild-python-front/src/sqltext/main/model_output_columns.rs b/crates/sqlbuild-python-front/src/sqltext/main/model_output_columns.rs new file mode 100644 index 0000000000..3c8c84f92b --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/model_output_columns.rs @@ -0,0 +1,14 @@ +//! Simple top-level SELECT output names and their authored locations. + +use crate::sqltext::_helpers::model_headers; +use crate::sqltext::models::ColumnLocation; +use pyo3::prelude::PyResult; + +/// Simple top-level SELECT output names and their authored locations. +#[inline] +pub fn model_output_columns( + contents: &str, + implicit_aliases: bool, +) -> PyResult> { + model_headers::model_output_columns(contents, implicit_aliases) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/main/optional_authored_value_to_python.rs b/crates/sqlbuild-python-front/src/sqltext/main/optional_authored_value_to_python.rs new file mode 100644 index 0000000000..6385780a54 --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/optional_authored_value_to_python.rs @@ -0,0 +1,17 @@ +//! Optional authored value to python. + +use crate::sqltext::_helpers::authored_values; +use pyo3::prelude::Py; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use sqlbuild_sqltext::compiler::models::AuthoredValue; + +/// Optional authored value to python. +#[inline] +pub fn optional_authored_value_to_python( + py: Python<'_>, + value: Option<&AuthoredValue>, +) -> PyResult>> { + authored_values::optional_authored_value_to_python(py, value) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/main/optional_record_syntax.rs b/crates/sqlbuild-python-front/src/sqltext/main/optional_record_syntax.rs new file mode 100644 index 0000000000..d329f2acc3 --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/optional_record_syntax.rs @@ -0,0 +1,13 @@ +//! The lexical rules a `SqlLexicalSyntax` record holds, or `None` for `None`. + +use crate::sqltext::_helpers::lexical_syntax; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; + +/// The lexical rules a `SqlLexicalSyntax` record holds, or `None` for `None`. +#[inline] +pub fn optional_record_syntax(value: &Bound<'_, PyAny>) -> PyResult> { + lexical_syntax::optional_record_syntax(value) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/main/parse_model_headers.rs b/crates/sqlbuild-python-front/src/sqltext/main/parse_model_headers.rs new file mode 100644 index 0000000000..068fe6c526 --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/parse_model_headers.rs @@ -0,0 +1,15 @@ +//! Parse model headers. + +use crate::sqltext::_helpers::model_headers; +use crate::sqltext::types::ParsedModelHeader; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; + +/// Parse model headers. +#[inline] +pub fn parse_model_headers( + py: Python<'_>, + headers: Vec, +) -> PyResult> { + model_headers::parse_model_headers(py, headers) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/main/record_syntax.rs b/crates/sqlbuild-python-front/src/sqltext/main/record_syntax.rs new file mode 100644 index 0000000000..a990fdc113 --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/record_syntax.rs @@ -0,0 +1,13 @@ +//! The lexical rules a `SqlLexicalSyntax` record holds. + +use crate::sqltext::_helpers::lexical_syntax; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; + +/// The lexical rules a `SqlLexicalSyntax` record holds. +#[inline] +pub fn record_syntax(instance: &Bound<'_, PyAny>) -> PyResult { + lexical_syntax::record_syntax(instance) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/main/register_code_scanner.rs b/crates/sqlbuild-python-front/src/sqltext/main/register_code_scanner.rs new file mode 100644 index 0000000000..f70b7bc051 --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/register_code_scanner.rs @@ -0,0 +1,12 @@ +//! Register the code scanner functions and classes. + +use crate::sqltext::_helpers::code_scanner; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the code scanner functions and classes. +#[inline] +pub fn register_code_scanner(module: &Bound<'_, PyModule>) -> PyResult<()> { + code_scanner::register(module) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/main/register_ddl_effects.rs b/crates/sqlbuild-python-front/src/sqltext/main/register_ddl_effects.rs new file mode 100644 index 0000000000..6ab4c7d18f --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/register_ddl_effects.rs @@ -0,0 +1,12 @@ +//! Register the ddl effects functions and classes. + +use crate::sqltext::_helpers::ddl_effects; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the ddl effects functions and classes. +#[inline] +pub fn register_ddl_effects(module: &Bound<'_, PyModule>) -> PyResult<()> { + ddl_effects::register(module) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/main/register_model_headers.rs b/crates/sqlbuild-python-front/src/sqltext/main/register_model_headers.rs new file mode 100644 index 0000000000..abf259e94a --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/register_model_headers.rs @@ -0,0 +1,12 @@ +//! Register the model headers functions and classes. + +use crate::sqltext::_helpers::model_headers; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the model headers functions and classes. +#[inline] +pub fn register_model_headers(module: &Bound<'_, PyModule>) -> PyResult<()> { + model_headers::register(module) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/main/register_placeholders.rs b/crates/sqlbuild-python-front/src/sqltext/main/register_placeholders.rs new file mode 100644 index 0000000000..e49345fc1b --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/register_placeholders.rs @@ -0,0 +1,12 @@ +//! Register the placeholders functions and classes. + +use crate::sqltext::_helpers::placeholders; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the placeholders functions and classes. +#[inline] +pub fn register_placeholders(module: &Bound<'_, PyModule>) -> PyResult<()> { + placeholders::register(module) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/main/register_sql_references.rs b/crates/sqlbuild-python-front/src/sqltext/main/register_sql_references.rs new file mode 100644 index 0000000000..98649fadff --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/register_sql_references.rs @@ -0,0 +1,12 @@ +//! Register the sql references functions and classes. + +use crate::sqltext::_helpers::sql_references; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the sql references functions and classes. +#[inline] +pub fn register_sql_references(module: &Bound<'_, PyModule>) -> PyResult<()> { + sql_references::register(module) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/main/sorted_texts.rs b/crates/sqlbuild-python-front/src/sqltext/main/sorted_texts.rs new file mode 100644 index 0000000000..f16064c9b8 --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/sorted_texts.rs @@ -0,0 +1,12 @@ +//! The sorted texts of a set of strings. + +use crate::sqltext::_helpers::lexical_syntax; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// The sorted texts of a set of strings. +#[inline] +pub fn sorted_texts(values: &Bound<'_, PyAny>) -> PyResult> { + lexical_syntax::sorted_texts(values) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/main/syntax_record.rs b/crates/sqlbuild-python-front/src/sqltext/main/syntax_record.rs new file mode 100644 index 0000000000..6cc6dfdb00 --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/main/syntax_record.rs @@ -0,0 +1,14 @@ +//! A `SqlLexicalSyntax` record holding `syntax`. + +use crate::sqltext::_helpers::lexical_syntax; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; + +/// A `SqlLexicalSyntax` record holding `syntax`. +#[inline] +pub fn syntax_record<'py>(py: Python<'py>, syntax: &LexicalSyntax) -> PyResult> { + lexical_syntax::syntax_record(py, syntax) +} diff --git a/crates/sqlbuild-python-front/src/sqltext/mod.rs b/crates/sqlbuild-python-front/src/sqltext/mod.rs new file mode 100644 index 0000000000..9b314966b6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/mod.rs @@ -0,0 +1,6 @@ +//! Lexical SQL text: code scanning, references, placeholders, model headers and static SQL. + +pub(crate) mod _helpers; +pub mod main; +pub mod models; +pub mod types; diff --git a/crates/sqlbuild-python-front/src/sqltext/models.rs b/crates/sqlbuild-python-front/src/sqltext/models.rs new file mode 100644 index 0000000000..7ebb26aa9f --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/models.rs @@ -0,0 +1,140 @@ +//! Public records of sqltext. + +use crate::render::types::SpanRow; +use pyo3::FromPyObject; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyAnyMethods; +use pyo3::prelude::PyResult; +use pyo3::prelude::Python; +use pyo3::pyclass; +use pyo3::pymethods; +use pyo3::types::PyDict; +use sqlbuild_python_base::records::main::construct::error_class::error_class; +use sqlbuild_python_base::records::types::ErrorId; +use sqlbuild_sqltext::code_scanner::main::code_scanner::code_scanner; +use sqlbuild_sqltext::code_scanner::main::scanner_matching_paren::scanner_matching_paren; +use sqlbuild_sqltext::code_scanner::main::scanner_non_code_end::scanner_non_code_end; +use sqlbuild_sqltext::code_scanner::models::CodeScanner; +use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; +use sqlbuild_sqltext::sql_scan::models::Unclosed; + +/// One SQL text scanned under an adapter's lexical rules, or the generic compiler rules. +#[pyclass(module = "sqlbuild._native", frozen)] +#[derive(Debug)] +pub struct SqlCodeScanner { + pub(crate) scanner: CodeScanner, + pub(crate) context: String, +} + +#[pymethods] +impl SqlCodeScanner { + #[new] + #[pyo3(signature = (sql, syntax, context))] + pub fn new(sql: &str, syntax: Option, context: String) -> Self { + Self { + scanner: code_scanner(sql, syntax.map(Into::into)), + context, + } + } + + /// The end of the comment or quoted text at `index`, or `None` when code starts there. + pub fn non_code_end(&self, py: Python<'_>, index: usize) -> PyResult> { + scanner_non_code_end(&self.scanner, index).map_err(|unclosed| self.error(py, unclosed)) + } + + /// The index of the parenthesis closing the one at `open`. + pub fn matching_paren(&self, py: Python<'_>, open: usize) -> PyResult { + scanner_matching_paren(&self.scanner, open).map_err(|unclosed| self.error(py, unclosed)) + } +} + +impl SqlCodeScanner { + /// `CompileInputError(" contains an unclosed ...")`. + pub(crate) fn error(&self, py: Python<'_>, unclosed: Unclosed) -> pyo3::prelude::PyErr { + let construct: &str = match unclosed { + Unclosed::BlockComment => "block comment", + Unclosed::Quote => "quoted string", + Unclosed::Parenthesis => "parenthesis", + }; + let message: String = format!("{} contains an unclosed {construct}", self.context); + let raised = || -> PyResult { + let error: Bound<'_, PyAny> = + error_class(py, ErrorId::CompileInput)?.call1((message,))?; + Ok(pyo3::prelude::PyErr::from_value(error)) + }; + raised().unwrap_or_else(|error| error) + } +} + +/// One natively scanned reference: kind 0 is an enum member, 1 a constant, 2 a SQL macro call. +#[derive(Debug, Clone)] +pub struct ScannedReference { + pub kind: u8, + pub name: String, + pub member: Option, + pub start: usize, + pub end: usize, +} + +/// One adapter's `SqlLexicalSyntax`, read from a Python mapping. +#[derive(Debug, Clone, FromPyObject)] +#[pyo3(from_item_all)] +pub struct LexicalSyntaxInput { + pub(crate) backslash_escape_quotes: Vec, + pub(crate) escape_string_prefix: bool, + pub(crate) raw_string_prefix: bool, + pub(crate) triple_quoted_strings: bool, + pub(crate) nested_block_comments: bool, + pub(crate) line_comment_prefixes: Vec, +} + +/// A column name and its authored line, column, end line and end column. +#[derive(Debug)] +pub struct ColumnLocation { + pub name: String, + pub line: usize, + pub column: usize, + pub end_line: usize, + pub end_column: usize, +} + +impl<'py> pyo3::IntoPyObject<'py> for ColumnLocation { + type Target = pyo3::types::PyTuple; + type Output = pyo3::Bound<'py, pyo3::types::PyTuple>; + type Error = pyo3::PyErr; + + fn into_pyobject(self, py: pyo3::Python<'py>) -> Result { + pyo3::IntoPyObject::into_pyobject( + ( + self.name, + self.line, + self.column, + self.end_line, + self.end_column, + ), + py, + ) + } +} + +/// One SQL text interpolated: its SQL, substitution spans, reads and error message. +#[derive(Debug)] +pub struct InterpolationRow { + /// The interpolated SQL, or `None` when unchanged. + pub sql: Option, + pub spans: Vec, + pub reads: Vec<(&'static str, String)>, + pub error: Option, +} + +/// Variables, environment, context values (or `None`), variable renderer and lexical rules. +#[derive(Debug)] +pub struct InterpolationSources<'py>( + pub Bound<'py, PyDict>, + pub Bound<'py, PyAny>, + pub Option>, + pub Bound<'py, PyAny>, + /// The lexical rules the SQL is authored in; `None` reads it under the generic rules. + pub Option, +); diff --git a/crates/sqlbuild-python-front/src/sqltext/types.rs b/crates/sqlbuild-python-front/src/sqltext/types.rs new file mode 100644 index 0000000000..bac8d76df6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/sqltext/types.rs @@ -0,0 +1,10 @@ +//! Public traits and type aliases of sqltext. + +use pyo3::prelude::Py; +use pyo3::prelude::PyAny; + +pub type ParsedModelHeader = ( + Option>, + Option>, + Option, +); diff --git a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/events.rs b/crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/events.rs similarity index 97% rename from crates/sqlbuild-python/src/bindings/_helpers/state_rows/events.rs rename to crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/events.rs index b3082aad36..58a33d0726 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/events.rs +++ b/crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/events.rs @@ -16,7 +16,8 @@ use sqlbuild_state::events::main::migration_event_id::migration_event_id; use sqlbuild_state::events::main::old_name_view_event_id::old_name_view_event_id; use sqlbuild_state::events::models::{EventRelation, StateCell, StateColumnType, StateValue}; -use crate::bindings::_helpers::state_rows::timestamps::{date_time_typed, presumed_utc}; +use crate::state_rows::_helpers::event_rows::timestamps::date_time_typed; +use crate::state_rows::_helpers::event_rows::timestamps::presumed_utc; use sqlbuild_python_base::boundary::models::Request; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::fields::field::field as native_field; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/freshness.rs b/crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/freshness.rs similarity index 96% rename from crates/sqlbuild-python/src/bindings/_helpers/state_rows/freshness.rs rename to crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/freshness.rs index 5264dcd08a..e3e00b6dba 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/freshness.rs +++ b/crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/freshness.rs @@ -19,10 +19,12 @@ use sqlbuild_state::freshness::models::{ }; use sqlbuild_state::freshness::types::TimestampParser; -use crate::bindings::_helpers::cursor::values::{DATETIME_MODULE, local_date_time}; -use crate::bindings::_helpers::state_rows::timestamps::{ - date_time_typed, in_utc, offset_aware, presumed_utc, -}; +use crate::cursor::constants::DATETIME_MODULE; +use crate::cursor::main::values::local_date_time::local_date_time; +use crate::state_rows::_helpers::event_rows::timestamps::date_time_typed; +use crate::state_rows::_helpers::event_rows::timestamps::in_utc; +use crate::state_rows::_helpers::event_rows::timestamps::offset_aware; +use crate::state_rows::_helpers::event_rows::timestamps::presumed_utc; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::records::main::construct::enum_member::enum_member; use sqlbuild_python_base::records::main::construct::record_class::record_class; diff --git a/crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/mod.rs b/crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/mod.rs new file mode 100644 index 0000000000..fd6367a2fd --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/mod.rs @@ -0,0 +1,3 @@ +pub(crate) mod events; +pub(crate) mod freshness; +pub(crate) mod timestamps; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/timestamps.rs b/crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/timestamps.rs similarity index 91% rename from crates/sqlbuild-python/src/bindings/_helpers/state_rows/timestamps.rs rename to crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/timestamps.rs index 6629ea2924..645abff126 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/timestamps.rs +++ b/crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/timestamps.rs @@ -3,7 +3,8 @@ use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult}; use sqlbuild_cursor::algebra::models::LocalDateTime; -use crate::bindings::_helpers::cursor::values::{DATETIME_MODULE, local_date_time}; +use crate::cursor::constants::DATETIME_MODULE; +use crate::cursor::main::values::local_date_time::local_date_time; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::records::main::fields::field::field as native_field; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_io.rs b/crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_io.rs similarity index 89% rename from crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_io.rs rename to crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_io.rs index aabedd2d5f..94b847285c 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_io.rs +++ b/crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_io.rs @@ -10,19 +10,27 @@ use sqlbuild_core::constants::OLD_NAME_VIEW_TABLE_NAME; use sqlbuild_state::events::main::recorded_renames::recorded_renames; use sqlbuild_state::events::models::RecordedRenameKey; -use crate::bindings::_helpers::state_rows::constants::{ - COLUMN_KIND, LOGGING_MODULE, MIGRATION_LOGGER, MIGRATION_WRITE_ATTEMPTS, - MIGRATION_WRITE_RETRY_BASE_SECONDS, MIGRATION_WRITE_RETRY_MESSAGE, MODEL_KIND, OLD_NAME_KIND, - TIME_MODULE, -}; -use crate::bindings::_helpers::state_rows::events::relation as event_relation; -use crate::bindings::_helpers::state_rows::migration_objects::{event_order, layout, state_error}; -use crate::bindings::_helpers::state_rows::migration_projections::old_name_views; -use crate::bindings::_helpers::state_rows::migration_rows::{ - decoded_events, read_statement, write_statements, -}; -use crate::bindings::_helpers::state_rows::models::{EventTable, EventTableLayout, StateAccess}; -use crate::bindings::_helpers::state_rows::timestamps::presumed_utc; +use crate::state_rows::_helpers::event_rows::events::relation as event_relation; +use crate::state_rows::_helpers::event_rows::timestamps::presumed_utc; +use crate::state_rows::_helpers::migrations::migration_objects::event_order; +use crate::state_rows::_helpers::migrations::migration_objects::layout; +use crate::state_rows::_helpers::migrations::migration_objects::state_error; +use crate::state_rows::_helpers::migrations::migration_projections::old_name_views; +use crate::state_rows::_helpers::migrations::migration_rows::decoded_events; +use crate::state_rows::_helpers::migrations::migration_rows::read_statement; +use crate::state_rows::_helpers::migrations::migration_rows::write_statements; +use crate::state_rows::constants::COLUMN_KIND; +use crate::state_rows::constants::LOGGING_MODULE; +use crate::state_rows::constants::MIGRATION_LOGGER; +use crate::state_rows::constants::MIGRATION_WRITE_ATTEMPTS; +use crate::state_rows::constants::MIGRATION_WRITE_RETRY_BASE_SECONDS; +use crate::state_rows::constants::MIGRATION_WRITE_RETRY_MESSAGE; +use crate::state_rows::constants::MODEL_KIND; +use crate::state_rows::constants::OLD_NAME_KIND; +use crate::state_rows::constants::TIME_MODULE; +use crate::state_rows::models::EventTable; +use crate::state_rows::models::EventTableLayout; +use crate::state_rows::models::StateAccess; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::models::Request; use sqlbuild_python_base::records::main::fields::field::field as native_field; @@ -187,7 +195,7 @@ fn append_event( Ok(()) } -fn access<'py>(request: &Request<'_, 'py>) -> PyResult> { +pub(crate) fn access<'py>(request: &Request<'_, 'py>) -> PyResult> { Ok(StateAccess { connection: request.get("connection")?, execute: request.get("execute")?, diff --git a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_objects.rs b/crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_objects.rs similarity index 92% rename from crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_objects.rs rename to crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_objects.rs index f477b7d8b4..64fdb804f0 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_objects.rs +++ b/crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_objects.rs @@ -12,9 +12,12 @@ use sqlbuild_state::events::constants::{ }; use sqlbuild_state::events::models::EventOrder; -use crate::bindings::_helpers::state_rows::constants::{COLUMN_KIND, MODEL_KIND, OLD_NAME_KIND}; -use crate::bindings::_helpers::state_rows::models::{EventTable, EventTableLayout}; -use crate::bindings::_helpers::state_rows::timestamps::presumed_utc; +use crate::state_rows::_helpers::event_rows::timestamps::presumed_utc; +use crate::state_rows::constants::COLUMN_KIND; +use crate::state_rows::constants::MODEL_KIND; +use crate::state_rows::constants::OLD_NAME_KIND; +use crate::state_rows::models::EventTable; +use crate::state_rows::models::EventTableLayout; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_projections.rs b/crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_projections.rs similarity index 96% rename from crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_projections.rs rename to crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_projections.rs index 8119870cf4..e2e0dc9087 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_projections.rs +++ b/crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_projections.rs @@ -11,9 +11,9 @@ use sqlbuild_state::events::models::{ ColumnEventKey, EventOrder, EventRelation, MoveEventKey, OldNameFactKey, OldNameStep, }; -use crate::bindings::_helpers::state_rows::constants::OLD_NAME_VIEW_CONFIG_KEY; -use crate::bindings::_helpers::state_rows::events::relation as event_relation; -use crate::bindings::_helpers::state_rows::migration_objects::event_order; +use crate::state_rows::_helpers::event_rows::events::relation as event_relation; +use crate::state_rows::_helpers::migrations::migration_objects::event_order; +use crate::state_rows::constants::OLD_NAME_VIEW_CONFIG_KEY; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_rows.rs b/crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_rows.rs similarity index 96% rename from crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_rows.rs rename to crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_rows.rs index 05f2bf62b7..77326fddcd 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_rows.rs +++ b/crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_rows.rs @@ -15,14 +15,15 @@ use sqlbuild_state::events::main::event_read_sql::event_read_sql; use sqlbuild_state::events::main::grants_json::grants_json; use sqlbuild_state::events::main::readable_columns::readable_columns; -use crate::bindings::_helpers::cursor::values::DATETIME_MODULE; -use crate::bindings::_helpers::state_rows::events::typed_insert_sql; -use crate::bindings::_helpers::state_rows::migration_objects::{ - layout, qualified_table, state_error, -}; -use crate::bindings::_helpers::state_rows::models::{EventTable, EventTableLayout}; -use crate::bindings::_helpers::state_rows::state_tables::state_table_create_sql; -use crate::bindings::_helpers::state_rows::timestamps::date_time_typed; +use crate::cursor::constants::DATETIME_MODULE; +use crate::state_rows::_helpers::event_rows::events::typed_insert_sql; +use crate::state_rows::_helpers::event_rows::timestamps::date_time_typed; +use crate::state_rows::_helpers::migrations::migration_objects::layout; +use crate::state_rows::_helpers::migrations::migration_objects::qualified_table; +use crate::state_rows::_helpers::migrations::migration_objects::state_error; +use crate::state_rows::_helpers::tables::state_tables::state_table_create_sql; +use crate::state_rows::models::EventTable; +use crate::state_rows::models::EventTableLayout; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::models::Request; use sqlbuild_python_base::records::main::construct::enum_member::enum_member; diff --git a/crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/mod.rs b/crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/mod.rs new file mode 100644 index 0000000000..aa91bc5990 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/mod.rs @@ -0,0 +1,4 @@ +pub(crate) mod migration_io; +pub(crate) mod migration_objects; +pub(crate) mod migration_projections; +pub(crate) mod migration_rows; diff --git a/crates/sqlbuild-python-front/src/state_rows/_helpers/mod.rs b/crates/sqlbuild-python-front/src/state_rows/_helpers/mod.rs new file mode 100644 index 0000000000..c980d67515 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/_helpers/mod.rs @@ -0,0 +1,3 @@ +pub(crate) mod event_rows; +pub(crate) mod migrations; +pub(crate) mod tables; diff --git a/crates/sqlbuild-python-front/src/state_rows/_helpers/tables/mod.rs b/crates/sqlbuild-python-front/src/state_rows/_helpers/tables/mod.rs new file mode 100644 index 0000000000..dbb106aba0 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/_helpers/tables/mod.rs @@ -0,0 +1 @@ +pub(crate) mod state_tables; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/state_tables.rs b/crates/sqlbuild-python-front/src/state_rows/_helpers/tables/state_tables.rs similarity index 98% rename from crates/sqlbuild-python/src/bindings/_helpers/state_rows/state_tables.rs rename to crates/sqlbuild-python-front/src/state_rows/_helpers/tables/state_tables.rs index c3769c7844..a5f914e949 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/state_tables.rs +++ b/crates/sqlbuild-python-front/src/state_rows/_helpers/tables/state_tables.rs @@ -16,7 +16,7 @@ use sqlbuild_state::state_tables::main::create_table_sql::create_table_sql; use sqlbuild_state::state_tables::main::values_insert_sql::values_insert_sql; use sqlbuild_state::state_tables::models::TableColumn; -use crate::bindings::_helpers::state_rows::freshness::record_event_id; +use crate::state_rows::_helpers::event_rows::freshness::record_event_id; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::models::Request; use sqlbuild_python_base::contracts::main::render_state_sql_literal::render_state_sql_literal; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/constants.rs b/crates/sqlbuild-python-front/src/state_rows/constants.rs similarity index 61% rename from crates/sqlbuild-python/src/bindings/_helpers/state_rows/constants.rs rename to crates/sqlbuild-python-front/src/state_rows/constants.rs index adf8039338..f7044b0732 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/constants.rs +++ b/crates/sqlbuild-python-front/src/state_rows/constants.rs @@ -1,13 +1,22 @@ -//! Python modules, names and messages of migration state rows. +//! Public constants of state rows. pub(crate) const OLD_NAME_VIEW_CONFIG_KEY: &str = "old_name_view"; -pub(crate) const MODEL_KIND: &str = "model"; -pub(crate) const COLUMN_KIND: &str = "column"; -pub(crate) const OLD_NAME_KIND: &str = "old_name"; + +pub const MODEL_KIND: &str = "model"; + +pub const COLUMN_KIND: &str = "column"; + +pub const OLD_NAME_KIND: &str = "old_name"; + pub(crate) const MIGRATION_LOGGER: &str = "sqlbuild.migrations"; + pub(crate) const LOGGING_MODULE: &str = "logging"; + pub(crate) const TIME_MODULE: &str = "time"; -pub(crate) const MIGRATION_WRITE_ATTEMPTS: i64 = 3; + +pub const MIGRATION_WRITE_ATTEMPTS: i64 = 3; + pub(crate) const MIGRATION_WRITE_RETRY_BASE_SECONDS: f64 = 0.05; + pub(crate) const MIGRATION_WRITE_RETRY_MESSAGE: &str = "migration event write attempt %s/%s failed for '%s'; retrying: %s"; diff --git a/crates/sqlbuild-python-front/src/state_rows/main/event_rows/age_policy.rs b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/age_policy.rs new file mode 100644 index 0000000000..994837c021 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/age_policy.rs @@ -0,0 +1,16 @@ +//! Optional timestamp age policy for one source freshness observation. + +use crate::state_rows::_helpers::event_rows::freshness; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Optional timestamp age policy for one source freshness observation. +#[inline] +pub fn age_policy<'py>( + policy: &Bound<'py, PyAny>, + data_version: &Bound<'py, PyAny>, + observed_at: &Bound<'py, PyAny>, +) -> PyResult>> { + freshness::age_policy(policy, data_version, observed_at) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/event_rows/date_time_typed.rs b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/date_time_typed.rs new file mode 100644 index 0000000000..7215ae0fd5 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/date_time_typed.rs @@ -0,0 +1,12 @@ +//! Whether `value` is a `datetime`. + +use crate::state_rows::_helpers::event_rows::timestamps; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Whether `value` is a `datetime`. +#[inline] +pub fn date_time_typed(value: &Bound<'_, PyAny>) -> PyResult { + timestamps::date_time_typed(value) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/event_rows/equivalent.rs b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/equivalent.rs new file mode 100644 index 0000000000..cb8bd180b5 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/equivalent.rs @@ -0,0 +1,16 @@ +//! Whether two source freshness records are equivalent for skip decisions. + +use crate::state_rows::_helpers::event_rows::freshness; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Whether two source freshness records are equivalent for skip decisions. +#[inline] +pub fn equivalent( + previous_record: &Bound<'_, PyAny>, + current_record: &Bound<'_, PyAny>, + lag_tolerance: Option<&str>, +) -> PyResult { + freshness::equivalent(previous_record, current_record, lag_tolerance) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/event_rows/in_utc.rs b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/in_utc.rs new file mode 100644 index 0000000000..8d28e7e853 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/in_utc.rs @@ -0,0 +1,12 @@ +//! `value.astimezone(UTC)`. + +use crate::state_rows::_helpers::event_rows::timestamps; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// `value.astimezone(UTC)`. +#[inline] +pub fn in_utc<'py>(value: &Bound<'py, PyAny>) -> PyResult> { + timestamps::in_utc(value) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/event_rows/mod.rs b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/mod.rs new file mode 100644 index 0000000000..261c2dc766 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/mod.rs @@ -0,0 +1,10 @@ +pub mod age_policy; +pub mod date_time_typed; +pub mod equivalent; +pub mod in_utc; +pub mod normalize; +pub mod offset_aware; +pub mod presumed_utc; +pub mod register_events; +pub mod register_freshness; +pub mod version_hash; diff --git a/crates/sqlbuild-python-front/src/state_rows/main/event_rows/normalize.rs b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/normalize.rs new file mode 100644 index 0000000000..ec853a1552 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/normalize.rs @@ -0,0 +1,15 @@ +//! A source freshness value normalized for stable state storage. + +use crate::state_rows::_helpers::event_rows::freshness; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// A source freshness value normalized for stable state storage. +#[inline] +pub fn normalize<'py>( + value: &Bound<'py, PyAny>, + value_kind: &Bound<'py, PyAny>, +) -> PyResult> { + freshness::normalize(value, value_kind) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/event_rows/offset_aware.rs b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/offset_aware.rs new file mode 100644 index 0000000000..88ffd3edd5 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/offset_aware.rs @@ -0,0 +1,12 @@ +//! Whether `value` has a `tzinfo` that reports an offset. + +use crate::state_rows::_helpers::event_rows::timestamps; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Whether `value` has a `tzinfo` that reports an offset. +#[inline] +pub fn offset_aware(value: &Bound<'_, PyAny>) -> PyResult { + timestamps::offset_aware(value) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/event_rows/presumed_utc.rs b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/presumed_utc.rs new file mode 100644 index 0000000000..9d8d99beed --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/presumed_utc.rs @@ -0,0 +1,13 @@ +//! The UTC wall time of `value`, reading a naive or offset-less value as UTC. + +use crate::state_rows::_helpers::event_rows::timestamps; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use sqlbuild_cursor::algebra::models::LocalDateTime; + +/// The UTC wall time of `value`, reading a naive or offset-less value as UTC. +#[inline] +pub fn presumed_utc(value: &Bound<'_, PyAny>) -> PyResult { + timestamps::presumed_utc(value) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/event_rows/register_events.rs b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/register_events.rs new file mode 100644 index 0000000000..530de6df36 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/register_events.rs @@ -0,0 +1,12 @@ +//! Register the events functions and classes. + +use crate::state_rows::_helpers::event_rows::events; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the events functions and classes. +#[inline] +pub fn register_events(module: &Bound<'_, PyModule>) -> PyResult<()> { + events::register(module) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/event_rows/register_freshness.rs b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/register_freshness.rs new file mode 100644 index 0000000000..61581e44e6 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/register_freshness.rs @@ -0,0 +1,12 @@ +//! Register the freshness functions and classes. + +use crate::state_rows::_helpers::event_rows::freshness; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the freshness functions and classes. +#[inline] +pub fn register_freshness(module: &Bound<'_, PyModule>) -> PyResult<()> { + freshness::register(module) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/event_rows/version_hash.rs b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/version_hash.rs new file mode 100644 index 0000000000..544e6287c0 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/event_rows/version_hash.rs @@ -0,0 +1,15 @@ +//! Hash the stable source freshness identity used as a graph input. + +use crate::state_rows::_helpers::event_rows::freshness; +use pyo3::prelude::PyResult; + +/// Hash the stable source freshness identity used as a graph input. +#[inline] +pub fn version_hash( + source_name: &str, + strategy: &str, + value_kind: &str, + data_version: &str, +) -> PyResult { + freshness::version_hash(source_name, strategy, value_kind, data_version) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/migrations/layout.rs b/crates/sqlbuild-python-front/src/state_rows/main/migrations/layout.rs new file mode 100644 index 0000000000..caae386fb9 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/migrations/layout.rs @@ -0,0 +1,11 @@ +//! The layout of the state table `kind` names: `model`, `column` or `old_name`. + +use crate::state_rows::_helpers::migrations::migration_objects; +use crate::state_rows::models::EventTableLayout; +use pyo3::prelude::PyResult; + +/// The layout of the state table `kind` names: `model`, `column` or `old_name`. +#[inline] +pub fn layout(kind: &str) -> PyResult { + migration_objects::layout(kind) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/migrations/mod.rs b/crates/sqlbuild-python-front/src/state_rows/main/migrations/mod.rs new file mode 100644 index 0000000000..58584513db --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/migrations/mod.rs @@ -0,0 +1,12 @@ +pub mod layout; +pub mod newest_column; +pub mod newest_move; +pub mod old_name_retention; +pub mod old_name_views; +pub mod read_events; +pub mod read_histories; +pub mod register_migration_io; +pub mod register_migration_projections; +pub mod register_migration_rows; +pub mod stored_columns_binding; +pub mod stored_old_name_columns; diff --git a/crates/sqlbuild-python-front/src/state_rows/main/migrations/newest_column.rs b/crates/sqlbuild-python-front/src/state_rows/main/migrations/newest_column.rs new file mode 100644 index 0000000000..aa92be6ad4 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/migrations/newest_column.rs @@ -0,0 +1,16 @@ +//! The latest recorded rename on `relation` naming either column, or `None`. + +use crate::state_rows::_helpers::migrations::migration_projections; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// The latest recorded rename on `relation` naming either column, or `None`. +#[inline] +pub fn newest_column<'py>( + events: &Bound<'py, PyAny>, + relation: &Bound<'py, PyAny>, + (origin_column, destination_column): (&str, &str), +) -> PyResult> { + migration_projections::newest_column(events, relation, (origin_column, destination_column)) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/migrations/newest_move.rs b/crates/sqlbuild-python-front/src/state_rows/main/migrations/newest_move.rs new file mode 100644 index 0000000000..c24e453093 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/migrations/newest_move.rs @@ -0,0 +1,15 @@ +//! The latest recorded move naming `relation` as origin or destination, or `None`. + +use crate::state_rows::_helpers::migrations::migration_projections; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// The latest recorded move naming `relation` as origin or destination, or `None`. +#[inline] +pub fn newest_move<'py>( + events: &Bound<'py, PyAny>, + relation: &Bound<'py, PyAny>, +) -> PyResult> { + migration_projections::newest_move(events, relation) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/migrations/old_name_retention.rs b/crates/sqlbuild-python-front/src/state_rows/main/migrations/old_name_retention.rs new file mode 100644 index 0000000000..6396c515f7 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/migrations/old_name_retention.rs @@ -0,0 +1,15 @@ +//! The model's old-name view retention, the project's when unset, or `None` when disabled. + +use crate::state_rows::_helpers::migrations::migration_projections; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// The model's old-name view retention, the project's when unset, or `None` when disabled. +#[inline] +pub fn old_name_retention<'py>( + config_values: &Bound<'py, PyAny>, + project_retention: &Bound<'py, PyAny>, +) -> PyResult> { + migration_projections::old_name_retention(config_values, project_retention) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/migrations/old_name_views.rs b/crates/sqlbuild-python-front/src/state_rows/main/migrations/old_name_views.rs new file mode 100644 index 0000000000..92d839abeb --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/migrations/old_name_views.rs @@ -0,0 +1,16 @@ +//! One history per recorded move whose old name needs a compatibility view, in move order. + +use crate::state_rows::_helpers::migrations::migration_projections; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// One history per recorded move whose old name needs a compatibility view, in move order. +#[inline] +pub fn old_name_views<'py>( + moves: &Bound<'py, PyAny>, + facts: &Bound<'py, PyAny>, +) -> PyResult> { + migration_projections::old_name_views(moves, facts) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/migrations/read_events.rs b/crates/sqlbuild-python-front/src/state_rows/main/migrations/read_events.rs new file mode 100644 index 0000000000..44beac2afc --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/migrations/read_events.rs @@ -0,0 +1,20 @@ +//! Every event of `layout`'s table this version reads from one schema, from `stored` columns when known. + +use crate::state_rows::_helpers::migrations::migration_io; +use crate::state_rows::models::EventTableLayout; +use crate::state_rows::models::StateAccess; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// Every event of `layout`'s table this version reads from one schema, from `stored` columns when known. +#[inline] +pub fn read_events<'py>( + access: &StateAccess<'py>, + layout: &EventTableLayout, + (database, schema): (Bound<'py, PyAny>, Bound<'py, PyAny>), + stored: Option<&[String]>, +) -> PyResult> { + migration_io::read_events(access, layout, (database, schema), stored) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/migrations/read_histories.rs b/crates/sqlbuild-python-front/src/state_rows/main/migrations/read_histories.rs new file mode 100644 index 0000000000..1c946a2d48 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/migrations/read_histories.rs @@ -0,0 +1,13 @@ +//! The old-name view history of every recorded move in a schema that holds both state tables. + +use crate::state_rows::_helpers::migrations::migration_io; +use pyo3::prelude::Bound; +use pyo3::prelude::PyResult; +use pyo3::types::PyDict; +use pyo3::types::PyTuple; + +/// The old-name view history of every recorded move in a schema that holds both state tables. +#[inline] +pub fn read_histories<'py>(request: Option<&Bound<'py, PyDict>>) -> PyResult> { + migration_io::read_histories(request) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/migrations/register_migration_io.rs b/crates/sqlbuild-python-front/src/state_rows/main/migrations/register_migration_io.rs new file mode 100644 index 0000000000..90b03f6d18 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/migrations/register_migration_io.rs @@ -0,0 +1,12 @@ +//! Register the migration io functions and classes. + +use crate::state_rows::_helpers::migrations::migration_io; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the migration io functions and classes. +#[inline] +pub fn register_migration_io(module: &Bound<'_, PyModule>) -> PyResult<()> { + migration_io::register(module) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/migrations/register_migration_projections.rs b/crates/sqlbuild-python-front/src/state_rows/main/migrations/register_migration_projections.rs new file mode 100644 index 0000000000..65e9d95e8d --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/migrations/register_migration_projections.rs @@ -0,0 +1,12 @@ +//! Register the migration projections functions and classes. + +use crate::state_rows::_helpers::migrations::migration_projections; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the migration projections functions and classes. +#[inline] +pub fn register_migration_projections(module: &Bound<'_, PyModule>) -> PyResult<()> { + migration_projections::register(module) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/migrations/register_migration_rows.rs b/crates/sqlbuild-python-front/src/state_rows/main/migrations/register_migration_rows.rs new file mode 100644 index 0000000000..8a095b7b1e --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/migrations/register_migration_rows.rs @@ -0,0 +1,12 @@ +//! Register the migration rows functions and classes. + +use crate::state_rows::_helpers::migrations::migration_rows; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the migration rows functions and classes. +#[inline] +pub fn register_migration_rows(module: &Bound<'_, PyModule>) -> PyResult<()> { + migration_rows::register(module) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/migrations/stored_columns_binding.rs b/crates/sqlbuild-python-front/src/state_rows/main/migrations/stored_columns_binding.rs new file mode 100644 index 0000000000..dfd775e2ba --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/migrations/stored_columns_binding.rs @@ -0,0 +1,18 @@ +//! The column names of one schema's old-name view state table. + +use crate::state_rows::_helpers::migrations::migration_io; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; +use pyo3::types::PyTuple; + +/// The column names of one schema's old-name view state table. +#[inline] +pub fn stored_columns_binding<'py>( + adapter: &Bound<'py, PyAny>, + connection: &Bound<'py, PyAny>, + database: Bound<'py, PyAny>, + schema: Bound<'py, PyAny>, +) -> PyResult> { + migration_io::stored_columns_binding(adapter, connection, database, schema) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/migrations/stored_old_name_columns.rs b/crates/sqlbuild-python-front/src/state_rows/main/migrations/stored_old_name_columns.rs new file mode 100644 index 0000000000..6c29967353 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/migrations/stored_old_name_columns.rs @@ -0,0 +1,16 @@ +//! The column names of one schema's old-name view state table, as the adapter lists them. + +use crate::state_rows::_helpers::migrations::migration_io; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// The column names of one schema's old-name view state table, as the adapter lists them. +#[inline] +pub fn stored_old_name_columns<'py>( + adapter: &Bound<'py, PyAny>, + connection: &Bound<'py, PyAny>, + (database, schema): (Bound<'py, PyAny>, Bound<'py, PyAny>), +) -> PyResult> { + migration_io::stored_old_name_columns(adapter, connection, (database, schema)) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/mod.rs b/crates/sqlbuild-python-front/src/state_rows/main/mod.rs new file mode 100644 index 0000000000..a9d30d5bd4 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/mod.rs @@ -0,0 +1,3 @@ +pub mod event_rows; +pub mod migrations; +pub mod tables; diff --git a/crates/sqlbuild-python-front/src/state_rows/main/tables/mod.rs b/crates/sqlbuild-python-front/src/state_rows/main/tables/mod.rs new file mode 100644 index 0000000000..cfe5add1dc --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/tables/mod.rs @@ -0,0 +1,2 @@ +pub mod register_state_tables; +pub mod state_table_create_sql; diff --git a/crates/sqlbuild-python-front/src/state_rows/main/tables/register_state_tables.rs b/crates/sqlbuild-python-front/src/state_rows/main/tables/register_state_tables.rs new file mode 100644 index 0000000000..db283b6c98 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/tables/register_state_tables.rs @@ -0,0 +1,12 @@ +//! Register the state tables functions and classes. + +use crate::state_rows::_helpers::tables::state_tables; +use pyo3::prelude::Bound; +use pyo3::prelude::PyModule; +use pyo3::prelude::PyResult; + +/// Register the state tables functions and classes. +#[inline] +pub fn register_state_tables(module: &Bound<'_, PyModule>) -> PyResult<()> { + state_tables::register(module) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/main/tables/state_table_create_sql.rs b/crates/sqlbuild-python-front/src/state_rows/main/tables/state_table_create_sql.rs new file mode 100644 index 0000000000..20b153bb59 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/main/tables/state_table_create_sql.rs @@ -0,0 +1,24 @@ +//! Create-if-missing DDL whose column types the adapter renders. + +use crate::state_rows::_helpers::tables::state_tables; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; +use pyo3::prelude::PyResult; + +/// Create-if-missing DDL whose column types the adapter renders. +#[inline] +pub fn state_table_create_sql<'py>( + qualified_name: &str, + (columns, column_types, required_columns): ( + &Bound<'py, PyAny>, + &Bound<'py, PyAny>, + &Bound<'py, PyAny>, + ), + render_framework_type: &Bound<'py, PyAny>, +) -> PyResult { + state_tables::state_table_create_sql( + qualified_name, + (columns, column_types, required_columns), + render_framework_type, + ) +} diff --git a/crates/sqlbuild-python-front/src/state_rows/mod.rs b/crates/sqlbuild-python-front/src/state_rows/mod.rs new file mode 100644 index 0000000000..22cf001f32 --- /dev/null +++ b/crates/sqlbuild-python-front/src/state_rows/mod.rs @@ -0,0 +1,6 @@ +//! Warehouse state rows: events, freshness, migrations, timestamps and the state tables. + +pub(crate) mod _helpers; +pub mod constants; +pub mod main; +pub mod models; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/models.rs b/crates/sqlbuild-python-front/src/state_rows/models.rs similarity index 77% rename from crates/sqlbuild-python/src/bindings/_helpers/state_rows/models.rs rename to crates/sqlbuild-python-front/src/state_rows/models.rs index b69ffba5c7..542ffd658c 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/models.rs +++ b/crates/sqlbuild-python-front/src/state_rows/models.rs @@ -1,6 +1,7 @@ -//! The layout of one append-only migration state table as the bindings use it. +//! Public records of state rows. -use pyo3::prelude::{Bound, PyAny}; +use pyo3::prelude::Bound; +use pyo3::prelude::PyAny; /// Which migration state table a request reads or writes. #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -12,8 +13,8 @@ pub(crate) enum EventTable { /// Name, columns, event relation attribute and messages of one migration state table. #[derive(Clone, Copy, Debug)] -pub(crate) struct EventTableLayout { - pub table: EventTable, +pub struct EventTableLayout { + pub(crate) table: EventTable, pub name: &'static str, pub columns: &'static [&'static str], pub relation_attribute: &'static str, @@ -24,7 +25,7 @@ pub(crate) struct EventTableLayout { /// How migration state reaches the warehouse: the connection, execute callable and name renderer. #[derive(Debug)] -pub(crate) struct StateAccess<'py> { +pub struct StateAccess<'py> { pub connection: Bound<'py, PyAny>, pub execute: Bound<'py, PyAny>, pub render_qualified_name: Bound<'py, PyAny>, diff --git a/crates/sqlbuild-python/Cargo.toml b/crates/sqlbuild-python/Cargo.toml index bd97610048..5296294002 100644 --- a/crates/sqlbuild-python/Cargo.toml +++ b/crates/sqlbuild-python/Cargo.toml @@ -41,6 +41,7 @@ sqlbuild-orchestration.workspace = true sqlbuild-project.workspace = true sqlbuild-pysource.workspace = true sqlbuild-python-base.workspace = true +sqlbuild-python-front.workspace = true sqlbuild-recall.workspace = true sqlbuild-refactor.workspace = true sqlbuild-render.workspace = true @@ -49,7 +50,6 @@ sqlbuild-scopes.workspace = true sqlbuild-sqltext.workspace = true sqlbuild-state.workspace = true sqlclean.workspace = true -stacker.workspace = true tokio.workspace = true uuid.workspace = true diff --git a/crates/sqlbuild-python/src/bindings/_helpers/analysis_session/model_analyses.rs b/crates/sqlbuild-python/src/bindings/_helpers/analysis_session/model_analyses.rs index 256fbc8e10..730a898710 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/analysis_session/model_analyses.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/analysis_session/model_analyses.rs @@ -17,7 +17,6 @@ use crate::bindings::_helpers::analysis_session::session::{ CacheStatsRow, FamilyRow, ModelRow, NativeModelAnalysisSession, RequestRow, start_model_analysis_session, }; -use crate::bindings::_helpers::attachments::cursor_intrinsics::analysis_cursor_sql; use crate::bindings::_helpers::compile_driver::analysis_cache::{ AnalysisCacheCounts, record_analysis_cache_metrics, }; @@ -36,6 +35,7 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::main::fields::mapping_items::mapping_items; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::attachments::main::analysis_cursor_sql::analysis_cursor_sql; const LOGGING_MODULE: &str = "logging"; const DEBUG_LOGGER: &str = "sqlbuild.compile"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/analysis_session/stage_functions.rs b/crates/sqlbuild-python/src/bindings/_helpers/analysis_session/stage_functions.rs index ef9222d133..68bc94ec1e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/analysis_session/stage_functions.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/analysis_session/stage_functions.rs @@ -19,7 +19,6 @@ use crate::bindings::_helpers::analysis_session::session::{ ContractRow, ExpressionShapesRow, FamilyRow, NativeModelAnalysisSession, PivotModelRow, PivotRequestRow, infer_expression_source_shapes, prove_dynamic_column_contracts, }; -use crate::bindings::_helpers::model_config::header_families::family_specs; use crate::bindings::models::ProjectCatalog; use sqlbuild_python_base::boundary::models::Request; use sqlbuild_python_base::compile_driver::constants::EXPRESSION_SHAPE_BATCHES; @@ -30,6 +29,7 @@ use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_items::mapping_items; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::model_config::main::headers::family_specs::family_specs; const BATCH_MODE: &str = "batch"; const TABLE_FUNCTION_KIND: &str = "table_fn"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/attachments/mod.rs b/crates/sqlbuild-python/src/bindings/_helpers/attachments/mod.rs index 06178594d6..7444bd0374 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/attachments/mod.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/attachments/mod.rs @@ -1,6 +1 @@ -pub(crate) mod argument_values; -pub(crate) mod ceremonial_select; -pub(crate) mod cursor_intrinsics; -pub(crate) mod function_headers; -pub(crate) mod reference_markers; pub(crate) mod registration; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/attachments/registration.rs b/crates/sqlbuild-python/src/bindings/_helpers/attachments/registration.rs index 2f62e267e3..0ad0079092 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/attachments/registration.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/attachments/registration.rs @@ -2,13 +2,13 @@ use pyo3::prelude::{Bound, PyModule, PyResult}; -use crate::bindings::_helpers::attachments::{ - ceremonial_select, cursor_intrinsics, reference_markers, -}; +use sqlbuild_python_front::attachments::main::register_ceremonial_select::register_ceremonial_select; +use sqlbuild_python_front::attachments::main::register_cursor_intrinsics::register_cursor_intrinsics; +use sqlbuild_python_front::attachments::main::register_reference_markers::register_reference_markers; pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { - cursor_intrinsics::register(module)?; - ceremonial_select::register(module)?; - reference_markers::register(module)?; + register_cursor_intrinsics(module)?; + register_ceremonial_select(module)?; + register_reference_markers(module)?; Ok(()) } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/audit_command/command.rs b/crates/sqlbuild-python/src/bindings/_helpers/audit_command/command.rs index 84e2457856..1fb668c0c9 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/audit_command/command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/audit_command/command.rs @@ -19,7 +19,6 @@ use sqlbuild_orchestration::runs::models::NodeOutcome; use crate::bindings::_helpers::build_progress::audit_progress::AuditProgressReporter; use crate::bindings::_helpers::build_progress::progress_reporters::ConnectionProgressReporter; use crate::bindings::_helpers::build_progress::progress_text::write_execution_header; -use crate::bindings::_helpers::command_runtime::concurrency::resolve_concurrency; use crate::bindings::_helpers::command_runtime::invocation::resolve_reported_command_invocation; use crate::bindings::_helpers::compile_driver::pipeline_entries::build_static_pipeline_result; use crate::bindings::_helpers::compile_driver::static_context::compile_static_command_context; @@ -43,6 +42,7 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::command_runtime::main::resolve_concurrency::resolve_concurrency; const EXECUTION_COMMAND: &str = "sqb audit"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/auditing/schema_audits.rs b/crates/sqlbuild-python/src/bindings/_helpers/auditing/schema_audits.rs index ec3d9abff9..50b57c771c 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/auditing/schema_audits.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/auditing/schema_audits.rs @@ -9,12 +9,13 @@ use sqlbuild_model_config::errors::{ConfigError, ErrorClass}; use sqlbuild_model_config::header_metadata::main::parse_audit_list::parse_audit_list; use sqlbuild_model_config::header_metadata::models::ParsedAudit; -use crate::bindings::_helpers::model_config::authored_nodes::PyNode; -use crate::bindings::_helpers::model_config::contract_classes::contract_classes; -use crate::bindings::_helpers::model_config::header_metadata::{ContractClasses, audit_tuple}; use sqlbuild_python_base::boundary::models::Request; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::types::ErrorId; +use sqlbuild_python_front::model_config::main::headers::audit_tuple::audit_tuple; +use sqlbuild_python_front::model_config::main::model_nodes::contract_classes::contract_classes; +use sqlbuild_python_front::model_config::models::ContractClasses; +use sqlbuild_python_front::model_config::models::PyNode; /// A resource identity error as `ResourceIdentityError`, anything else as `fallback_class(message)`. fn raised( diff --git a/crates/sqlbuild-python/src/bindings/_helpers/authored_values/mod.rs b/crates/sqlbuild-python/src/bindings/_helpers/authored_values/mod.rs index b74d618669..7444bd0374 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/authored_values/mod.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/authored_values/mod.rs @@ -1,5 +1 @@ -mod fields; -pub(crate) mod project_vars; -mod python_nodes; pub(crate) mod registration; -pub(crate) mod sql_values; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/authored_values/registration.rs b/crates/sqlbuild-python/src/bindings/_helpers/authored_values/registration.rs index c1c11ce4c5..7369430883 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/authored_values/registration.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/authored_values/registration.rs @@ -1,7 +1,11 @@ use pyo3::prelude::{Bound, PyModule, PyResult}; pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { - crate::bindings::_helpers::authored_values::fields::register(module)?; - crate::bindings::_helpers::authored_values::project_vars::register(module)?; - crate::bindings::_helpers::authored_values::python_nodes::register(module) + sqlbuild_python_front::authored_values::main::register_fields::register_fields(module)?; + sqlbuild_python_front::authored_values::main::register_project_vars::register_project_vars( + module, + )?; + sqlbuild_python_front::authored_values::main::register_python_nodes::register_python_nodes( + module, + ) } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/build_command/command.rs b/crates/sqlbuild-python/src/bindings/_helpers/build_command/command.rs index 1ecd6227f4..8e3408df42 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/build_command/command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/build_command/command.rs @@ -20,9 +20,6 @@ use crate::bindings::_helpers::build_command::planning::{ }; use crate::bindings::_helpers::check::check_core::relevant_check_functions; use crate::bindings::_helpers::compiled_project::snapshot_execution::WorkerBuild; -use crate::bindings::_helpers::discovery::provider_secrets::{ - consumer_uses, provider_uses, require_used_secrets, sink_uses, -}; use crate::bindings::_helpers::graph::python_node_graph::python_node_graph; use crate::bindings::_helpers::observations::source_capture::{ arm_source_capture, take_source_capture, @@ -35,6 +32,10 @@ use sqlbuild_python_base::build_command::main::tuple::tuple; use sqlbuild_python_base::diagnostics::models::BuildPhaseTimingTracker; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::discovery::main::sources::consumer_uses::consumer_uses; +use sqlbuild_python_front::discovery::main::sources::provider_uses::provider_uses; +use sqlbuild_python_front::discovery::main::sources::require_used_secrets::require_used_secrets; +use sqlbuild_python_front::discovery::main::sources::sink_uses::sink_uses; fn run_with_providers(context: &BuildContext<'_>) -> PyResult { let py: Python<'_> = context.py(); diff --git a/crates/sqlbuild-python/src/bindings/_helpers/build_command/defer_clone.rs b/crates/sqlbuild-python/src/bindings/_helpers/build_command/defer_clone.rs index 4ee06a5390..dd9b0fb38d 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/build_command/defer_clone.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/build_command/defer_clone.rs @@ -21,7 +21,6 @@ use crate::bindings::_helpers::build_command::policies::build_command_error; use crate::bindings::_helpers::build_command::policies::enforce_model_execution_limit_binding; use crate::bindings::_helpers::clone::clone_pipeline::run_clone_pipeline_with_options; use crate::bindings::_helpers::compile_driver::project::build_compiled_project; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_config; use crate::bindings::_helpers::dbt_interop::reference_resolver::resolve_external_sql_reference_resolver; use crate::bindings::_helpers::planner_scope::retained::{ScopeData, scope_data}; use crate::bindings::_helpers::planner_scope::scope::build_planner_scope; @@ -34,6 +33,7 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced::replaced; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_target_config::resolve_target_config; const VIEW_MATERIALIZATION: &str = "view"; const RECREATED_TYPES: [&str; 2] = ["udf", "table_fn"]; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/build_command/execution.rs b/crates/sqlbuild-python/src/bindings/_helpers/build_command/execution.rs index 294c8c5da0..59374d9439 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/build_command/execution.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/build_command/execution.rs @@ -32,10 +32,8 @@ use crate::bindings::_helpers::consumption::recorder::{ ConsumptionRecorder, Prepared, held_back_text, prepare as prepare_consumption, run_reason_text, }; use crate::bindings::_helpers::cost_telemetry::context::CostContext; -use crate::bindings::_helpers::cursor::overrides::{cursor_integer, cursor_timestamp}; use crate::bindings::_helpers::freshness::publication::append_freshness_records; use crate::bindings::_helpers::graph::python_node_graph::python_node_graph; -use crate::bindings::_helpers::native_host::consumption_state::recorder_callbacks; use crate::bindings::_helpers::observations::publication::append_build_observations; use crate::bindings::_helpers::planner_resolution::cursor_overrides::type_cursor_overrides; use crate::bindings::_helpers::sql_test_command::test_command::timeout_record; @@ -59,6 +57,9 @@ use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::cursor::main::overrides::cursor_integer::cursor_integer; +use sqlbuild_python_front::cursor::main::overrides::cursor_timestamp::cursor_timestamp; +use sqlbuild_python_front::native_host::main::recorder_callbacks::recorder_callbacks; use sqlbuild_state::consumption::models::ChangedPolicy; const EXECUTION_COMMAND: &str = "sqb build"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/build_command/invocation.rs b/crates/sqlbuild-python/src/bindings/_helpers/build_command/invocation.rs index 5556b457d0..d5ae29884b 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/build_command/invocation.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/build_command/invocation.rs @@ -12,15 +12,9 @@ use sqlbuild_core::build_command::models::DurationLimit; use crate::bindings::_helpers::build_command::policies::build_command_error; use crate::bindings::_helpers::build_progress::progress_reporters::ConnectionProgressReporter; use crate::bindings::_helpers::build_progress::progress_reporters::PlanningProgressReporter; -use crate::bindings::_helpers::command_runtime::concurrency::resolve_concurrency; use crate::bindings::_helpers::command_runtime::connection::resolve_project_connection_config; -use crate::bindings::_helpers::compile_attachment::effective_config::build_effective_settings_config; use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; use crate::bindings::_helpers::compiled_project::snapshot_execution::WorkerBuild; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_config; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_name; -use crate::bindings::_helpers::discovery::provider_secrets::SecretPolicy; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::build_command::main::boolean::boolean; @@ -32,6 +26,12 @@ use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::command_runtime::main::resolve_concurrency::resolve_concurrency; +use sqlbuild_python_front::compile_attachment::main::build_effective_settings_config::build_effective_settings_config; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use sqlbuild_python_front::contracts::main::resolve_target_config::resolve_target_config; +use sqlbuild_python_front::contracts::main::resolve_target_name::resolve_target_name; +use sqlbuild_python_front::discovery::models::SecretPolicy; const DEFER_CONFLICT_CODE: &str = "C408"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/change_selection/base_snapshot.rs b/crates/sqlbuild-python/src/bindings/_helpers/change_selection/base_snapshot.rs index bf71b84c81..2fee2b0bf3 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/change_selection/base_snapshot.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/change_selection/base_snapshot.rs @@ -25,10 +25,10 @@ use crate::bindings::_helpers::change_selection::base_cache::{ use crate::bindings::_helpers::change_selection::base_compile::NOTES_EXTENSION; use crate::bindings::_helpers::change_selection::environment_nodes::with_base_dependencies; use crate::bindings::_helpers::compile_command::runtime_identity::interpreter_values; -use crate::bindings::_helpers::discovery::project_config::configured_git_base_ref; use crate::bindings::_helpers::scenario_command::setup::{cli_user_error, flush, write}; use sqlbuild_python_base::planner_identity::constants::COMPACT; use sqlbuild_python_base::planner_identity::main::sorted_dumps::sorted_dumps; +use sqlbuild_python_front::discovery::main::project::configured_git_base_ref::configured_git_base_ref; const CACHE_DIRECTORY: [&str; 2] = ["target", "since"]; /// Where base compiles work when the project's cache directory cannot be created. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/check/check_command.rs b/crates/sqlbuild-python/src/bindings/_helpers/check/check_command.rs index b843473116..0982412eeb 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/check/check_command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/check/check_command.rs @@ -8,9 +8,6 @@ use crate::bindings::_helpers::compile_driver::relation_targets::build_project_r use crate::bindings::_helpers::compile_driver::relation_targets::build_python_relation_targets; use crate::bindings::_helpers::compile_driver::static_context::compile_static_command_context; use crate::bindings::_helpers::dbt_interop::reference_resolver::resolve_external_sql_reference_resolver; -use crate::bindings::_helpers::discovery::provider_secrets::{ - consumer_uses, require_used_secrets, sink_uses, -}; use crate::bindings::_helpers::graph::algorithms::transitive_closure_many; use crate::bindings::_helpers::graph::execution_gates::sql_ref_key; use crate::bindings::_helpers::graph::python_lifecycle::build_python_sql_run_lifecycle; @@ -36,6 +33,9 @@ use sqlbuild_python_base::native_host::main::connection_failure::connection_fail use sqlbuild_python_base::records::main::construct::enum_member::enum_member; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::construct::record_class::record_class; +use sqlbuild_python_front::discovery::main::sources::consumer_uses::consumer_uses; +use sqlbuild_python_front::discovery::main::sources::require_used_secrets::require_used_secrets; +use sqlbuild_python_front::discovery::main::sources::sink_uses::sink_uses; use crate::bindings::_helpers::check::check_core::{ ReadSideInputs, load_results_by_loader_name, record_python_run_state_results, diff --git a/crates/sqlbuild-python/src/bindings/_helpers/cli/dispatch.rs b/crates/sqlbuild-python/src/bindings/_helpers/cli/dispatch.rs index 18af7aaf5c..00ea711da8 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/cli/dispatch.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/cli/dispatch.rs @@ -17,7 +17,6 @@ use crate::bindings::_helpers::dbt_command::init::run_dbt_init_command; use crate::bindings::_helpers::debug_command::run_debug::run_debug_command; use crate::bindings::_helpers::diff_report::command::run_diff_command; use crate::bindings::_helpers::diff_report::support::cli_error; -use crate::bindings::_helpers::discovery::provider_secrets::MissingSecretsScope; use crate::bindings::_helpers::format_command::command::run_format_command; use crate::bindings::_helpers::freshness::freshness_command::run_freshness_command; use crate::bindings::_helpers::init_command::command::run_init_command; @@ -57,6 +56,7 @@ use sqlbuild_core::format_command::main::format_path_selectors::format_path_sele use sqlbuild_python_base::cli::main::withhold_launch_record::withhold_launch_record; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::construct::record_class::record_class; +use sqlbuild_python_front::discovery::models::MissingSecretsScope; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::within::within; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/cli/registration.rs b/crates/sqlbuild-python/src/bindings/_helpers/cli/registration.rs index 662970cd50..a8e12a58bc 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/cli/registration.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/cli/registration.rs @@ -28,10 +28,10 @@ pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { janitor::registration::register(module)?; plan_command::registration::register(module)?; freshness::registration::register(module)?; - crate::bindings::_helpers::native_host::consumption_state::register(module)?; - crate::bindings::_helpers::native_host::observations_state::register(module)?; + sqlbuild_python_front::native_host::main::register_consumption_state::register_consumption_state(module)?; + sqlbuild_python_front::native_host::main::register_observations_state::register_observations_state(module)?; crate::bindings::_helpers::native_host::resource_costs_state::register(module)?; - crate::bindings::_helpers::native_host::audit_results_state::register(module)?; + sqlbuild_python_front::native_host::main::register_audit_results_state::register_audit_results_state(module)?; clone::registration::register(module)?; compute_logs::registration::register(module)?; execution_history::registration::register(module)?; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/clone/clone_command.rs b/crates/sqlbuild-python/src/bindings/_helpers/clone/clone_command.rs index a9b9a09989..f4844e130a 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/clone/clone_command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/clone/clone_command.rs @@ -27,9 +27,6 @@ use crate::bindings::_helpers::clone::clone_pipeline::{ClonePipeline, timed_clon use crate::bindings::_helpers::clone::clone_progress::{clone_item_text, write_line}; use crate::bindings::_helpers::command_runtime::connection::resolve_target_connection_config; use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_config; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_name; use crate::bindings::_helpers::dbt_interop::reference_resolver::resolve_external_sql_reference_resolver; use crate::bindings::_helpers::planner_entries::clone_plans::PhaseTimings; use crate::bindings::_helpers::planner_selection::unit_tests::reject_unit_test_selectors; @@ -48,6 +45,9 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use sqlbuild_python_front::contracts::main::resolve_target_config::resolve_target_config; +use sqlbuild_python_front::contracts::main::resolve_target_name::resolve_target_name; const CLONE_LOGGER: &str = "sqlbuild.clone"; /// The clone phase that copies relations into the destination. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/clone/clone_execution.rs b/crates/sqlbuild-python/src/bindings/_helpers/clone/clone_execution.rs index 0e1168cf78..2820d658f5 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/clone/clone_execution.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/clone/clone_execution.rs @@ -13,7 +13,6 @@ use crate::bindings::_helpers::clone::clone_command::Invocation; use crate::bindings::_helpers::clone::clone_progress::{ CloneFingerprintReporter, CloneItemPrinter, }; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_config; use crate::bindings::_helpers::result_output::event_writer::ExecutionEventWriter; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::within::within; @@ -24,6 +23,7 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_items::mapping_items; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_target_config::resolve_target_config; const DESTINATION_ENTRY_GROUPS: [&str; 4] = [ "destination_source_entries", diff --git a/crates/sqlbuild-python/src/bindings/_helpers/clone/clone_pipeline.rs b/crates/sqlbuild-python/src/bindings/_helpers/clone/clone_pipeline.rs index 331227a146..184caf11c2 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/clone/clone_pipeline.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/clone/clone_pipeline.rs @@ -5,13 +5,13 @@ use pyo3::types::{PyBool, PyDict, PyTuple}; use pyo3::{pyfunction, wrap_pyfunction}; use crate::bindings::_helpers::compile_driver::project::build_compiled_project; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_config; use crate::bindings::_helpers::planner_entries::clone_plans::{PhaseTimings, timed_clone_planning}; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::boundary::models::Request; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_target_config::resolve_target_config; /// The phase name of one target compile, before the target name. const COMPILE_PHASE_PREFIX: &str = "compile_"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/command_runtime/connection.rs b/crates/sqlbuild-python/src/bindings/_helpers/command_runtime/connection.rs index 2fdb7a55d1..95d3841303 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/command_runtime/connection.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/command_runtime/connection.rs @@ -19,15 +19,15 @@ use sqlbuild_host::entries::models::ThirdPartyHost; use crate::bindings::_helpers::command_runtime::runtime_errors::raised; use crate::bindings::_helpers::command_runtime::warehouses::{WarehouseInputs, apply_warehouse}; -use crate::bindings::_helpers::compile_attachment::effective_config::build_effective_connection_config; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_config; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_name; use crate::bindings::_helpers::dbt_interop::profile_connection::resolve_raw_dbt_profile_connection; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::compile_attachment::main::build_effective_connection_config::build_effective_connection_config; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use sqlbuild_python_front::contracts::main::resolve_target_config::resolve_target_config; +use sqlbuild_python_front::contracts::main::resolve_target_name::resolve_target_name; const ATTACH_KEY: &str = "attach"; const ATTACH_PATH_KEY: &str = "path"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/command_runtime/invocation.rs b/crates/sqlbuild-python/src/bindings/_helpers/command_runtime/invocation.rs index 9120cbd84a..8590c9746b 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/command_runtime/invocation.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/command_runtime/invocation.rs @@ -7,8 +7,6 @@ use crate::bindings::_helpers::build_progress::progress_reporters::ConnectionPro use crate::bindings::_helpers::build_progress::progress_reporters::PlanningProgressReporter; use crate::bindings::_helpers::command_runtime::connection::resolve_project_connection_config; use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; -use crate::bindings::_helpers::discovery::provider_secrets::SecretPolicy; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::keywords::keywords; @@ -17,6 +15,8 @@ use sqlbuild_python_base::presentation_text::main::stdout_supports_color::stdout use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use sqlbuild_python_front::discovery::models::SecretPolicy; /// The project directory, discovered inputs, adapter context, colour and progress stream. struct InvocationContext<'py> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/command_runtime/mod.rs b/crates/sqlbuild-python/src/bindings/_helpers/command_runtime/mod.rs index 9e2bda19bc..4d947aefd7 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/command_runtime/mod.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/command_runtime/mod.rs @@ -1,4 +1,3 @@ -pub(crate) mod concurrency; pub(crate) mod connection; pub(crate) mod invocation; pub(crate) mod preview_target; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/command_runtime/warehouses.rs b/crates/sqlbuild-python/src/bindings/_helpers/command_runtime/warehouses.rs index fab0bb4d15..20515e7b7a 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/command_runtime/warehouses.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/command_runtime/warehouses.rs @@ -22,17 +22,17 @@ use crate::bindings::_helpers::command_runtime::runtime_errors::{ expected_resolution_error, raised, }; use crate::bindings::_helpers::command_runtime::warehouse_scope::current_command_warehouse_scope; -use crate::bindings::_helpers::compile_attachment::effective_config::build_effective_runtime_config; -use crate::bindings::_helpers::compile_driver::config_validation::session_warehouse_support; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_name; -use crate::bindings::_helpers::discovery::configuration::discover_project_configuration; -use crate::bindings::_helpers::model_config::template_data::expanded_template_data; use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::compile_attachment::main::build_effective_runtime_config::build_effective_runtime_config; +use sqlbuild_python_front::compile_driver::main::session_warehouse_support::session_warehouse_support; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use sqlbuild_python_front::contracts::main::resolve_target_name::resolve_target_name; +use sqlbuild_python_front::discovery::main::project::discover_project_configuration::discover_project_configuration; +use sqlbuild_python_front::model_config::main::config::expanded_template_data::expanded_template_data; /// The `WarehouseGroup` whose warehouse is a target's `warehouses.build`; any other reads `query`. const BUILD_GROUP: &str = "build"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/declaration_scope.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/declaration_scope.rs index 89247cc49e..c6399918c0 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/declaration_scope.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/declaration_scope.rs @@ -4,13 +4,7 @@ use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult, Python}; use pyo3::pyfunction; use pyo3::types::PyTuple; -use crate::bindings::_helpers::render::declaration_values::declaration_scope_resolver; -use crate::bindings::_helpers::scopes::scope_index::open_native_scope_index; -use crate::bindings::_helpers::scopes::scope_lookup::build_scope_lookup; -use crate::bindings::_helpers::scopes::scope_validation::validate_scope_index; -use crate::bindings::_helpers::sql_test_glue::authored_ctes::validate_authored_sql_test_ctes; use crate::bindings::_helpers::sql_test_glue::constants::SQL_TEST_EXPECTED_MODELS_SCAN_ALGORITHM; -use crate::bindings::_helpers::sqltext::lexical_syntax::LexicalSyntaxInput; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::cache::models::SqlTestScanCache; @@ -22,6 +16,12 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_items::mapping_items; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::render::main::declarations::declaration_scope_resolver::declaration_scope_resolver; +use sqlbuild_python_front::scopes::main::checks::validate_scope_index::validate_scope_index; +use sqlbuild_python_front::scopes::main::index::build_scope_lookup::build_scope_lookup; +use sqlbuild_python_front::scopes::main::index::open_native_scope_index::open_native_scope_index; +use sqlbuild_python_front::sql_test_glue::main::validate_authored_sql_test_ctes::validate_authored_sql_test_ctes; +use sqlbuild_python_front::sqltext::models::LexicalSyntaxInput; fn compile_error(py: Python<'_>, message: Bound<'_, PyAny>) -> PyResult { Ok(PyErr::from_value( diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/mod.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/mod.rs index 5737802a12..a5d3007cac 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/mod.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/mod.rs @@ -1,6 +1,5 @@ pub(crate) mod cursor_roles; pub(crate) mod declaration_scope; -pub(crate) mod effective_config; pub(crate) mod model_config; pub(crate) mod model_inputs; pub(crate) mod registration; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/model_config.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/model_config.rs index bf8764fa89..d945fb86d7 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/model_config.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/model_config.rs @@ -6,13 +6,13 @@ use pyo3::types::{PyDict, PyDictMethods, PyTuple}; use crate::bindings::_helpers::compile_attachment::storage_policies::inherited_storage; use crate::bindings::_helpers::input_loops::loop_classes::table_backed; -use crate::bindings::_helpers::model_config::model_config_builder::NativeModelConfigBuilder; -use crate::bindings::_helpers::model_config::unicode_environment::unicode_environment; use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::model_config::main::model_nodes::unicode_environment::unicode_environment; +use sqlbuild_python_front::model_config::models::NativeModelConfigBuilder; /// Capture the project inputs every model's native config build and validation read. #[pyfunction] diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/model_inputs.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/model_inputs.rs index b49c068239..0d2924508e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/model_inputs.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/model_inputs.rs @@ -10,18 +10,11 @@ use sqlbuild_analysis::assembly::project::main::sql_analysis_opt_out_help::sql_a use sqlbuild_host::entries::models::UserCodeHost; -use crate::bindings::_helpers::attachments::cursor_intrinsics::reserved_cursor_markers; use crate::bindings::_helpers::compile_attachment::model_config::native_model_config_session; use crate::bindings::_helpers::compiled_project::project::NativeCompiledProject; use crate::bindings::_helpers::compiled_views::model_input_view::NativeModelInput; -use crate::bindings::_helpers::discovery::model_file_record::NativeModelFile; use crate::bindings::_helpers::input_loops::loop_classes::model_loop_classes; use crate::bindings::_helpers::input_loops::model_loop::{LoopSwitches, NativeModelLoop}; -use crate::bindings::_helpers::model_config::contract_classes::contract_classes; -use crate::bindings::_helpers::model_config::model_validator::NativeModelValidator; -use crate::bindings::_helpers::model_config::unicode_environment::unicode_environment; -use crate::bindings::_helpers::render::declaration_values::ConstantRendering; -use crate::bindings::_helpers::render::macro_expansion_result::macro_expansion_classes; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::models::KeywordArguments; @@ -29,6 +22,13 @@ use sqlbuild_python_base::records::main::construct::enum_member::enum_member; use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::construct::record_class::record_class; +use sqlbuild_python_front::attachments::main::reserved_cursor_markers::reserved_cursor_markers; +use sqlbuild_python_front::discovery::models::NativeModelFile; +use sqlbuild_python_front::model_config::main::model_nodes::contract_classes::contract_classes; +use sqlbuild_python_front::model_config::main::model_nodes::unicode_environment::unicode_environment; +use sqlbuild_python_front::model_config::models::NativeModelValidator; +use sqlbuild_python_front::render::main::expansion::macro_expansion_classes::macro_expansion_classes; +use sqlbuild_python_front::render::models::ConstantRendering; use sqlbuild_core::constants::PROJECT_CONFIG_FILENAME; use sqlbuild_python_base::native_host::main::host_entry::host_entry; @@ -36,6 +36,8 @@ use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::authored_values::main::render_project_var_text_function::render_project_var_text_function; +use sqlbuild_python_front::model_config::main::config::record_template_reads_function::record_template_reads_function; /// The explicit reference call kinds and the `SqlResourceRefKind` member each resolves to. const EXPLICIT_REFERENCE_KINDS: [(&str, &str); 3] = [("ref", "MODEL"), ("source", "SOURCE"), ("seed", "SEED")]; @@ -138,7 +140,7 @@ fn sql_hook_inputs<'py>( ("environment", unicode_environment(py)?), ( "render_project_var", - pyo3::wrap_pyfunction!(crate::bindings::_helpers::authored_values::project_vars::render_project_var_text, py)?.into_any(), + render_project_var_text_function(py)?.into_any(), ), ( "sql_resource_ref", @@ -242,11 +244,7 @@ pub(crate) fn build_model_inputs<'py>( ), ( "record_template_reads", - pyo3::wrap_pyfunction!( - crate::bindings::_helpers::model_config::template_data::record_template_reads, - py - )? - .into_any(), + record_template_reads_function(py)?.into_any(), ), ( "visible_declarations", diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/registration.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/registration.rs index ea6f752684..a6aa6e901d 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/registration.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/registration.rs @@ -4,43 +4,28 @@ use pyo3::prelude::{Bound, PyModule, PyModuleMethods, PyResult}; use pyo3::wrap_pyfunction; use crate::bindings::_helpers::compile_attachment::{ - cursor_roles, declaration_scope, effective_config, model_config, model_inputs, - sql_expansion_context, target, + cursor_roles, declaration_scope, model_config, model_inputs, sql_expansion_context, target, }; +use sqlbuild_python_front::compile_attachment::main::build_effective_connection_config_function::build_effective_connection_config_function; +use sqlbuild_python_front::compile_attachment::main::build_effective_connection_function::build_effective_connection_function; +use sqlbuild_python_front::compile_attachment::main::build_effective_runtime_config_function::build_effective_runtime_config_function; +use sqlbuild_python_front::compile_attachment::main::build_effective_settings_config_function::build_effective_settings_config_function; +use sqlbuild_python_front::compile_attachment::main::build_effective_settings_function::build_effective_settings_function; +use sqlbuild_python_front::compile_attachment::main::build_effective_target_config_function::build_effective_target_config_function; +use sqlbuild_python_front::compile_attachment::main::build_effective_vars_function::build_effective_vars_function; pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { module.add_function(wrap_pyfunction!( sql_expansion_context::build_sql_expansion_context, module )?)?; - module.add_function(wrap_pyfunction!( - effective_config::build_effective_connection, - module - )?)?; - module.add_function(wrap_pyfunction!( - effective_config::build_effective_settings, - module - )?)?; - module.add_function(wrap_pyfunction!( - effective_config::build_effective_vars, - module - )?)?; - module.add_function(wrap_pyfunction!( - effective_config::build_effective_target_config, - module - )?)?; - module.add_function(wrap_pyfunction!( - effective_config::build_effective_connection_config, - module - )?)?; - module.add_function(wrap_pyfunction!( - effective_config::build_effective_runtime_config, - module - )?)?; - module.add_function(wrap_pyfunction!( - effective_config::build_effective_settings_config, - module - )?)?; + module.add_function(build_effective_connection_function(module)?)?; + module.add_function(build_effective_settings_function(module)?)?; + module.add_function(build_effective_vars_function(module)?)?; + module.add_function(build_effective_target_config_function(module)?)?; + module.add_function(build_effective_connection_config_function(module)?)?; + module.add_function(build_effective_runtime_config_function(module)?)?; + module.add_function(build_effective_settings_config_function(module)?)?; module.add_function(wrap_pyfunction!( model_config::native_model_config_session, module diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/sql_expansion_context.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/sql_expansion_context.rs index 226900a3fb..da924c246f 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/sql_expansion_context.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/sql_expansion_context.rs @@ -8,14 +8,7 @@ use sqlbuild_host::entries::models::UserCodeHost; use crate::bindings::_helpers::compile_attachment::declaration_scope::build_declaration_scope; use crate::bindings::_helpers::compile_attachment::declaration_scope::rebind_declaration_scope; -use crate::bindings::_helpers::compile_attachment::effective_config::{ - build_effective_vars, target_selection, -}; use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_collection_rendering; -use crate::bindings::_helpers::render::authored_sql::SqlExpansionInputs; -use crate::bindings::_helpers::render::declaration_indexes::public_declaration_indexes; use pyo3::IntoPyObjectExt; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::boundary::models::KeywordArguments; @@ -23,6 +16,12 @@ use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::compile_attachment::main::build_effective_vars::build_effective_vars; +use sqlbuild_python_front::compile_attachment::main::target_selection::target_selection; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use sqlbuild_python_front::contracts::main::resolve_effective_collection_rendering::resolve_effective_collection_rendering; +use sqlbuild_python_front::render::main::declarations::public_declaration_indexes::public_declaration_indexes; +use sqlbuild_python_front::render::models::SqlExpansionInputs; /// Build the declaration scope of `discovered`; a static scope lends only its index to macros. fn declaration_scope<'py>( diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/target.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/target.rs index b997929a6b..7bda60a51e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/target.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/target.rs @@ -4,21 +4,22 @@ use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; use pyo3::pyfunction; use pyo3::types::{PyDict, PyDictMethods, PyString, PyTuple}; -use crate::bindings::_helpers::compile_attachment::effective_config::project_vars; use crate::bindings::_helpers::compile_command::constants::{ COMPILE_CACHE_DISABLE_ENV_VAR, COMPILE_CACHE_DISABLE_VALUE, RETIRED_CACHE_DIRECTORY_NAMES, }; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_config; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_name; use crate::bindings::_helpers::frontier::cache_directory::cache_directory; use crate::bindings::_helpers::frontier::constants::{ COMPILER_CACHE_DIRECTORY_NAME, RETIRED_CACHE_NAMESPACE_SUFFIXES, }; -use crate::bindings::_helpers::model_config::template_data::{early_model_templates, run_id}; use pyo3::IntoPyObjectExt; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::compile_attachment::main::project_vars::project_vars; +use sqlbuild_python_front::contracts::main::resolve_target_config::resolve_target_config; +use sqlbuild_python_front::contracts::main::resolve_target_name::resolve_target_name; +use sqlbuild_python_front::model_config::main::config::early_model_templates::early_model_templates; +use sqlbuild_python_front::model_config::main::config::run_id::run_id; const DATABASE_KEY: &str = "database"; const SCHEMA_KEY: &str = "schema"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_command/report.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_command/report.rs index e9a710d0b0..8ce8ee5894 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_command/report.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_command/report.rs @@ -14,8 +14,6 @@ use sqlbuild_core::cli_text::models::{ use sqlbuild_host::entries::models::UserCodeHost; use crate::bindings::_helpers::compile_command::surrogates::SurrogateText; -use crate::bindings::_helpers::discovery::constants::SQL_HOOK_OUTPUT_FIELDS; -use crate::bindings::_helpers::discovery::hook_entries::hook_entries; use crate::bindings::_helpers::semantic_shapes::coverage::semantic_coverage; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::models::KeywordArguments; @@ -28,6 +26,8 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::main::fields::mapping_get_or::mapping_get_or; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::discovery::constants::SQL_HOOK_OUTPUT_FIELDS; +use sqlbuild_python_front::discovery::main::headers::hook_entries::hook_entries; const METADATA_MODULE: &str = "importlib.metadata"; const TARGET_DIRECTORY: &str = "target"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_command/reuse_attempt.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_command/reuse_attempt.rs index 86e566f8af..dd5044785d 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_command/reuse_attempt.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_command/reuse_attempt.rs @@ -41,9 +41,7 @@ use crate::bindings::_helpers::compile_driver::phases::{elapsed_ms, monotonic}; use crate::bindings::_helpers::compile_outputs::reuse::{ ReuseCheckPy, ReuseRulesPy, check_compile_reuse, }; -use crate::bindings::_helpers::discovery::project_config::warn_deprecated_settings; use crate::bindings::_helpers::frontier::cache_directory::cache_directory; -use crate::bindings::_helpers::macro_bridge::first_compile::keep_delta_claim; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::keywords::keywords; @@ -58,6 +56,8 @@ use sqlbuild_python_base::presentation_text::main::stdout_supports_color::stdout use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::registry::native_attr::native_attr; use sqlbuild_python_base::records::types::NativeAttr; +use sqlbuild_python_front::discovery::main::project::warn_deprecated_settings::warn_deprecated_settings; +use sqlbuild_python_front::macro_bridge::main::keep_delta_claim::keep_delta_claim; const REUSE_REQUEST: FacadeHost = FacadeHost::CompileReuseRequest; const HIT: &str = "hit"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_command/runtime_identity.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_command/runtime_identity.rs index c63f5d157d..b2cbf7d862 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_command/runtime_identity.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_command/runtime_identity.rs @@ -7,11 +7,11 @@ use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyModule, PyModuleMethods, PyRes use pyo3::types::{PyDict, PyDictMethods, PyList, PyTuple}; use pyo3::{IntoPyObjectExt, pyfunction, wrap_pyfunction}; -use crate::bindings::_helpers::discovery::provider_secrets::invocation_allows_missing_secrets; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::registry::native_attr::native_attr; use sqlbuild_python_base::records::types::NativeAttr; +use sqlbuild_python_front::discovery::main::sources::invocation_allows_missing_secrets::invocation_allows_missing_secrets; /// The version of the runtime identity a stored compile records. const REUSE_FORMAT_VERSION: &str = "1"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/analysis.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/analysis.rs index 6fab69d476..1a127cd3fa 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/analysis.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/analysis.rs @@ -11,7 +11,6 @@ use sqlbuild_rules::lint_text::main::counts_toward_exit::counts_toward_exit; use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; use crate::bindings::_helpers::compile_driver::project::build_project_graph_with_analysis_selection; use crate::bindings::_helpers::contracts::contract_diagnostics::evaluate_model_contracts; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; use crate::bindings::_helpers::lineage::project_lineage::build_project_column_lineage; use crate::bindings::_helpers::planner_selection::selectors::select_project_graph; use crate::bindings::_helpers::planner_selection::unit_tests::reject_unit_test_selectors; @@ -36,6 +35,7 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced::replaced; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; const RICH_LINEAGE: &str = "rich"; const FAST_LINEAGE: &str = "fast"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_analysis.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_analysis.rs index d00ffb9d14..d74df6da1c 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_analysis.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_analysis.rs @@ -27,12 +27,10 @@ use crate::bindings::_helpers::compile_driver::analysis_cache::analysis_cache_co use crate::bindings::_helpers::compile_driver::assembly::{AssemblyRequest, AssemblyStage}; use crate::bindings::_helpers::compiled_views::model_input_view::attached_schema; use crate::bindings::_helpers::compiled_views::source_views::read_source_view; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; use crate::bindings::_helpers::project_assembly::declared_relations::{ DeclaredRelations, DeclaredShapes, declared_relations, }; use crate::bindings::_helpers::semantic_shapes::declarations::{declared_types, function_names}; -use crate::bindings::_helpers::sqltext::lexical_syntax::optional_record_syntax; use sqlbuild_model_config::header_metadata::models::DynamicFamily; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::compile_context::models::PythonProcessClock; @@ -48,6 +46,8 @@ use sqlbuild_python_base::records::main::fields::mapping_get_or::mapping_get_or; use sqlbuild_python_base::records::main::fields::mapping_items::mapping_items; use sqlbuild_python_base::records::main::fields::replaced::replaced; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use sqlbuild_python_front::sqltext::main::optional_record_syntax::optional_record_syntax; use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; use std::collections::HashMap; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_checks.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_checks.rs index a2ee44856e..c3374d41f5 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_checks.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_checks.rs @@ -3,13 +3,6 @@ use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; use pyo3::types::{PyBool, PyDict, PyDictMethods, PyString, PyTuple}; -use crate::bindings::_helpers::attachments::cursor_intrinsics::validated_model_cursor_sql; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; -use crate::bindings::_helpers::render::declaration_values::declaration_scope_resolver; -use crate::bindings::_helpers::render::macro_expansion_result::{ - ExpansionRequest, expansion_result, -}; -use crate::bindings::_helpers::render::sql_macro_mocks::with_sql_macro_mocks; use pyo3::IntoPyObjectExt; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::records::main::construct::enum_member::enum_member; @@ -19,6 +12,12 @@ use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced::replaced; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::attachments::main::validated_model_cursor_sql::validated_model_cursor_sql; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use sqlbuild_python_front::render::main::declarations::declaration_scope_resolver::declaration_scope_resolver; +use sqlbuild_python_front::render::main::expansion::expansion_result::expansion_result; +use sqlbuild_python_front::render::main::sql_macros::with_sql_macro_mocks::with_sql_macro_mocks; +use sqlbuild_python_front::render::models::ExpansionRequest; /// The `CompiledSqlScenario` fields copied from its input, in Python's keyword order. const SCENARIO_FIELDS: [&str; 12] = [ diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_facts.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_facts.rs index cbb08a55c3..60ef674765 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_facts.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_facts.rs @@ -9,7 +9,6 @@ use crate::bindings::_helpers::analysis_session::session::{ FamilyRow, NativeModelAnalysisSession, PivotRequestRow, prove_dynamic_column_contracts, }; use crate::bindings::_helpers::compile_driver::assembly_analysis::AnalysisContext; -use crate::bindings::_helpers::model_config::header_families::HeaderFamilies; use crate::bindings::_helpers::project_assembly::models::{NativeModelFacts, NativeProjectFacts}; use crate::bindings::_helpers::project_assembly::native_resources::assemble_native_project_resources; use crate::bindings::_helpers::project_assembly::syntax_checks::model_syntax_checks; @@ -22,6 +21,7 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::model_config::models::HeaderFamilies; /// `NativeProjectFacts` of `inputs`: resources, syntax validity, deps and standalone pivot proofs. pub(crate) fn native_project_facts<'py>( diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_models.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_models.rs index 6d70cc38a6..1008452f1f 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_models.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_models.rs @@ -11,7 +11,6 @@ use crate::bindings::_helpers::analysis_session::model_analyses::ModelAnalyses; use crate::bindings::_helpers::analysis_session::profile_inputs::profile_dialect; use crate::bindings::_helpers::analysis_session::query_columns::ColumnsRow; use crate::bindings::_helpers::analysis_session::stage_functions::query_column_rows; -use crate::bindings::_helpers::attachments::cursor_intrinsics::analysis_cursor_sql; use crate::bindings::_helpers::compile_driver::assembly_analysis::{ AnalysisContext, model_stem, selected_for_analysis, }; @@ -22,12 +21,13 @@ use crate::bindings::_helpers::project_assembly::syntax_checks::model_placeholde use crate::bindings::_helpers::project_assembly::syntax_validation::{ ParseOptions, validate_hook_sql_syntax, validate_sql_syntax, }; -use crate::bindings::_helpers::render::macro_calls::top_level_macro_call_names; use sqlbuild_python_base::boundary::main::native_compiler_error::native_compiler_error; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::attachments::main::analysis_cursor_sql::analysis_cursor_sql; +use sqlbuild_python_front::render::main::calls::top_level_macro_call_names::top_level_macro_call_names; const NATIVE_FAILURE_PREFIX: &str = "NativeCompilerError: "; const HOOK_NAMES: [&str; 2] = ["pre_hooks", "post_hooks"]; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_project.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_project.rs index d966251b77..089b7861b2 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_project.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_project.rs @@ -25,12 +25,6 @@ use crate::bindings::_helpers::compile_driver::assembly_models::{ }; use crate::bindings::_helpers::compile_driver::assembly_sql_tests::assembled_sql_tests; use crate::bindings::_helpers::compiled_views::compiled_model_view::NativeCompiledModel; -use crate::bindings::_helpers::contracts::spec_resolution::{ - resolve_effective_adapter_name, resolve_effective_scenario_config, -}; -use crate::bindings::_helpers::model_config::template_data::early_model_templates; -use crate::bindings::_helpers::scopes::scope_errors::report_scope_index_errors; -use crate::bindings::_helpers::scopes::scope_validation::scope_index_with_compile_usages; use crate::bindings::_helpers::semantic_checks::stage::{ SemanticCompletion, completed_semantic_project, }; @@ -44,6 +38,11 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::main::fields::path_posix::path_posix; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use sqlbuild_python_front::contracts::main::resolve_effective_scenario_config::resolve_effective_scenario_config; +use sqlbuild_python_front::model_config::main::config::early_model_templates::early_model_templates; +use sqlbuild_python_front::scopes::main::checks::scope_index_with_compile_usages::scope_index_with_compile_usages; +use sqlbuild_python_front::scopes::main::reports::report_scope_index_errors::report_scope_index_errors; const SOURCE_SLOT: &str = "source"; const SEED_SLOT: &str = "seed"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/deferral.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/deferral.rs index 1bf2372e9f..ec03b3a6f9 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/deferral.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/deferral.rs @@ -10,7 +10,6 @@ use sqlbuild_python_base::records::main::construct::new_plain_error::new_plain_e use sqlbuild_model_config::templates::main::deferred_target_segments::deferred_target_segments; use sqlbuild_model_config::templates::models::DeferredSegment; -use crate::bindings::_helpers::authored_values::project_vars::render_project_var_text; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::records::main::construct::new_record::new_record; @@ -19,6 +18,7 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_values::mapping_values; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::authored_values::main::render_project_var_text::render_project_var_text; const PRESERVE_TARGET_VALUE: &str = "preserve"; /// `sorted(DEFERRED_TARGET_CONTEXT_KEYS)`. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/discovery.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/discovery.rs index ae41fdc99d..5d97463a57 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/discovery.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/discovery.rs @@ -6,42 +6,7 @@ use pyo3::{IntoPyObject, pyfunction, wrap_pyfunction}; use sqlbuild_host::entries::models::{ExecutorHost, UserCodeHost}; -use crate::bindings::_helpers::compile_driver::config_validation::{ - ProjectConfiguration, reject_invalid_project_configuration, -}; use crate::bindings::_helpers::compile_driver::integration_loaders::integration_loader_functions; -use crate::bindings::_helpers::discovery::constants::{ - ALLOW_MISSING_SECRETS_ENV, ALLOW_MISSING_SECRETS_SETTING, TRUE_ENV_VALUES, -}; -use crate::bindings::_helpers::discovery::declaration_records::{ - discover_adapter_file, discover_audit_files, discover_constant_files, discover_enum_files, - discover_macro_files, discover_model_schema_files, discover_seed_files, - discover_sql_function_files, discover_sql_hook_files, retained_discovery_session, -}; -use crate::bindings::_helpers::discovery::imported_providers::{ - discover_event_exporter_functions, discover_provider_classes, -}; -use crate::bindings::_helpers::discovery::imported_python_nodes::{ - discover_hook_functions, discover_materialization_files, discover_python_node_functions, -}; -use crate::bindings::_helpers::discovery::model_records::{ - ModelFileSelection, discovered_model_files, -}; -use crate::bindings::_helpers::discovery::project_config::{ - load_local_config_file, load_project_config_file, warn_deprecated_settings, -}; -use crate::bindings::_helpers::discovery::provider_secrets::{ - SecretPolicy, invocation_allows_missing_secrets, -}; -use crate::bindings::_helpers::discovery::python_function_files::discover_python_function_files; -use crate::bindings::_helpers::discovery::python_paths::reject_unsupported_python_paths; -use crate::bindings::_helpers::discovery::snapshot::in_snapshot; -use crate::bindings::_helpers::discovery::sql_test_records::{ - discover_scenario_files, discover_test_files, -}; -use crate::bindings::_helpers::discovery::yaml_records::{ - discover_schema_files, discover_source_files, -}; use crate::bindings::_helpers::frontier::compile_frontier::{FrontierStage, produced}; use pyo3::IntoPyObjectExt; use sqlbuild_python_base::boundary::main::call_with::call_with; @@ -55,6 +20,40 @@ use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::compile_driver::main::reject_invalid_project_configuration::reject_invalid_project_configuration; +use sqlbuild_python_front::compile_driver::models::ProjectConfiguration; +use sqlbuild_python_front::discovery::constants::ALLOW_MISSING_SECRETS_ENV; +use sqlbuild_python_front::discovery::constants::ALLOW_MISSING_SECRETS_SETTING; +use sqlbuild_python_front::discovery::constants::TRUE_ENV_VALUES; +use sqlbuild_python_front::discovery::main::project::load_local_config_file::load_local_config_file; +use sqlbuild_python_front::discovery::main::project::load_project_config_file::load_project_config_file; +use sqlbuild_python_front::discovery::main::project::warn_deprecated_settings::warn_deprecated_settings; +use sqlbuild_python_front::discovery::main::python_files::discover_event_exporter_functions::discover_event_exporter_functions; +use sqlbuild_python_front::discovery::main::python_files::discover_hook_functions::discover_hook_functions; +use sqlbuild_python_front::discovery::main::python_files::discover_materialization_files::discover_materialization_files; +use sqlbuild_python_front::discovery::main::python_files::discover_provider_classes::discover_provider_classes; +use sqlbuild_python_front::discovery::main::python_files::discover_python_function_files::discover_python_function_files; +use sqlbuild_python_front::discovery::main::python_files::discover_python_node_functions::discover_python_node_functions; +use sqlbuild_python_front::discovery::main::python_files::reject_unsupported_python_paths::reject_unsupported_python_paths; +use sqlbuild_python_front::discovery::main::records::discover_adapter_file::discover_adapter_file; +use sqlbuild_python_front::discovery::main::records::discover_audit_files::discover_audit_files; +use sqlbuild_python_front::discovery::main::records::discover_constant_files::discover_constant_files; +use sqlbuild_python_front::discovery::main::records::discover_enum_files::discover_enum_files; +use sqlbuild_python_front::discovery::main::records::discover_macro_files::discover_macro_files; +use sqlbuild_python_front::discovery::main::records::discover_model_schema_files::discover_model_schema_files; +use sqlbuild_python_front::discovery::main::records::discover_scenario_files::discover_scenario_files; +use sqlbuild_python_front::discovery::main::records::discover_schema_files::discover_schema_files; +use sqlbuild_python_front::discovery::main::records::discover_seed_files::discover_seed_files; +use sqlbuild_python_front::discovery::main::records::discover_source_files::discover_source_files; +use sqlbuild_python_front::discovery::main::records::discover_sql_function_files::discover_sql_function_files; +use sqlbuild_python_front::discovery::main::records::discover_sql_hook_files::discover_sql_hook_files; +use sqlbuild_python_front::discovery::main::records::discover_test_files::discover_test_files; +use sqlbuild_python_front::discovery::main::records::discovered_model_files::discovered_model_files; +use sqlbuild_python_front::discovery::main::records::retained_discovery_session::retained_discovery_session; +use sqlbuild_python_front::discovery::main::snapshots::in_snapshot::in_snapshot; +use sqlbuild_python_front::discovery::main::sources::invocation_allows_missing_secrets::invocation_allows_missing_secrets; +use sqlbuild_python_front::discovery::models::ModelFileSelection; +use sqlbuild_python_front::discovery::models::SecretPolicy; const SQL_ANALYSIS_SETTING_KEY: &str = "sql_analysis"; /// The setting that turns delta compiles, and the project image they read, off. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/inputs.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/inputs.rs index f7248baa18..6bad877a8f 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/inputs.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/inputs.rs @@ -6,19 +6,18 @@ use pyo3::{pyfunction, wrap_pyfunction}; use sqlbuild_host::entries::models::UserCodeHost; use crate::bindings::_helpers::compile_attachment::declaration_scope::build_declaration_scope; -use crate::bindings::_helpers::compile_attachment::effective_config::{ - build_effective_connection, build_effective_settings, build_effective_vars, -}; +use sqlbuild_python_front::compile_attachment::main::build_effective_connection::build_effective_connection; +use sqlbuild_python_front::compile_attachment::main::build_effective_settings::build_effective_settings; +use sqlbuild_python_front::compile_attachment::main::build_effective_vars::build_effective_vars; use crate::bindings::_helpers::compile_attachment::model_inputs::build_model_inputs; use sqlbuild_python_base::compile_context::main::diagnostic_collector::collect_compile_diagnostics::collect_compile_diagnostics; use crate::bindings::_helpers::compiled_project::project::NativeCompiledProject; use crate::bindings::_helpers::compiled_views::records::{compile_inputs_view, inputs_with}; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; use crate::bindings::_helpers::input_loops::attachment::{attach_checks, attach_resources}; -use crate::bindings::_helpers::model_config::template_data::run_id; -use crate::bindings::_helpers::render::declaration_indexes::{ - public_declaration_indexes, public_model_schema_index, -}; +use sqlbuild_python_front::model_config::main::config::run_id::run_id; +use sqlbuild_python_front::render::main::declarations::public_declaration_indexes::public_declaration_indexes; +use sqlbuild_python_front::render::main::declarations::public_model_schema_index::public_model_schema_index; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::boundary::main::within::within; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/mod.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/mod.rs index e0b34f994a..e7112cca71 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/mod.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/mod.rs @@ -8,7 +8,6 @@ pub(crate) mod assembly_models; pub(crate) mod assembly_project; pub(crate) mod assembly_sql_tests; pub(crate) mod command; -pub(crate) mod config_validation; pub(crate) mod deferral; pub(crate) mod diff; pub(crate) mod discovery; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/phases.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/phases.rs index 2b619310b6..e2f94f9638 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/phases.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/phases.rs @@ -9,7 +9,6 @@ use crate::bindings::_helpers::compile_command::reuse_recording::ArtifactRecorde use crate::bindings::_helpers::compile_command::target_writer::{ Prepared, planning_diagnostics, write_static_target, }; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; use crate::bindings::_helpers::dag_artifact::artifact::build_dag_json; use crate::bindings::_helpers::graph::python_node_graph::python_node_graph; use crate::bindings::_helpers::manifest::builder::build_manifest; @@ -23,6 +22,7 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; const EMPTY_DAG_PATH: &str = ""; const TARGET_DIRECTORY: &str = "target"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/pipeline.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/pipeline.rs index c1f3620e1c..eb1a3b50b9 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/pipeline.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/pipeline.rs @@ -4,7 +4,6 @@ use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyModule, PyModuleMethods, PyRes use pyo3::types::{PyDict, PySet, PySetMethods}; use pyo3::{IntoPyObject, PyErr, pyfunction, wrap_pyfunction}; -use crate::bindings::_helpers::compile_attachment::effective_config::build_effective_connection_config; use crate::bindings::_helpers::compile_driver::phases::monotonic; use crate::bindings::_helpers::compile_driver::pipeline_entries::compile_analysis_selection; use crate::bindings::_helpers::compile_driver::project::build_compiled_project; @@ -19,6 +18,7 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced::replaced; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::compile_attachment::main::build_effective_connection_config::build_effective_connection_config; /// The current build's phase timing tracker, when one is recording. pub(crate) fn timing_tracker(py: Python<'_>) -> PyResult> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/project.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/project.rs index 9e397246e4..488081bd09 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/project.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/project.rs @@ -20,19 +20,18 @@ use crate::bindings::_helpers::compile_driver::targets::{ requires_explicit_targets, }; use crate::bindings::_helpers::frontier::compile_frontier::{FrontierStage, bridged, produced}; -use crate::bindings::_helpers::sqltext::lexical_syntax::{optional_record_syntax, syntax_record}; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::records::main::construct::enum_member::enum_member; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; +use sqlbuild_python_front::sqltext::main::optional_record_syntax::optional_record_syntax; +use sqlbuild_python_front::sqltext::main::syntax_record::syntax_record; use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; use crate::bindings::_helpers::compile_driver::assembly::assemble_project; use crate::bindings::_helpers::compile_driver::selection_phases::resolve_analysis_model_names; use crate::bindings::_helpers::compiled_views::records::project_with; use crate::bindings::_helpers::contracts::contract_diagnostics::promotion_conflict_diagnostics; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_collection_rendering; use pyo3::IntoPyObjectExt; use sqlbuild_core::constants::PROJECT_CONFIG_FILENAME; use sqlbuild_core::constants::TABLE_PROMOTION_MODE_SETTING_KEY; @@ -42,6 +41,8 @@ use sqlbuild_python_base::compile_driver::constants::PROMOTION_CONFLICTS; use sqlbuild_python_base::compile_driver::main::count_stage::count_stage; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use sqlbuild_python_front::contracts::main::resolve_effective_collection_rendering::resolve_effective_collection_rendering; const LOCAL_CONFIG_FILENAME: &str = "sqlbuild_local.toml"; /// Optional keywords of the project graph builders. const GRAPH_OPTIONAL: [&str; 7] = [ diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/targets.rs b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/targets.rs index ebe177bb4a..e665d8bde7 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/targets.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compile_driver/targets.rs @@ -22,9 +22,9 @@ use sqlbuild_core::text::main::python_strip::python_strip; use sqlbuild_model_config::templates::models::TemplateOptions; -use crate::bindings::_helpers::model_config::template_data::expanded_template_data; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::boundary::models::KeywordArguments; +use sqlbuild_python_front::model_config::main::config::expanded_template_data::expanded_template_data; /// Connection settings that identify the warehouse two targets write to. const CONNECTION_IDENTITY_KEYS: [&str; 7] = [ @@ -41,11 +41,7 @@ const EXPLICIT_TARGET_ADAPTERS: [&str; 3] = ["snowflake", "bigquery", "databrick const LOADER_NAMESPACE_LABEL: &str = "managed loader target namespace"; const DEFAULTS_HELP_PURPOSE: &str = "to set project-wide defaults"; const NAMED_TARGET_HELP_PURPOSE: &str = "to build this target into that schema"; -use crate::bindings::_helpers::compile_attachment::effective_config::build_effective_connection_config; -use crate::bindings::_helpers::compile_attachment::effective_config::build_effective_runtime_config; use crate::bindings::_helpers::compile_attachment::target::resolved_target; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_config; -use crate::bindings::_helpers::discovery::guidance::setting_help; use pyo3::IntoPyObjectExt; use sqlbuild_core::constants::PROJECT_CONFIG_FILENAME; use sqlbuild_python_base::records::main::construct::error_class::error_class; @@ -53,6 +49,10 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::main::fields::mapping_items::mapping_items; use sqlbuild_python_base::records::types::ErrorId; +use sqlbuild_python_front::compile_attachment::main::build_effective_connection_config::build_effective_connection_config; +use sqlbuild_python_front::compile_attachment::main::build_effective_runtime_config::build_effective_runtime_config; +use sqlbuild_python_front::contracts::main::resolve_target_config::resolve_target_config; +use sqlbuild_python_front::discovery::main::failures::setting_help::setting_help; const DEFAULTS_SECTION: &str = "defaults"; /// One optional `(database, schema)` namespace. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compiled_project/job_catalog.rs b/crates/sqlbuild-python/src/bindings/_helpers/compiled_project/job_catalog.rs index dc6026816b..f9b2367126 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compiled_project/job_catalog.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compiled_project/job_catalog.rs @@ -19,7 +19,7 @@ use sqlbuild_discovery::orchestration_files::models::{OrchestrationInventory, Ru use crate::bindings::_helpers::compiled_project::constants::{ JOB_SELECTOR_KINDS, SELECTOR_INTERSECTION, SENSOR_RUN_ARGUMENT, }; -use crate::bindings::_helpers::discovery::orchestration_files::orchestration_declarations; +use sqlbuild_python_front::discovery::main::sources::orchestration_declarations::orchestration_declarations; /// Each job and group's selection, and the names of those a schedule or sensor starts. type Catalog = (BTreeMap, BTreeSet); diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compiled_project/project.rs b/crates/sqlbuild-python/src/bindings/_helpers/compiled_project/project.rs index c4f635c57d..6f644d93cc 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compiled_project/project.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compiled_project/project.rs @@ -56,11 +56,11 @@ use crate::bindings::_helpers::compiled_views::seed_views::{ use crate::bindings::_helpers::compiled_views::source_views::{ NativeCompiledSource, NativeSourceInput, SourceRecord, }; -use crate::bindings::_helpers::render::declaration_values::ConstantRendering; use sqlbuild_project::types::InferredRow; use sqlbuild_project::types::ObjectKeyRow; use sqlbuild_project::types::SourceNamespace; use sqlbuild_python_base::boundary::main::native_compiler_error::native_compiler_error; +use sqlbuild_python_front::render::models::ConstantRendering; pub(crate) const CONTRACT_KEY: &str = "contract"; const INPUT_CLASSES_UNSET: &str = "no model loop recorded inputs into this project"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compiled_project/snapshot_models.rs b/crates/sqlbuild-python/src/bindings/_helpers/compiled_project/snapshot_models.rs index 1ee1ad8cc2..76bdb01204 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compiled_project/snapshot_models.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compiled_project/snapshot_models.rs @@ -13,7 +13,6 @@ use sqlbuild_analysis::compiled_project::models::CompiledModelFacts; use sqlbuild_analysis::sql_macros::main::typed_analysis_sql::typed_analysis_sql; use sqlbuild_orchestration::snapshots::models::SnapshotNode; -use crate::bindings::_helpers::attachments::cursor_intrinsics::analysis_cursor_splices; use crate::bindings::_helpers::compiled_project::project::NativeCompiledProject; use crate::bindings::_helpers::compiled_project::snapshot::{ dependency_keys, destination, insert_node, @@ -21,6 +20,7 @@ use crate::bindings::_helpers::compiled_project::snapshot::{ use crate::bindings::_helpers::compiled_views::compiled_model_view::NativeCompiledModel; use crate::bindings::_helpers::compiled_views::model_input_view::ModelInputRecord; use crate::bindings::_helpers::compiled_views::project_view::NativeProjectView; +use sqlbuild_python_front::attachments::main::analysis_cursor_splices::analysis_cursor_splices; /// Each model's snapshot node, and the `columns` document of ranges kept out of node identity. pub(crate) fn model_nodes( diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/audit_views.rs b/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/audit_views.rs index 984526d334..5b08d91959 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/audit_views.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/audit_views.rs @@ -15,9 +15,9 @@ use crate::bindings::_helpers::compiled_views::model_input_view::{ InputViewClasses, reference_tuple, view_classes, }; use crate::bindings::_helpers::compiled_views::project_host::PyProjectHost; -use crate::bindings::_helpers::scopes::scope_report_objects::json_to_python; use sqlbuild_project::models::ReferenceRow; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::scopes::main::reports::json_to_python::json_to_python; const AUDIT_RESOURCE: &str = "audit"; const AUDIT_CLASSES: &str = "audits"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/compiled_model_analysis.rs b/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/compiled_model_analysis.rs index 4796268646..ca2d959b72 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/compiled_model_analysis.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/compiled_model_analysis.rs @@ -30,12 +30,12 @@ use crate::bindings::_helpers::analysis_session::session::NativeModelAnalysisSes use crate::bindings::_helpers::compiled_views::compiled_model_view::CompiledViewClasses; use crate::bindings::_helpers::compiled_views::model_input_view::ModelInputRecord; use crate::bindings::_helpers::compiled_views::project_host::PyProjectHost; -use crate::bindings::_helpers::discovery::model_file_record::NativeModelFile; use crate::bindings::_helpers::lineage::lineage_facts::{confidence_member, transform_kind_member}; -use crate::bindings::_helpers::render::macro_call_rows::span_expansion; use sqlbuild_python_base::boundary::main::compiler_error::compiler_error; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::discovery::models::NativeModelFile; +use sqlbuild_python_front::render::main::calls::span_expansion::span_expansion; const COMPILE_PHASE: &str = "compile"; const ERROR_SEVERITY: &str = "error"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/compiled_model_view.rs b/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/compiled_model_view.rs index 47b1933493..24e937b063 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/compiled_model_view.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/compiled_model_view.rs @@ -1,9 +1,9 @@ //! A compiled model, read from the native compiled project that owns it. -use crate::bindings::_helpers::model_config::header_audits::HeaderAudits; use sqlbuild_project::models as project_models; use sqlbuild_project::models::{DestinationFact, ModelMetadataTexts}; use sqlbuild_project::types::InferredRow; +use sqlbuild_python_front::model_config::models::HeaderAudits; use std::sync::Arc; use pyo3::prelude::{Bound, Py, PyAny, PyAnyMethods, PyResult, Python}; @@ -29,10 +29,10 @@ use crate::bindings::_helpers::compiled_views::model_input_view::{ }; use crate::bindings::_helpers::compiled_views::project_host::PyProjectHost; use crate::bindings::_helpers::compiled_views::relation_keys::RelationKeyRow; -use crate::bindings::_helpers::discovery::model_file_record::NativeModelFile; use crate::bindings::_helpers::graph::project_graph::ResourceRow; -use crate::bindings::_helpers::model_config::header_metadata::HeaderColumns; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::discovery::models::NativeModelFile; +use sqlbuild_python_front::model_config::models::HeaderColumns; const DATABASE_KEY: &str = "database"; const SCHEMA_KEY: &str = "schema"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/model_input_view.rs b/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/model_input_view.rs index 7b57e33aa6..df851fe4ee 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/model_input_view.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/model_input_view.rs @@ -20,14 +20,17 @@ use crate::bindings::_helpers::compiled_views::compiled_model_view::{ }; use crate::bindings::_helpers::compiled_views::project_host::PyProjectHost; use crate::bindings::_helpers::compiled_views::relation_keys::{RelationKeyRow, relation_key_row}; -use crate::bindings::_helpers::discovery::model_file_record::{NativeModelFile, projected_text}; -use crate::bindings::_helpers::model_config::header_audits::HeaderAudits; -use crate::bindings::_helpers::model_config::header_families::{HeaderFamilies, family_specs}; -use crate::bindings::_helpers::model_config::header_metadata::HeaderColumns; -use crate::bindings::_helpers::render::macro_call_rows::{SpanRow, span_tuple}; use sqlbuild_model_config::header_metadata::models::DynamicFamily; use sqlbuild_project::models::ReferenceRow; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::discovery::main::records::projected_text::projected_text; +use sqlbuild_python_front::discovery::models::NativeModelFile; +use sqlbuild_python_front::model_config::main::headers::family_specs::family_specs; +use sqlbuild_python_front::model_config::models::HeaderAudits; +use sqlbuild_python_front::model_config::models::HeaderColumns; +use sqlbuild_python_front::model_config::models::HeaderFamilies; +use sqlbuild_python_front::render::main::calls::span_tuple::span_tuple; +use sqlbuild_python_front::render::types::SpanRow; const MODEL_RELATION_KIND: &str = "ref"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/relation_keys.rs b/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/relation_keys.rs index 8ed4f3cdce..19829fd9a8 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/relation_keys.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/compiled_views/relation_keys.rs @@ -21,8 +21,8 @@ use crate::bindings::_helpers::compiled_views::model_input_view::{ use crate::bindings::_helpers::compiled_views::source_views::{ SourceKeyFacts, SourceViews, read_source_view, }; -use crate::bindings::_helpers::discovery::project_facts::seed_csv_settings; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::discovery::main::project::seed_csv_settings::seed_csv_settings; const MATERIALIZED_CONFIG: &str = "materialized"; const INCREMENTAL_MODE_CONFIG: &str = "incremental_mode"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/consumption/policy.rs b/crates/sqlbuild-python/src/bindings/_helpers/consumption/policy.rs index 905f2ca018..97b34ea561 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/consumption/policy.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/consumption/policy.rs @@ -10,9 +10,9 @@ use sqlbuild_state::consumption::models::{ }; use crate::bindings::_helpers::compiled_project::job_catalog::triggered_jobs; -use crate::bindings::_helpers::discovery::project_config::configured_changes; use crate::bindings::_helpers::graph::project_graph::NativeProjectGraph; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::discovery::main::project::configured_changes::configured_changes; const DEFINITION: &str = "definition"; const SOURCE_DATA: &str = "source_data"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/consumption/recorder.rs b/crates/sqlbuild-python/src/bindings/_helpers/consumption/recorder.rs index 7d430dc305..54655ad6ed 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/consumption/recorder.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/consumption/recorder.rs @@ -23,10 +23,10 @@ use uuid::Uuid; use crate::bindings::_helpers::consumption::facts::{ BuildFacts, MODEL, SEED, build_facts, enum_text, }; -use crate::bindings::_helpers::native_host::consumption_state::{ - ConsumptionConnection, Location, NodeCompleteHook, -}; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::native_host::models::ConsumptionConnection; +use sqlbuild_python_front::native_host::models::Location; +use sqlbuild_python_front::native_host::models::NodeCompleteHook; /// Succeeded rows are flushed once this many executions are pending. const FLUSH_EXECUTIONS: usize = 100; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/consumption/relation_reads.rs b/crates/sqlbuild-python/src/bindings/_helpers/consumption/relation_reads.rs index 809fb4a1de..2b1e918e9e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/consumption/relation_reads.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/consumption/relation_reads.rs @@ -9,9 +9,9 @@ use sqlbuild_state::consumption::models::{InputFact, NodeKey, RelationKey}; use crate::bindings::_helpers::analysis::relation_names::{ RelationRow, extract_sql_relation_names, }; -use crate::bindings::_helpers::native_host::consumption_state::optional_text; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_items::mapping_items; +use sqlbuild_python_front::native_host::main::optional_text::optional_text; /// Function calls, `__udf("name")(...)`, parsed as plain calls; their reads are declared inputs. const FUNCTION_CALLS: [&str; 2] = ["__udf", "__table_fn"]; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/contract_command/command.rs b/crates/sqlbuild-python/src/bindings/_helpers/contract_command/command.rs index 7abdec05e8..8ac95d3422 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/contract_command/command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/contract_command/command.rs @@ -26,7 +26,6 @@ use crate::bindings::_helpers::compile_driver::project::build_compiled_project; use crate::bindings::_helpers::contract_command::write::{ContractWrite, write_contracts}; use crate::bindings::_helpers::planner_selection::selectors::select_project_graph; use crate::bindings::_helpers::planner_selection::unit_tests::reject_unit_test_selectors; -use crate::bindings::_helpers::refactor::contract_compare::compare_contracts; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::keywords::keywords; @@ -38,6 +37,7 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::refactor::main::compare_contracts::compare_contracts; const GENERATE_ACTION: &str = "generate"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/contract_command/write.rs b/crates/sqlbuild-python/src/bindings/_helpers/contract_command/write.rs index a0f0fcd71d..9352b77d16 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/contract_command/write.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/contract_command/write.rs @@ -7,9 +7,6 @@ use pyo3::types::{PyDict, PyDictMethods, PyList, PyListMethods, PyTuple}; use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; use crate::bindings::_helpers::compile_driver::project::build_compiled_project; use crate::bindings::_helpers::format_command::files::write_file_atomically; -use crate::bindings::_helpers::refactor::contract_edits::edit_contract_model; -use crate::bindings::_helpers::refactor::contract_edits::edit_contract_source; -use crate::bindings::_helpers::refactor::contract_edits::remaining_contract_findings; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::records::main::construct::enum_member::enum_member; @@ -18,6 +15,9 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_keywords; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::refactor::main::edit_contract_model::edit_contract_model; +use sqlbuild_python_front::refactor::main::edit_contract_source::edit_contract_source; +use sqlbuild_python_front::refactor::main::remaining_contract_findings::remaining_contract_findings; const UTF8: &str = "utf-8"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/contracts/contract_diagnostics.rs b/crates/sqlbuild-python/src/bindings/_helpers/contracts/contract_diagnostics.rs index 9b2a843b48..361d2c5738 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/contracts/contract_diagnostics.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/contracts/contract_diagnostics.rs @@ -24,11 +24,12 @@ use crate::bindings::_helpers::compiled_views::records::compiled_project_facts; use crate::bindings::_helpers::contracts::model_contracts::{ ConflictRow, DiagnosticRow, evaluate_project_model_contracts, project_promotion_conflicts, }; -use crate::bindings::_helpers::sqltext::model_headers::{ColumnLocation, location_rows}; use sqlbuild_python_base::records::main::construct::enum_from_value::enum_from_value; use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::sqltext::main::location_rows::location_rows; +use sqlbuild_python_front::sqltext::models::ColumnLocation; const PATHLIB_MODULE: &str = "pathlib"; const GENERIC_DIALECT: &str = "generic"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/contracts/mod.rs b/crates/sqlbuild-python/src/bindings/_helpers/contracts/mod.rs index 3565cb6f91..375db96d18 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/contracts/mod.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/contracts/mod.rs @@ -1,6 +1,4 @@ pub(crate) mod contract_diagnostics; -pub(crate) mod effective_config; pub(crate) mod exception_types; pub(crate) mod model_contracts; pub(crate) mod registration; -pub(crate) mod spec_resolution; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/contracts/registration.rs b/crates/sqlbuild-python/src/bindings/_helpers/contracts/registration.rs index 30f503d77e..a1f676c557 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/contracts/registration.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/contracts/registration.rs @@ -2,21 +2,21 @@ use pyo3::prelude::{Bound, PyModule, PyResult}; -use crate::bindings::_helpers::authored_values::sql_values; -use crate::bindings::_helpers::contracts::{ - contract_diagnostics, effective_config, exception_types, spec_resolution, -}; -use crate::bindings::_helpers::discovery::project_config; +use crate::bindings::_helpers::contracts::{contract_diagnostics, exception_types}; use sqlbuild_python_base::contracts::main::register_resource_identities::register_resource_identities; use sqlbuild_python_base::contracts::main::register_state_literals::register_state_literals; +use sqlbuild_python_front::authored_values::main::register_sql_values::register_sql_values; +use sqlbuild_python_front::contracts::main::register_effective_config::register_effective_config; +use sqlbuild_python_front::contracts::main::register_spec_resolution::register_spec_resolution; +use sqlbuild_python_front::discovery::main::project::register_project_config::register_project_config; pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { contract_diagnostics::register(module)?; - effective_config::register(module)?; + register_effective_config(module)?; exception_types::register(module)?; - project_config::register(module)?; + register_project_config(module)?; register_resource_identities(module)?; - spec_resolution::register(module)?; - sql_values::register(module)?; + register_spec_resolution(module)?; + register_sql_values(module)?; register_state_literals(module) } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/cost_command/refresh.rs b/crates/sqlbuild-python/src/bindings/_helpers/cost_command/refresh.rs index 56ba668b30..b19e980701 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/cost_command/refresh.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/cost_command/refresh.rs @@ -11,9 +11,7 @@ use sqlbuild_core::cost_command::models::CostCoverage; use sqlbuild_host::entries::models::ExecutorHost; use crate::bindings::_helpers::command_runtime::connection::resolve_project_connection_config; -use crate::bindings::_helpers::compile_attachment::effective_config::build_effective_target_config; use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; use crate::bindings::_helpers::cost_report::functions::read_cost_run; use crate::bindings::_helpers::cost_report::functions::resolve_cost_run; use crate::bindings::_helpers::cost_report::functions::write_cost_run; @@ -26,6 +24,8 @@ use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_keywords; +use sqlbuild_python_front::compile_attachment::main::build_effective_target_config::build_effective_target_config; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; /// Collection budget of an explicit `sqb cost` refresh, which a user waits for on purpose. const REFRESH_BUDGET_SECONDS: f64 = 300.0; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/cost_report/functions.rs b/crates/sqlbuild-python/src/bindings/_helpers/cost_report/functions.rs index 8f03efd327..f6145f6d98 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/cost_report/functions.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/cost_report/functions.rs @@ -17,8 +17,8 @@ use crate::bindings::_helpers::cost_report::records::{ cost_run, cost_runs, record_object, record_tuple, }; use crate::bindings::_helpers::cost_report::store; -use crate::bindings::_helpers::scopes::scope_report_objects::json_to_python; use sqlbuild_python_base::boundary::models::KeywordArguments; +use sqlbuild_python_front::scopes::main::reports::json_to_python::json_to_python; const BREAKDOWN_OPTIONS: (&[&str], &[&str]) = ( &["record", "use_color"], diff --git a/crates/sqlbuild-python/src/bindings/_helpers/cost_telemetry/ledger.rs b/crates/sqlbuild-python/src/bindings/_helpers/cost_telemetry/ledger.rs index bc34d1abf0..0f8c8fc14c 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/cost_telemetry/ledger.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/cost_telemetry/ledger.rs @@ -17,7 +17,6 @@ use sqlbuild_core::json::models::{JsonDialect, JsonInteger, JsonValue, StdlibJso use crate::bindings::_helpers::cost_telemetry::health::mark_ledger_failure; use crate::bindings::_helpers::cost_telemetry::values::process_object; -use crate::bindings::_helpers::cursor::values::DATETIME_MODULE; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::within::within; use sqlbuild_python_base::boundary::models::KeywordArguments; @@ -27,6 +26,7 @@ use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::main::registry::native_attr::native_attr; use sqlbuild_python_base::records::types::NativeAttr; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::cursor::constants::DATETIME_MODULE; static LEDGER_LOCK: PyOnceLock> = PyOnceLock::new(); diff --git a/crates/sqlbuild-python/src/bindings/_helpers/cost_telemetry/snowflake.rs b/crates/sqlbuild-python/src/bindings/_helpers/cost_telemetry/snowflake.rs index 0b3e650146..708bc7c78b 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/cost_telemetry/snowflake.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/cost_telemetry/snowflake.rs @@ -21,7 +21,6 @@ use crate::bindings::_helpers::cost_telemetry::allocation::{ }; use crate::bindings::_helpers::cost_telemetry::health::consume_ledger_failure; use crate::bindings::_helpers::cost_telemetry::ledger::read_ledger; -use crate::bindings::_helpers::cursor::values::DATETIME_MODULE; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::within::within; use sqlbuild_python_base::boundary::models::KeywordArguments; @@ -30,6 +29,7 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_keywords; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::cursor::constants::DATETIME_MODULE; /// Default budget of one collection, which the at-exit collection keeps short. const DEADLINE_SECONDS: f64 = 30.0; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/cost_telemetry/values.rs b/crates/sqlbuild-python/src/bindings/_helpers/cost_telemetry/values.rs index a731e96140..5a415eec9a 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/cost_telemetry/values.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/cost_telemetry/values.rs @@ -7,10 +7,10 @@ use pyo3::sync::PyOnceLock; use pyo3::types::{PyDict, PyTuple}; use sqlbuild_core::cost_allocation::models::PyDecimal; -use crate::bindings::_helpers::cursor::values::DATETIME_MODULE; -use crate::bindings::_helpers::state_rows::timestamps::offset_aware; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::cursor::constants::DATETIME_MODULE; +use sqlbuild_python_front::state_rows::main::event_rows::offset_aware::offset_aware; const DECIMAL_MODULE: &str = "decimal"; /// The methods an adapter with warehouse cost telemetry implements. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/cursor/mod.rs b/crates/sqlbuild-python/src/bindings/_helpers/cursor/mod.rs index a1ea62d802..7444bd0374 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/cursor/mod.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/cursor/mod.rs @@ -1,7 +1 @@ -pub(crate) mod conversion; -pub(crate) mod durations; -pub(crate) mod intervals; -pub(crate) mod overrides; pub(crate) mod registration; -pub(crate) mod scalars; -pub(crate) mod values; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/cursor/registration.rs b/crates/sqlbuild-python/src/bindings/_helpers/cursor/registration.rs index ed10c4959d..23f5f77014 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/cursor/registration.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/cursor/registration.rs @@ -2,11 +2,13 @@ use pyo3::prelude::{Bound, PyModule, PyResult}; -use crate::bindings::_helpers::cursor::{durations, intervals, scalars}; +use sqlbuild_python_front::cursor::main::durations::register_durations::register_durations; +use sqlbuild_python_front::cursor::main::intervals::register_intervals::register_intervals; +use sqlbuild_python_front::cursor::main::scalars::register_scalars::register_scalars; pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { - scalars::register(module)?; - intervals::register(module)?; - durations::register(module)?; + register_scalars(module)?; + register_intervals(module)?; + register_durations(module)?; Ok(()) } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/pipeline_phases.rs b/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/pipeline_phases.rs index 4711e6a15a..f6212e2fb0 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/pipeline_phases.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/pipeline_phases.rs @@ -5,8 +5,6 @@ use pyo3::types::PyDict; use pyo3::{IntoPyObject, pyfunction, wrap_pyfunction}; use crate::bindings::_helpers::build_progress::progress_reporters::ConnectionProgressReporter; -use crate::bindings::_helpers::command_runtime::concurrency::resolve_concurrency; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_config; use crate::bindings::_helpers::dbt_interop::execution::render_dbt_execution_summary_footer; use crate::bindings::_helpers::dbt_interop::pipeline_prologue::progress; use crate::bindings::_helpers::dbt_interop::plan::render_dbt_interop_plan; @@ -26,6 +24,8 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced::replaced; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::command_runtime::main::resolve_concurrency::resolve_concurrency; +use sqlbuild_python_front::contracts::main::resolve_target_config::resolve_target_config; const OPTIONS: (&[&str], &[&str]) = ( &["request", "invocation"], diff --git a/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/pipeline_prologue.rs b/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/pipeline_prologue.rs index 914f1ba3fe..e226cf5c8c 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/pipeline_prologue.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/pipeline_prologue.rs @@ -2,7 +2,6 @@ use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; use crate::bindings::_helpers::compile_driver::project::build_compiled_project; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; use crate::bindings::_helpers::dbt_interop::cli::resolve_dbt_executable; use crate::bindings::_helpers::dbt_interop::cli::route_dbt_interop_args; use crate::bindings::_helpers::dbt_interop::graph::build_dbt_combined_graph; @@ -18,6 +17,7 @@ use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; use crate::bindings::_helpers::dbt_interop::reference_resolver::DbtCompileReferenceResolver; use crate::bindings::_helpers::dbt_interop::runtime_config::{ diff --git a/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/plan_output.rs b/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/plan_output.rs index 138bd0bf77..3ba6d26f14 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/plan_output.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/plan_output.rs @@ -9,7 +9,6 @@ use crate::bindings::_helpers::command_runtime::connection::{ anchor_local_database_path, with_dbt_profile, }; use crate::bindings::_helpers::command_runtime::warehouses::apply_command_warehouse; -use crate::bindings::_helpers::compile_attachment::effective_config::build_effective_connection_config; use crate::bindings::_helpers::compile_driver::deferral::resolve_model_deferral_inputs; use crate::bindings::_helpers::compile_driver::plan_result::connection_with_hooks; use crate::bindings::_helpers::planner_entries::display_plan::build_display_only_sqlbuild_plan; @@ -28,6 +27,7 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced::replaced; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::compile_attachment::main::build_effective_connection_config::build_effective_connection_config; const BUILD_OPTIONS: (&[&str], &[&str]) = (&["environment", "request", "hooks"], &[]); const ATTACH_OPTIONS: (&[&str], &[&str]) = ( diff --git a/crates/sqlbuild-python/src/bindings/_helpers/debug_command/run_debug.rs b/crates/sqlbuild-python/src/bindings/_helpers/debug_command/run_debug.rs index 3c21e86d6d..5be09d62b7 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/debug_command/run_debug.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/debug_command/run_debug.rs @@ -34,10 +34,7 @@ use crate::bindings::_helpers::command_runtime::warehouses::{ CommandScope, WarehouseInputs, apply_warehouse, command_scope, find_authored, resolve_warehouse, }; use crate::bindings::_helpers::compile_attachment::target::build_effective_target_namespace; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; use crate::bindings::_helpers::diff_report::query::NAMESPACELESS_ADAPTERS; -use crate::bindings::_helpers::discovery::configuration::discover_configured_providers; -use crate::bindings::_helpers::discovery::provider_secrets::SecretPolicy; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::keywords::keywords; @@ -51,6 +48,9 @@ use sqlbuild_python_base::presentation_text::main::stdout_supports_color::stdout use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use sqlbuild_python_front::discovery::main::project::discover_configured_providers::discover_configured_providers; +use sqlbuild_python_front::discovery::models::SecretPolicy; const DEBUG_OPTIONS: (&[&str], &[&str]) = ( &[], diff --git a/crates/sqlbuild-python/src/bindings/_helpers/diff_report/command.rs b/crates/sqlbuild-python/src/bindings/_helpers/diff_report/command.rs index 1389abde3a..f34d93ed9b 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/diff_report/command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/diff_report/command.rs @@ -21,8 +21,6 @@ use sqlbuild_host::entries::models::{AdapterHost, ExecutorHost}; use crate::bindings::_helpers::command_runtime::connection::resolve_target_connection_config; use crate::bindings::_helpers::compile_driver::diff::run_diff_pipeline; use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_config; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_name; use crate::bindings::_helpers::dbt_interop::reference_resolver::resolve_external_sql_reference_resolver; use crate::bindings::_helpers::diff_report::facts::diff_facts; use crate::bindings::_helpers::diff_report::output::publish_diff_output; @@ -33,7 +31,6 @@ use crate::bindings::_helpers::diff_report::support::{ call, caused, cli_error, error_text, is_exception, matches_class, matches_native, none, object, request_facts, user_error_parts, }; -use crate::bindings::_helpers::discovery::configuration::discover_project_configuration; use crate::bindings::_helpers::planner_selection::unit_tests::reject_unit_test_selectors; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::keywords::keywords; @@ -43,6 +40,9 @@ use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; +use sqlbuild_python_front::contracts::main::resolve_target_config::resolve_target_config; +use sqlbuild_python_front::contracts::main::resolve_target_name::resolve_target_name; +use sqlbuild_python_front::discovery::main::project::discover_project_configuration::discover_project_configuration; const DEFAULT_DIFF_MAX_FULL_ROWS: i64 = 10_000_000; const ADAPTER_ERRORS: AdapterHost = AdapterHost::AdapterUserError; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/diff_report/query.rs b/crates/sqlbuild-python/src/bindings/_helpers/diff_report/query.rs index 90f7869f5f..29afbc7e3f 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/diff_report/query.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/diff_report/query.rs @@ -16,9 +16,7 @@ use sqlbuild_cli::diff_report::types::PhaseSeconds; use sqlbuild_host::entries::models::{AdapterHost, ExecutorHost}; use crate::bindings::_helpers::command_runtime::connection::resolve_project_connection_config; -use crate::bindings::_helpers::compile_attachment::effective_config::build_effective_runtime_config; use crate::bindings::_helpers::compile_attachment::target::build_effective_target_namespace; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; use crate::bindings::_helpers::diff_report::support::{ call, cli_error, error_text, none, object, progress_line, }; @@ -36,6 +34,8 @@ use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; use sqlbuild_python_base::types::CompilerDetach; +use sqlbuild_python_front::compile_attachment::main::build_effective_runtime_config::build_effective_runtime_config; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; const GENERIC_DIALECT: &str = "generic"; pub(crate) const NAMESPACELESS_ADAPTERS: [&str; 2] = ["duckdb", "motherduck"]; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/constants.rs b/crates/sqlbuild-python/src/bindings/_helpers/discovery/constants.rs deleted file mode 100644 index 9e24509e7e..0000000000 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/constants.rs +++ /dev/null @@ -1,21 +0,0 @@ -//! The fields discovery reports for SQL hook entries. - -/// The fields a SQL hook entry reports, in output order. -pub(crate) const SQL_HOOK_OUTPUT_FIELDS: [&str; 6] = [ - "statement", - "name", - "relative_path", - "definition_sql", - "kwargs", - "description", -]; - -/// The flag of the static commands that lets them compile without provider secrets. -pub(crate) const ALLOW_MISSING_SECRETS_FLAG: &str = "--allow-missing-secrets"; -/// The environment variable that sets `--allow-missing-secrets`. -pub(crate) const ALLOW_MISSING_SECRETS_ENV: &str = "SQLBUILD_ALLOW_MISSING_SECRETS"; -/// The `[settings]` key of `sqlbuild_local.toml` that sets `--allow-missing-secrets`. -pub(crate) const ALLOW_MISSING_SECRETS_SETTING: &str = "allow_missing_secrets"; - -/// Environment values that switch a boolean `SQLBUILD_*` variable on. -pub(crate) const TRUE_ENV_VALUES: [&str; 4] = ["1", "on", "true", "yes"]; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/mod.rs b/crates/sqlbuild-python/src/bindings/_helpers/discovery/mod.rs index a83fee866c..7444bd0374 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/mod.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/discovery/mod.rs @@ -1,38 +1 @@ -pub(crate) mod configuration; -pub(crate) mod constants; -pub(crate) mod declaration_files; -pub(crate) mod declaration_records; -pub(crate) mod description_inputs; -pub(crate) mod faults; -pub(crate) mod getters; -pub(crate) mod guidance; -pub(crate) mod header_declarations; -pub(crate) mod header_keys; -pub(crate) mod header_values; -pub(crate) mod hook_entries; -pub(crate) mod imported_modules; -pub(crate) mod imported_providers; -pub(crate) mod imported_python_nodes; -pub(crate) mod key_checks; -pub(crate) mod locations; -pub(crate) mod model_file_record; -pub(crate) mod model_records; -pub(crate) mod orchestration_files; -pub(crate) mod orchestration_values; -pub(crate) mod project_config; -pub(crate) mod project_facts; -pub(crate) mod project_files; -pub(crate) mod project_validation; -pub(crate) mod provider_secrets; -pub(crate) mod python_function_files; -pub(crate) mod python_hook_files; -pub(crate) mod python_module_files; -pub(crate) mod python_paths; -pub(crate) mod raised; pub(crate) mod registration; -pub(crate) mod scope_snapshot; -pub(crate) mod snapshot; -pub(crate) mod sql_test_blocks; -pub(crate) mod sql_test_records; -pub(crate) mod yaml_entries; -pub(crate) mod yaml_records; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/model_file_record.rs b/crates/sqlbuild-python/src/bindings/_helpers/discovery/model_file_record.rs deleted file mode 100644 index c07a7efcb5..0000000000 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/model_file_record.rs +++ /dev/null @@ -1,630 +0,0 @@ -//! A discovered SQL model file as a native record whose Python attributes are built on demand. - -use std::path::PathBuf; -use std::sync::Arc; - -use crate::bindings::_helpers::sqltext::authored_values::map_to_python; -use pyo3::exceptions::{PyRuntimeError, PyTypeError}; -use pyo3::prelude::{Bound, Py, PyAny, PyAnyMethods, PyResult, Python}; -use pyo3::sync::PyOnceLock; -use pyo3::types::{PyDict, PyDictMethods, PyString, PyStringMethods, PyTuple}; -use pyo3::{FromPyObject, IntoPyObject, IntoPyObjectExt, pyclass, pymethods}; -use sqlbuild_discovery::model_files::main::model_file_stem::model_file_stem; -use sqlbuild_discovery::models::LineColumnSpan; -use sqlbuild_python_base::records::main::construct::new_record::new_record; -use sqlbuild_python_base::records::main::fields::field::field; -use sqlbuild_python_base::records::types::RecordId; -use sqlbuild_sqltext::compiler::models::AuthoredValue; - -const FIELD_NAMES: [&str; 10] = [ - "file_path", - "relative_path", - "contents", - "header_values", - "header_column_locations", - "output_column_locations", - "query_sql", - "enum_declarations", - "constant_declarations", - "extract_implicit_alias_columns", -]; -const STEM_ATTRIBUTE: &str = "stem"; - -/// Authored locations: native rows until Python reads them, then a cached dict. -struct Locations { - rows: Vec<(String, LineColumnSpan)>, - projected: PyOnceLock>, -} - -impl Locations { - fn from_rows(rows: Vec<(String, LineColumnSpan)>) -> Self { - Self { - rows, - projected: PyOnceLock::new(), - } - } - - /// These locations for another record: the rows, and the dict once Python has read it. - fn shared(&self, py: Python<'_>) -> Self { - let projected: PyOnceLock> = PyOnceLock::new(); - if let Some(dict) = self.projected.get(py) { - let _ = projected.set(py, dict.clone_ref(py)); - } - Self { - rows: self.rows.clone(), - projected, - } - } - - fn from_dict(py: Python<'_>, dict: Py) -> Self { - let projected: PyOnceLock> = PyOnceLock::new(); - let _ = projected.set(py, dict); - Self { - rows: Vec::new(), - projected, - } - } - - /// Python's `{name: SourceLocation(...)}`: a repeated name keeps its first position and last value. - fn dict<'py>(&self, path: &Bound<'py, PyAny>) -> PyResult> { - let py: Python<'py> = path.py(); - Ok(self - .projected - .get_or_try_init(py, || { - let dict: Bound<'py, PyDict> = PyDict::new(py); - for (name, span) in &self.rows { - let location: Bound<'py, PyAny> = new_record( - py, - RecordId::SourceLocation, - (path, span.line, span.column, span.end_line, span.end_column), - None, - )?; - dict.set_item(name, location)?; - } - Ok::<_, pyo3::PyErr>(dict.unbind()) - })? - .bind(py) - .clone()) - } -} - -/// The names a model file is known by, as Python's `pathlib` spells them. -#[derive(Clone)] -pub(crate) struct ModelFileTexts { - /// `file_path.stem`, the model's name. - pub(crate) name: String, - /// `relative_path.as_posix()`. - pub(crate) posix_path: String, - /// `str(relative_path)`. - pub(crate) relative_path: String, - /// `str(file_path)`. - pub(crate) file_path: String, -} - -/// A model file's paths: native text, with the Python path objects built on first read. -struct ModelFilePaths { - native_file_path: PathBuf, - /// `None` when a path is not text Python can encode, so readers raise as Python does. - texts: Option, - /// `(file_path, relative_path)` as Python path objects. - objects: PyOnceLock<(Py, Py)>, - /// The relative path the objects are built from, unless they were given. - relative: Option, -} - -impl ModelFilePaths { - /// Paths given as Python objects; their text is read once, here. - fn given(py: Python<'_>, file_path: Py, relative_path: Py) -> PyResult { - let native_file_path: PathBuf = file_path.bind(py).extract()?; - let relative: PathBuf = relative_path.bind(py).extract()?; - let texts: Option = - native_file_path - .to_str() - .zip(relative.to_str()) - .map(|(file_text, relative_text)| ModelFileTexts { - name: model_file_stem(&posix(file_text)).to_owned(), - posix_path: posix(relative_text), - relative_path: relative_text.to_owned(), - file_path: file_text.to_owned(), - }); - let objects: PyOnceLock<(Py, Py)> = PyOnceLock::new(); - let _ = objects.set(py, (file_path, relative_path)); - Ok(Self { - native_file_path, - texts, - objects, - relative: None, - }) - } - - /// Paths native discovery named; their Python path objects are built only when read. - fn discovered(relative_path: &str, file_path: String) -> Self { - let name: String = model_file_stem(relative_path).to_owned(); - Self { - native_file_path: PathBuf::from(&file_path), - texts: Some(ModelFileTexts { - name, - posix_path: relative_path.to_owned(), - relative_path: relative_path.replace('/', std::path::MAIN_SEPARATOR_STR), - file_path, - }), - objects: PyOnceLock::new(), - relative: Some(PathBuf::from(relative_path)), - } - } - - fn shared(&self, py: Python<'_>) -> Self { - let objects: PyOnceLock<(Py, Py)> = PyOnceLock::new(); - if let Some((file_path, relative_path)) = self.objects.get(py) { - let _ = objects.set(py, (file_path.clone_ref(py), relative_path.clone_ref(py))); - } - Self { - native_file_path: self.native_file_path.clone(), - texts: self.texts.clone(), - objects, - relative: self.relative.clone(), - } - } - - /// `(file_path, relative_path)` as the `pathlib` objects discovery names the file by. - fn objects<'py>(&self, py: Python<'py>) -> PyResult<(Bound<'py, PyAny>, Bound<'py, PyAny>)> { - let (file_path, relative_path) = self.objects.get_or_try_init(py, || { - let Some(relative) = &self.relative else { - return Err(PyRuntimeError::new_err("a model file has no paths")); - }; - Ok::<_, pyo3::PyErr>(( - self.native_file_path.as_path().into_pyobject(py)?.unbind(), - relative.as_path().into_pyobject(py)?.unbind(), - )) - })?; - Ok((file_path.bind(py).clone(), relative_path.bind(py).clone())) - } - - /// The file's names, or the error Python raises reading a name that is not UTF-8 text. - fn texts(&self, py: Python<'_>) -> PyResult<&ModelFileTexts> { - if let Some(texts) = &self.texts { - return Ok(texts); - } - let (file_path, relative_path) = self.objects(py)?; - for path in [file_path, relative_path] { - path.str()?.to_str()?; - } - Err(PyRuntimeError::new_err("a model file path is not text")) - } -} - -/// `text` with the platform's path separator spelled `/`, as `PurePath.as_posix` spells it. -fn posix(text: &str) -> String { - text.replace(std::path::MAIN_SEPARATOR, "/") -} - -/// `text` as the Python string `cache` shares with every reader, built on first read. -pub(crate) fn projected_text<'py>( - py: Python<'py>, - cache: &PyOnceLock>, - text: &str, -) -> Bound<'py, PyString> { - cache - .get_or_init(py, || PyString::new(py, text).unbind()) - .bind(py) - .clone() -} - -/// A model header's authored values: native entries, with the Python dict built on first read. -struct HeaderValues { - native: Option>, - projected: PyOnceLock>, -} - -impl HeaderValues { - fn native(values: Vec<(String, AuthoredValue)>) -> Self { - Self { - native: Some(values.into()), - projected: PyOnceLock::new(), - } - } - - fn given(py: Python<'_>, values: Py) -> Self { - let projected: PyOnceLock> = PyOnceLock::new(); - let _ = projected.set(py, values); - Self { - native: None, - projected, - } - } - - fn shared(&self, py: Python<'_>) -> Self { - let projected: PyOnceLock> = PyOnceLock::new(); - if let Some(dict) = self.projected.get(py) { - let _ = projected.set(py, dict.clone_ref(py)); - } - Self { - native: self.native.clone(), - projected, - } - } - - fn dict<'py>(&self, py: Python<'py>) -> PyResult> { - Ok(self - .projected - .get_or_try_init(py, || { - let values: &[(String, AuthoredValue)] = self.native.as_deref().unwrap_or_default(); - map_to_python(py, values)? - .into_bound(py) - .downcast_into::() - .map(Bound::unbind) - .map_err(pyo3::PyErr::from) - })? - .bind(py) - .clone()) - } -} - -/// A discovered SQL model file and its raw contents. -#[pyclass(module = "sqlbuild._native", name = "DiscoveredSqlModelFile", frozen)] -pub(crate) struct NativeModelFile { - paths: ModelFilePaths, - contents: Arc, - /// `contents` and `query_sql` as the Python strings readers share, built on first read. - projected_texts: (PyOnceLock>, PyOnceLock>), - header_values: HeaderValues, - header_column_locations: Locations, - output_column_locations: Locations, - query_sql: Arc, - enum_declarations: Py, - constant_declarations: Py, - extract_implicit_alias_columns: bool, -} - -/// What native discovery read for one model file. -pub(crate) struct ModelFileParts { - pub(crate) contents: String, - pub(crate) header_values: Vec<(String, AuthoredValue)>, - pub(crate) header_column_locations: Vec<(String, LineColumnSpan)>, - pub(crate) output_column_locations: Vec<(String, LineColumnSpan)>, - pub(crate) query_sql: String, - pub(crate) extract_implicit_alias_columns: bool, -} - -/// How discovery names a model file: natively, or by Python paths for names Python escapes. -pub(crate) enum DiscoveredPaths { - /// The `/`-separated relative path and `str(project_dir / relative_path)`. - Native(String, String), - /// `(file_path, relative_path)` built by Python. - Python(Py, Py), -} - -/// A model file before its header declarations are attached. -pub(crate) struct PendingModelFile { - paths: ModelFilePaths, - parts: ModelFileParts, -} - -impl PendingModelFile { - pub(crate) fn new( - py: Python<'_>, - paths: DiscoveredPaths, - parts: ModelFileParts, - ) -> PyResult { - let paths: ModelFilePaths = match paths { - DiscoveredPaths::Native(relative_path, file_path) => { - ModelFilePaths::discovered(&relative_path, file_path) - } - DiscoveredPaths::Python(file_path, relative_path) => { - ModelFilePaths::given(py, file_path, relative_path)? - } - }; - Ok(Self { paths, parts }) - } - - /// The model's name, its file stem. - pub(crate) fn name(&self, py: Python<'_>) -> PyResult { - match &self.paths.texts { - Some(texts) => Ok(texts.name.clone()), - None => field(&self.paths.objects(py)?.0, STEM_ATTRIBUTE)?.extract(), - } - } - - /// The relative path as the Python path object the record keeps. - pub(crate) fn relative_path<'py>(&self, py: Python<'py>) -> PyResult> { - Ok(self.paths.objects(py)?.1) - } - - /// The authored header value of `key`. - pub(crate) fn header_value(&self, key: &str) -> Option<&AuthoredValue> { - self.parts - .header_values - .iter() - .rev() - .find(|(name, _)| name == key) - .map(|(_, value)| value) - } - - pub(crate) fn finished(self, declarations: (Py, Py)) -> NativeModelFile { - let (enum_declarations, constant_declarations) = declarations; - let parts: ModelFileParts = self.parts; - NativeModelFile { - paths: self.paths, - contents: parts.contents.into(), - projected_texts: (PyOnceLock::new(), PyOnceLock::new()), - header_values: HeaderValues::native(parts.header_values), - header_column_locations: Locations::from_rows(parts.header_column_locations), - output_column_locations: Locations::from_rows(parts.output_column_locations), - query_sql: parts.query_sql.into(), - enum_declarations, - constant_declarations, - extract_implicit_alias_columns: parts.extract_implicit_alias_columns, - } - } -} - -/// The keyword fields Python constructs a model file record with. -#[derive(FromPyObject)] -#[pyo3(from_item_all)] -struct ModelFileFields { - file_path: Py, - relative_path: Py, - contents: Py, - header_values: Py, - header_column_locations: Py, - output_column_locations: Py, - query_sql: Py, - #[pyo3(default)] - enum_declarations: Option>, - #[pyo3(default)] - constant_declarations: Option>, - #[pyo3(default = true)] - extract_implicit_alias_columns: bool, -} - -impl NativeModelFile { - pub(crate) fn header_locations<'py>(&self, py: Python<'py>) -> PyResult> { - self.header_column_locations - .dict(&self.paths.objects(py)?.1) - } - - /// The header's authored values as the Python dict config builds read. - pub(crate) fn header_value_dict<'py>(&self, py: Python<'py>) -> PyResult> { - self.header_values.dict(py) - } - - /// The header columns' authored locations, unless Python constructed this record. - pub(crate) fn header_location_rows(&self) -> &[(String, LineColumnSpan)] { - &self.header_column_locations.rows - } - - /// The header's native authored values, unless Python constructed this record. - pub(crate) fn native_header_values(&self) -> Option<&Arc<[(String, AuthoredValue)]>> { - self.header_values.native.as_ref() - } - - pub(crate) fn declaration_tuples<'py>( - &self, - py: Python<'py>, - ) -> (&Bound<'py, PyTuple>, &Bound<'py, PyTuple>) { - ( - self.enum_declarations.bind(py), - self.constant_declarations.bind(py), - ) - } - - /// The file path as a native path. - pub(crate) fn file_path_buf(&self) -> PathBuf { - self.paths.native_file_path.clone() - } - - /// The file's names, or the error Python raises reading a name that is not UTF-8 text. - pub(crate) fn path_texts(&self, py: Python<'_>) -> PyResult { - self.paths.texts(py).cloned() - } - - /// `relative_path.as_posix()`. - pub(crate) fn posix_path(&self, py: Python<'_>) -> PyResult { - Ok(self.paths.texts(py)?.posix_path.clone()) - } - - /// `str(relative_path)`. - pub(crate) fn relative_text(&self, py: Python<'_>) -> PyResult { - Ok(self.paths.texts(py)?.relative_path.clone()) - } - - /// `str(relative_path.parent)`, the folder project graphs group the model by. - pub(crate) fn folder(&self, py: Python<'_>) -> PyResult { - Ok(self - .paths - .texts(py)? - .relative_path - .rsplit_once(std::path::MAIN_SEPARATOR) - .map_or_else(|| ".".to_owned(), |(folder, _)| folder.to_owned())) - } - - /// `(file_path, relative_path)` as Python path objects. - pub(crate) fn path_objects<'py>( - &self, - py: Python<'py>, - ) -> PyResult<(Bound<'py, PyAny>, Bound<'py, PyAny>)> { - self.paths.objects(py) - } - - /// The authored query below the header. - pub(crate) fn query_text(&self) -> &Arc { - &self.query_sql - } - - /// The whole authored file. - pub(crate) fn contents_text(&self) -> &Arc { - &self.contents - } - - fn fields<'py>(&self, py: Python<'py>) -> PyResult>> { - let (file_path, relative_path) = self.paths.objects(py)?; - Ok(vec![ - file_path, - relative_path.clone(), - self.contents(py).into_any(), - self.header_values.dict(py)?.into_any(), - self.header_column_locations - .dict(&relative_path)? - .into_any(), - self.output_column_locations - .dict(&relative_path)? - .into_any(), - self.query_sql(py).into_any(), - self.enum_declarations.bind(py).clone().into_any(), - self.constant_declarations.bind(py).clone().into_any(), - pyo3::types::PyBool::new(py, self.extract_implicit_alias_columns) - .to_owned() - .into_any(), - ]) - } -} - -#[pymethods] -impl NativeModelFile { - #[new] - #[pyo3(signature = (**fields))] - fn new(py: Python<'_>, fields: Option>) -> PyResult { - let Some(fields) = fields else { - return Err(PyTypeError::new_err( - "DiscoveredSqlModelFile requires its fields", - )); - }; - for key in fields.keys() { - let key: String = key.extract()?; - if !FIELD_NAMES.contains(&key.as_str()) { - return Err(PyTypeError::new_err(format!( - "DiscoveredSqlModelFile got an unexpected keyword argument '{key}'" - ))); - } - } - let fields: ModelFileFields = fields.extract()?; - Ok(Self { - paths: ModelFilePaths::given(py, fields.file_path, fields.relative_path)?, - contents: fields.contents.bind(py).to_str()?.into(), - projected_texts: (PyOnceLock::new(), PyOnceLock::new()), - header_values: HeaderValues::given(py, fields.header_values), - header_column_locations: Locations::from_dict(py, fields.header_column_locations), - output_column_locations: Locations::from_dict(py, fields.output_column_locations), - query_sql: fields.query_sql.bind(py).to_str()?.into(), - enum_declarations: fields - .enum_declarations - .unwrap_or_else(|| PyTuple::empty(py).unbind()), - constant_declarations: fields - .constant_declarations - .unwrap_or_else(|| PyTuple::empty(py).unbind()), - extract_implicit_alias_columns: fields.extract_implicit_alias_columns, - }) - } - - /// This file with edited contents and query, as `dataclasses.replace` would make it. - pub(crate) fn with_text( - &self, - py: Python<'_>, - contents: Py, - query_sql: Py, - ) -> PyResult { - Ok(Self { - paths: self.paths.shared(py), - contents: contents.bind(py).to_str()?.into(), - projected_texts: (PyOnceLock::new(), PyOnceLock::new()), - header_values: self.header_values.shared(py), - header_column_locations: self.header_column_locations.shared(py), - output_column_locations: self.output_column_locations.shared(py), - query_sql: query_sql.bind(py).to_str()?.into(), - enum_declarations: self.enum_declarations.clone_ref(py), - constant_declarations: self.constant_declarations.clone_ref(py), - extract_implicit_alias_columns: self.extract_implicit_alias_columns, - }) - } - - #[getter] - pub(crate) fn file_path(&self, py: Python<'_>) -> PyResult> { - Ok(self.paths.objects(py)?.0.unbind()) - } - - #[getter] - pub(crate) fn relative_path(&self, py: Python<'_>) -> PyResult> { - Ok(self.paths.objects(py)?.1.unbind()) - } - - #[getter] - pub(crate) fn contents<'py>(&self, py: Python<'py>) -> Bound<'py, PyString> { - projected_text(py, &self.projected_texts.0, &self.contents) - } - - #[getter] - pub(crate) fn header_values(&self, py: Python<'_>) -> PyResult> { - Ok(self.header_values.dict(py)?.unbind()) - } - - #[getter] - pub(crate) fn header_column_locations<'py>( - &self, - py: Python<'py>, - ) -> PyResult> { - self.header_locations(py) - } - - #[getter] - pub(crate) fn output_column_locations<'py>( - &self, - py: Python<'py>, - ) -> PyResult> { - self.output_column_locations - .dict(&self.paths.objects(py)?.1) - } - - #[getter] - pub(crate) fn query_sql<'py>(&self, py: Python<'py>) -> Bound<'py, PyString> { - projected_text(py, &self.projected_texts.1, &self.query_sql) - } - - #[getter] - pub(crate) fn enum_declarations(&self, py: Python<'_>) -> Py { - self.enum_declarations.clone_ref(py) - } - - #[getter] - pub(crate) fn constant_declarations(&self, py: Python<'_>) -> Py { - self.constant_declarations.clone_ref(py) - } - - #[getter] - pub(crate) fn extract_implicit_alias_columns(&self) -> bool { - self.extract_implicit_alias_columns - } - - fn __eq__(&self, py: Python<'_>, other: &Bound<'_, PyAny>) -> PyResult> { - let Ok(other) = other.downcast::() else { - return Ok(py.NotImplemented()); - }; - let other: &NativeModelFile = other.get(); - for (left, right) in self.fields(py)?.iter().zip(other.fields(py)?) { - if !left.eq(right)? { - return false.into_py_any(py); - } - } - true.into_py_any(py) - } - - fn __repr__(&self, py: Python<'_>) -> PyResult { - let fields: Vec = FIELD_NAMES - .iter() - .zip(self.fields(py)?) - .map(|(name, value)| Ok(format!("{name}={}", value.repr()?))) - .collect::>()?; - Ok(format!("DiscoveredSqlModelFile({})", fields.join(", "))) - } - - /// The keyword fields `copy` and `pickle` rebuild this record from. - fn __getnewargs_ex__<'py>( - slf: &Bound<'py, Self>, - ) -> PyResult<(Bound<'py, PyTuple>, Bound<'py, PyDict>)> { - let py: Python<'py> = slf.py(); - let keywords: Bound<'py, PyDict> = PyDict::new(py); - for (name, value) in FIELD_NAMES.iter().zip(slf.get().fields(py)?) { - keywords.set_item(name, value)?; - } - Ok((PyTuple::empty(py), keywords)) - } -} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/discovery/registration.rs b/crates/sqlbuild-python/src/bindings/_helpers/discovery/registration.rs index 37d4db2725..652232047c 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/discovery/registration.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/discovery/registration.rs @@ -2,36 +2,51 @@ use pyo3::prelude::{Bound, PyModule, PyResult}; -use crate::bindings::_helpers::discovery::{ - declaration_files, declaration_records, description_inputs, guidance, header_declarations, - header_values, hook_entries, imported_python_nodes, key_checks, locations, model_records, - project_files, project_validation, python_function_files, python_hook_files, - python_module_files, raised, scope_snapshot, snapshot, sql_test_records, yaml_entries, - yaml_records, -}; +use sqlbuild_python_front::discovery::main::failures::register_guidance::register_guidance; +use sqlbuild_python_front::discovery::main::failures::register_raised::register_raised; +use sqlbuild_python_front::discovery::main::headers::register_header_declarations::register_header_declarations; +use sqlbuild_python_front::discovery::main::headers::register_header_values::register_header_values; +use sqlbuild_python_front::discovery::main::headers::register_hook_entries::register_hook_entries; +use sqlbuild_python_front::discovery::main::headers::register_key_checks::register_key_checks; +use sqlbuild_python_front::discovery::main::project::register_locations::register_locations; +use sqlbuild_python_front::discovery::main::project::register_project_files::register_project_files; +use sqlbuild_python_front::discovery::main::project::register_project_validation::register_project_validation; +use sqlbuild_python_front::discovery::main::python_files::register_imported_python_nodes::register_imported_python_nodes; +use sqlbuild_python_front::discovery::main::python_files::register_python_function_files::register_python_function_files; +use sqlbuild_python_front::discovery::main::python_files::register_python_hook_files::register_python_hook_files; +use sqlbuild_python_front::discovery::main::python_files::register_python_module_files::register_python_module_files; +use sqlbuild_python_front::discovery::main::records::register_declaration_records::register_declaration_records; +use sqlbuild_python_front::discovery::main::records::register_description_inputs::register_description_inputs; +use sqlbuild_python_front::discovery::main::records::register_model_records::register_model_records; +use sqlbuild_python_front::discovery::main::records::register_sql_test_records::register_sql_test_records; +use sqlbuild_python_front::discovery::main::records::register_yaml_records::register_yaml_records; +use sqlbuild_python_front::discovery::main::snapshots::register_scope_snapshot::register_scope_snapshot; +use sqlbuild_python_front::discovery::main::snapshots::register_snapshot::register_snapshot; +use sqlbuild_python_front::discovery::main::sources::register_declaration_files::register_declaration_files; +use sqlbuild_python_front::discovery::main::sources::register_yaml_entries::register_yaml_entries; pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { - project_files::register(module)?; - snapshot::register(module)?; - scope_snapshot::register(module)?; - declaration_files::register(module)?; - declaration_records::register(module)?; - python_function_files::register(module)?; - python_hook_files::register(module)?; - python_module_files::register(module)?; - model_records::register(module)?; - sql_test_records::register(module)?; - yaml_records::register(module)?; - raised::register(module)?; - locations::register(module)?; - header_declarations::register(module)?; - key_checks::register(module)?; - project_validation::register(module)?; - yaml_entries::register(module)?; - header_values::register(module)?; - guidance::register(module)?; - description_inputs::register(module)?; - hook_entries::register(module)?; - imported_python_nodes::register(module)?; + register_project_files(module)?; + register_snapshot(module)?; + register_scope_snapshot(module)?; + register_declaration_files(module)?; + register_declaration_records(module)?; + register_python_function_files(module)?; + register_python_hook_files(module)?; + register_python_module_files(module)?; + register_model_records(module)?; + register_sql_test_records(module)?; + register_yaml_records(module)?; + register_raised(module)?; + register_locations(module)?; + register_header_declarations(module)?; + register_key_checks(module)?; + register_project_validation(module)?; + register_yaml_entries(module)?; + register_header_values(module)?; + register_guidance(module)?; + register_description_inputs(module)?; + register_hook_entries(module)?; + register_imported_python_nodes(module)?; Ok(()) } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/execution_history/conversion.rs b/crates/sqlbuild-python/src/bindings/_helpers/execution_history/conversion.rs index cd72890a7f..0585f065b3 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/execution_history/conversion.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/execution_history/conversion.rs @@ -14,11 +14,12 @@ use sqlbuild_state::execution_history::models::{ }; use sqlbuild_state::execution_history::types::UtcTime; -use crate::bindings::_helpers::cursor::values::{DATETIME_MODULE, local_date_time}; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::cursor::constants::DATETIME_MODULE; +use sqlbuild_python_front::cursor::main::values::local_date_time::local_date_time; const UTC_SUFFIX: &str = "Z"; const UTC_OFFSET: &str = "+00:00"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/exported_constants/constants.rs b/crates/sqlbuild-python/src/bindings/_helpers/exported_constants/constants.rs index c7ecfe0ed6..2f51322b96 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/exported_constants/constants.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/exported_constants/constants.rs @@ -38,9 +38,6 @@ use sqlbuild_state::execution_history::constants::{ DEFAULT_PAGE_LIMIT, MAX_PAGE_LIMIT, SCHEMA_VERSION, }; -use crate::bindings::_helpers::attachments::cursor_intrinsics::{ - MICROBATCH_END_SENTINEL, MICROBATCH_START_SENTINEL, -}; use crate::bindings::_helpers::compile_command::constants::{ REUSE_DISABLE_ENV_VAR, TRACKED_ENVIRONMENT_PREFIXES, UNTRACKED_ENVIRONMENT_NAMES, }; @@ -51,7 +48,9 @@ use crate::bindings::_helpers::frontier::stage_capture::CAPTURE_DIR_ENV_VAR; use crate::bindings::_helpers::result_output::event_writer::RESULT_PATH_ENV; use crate::bindings::_helpers::rules::constants::CUSTOM_HOST_RUNTIME_VERSION; use crate::bindings::_helpers::semantic_shapes::shapes::{VALID_FROM_DEFAULT, VALID_TO_DEFAULT}; -use crate::bindings::_helpers::state_rows::constants::MIGRATION_WRITE_ATTEMPTS; +use sqlbuild_python_front::attachments::constants::MICROBATCH_END_SENTINEL; +use sqlbuild_python_front::attachments::constants::MICROBATCH_START_SENTINEL; +use sqlbuild_python_front::state_rows::constants::MIGRATION_WRITE_ATTEMPTS; /// Text constants exported under their Python names. pub(crate) const EXPORTED_TEXTS: &[(&str, &str)] = &[ diff --git a/crates/sqlbuild-python/src/bindings/_helpers/exported_constants/registration.rs b/crates/sqlbuild-python/src/bindings/_helpers/exported_constants/registration.rs index cecee1955a..80d54a4cf9 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/exported_constants/registration.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/exported_constants/registration.rs @@ -3,13 +3,13 @@ use pyo3::prelude::{Bound, PyAnyMethods, PyModule, PyModuleMethods, PyResult}; use pyo3::types::{PyDict, PyDictMethods, PyFrozenSet, PyTuple}; -use crate::bindings::_helpers::cursor::conversion::GRAIN_NAMES; use crate::bindings::_helpers::exported_constants::constants::{ EXPORTED_INTEGERS, EXPORTED_TEXT_SETS, EXPORTED_TEXT_TUPLES, EXPORTED_TEXTS, }; use sqlbuild_cli::launcher::main::install_native_build_identity::install_native_build_identity; use sqlbuild_python_base::boundary::main::compiler_error::compiler_error; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::cursor::constants::GRAIN_NAMES; /// Registers after the native enums, since `GRAIN_ORDER` is keyed by `CursorGrain` members. pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/format_command/run.rs b/crates/sqlbuild-python/src/bindings/_helpers/format_command/run.rs index 86eccff280..20ba1bd9b6 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/format_command/run.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/format_command/run.rs @@ -18,7 +18,6 @@ use sqlbuild_rules::lint_text::models::{ FormatFault, FormatFile, FormattedBodies, SuppressionFinding, }; -use crate::bindings::_helpers::discovery::description_inputs::externally_described_models; use crate::bindings::_helpers::format_command::cache::FormatCache; use crate::bindings::_helpers::format_command::files::{ FormatChange, PendingWrite, persist_changes, @@ -46,6 +45,7 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; use sqlbuild_python_base::types::CompilerDetach; +use sqlbuild_python_front::discovery::main::records::externally_described_models::externally_described_models; const DESCRIPTION_PRESENT: &str = "description-present"; /// The fix that rewrites descriptions escaping or doubling double quotes as `"""` strings. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/format_command/selection.rs b/crates/sqlbuild-python/src/bindings/_helpers/format_command/selection.rs index fa4dbbd098..539fb0eec0 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/format_command/selection.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/format_command/selection.rs @@ -15,16 +15,6 @@ use sqlbuild_rules::lint_text::main::scan_fixture_null_candidates::scan_fixture_ use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; use crate::bindings::_helpers::compile_driver::project::build_project_graph; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; -use crate::bindings::_helpers::discovery::declaration_records::discover_model_schema_files; -use crate::bindings::_helpers::discovery::model_records::discover_model_files; -use crate::bindings::_helpers::discovery::project_config::load_local_config_file; -use crate::bindings::_helpers::discovery::project_config::load_project_config_file; -use crate::bindings::_helpers::discovery::snapshot::directory_snapshot_scope; -use crate::bindings::_helpers::discovery::sql_test_records::discover_test_files; -use crate::bindings::_helpers::discovery::yaml_records::{ - discover_schema_files, discover_source_files, -}; use crate::bindings::_helpers::planner_selection::selectors::select_project_graph; use crate::bindings::_helpers::planner_selection::unit_tests::reject_unit_test_selectors; use sqlbuild_python_base::boundary::main::keywords::keywords; @@ -37,6 +27,15 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use sqlbuild_python_front::discovery::main::project::load_local_config_file::load_local_config_file; +use sqlbuild_python_front::discovery::main::project::load_project_config_file::load_project_config_file; +use sqlbuild_python_front::discovery::main::records::discover_model_files::discover_model_files; +use sqlbuild_python_front::discovery::main::records::discover_model_schema_files::discover_model_schema_files; +use sqlbuild_python_front::discovery::main::records::discover_schema_files::discover_schema_files; +use sqlbuild_python_front::discovery::main::records::discover_source_files::discover_source_files; +use sqlbuild_python_front::discovery::main::records::discover_test_files::discover_test_files; +use sqlbuild_python_front::discovery::main::snapshots::directory_snapshot_scope::directory_snapshot_scope; const SELECTION_CODE: &str = "S007"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/freshness/freshness_command.rs b/crates/sqlbuild-python/src/bindings/_helpers/freshness/freshness_command.rs index 6a6e07528e..8c6b61c763 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/freshness/freshness_command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/freshness/freshness_command.rs @@ -18,7 +18,6 @@ use crate::bindings::_helpers::command_runtime::connection::resolve_project_conn use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; use crate::bindings::_helpers::compile_driver::project::build_project_graph; use crate::bindings::_helpers::compiled_project::snapshot_execution::VerifiedRun; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; use crate::bindings::_helpers::freshness::freshness_observe::{PreviousState, observe_freshness}; use crate::bindings::_helpers::freshness::observation::Observer; use crate::bindings::_helpers::freshness::state_io::{StateRead, read_latest}; @@ -32,6 +31,7 @@ use sqlbuild_python_base::native_host::main::connection_failure::connection_fail use sqlbuild_python_base::presentation_text::main::stdout_supports_color::stdout_supports_color; use sqlbuild_python_base::records::main::construct::enum_member::enum_member; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; use sqlbuild_core::constants::SOURCE_FRESHNESS_TABLE_NAME as STATE_TABLE_NAME; use sqlbuild_python_base::native_host::main::host_entry::host_entry; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/freshness/freshness_observe.rs b/crates/sqlbuild-python/src/bindings/_helpers/freshness/freshness_observe.rs index f2b9aa9219..a7712a43d3 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/freshness/freshness_observe.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/freshness/freshness_observe.rs @@ -16,7 +16,6 @@ use crate::bindings::_helpers::freshness::observation::{ Observer, observation_record, observation_source, observe_adapter_batch, observe_configured, strategy, }; -use crate::bindings::_helpers::state_rows::freshness::{age_policy, equivalent}; use sqlbuild_core::freshness_text::main::freshness_status::freshness_status; use sqlbuild_core::freshness_text::models::{ FreshnessSourceResult, FreshnessStatus, StateComparison, @@ -25,6 +24,8 @@ use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; +use sqlbuild_python_front::state_rows::main::event_rows::age_policy::age_policy; +use sqlbuild_python_front::state_rows::main::event_rows::equivalent::equivalent; const ADAPTER_STRATEGY: &str = "adapter"; const UNAVAILABLE_REASON: &str = "unavailable"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/freshness/observation.rs b/crates/sqlbuild-python/src/bindings/_helpers/freshness/observation.rs index aeba5c4d31..169e044634 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/freshness/observation.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/freshness/observation.rs @@ -12,8 +12,6 @@ use crate::bindings::_helpers::freshness::support::{ text, }; use crate::bindings::_helpers::references::source_relations::render_source_read; -use crate::bindings::_helpers::state_rows::freshness::{normalize, version_hash}; -use crate::bindings::_helpers::state_rows::timestamps::{in_utc, offset_aware}; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::within::within; use sqlbuild_python_base::native_host::main::host_entry::host_entry; @@ -27,6 +25,10 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get_or::mapping_get_or; use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_keywords; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::state_rows::main::event_rows::in_utc::in_utc; +use sqlbuild_python_front::state_rows::main::event_rows::normalize::normalize; +use sqlbuild_python_front::state_rows::main::event_rows::offset_aware::offset_aware; +use sqlbuild_python_front::state_rows::main::event_rows::version_hash::version_hash; const ADAPTER_STRATEGY: &str = "adapter"; const COLUMN_STRATEGY: &str = "column"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/freshness/planning.rs b/crates/sqlbuild-python/src/bindings/_helpers/freshness/planning.rs index eb97aa8dd2..aabf7ddd0d 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/freshness/planning.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/freshness/planning.rs @@ -21,7 +21,6 @@ use crate::bindings::_helpers::freshness::observation::{ use crate::bindings::_helpers::freshness::state_io::{StateRead, read_latest}; use crate::bindings::_helpers::freshness::support::text; use crate::bindings::_helpers::planner_scope::retained::scope_data; -use crate::bindings::_helpers::state_rows::freshness::{age_policy, equivalent}; use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::construct::enum_member::enum_member; @@ -31,6 +30,8 @@ use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::main::fields::mapping_get_or::mapping_get_or; use sqlbuild_python_base::records::types::RecordId; use sqlbuild_python_base::warehouse_access::main::is_warehouse_access_refused::is_warehouse_access_refused; +use sqlbuild_python_front::state_rows::main::event_rows::age_policy::age_policy; +use sqlbuild_python_front::state_rows::main::event_rows::equivalent::equivalent; const ADAPTER_STRATEGY: &str = "adapter"; const NO_CONFIG_MESSAGE: &str = "no freshness config and adapter metadata unavailable"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/freshness/state_io.rs b/crates/sqlbuild-python/src/bindings/_helpers/freshness/state_io.rs index 0879f31789..317e8a32e4 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/freshness/state_io.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/freshness/state_io.rs @@ -11,13 +11,9 @@ use sqlbuild_state::freshness::constants::{ use sqlbuild_state::freshness::main::read_latest_sql::read_latest_sql; use sqlbuild_state::freshness::main::relevant_sources_sql::relevant_sources_sql; -use crate::bindings::_helpers::cursor::values::DATETIME_MODULE; use crate::bindings::_helpers::freshness::support::{ INPUT_ERROR, exception_text, freshness_error, optional_str, presumed_utc_datetime, text, }; -use crate::bindings::_helpers::native_host::consumption_state::state_table_name; -use crate::bindings::_helpers::state_rows::state_tables::state_table_create_sql; -use crate::bindings::_helpers::state_rows::timestamps::date_time_typed; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::models::KeywordArguments; @@ -25,6 +21,10 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; use sqlbuild_python_base::warehouse_access::main::ensure_event_id_column::ensure_event_id_column; +use sqlbuild_python_front::cursor::constants::DATETIME_MODULE; +use sqlbuild_python_front::native_host::main::state_table_name::state_table_name; +use sqlbuild_python_front::state_rows::main::event_rows::date_time_typed::date_time_typed; +use sqlbuild_python_front::state_rows::main::tables::state_table_create_sql::state_table_create_sql; const MISSING_SCHEMA_MESSAGE: &str = "source freshness table requires a target schema"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/freshness/support.rs b/crates/sqlbuild-python/src/bindings/_helpers/freshness/support.rs index da4822caa8..93d3fb0850 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/freshness/support.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/freshness/support.rs @@ -4,12 +4,14 @@ use pyo3::exceptions::PyException; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult, Python}; use pyo3::types::{PyDict, PyString}; -use crate::bindings::_helpers::cursor::values::DATETIME_MODULE; use crate::bindings::_helpers::freshness::exception_types::{ SourceFreshnessInputError, SourceFreshnessObservationError, }; -use crate::bindings::_helpers::state_rows::timestamps::{date_time_typed, in_utc, offset_aware}; use sqlbuild_python_base::boundary::main::imported::imported; +use sqlbuild_python_front::cursor::constants::DATETIME_MODULE; +use sqlbuild_python_front::state_rows::main::event_rows::date_time_typed::date_time_typed; +use sqlbuild_python_front::state_rows::main::event_rows::in_utc::in_utc; +use sqlbuild_python_front::state_rows::main::event_rows::offset_aware::offset_aware; pub(crate) const OBSERVATION_ERROR: fn(String) -> PyErr = SourceFreshnessObservationError::new_err; pub(crate) const INPUT_ERROR: fn(String) -> PyErr = SourceFreshnessInputError::new_err; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/graph/python_node_graph.rs b/crates/sqlbuild-python/src/bindings/_helpers/graph/python_node_graph.rs index 4ace206d30..cfebc0428e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/graph/python_node_graph.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/graph/python_node_graph.rs @@ -8,8 +8,6 @@ use sqlbuild_analysis::python_selection::models::{InventoryIndexes, InventoryNod use sqlbuild_host::entries::models::UserCodeHost; use sqlbuild_python_base::native_host::main::within_identity_pass::within_identity_pass; -use crate::bindings::_helpers::discovery::imported_modules::provider_usages; -use crate::bindings::_helpers::discovery::imported_python_nodes::node_identity; use crate::bindings::_helpers::graph::python_selection::resolve_python_sql_run_selection; use crate::bindings::_helpers::graph::views::compiled_graph_keys; use sqlbuild_python_base::boundary::main::call_with::call_with; @@ -19,6 +17,8 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::discovery::main::python_files::node_identity::node_identity; +use sqlbuild_python_front::discovery::main::python_files::provider_usages::provider_usages; const NAME_KEY: &str = "name"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/audit_loop.rs b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/audit_loop.rs index 5be7d8d2ce..7c03d6d5f0 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/audit_loop.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/audit_loop.rs @@ -37,15 +37,16 @@ use crate::bindings::_helpers::input_loops::model_loop_named::{ use crate::bindings::_helpers::input_loops::source_loop::{ AuthoredExpansion, expanded_authored_sql, file_declarations, }; -use crate::bindings::_helpers::model_config::authored_nodes::PyNode; -use crate::bindings::_helpers::model_config::header_audits::{AuditInstance, HeaderAudits}; -use crate::bindings::_helpers::model_config::header_metadata::HeaderColumns; -use crate::bindings::_helpers::model_config::header_metadata::thresholds; -use crate::bindings::_helpers::model_config::model_validator::NativeModelValidator; use sqlbuild_project::models::AttachedTarget; use sqlbuild_project::models::ReferenceRow; use sqlbuild_python_base::compile_context::main::delta::record_source_reads::record_source_reads; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::model_config::main::headers::thresholds::thresholds; +use sqlbuild_python_front::model_config::models::AuditInstance; +use sqlbuild_python_front::model_config::models::HeaderAudits; +use sqlbuild_python_front::model_config::models::HeaderColumns; +use sqlbuild_python_front::model_config::models::NativeModelValidator; +use sqlbuild_python_front::model_config::models::PyNode; const THRESHOLDS_KEY: &str = "thresholds"; const MINIMUM_SAMPLES_KEY: &str = "minimum_samples"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/function_loop.rs b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/function_loop.rs index 1054b80b3c..19050d2648 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/function_loop.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/function_loop.rs @@ -29,7 +29,6 @@ use sqlbuild_sqltext::sql_references::main::extract_sql_references::extract_sql_ use sqlbuild_sqltext::sql_references::models::ReferenceExtraction; use crate::bindings::_helpers::analysis_session::query_columns::query_columns_error; -use crate::bindings::_helpers::attachments::function_headers::parsed_header; use crate::bindings::_helpers::compiled_project::attachment_inputs::{ FunctionRow, FunctionSettings, }; @@ -44,12 +43,13 @@ use crate::bindings::_helpers::input_loops::model_loop_inputs::reference_row; use crate::bindings::_helpers::input_loops::source_loop::{ AuthoredExpansion, expanded_authored_sql, expanded_template, parse_checked, scoped_declarations, }; -use crate::bindings::_helpers::model_config::model_validator::NativeModelValidator; use sqlbuild_project::models::DestinationFact; use sqlbuild_project::models::PythonRuntime; use sqlbuild_project::models::ReferenceRow; use sqlbuild_project::types::NamedTypeRow; use sqlbuild_python_base::compile_context::main::delta::record_source_reads::record_source_reads; +use sqlbuild_python_front::attachments::main::parsed_header::parsed_header; +use sqlbuild_python_front::model_config::models::NativeModelValidator; const PRESERVE_TARGET_VALUE: &str = "preserve"; const GENERIC_DIALECT: &str = "generic"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop.rs b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop.rs index 603ec3c3c2..962dbc097b 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop.rs @@ -48,7 +48,6 @@ use crate::bindings::_helpers::compiled_views::model_input_view::NativeModelInpu use crate::bindings::_helpers::compiled_views::source_views::{ AttachedSource, NativeSourceInput, retain_sources, }; -use crate::bindings::_helpers::discovery::model_file_record::{ModelFileTexts, NativeModelFile}; use crate::bindings::_helpers::input_loops::audit_loop::{AttachmentOwner, attached_audits}; use crate::bindings::_helpers::input_loops::function_loop::{ attached_functions, checked_table_function_arities, @@ -91,28 +90,32 @@ use crate::bindings::_helpers::input_loops::model_loop_visibility::{ }; use crate::bindings::_helpers::input_loops::source_loop::attached_sources; use crate::bindings::_helpers::input_loops::sql_test_loop::TestScope; -use crate::bindings::_helpers::model_config::config_classes::ConfigClasses; -use crate::bindings::_helpers::model_config::config_errors::raised_config_exception; -use crate::bindings::_helpers::model_config::header_metadata::ContractClasses; -use crate::bindings::_helpers::model_config::model_validator::NativeModelValidator; -use crate::bindings::_helpers::render::declaration_expansion::{ - DeclarationExpansion, ExpandedDeclarations, ExpansionClasses, ExpansionConsumer, - expand_declarations, -}; -use crate::bindings::_helpers::render::declaration_values::ConstantRendering; -use crate::bindings::_helpers::render::macro_call_rows::SpanRow; -use crate::bindings::_helpers::render::macro_call_rows::span_row; -use crate::bindings::_helpers::render::sql_macro_host::{SqlCallOrigin, SqlMacroSource}; -use crate::bindings::_helpers::sqltext::declaration_references::declaration_scan; -use crate::bindings::_helpers::sqltext::lexical_syntax::LexicalSyntaxInput; -use crate::bindings::_helpers::sqltext::static_sql::{ - InterpolationRow as SqlInterpolationRow, InterpolationSources, interpolation_batch, -}; use sqlbuild_project::models::ReferenceRow; use sqlbuild_python_base::boundary::main::compiler_error::compiler_error; use sqlbuild_python_base::cache::models::NativeParseStore; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::types::CompilerDetach; +use sqlbuild_python_front::discovery::models::ModelFileTexts; +use sqlbuild_python_front::discovery::models::NativeModelFile; +use sqlbuild_python_front::model_config::main::config::raised_config_exception::raised_config_exception; +use sqlbuild_python_front::model_config::models::ConfigClasses; +use sqlbuild_python_front::model_config::models::ContractClasses; +use sqlbuild_python_front::model_config::models::NativeModelValidator; +use sqlbuild_python_front::render::main::calls::span_row::span_row; +use sqlbuild_python_front::render::main::declarations::expand_declarations::expand_declarations; +use sqlbuild_python_front::render::models::ConstantRendering; +use sqlbuild_python_front::render::models::DeclarationExpansion; +use sqlbuild_python_front::render::models::DeclarationExpansionClasses; +use sqlbuild_python_front::render::models::ExpandedDeclarations; +use sqlbuild_python_front::render::models::ExpansionConsumer; +use sqlbuild_python_front::render::models::SqlCallOrigin; +use sqlbuild_python_front::render::models::SqlMacroSource; +use sqlbuild_python_front::render::types::SpanRow; +use sqlbuild_python_front::sqltext::main::declaration_scan::declaration_scan; +use sqlbuild_python_front::sqltext::main::interpolation_batch::interpolation_batch; +use sqlbuild_python_front::sqltext::models::InterpolationRow as SqlInterpolationRow; +use sqlbuild_python_front::sqltext::models::InterpolationSources; +use sqlbuild_python_front::sqltext::models::LexicalSyntaxInput; const MATERIALIZED_KEY: &str = "materialized"; const CURSOR_KEY: &str = "cursor"; @@ -659,7 +662,7 @@ impl NativeModelLoop { }; let interpolated: String = applied_interpolation(context, interpolation)?; let (references, stop) = scan.clone().unwrap_or_default(); - let expansion_classes: ExpansionClasses<'py> = ExpansionClasses { + let expansion_classes: DeclarationExpansionClasses<'py> = DeclarationExpansionClasses { usage_record: context.classes.usage_record.clone(), compile_error: context.classes.compile_error.clone(), }; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_config.rs b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_config.rs index 2cb2ebd0e7..502891c5c4 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_config.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_config.rs @@ -13,15 +13,17 @@ use sqlbuild_model_config::config_presence::main::contains_template::contains_te use sqlbuild_model_config::config_presence::main::mutable_config_value::mutable_config_value; use sqlbuild_sqltext::compiler::models::AuthoredValue; -use crate::bindings::_helpers::discovery::model_file_record::NativeModelFile; use crate::bindings::_helpers::input_loops::model_loop::{LoopContext, config_error}; -use crate::bindings::_helpers::model_config::authored_nodes::PyNode; -use crate::bindings::_helpers::model_config::config_classes::{ConfigClasses, config_fields, view}; -use crate::bindings::_helpers::model_config::config_nodes::carried_node; -use crate::bindings::_helpers::model_config::model_config_builder::{ - BuiltConfig, ConfigBuild, NativeModelConfigBuilder, -}; -use crate::bindings::_helpers::model_config::typed_config::BuiltConfigValues; +use sqlbuild_python_front::discovery::models::NativeModelFile; +use sqlbuild_python_front::model_config::main::config::carried_node::carried_node; +use sqlbuild_python_front::model_config::main::config::config_fields::config_fields; +use sqlbuild_python_front::model_config::main::config::view::view; +use sqlbuild_python_front::model_config::models::BuiltConfig; +use sqlbuild_python_front::model_config::models::ConfigBuild; +use sqlbuild_python_front::model_config::models::ConfigClasses; +use sqlbuild_python_front::model_config::models::NativeModelConfigBuilder; +use sqlbuild_python_front::model_config::models::PyNode; +use sqlbuild_python_front::model_config::types::BuiltConfigValues; const COLUMNS_KEY: &str = "columns"; const DESCRIPTION_KEY: &str = "description"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_contracts.rs b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_contracts.rs index 94c5f85d75..ed82993a64 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_contracts.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_contracts.rs @@ -9,11 +9,13 @@ use sqlbuild_analysis::compiled_project::models::SchemaColumnFact; use crate::bindings::_helpers::input_loops::model_loop::LoopContext; use crate::bindings::_helpers::input_loops::model_loop_schema::DeclaredColumns; -use crate::bindings::_helpers::model_config::config_nodes::{PyConfigNode, config_node}; -use crate::bindings::_helpers::model_config::header_metadata::{HeaderColumn, HeaderColumns}; use sqlbuild_model_config::config_values::models::ConfigNode; use sqlbuild_model_config::header_metadata::models::ParsedAudit; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::model_config::main::config::config_node::config_node; +use sqlbuild_python_front::model_config::models::HeaderColumn; +use sqlbuild_python_front::model_config::models::HeaderColumns; +use sqlbuild_python_front::model_config::types::PyConfigNode; const CASES_ATTRIBUTE: &str = "cases"; const RELATIVE_PATH_ATTRIBUTE: &str = "relative_path"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_header.rs b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_header.rs index a14e4b5d5d..0becc419a9 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_header.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_header.rs @@ -18,7 +18,6 @@ use sqlbuild_model_config::model_validation::models::ColumnMigration; use sqlbuild_model_config::types::NodeKind; use crate::bindings::_helpers::compiled_project::schema_facts::family_fact; -use crate::bindings::_helpers::discovery::model_file_record::NativeModelFile; use crate::bindings::_helpers::input_loops::model_loop::{ LoopContext, compile_error, config_error, }; @@ -29,20 +28,24 @@ use crate::bindings::_helpers::input_loops::model_loop_inputs::present; use crate::bindings::_helpers::input_loops::model_loop_schema::{ DeclaredColumns, ModelSchema, merged_columns, schema_enums, }; -use crate::bindings::_helpers::model_config::column_migrations::column_migration_error; -use crate::bindings::_helpers::model_config::config_errors::native_config_error; -use crate::bindings::_helpers::model_config::header_audits::HeaderAudits; -use crate::bindings::_helpers::model_config::header_families::HeaderFamilies; -use crate::bindings::_helpers::model_config::header_metadata::{ - HeaderColumn, HeaderColumns, HeaderValue, NativeColumnSpec, native_schema_column, - parsed_audit_identity, -}; -use crate::bindings::_helpers::model_config::typed_config::{config_node_of, typed_values}; use sqlbuild_discovery::model_files::models::{HeaderFacts, NativeColumn}; use sqlbuild_python_base::compile_driver::constants::NATIVE_HEADER_COLUMNS; use sqlbuild_python_base::compile_driver::constants::PARSED_HEADER_COLUMNS; use sqlbuild_python_base::compile_driver::main::count_stage::count_stage; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::discovery::models::NativeModelFile; +use sqlbuild_python_front::model_config::main::config::config_node_of::config_node_of; +use sqlbuild_python_front::model_config::main::config::native_config_error::native_config_error; +use sqlbuild_python_front::model_config::main::config::typed_values::typed_values; +use sqlbuild_python_front::model_config::main::headers::native_schema_column::native_schema_column; +use sqlbuild_python_front::model_config::main::headers::parsed_audit_identity::parsed_audit_identity; +use sqlbuild_python_front::model_config::main::model_nodes::column_migration_error::column_migration_error; +use sqlbuild_python_front::model_config::models::HeaderAudits; +use sqlbuild_python_front::model_config::models::HeaderColumn; +use sqlbuild_python_front::model_config::models::HeaderColumns; +use sqlbuild_python_front::model_config::models::HeaderFamilies; +use sqlbuild_python_front::model_config::models::NativeColumnSpec; +use sqlbuild_python_front::model_config::types::HeaderValue; const DESCRIPTION_KEY: &str = "description"; const COLUMNS_KEY: &str = "columns"; @@ -222,7 +225,7 @@ pub(crate) fn header_schema<'py>( let resolved: EnumColumns<'py> = enum_columns(context, (&enums, source.visible), source.values, columns)?; let fact: ModelSchemaFact = ModelSchemaFact { - audit_count: u32::try_from(audits.len()).unwrap_or(u32::MAX), + audit_count: u32::try_from(audits.count()).unwrap_or(u32::MAX), columns: resolved.facts, dynamic_columns: family_facts, type_enforcement, diff --git a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_hooks.rs b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_hooks.rs index 2e44b18827..5ac32c69f0 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_hooks.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_hooks.rs @@ -18,7 +18,6 @@ use sqlbuild_attachments::cursor_intrinsics::models::IntrinsicCheck; use sqlbuild_sqltext::sql_references::main::extract_sql_references::extract_sql_references; use sqlbuild_sqltext::sql_references::models::ReferenceExtraction; -use crate::bindings::_helpers::attachments::argument_values::argument_pairs; use crate::bindings::_helpers::input_loops::model_loop::{ LoopContext, NativeModelLoop, VisibleDeclarations, compile_error, record_reads, validation_outcome, @@ -35,15 +34,18 @@ use crate::bindings::_helpers::input_loops::model_loop_named::{ SQL_HOOK_DECLARATION, named_usages, }; use crate::bindings::_helpers::input_loops::model_loop_visibility::ModelVisibility; -use crate::bindings::_helpers::render::declaration_expansion::{ - DeclarationExpansion, ExpandedDeclarations, ExpansionClasses, ExpansionConsumer, - expand_declarations, -}; -use crate::bindings::_helpers::render::sql_macro_host::SqlMacroSource; -use crate::bindings::_helpers::sqltext::declaration_references::declaration_scan; -use crate::bindings::_helpers::sqltext::static_sql::{InterpolationSources, interpolated}; use sqlbuild_project::models::ReferenceRow; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::attachments::main::argument_pairs::argument_pairs; +use sqlbuild_python_front::render::main::declarations::expand_declarations::expand_declarations; +use sqlbuild_python_front::render::models::DeclarationExpansion; +use sqlbuild_python_front::render::models::DeclarationExpansionClasses; +use sqlbuild_python_front::render::models::ExpandedDeclarations; +use sqlbuild_python_front::render::models::ExpansionConsumer; +use sqlbuild_python_front::render::models::SqlMacroSource; +use sqlbuild_python_front::sqltext::main::declaration_scan::declaration_scan; +use sqlbuild_python_front::sqltext::main::interpolated::interpolated; +use sqlbuild_python_front::sqltext::models::InterpolationSources; const REFERENCES_METHOD: &str = "references"; const STATEMENT_ATTRIBUTE: &str = "statement"; @@ -489,7 +491,7 @@ impl<'py> HookRun<'_, '_, 'py> { scope: &Scope<'_, 'py>, ) -> PyResult> { let (references, stop) = declaration_scan(sql, Some(&self.model_loop.syntax)); - let classes: ExpansionClasses<'py> = ExpansionClasses { + let classes: DeclarationExpansionClasses<'py> = DeclarationExpansionClasses { usage_record: self.context.classes.usage_record.clone(), compile_error: self.context.classes.compile_error.clone(), }; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_host.rs b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_host.rs index 164c1bf4bf..d75cfcf5b0 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_host.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_host.rs @@ -22,21 +22,25 @@ use crate::bindings::_helpers::compiled_project::project::{ use crate::bindings::_helpers::compiled_views::model_input_view::{ InputProjections, ModelInputHandles, ModelInputRecord, SchemaHandles, SchemaRecord, }; -use crate::bindings::_helpers::discovery::model_file_record::{ModelFileTexts, NativeModelFile}; use crate::bindings::_helpers::input_loops::model_loop_header::AttachedHeader; use crate::bindings::_helpers::input_loops::model_loop_inputs::{ HOOK_KEYS, reference_fact, stripped_values, }; -use crate::bindings::_helpers::model_config::config_nodes::carried_node; -use crate::bindings::_helpers::model_config::typed_config::{retain_values, typed_values}; -use crate::bindings::_helpers::render::declaration_expansion::{ExpandedDeclarations, span_rows}; -use crate::bindings::_helpers::render::macro_call_rows::{SpanRow, span_row}; -use crate::bindings::_helpers::render::macro_expansion::ExpansionOutput; -use crate::bindings::_helpers::sqltext::declaration_references::ScannedReference; use sqlbuild_project::models::ExpansionRecord; use sqlbuild_project::models::ReferenceRow; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_keywords; +use sqlbuild_python_front::discovery::models::ModelFileTexts; +use sqlbuild_python_front::discovery::models::NativeModelFile; +use sqlbuild_python_front::model_config::main::config::carried_node::carried_node; +use sqlbuild_python_front::model_config::main::config::retain_values::retain_values; +use sqlbuild_python_front::model_config::main::config::typed_values::typed_values; +use sqlbuild_python_front::render::main::calls::span_row::span_row; +use sqlbuild_python_front::render::main::declarations::span_rows::span_rows; +use sqlbuild_python_front::render::models::ExpandedDeclarations; +use sqlbuild_python_front::render::models::ExpansionOutput; +use sqlbuild_python_front::render::types::SpanRow; +use sqlbuild_python_front::sqltext::models::ScannedReference; const HEADER_KEYS_ATTRIBUTE: &str = "model_header_keys"; const LAYER_SCHEMA_ATTRIBUTE: &str = "layer_schema"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_macros.rs b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_macros.rs index ba2a752650..99dff69f7d 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_macros.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_macros.rs @@ -14,12 +14,13 @@ use crate::bindings::_helpers::input_loops::model_loop::{ LoopContext, VisibleDeclarations, compile_error, }; use crate::bindings::_helpers::input_loops::model_loop_inputs::reference_row; -use crate::bindings::_helpers::render::macro_expansion::{ - ExpansionOutput, NativeMacroExpansion, StateInput, expanded, -}; -use crate::bindings::_helpers::sqltext::lexical_syntax::LexicalSyntaxInput; use sqlbuild_project::models::ReferenceRow; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::render::main::expansion::expanded::expanded; +use sqlbuild_python_front::render::models::ExpansionOutput; +use sqlbuild_python_front::render::models::NativeMacroExpansion; +use sqlbuild_python_front::render::models::StateInput; +use sqlbuild_python_front::sqltext::models::LexicalSyntaxInput; /// Fields of `_VisibleModelDeclarations` a `DeclarationResolutionContext` is built from. const CONTEXT_FIELDS: [&str; 9] = [ diff --git a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_named.rs b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_named.rs index 77d6b680e6..d0dfcb0890 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_named.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_named.rs @@ -58,7 +58,7 @@ pub(crate) const AUDIT_DECLARATION: NamedKind = NamedKind { label: "Generic audit", role: "audits/generic", }; -use crate::bindings::_helpers::scopes::compile_usages::CURRENT_FOLDER; +use sqlbuild_python_front::scopes::constants::CURRENT_FOLDER; use sqlbuild_scopes::scope_index::main::declared_scope_path_message::declared_scope_path_message; /// The usage of the indexed declaration `name`, if any, reporting S006 when it is hidden. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_schema.rs b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_schema.rs index 1ce7960b6a..0a25bfd463 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_schema.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_schema.rs @@ -8,8 +8,8 @@ use sqlbuild_analysis::compiled_project::models::SchemaColumnFact; use crate::bindings::_helpers::compiled_project::schema_facts::python_column_fact; use crate::bindings::_helpers::input_loops::model_loop::{LoopContext, compile_error}; use crate::bindings::_helpers::input_loops::model_loop_inputs::present; -use crate::bindings::_helpers::model_config::header_metadata::HeaderColumn; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::model_config::models::HeaderColumn; const MODEL_SCHEMA_KEY: &str = "model_schema"; const NAME_FIELD: &str = "name"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_visibility.rs b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_visibility.rs index 140e7581b2..0c032f1090 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_visibility.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_visibility.rs @@ -9,9 +9,9 @@ use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; use pyo3::types::{PyDict, PyDictMethods, PyTuple}; use crate::bindings::_helpers::input_loops::model_loop::{LoopContext, VisibleDeclarations}; -use crate::bindings::_helpers::render::sql_macro_host::MacroScopes; -use crate::bindings::_helpers::scopes::declaration_contexts::NativeDeclarationContexts; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::render::types::MacroScopes; +use sqlbuild_python_front::scopes::models::NativeDeclarationContexts; const NAME_FIELD: &str = "name"; const NATIVE_CONTEXTS_ATTRIBUTE: &str = "native_contexts"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/resource_diagnostics.rs b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/resource_diagnostics.rs index 0cfad4fc9c..4ea914fa10 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/resource_diagnostics.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/resource_diagnostics.rs @@ -28,13 +28,13 @@ use crate::bindings::_helpers::compiled_project::attachment_inputs::{ }; use crate::bindings::_helpers::compiled_project::project::NativeCompiledProject; use crate::bindings::_helpers::compiled_views::seed_views::{SeedParts, SeedViews}; -use crate::bindings::_helpers::discovery::model_file_record::NativeModelFile; use sqlbuild_project::models::ReferenceRow; use sqlbuild_python_base::compile_context::main::delta::capture::capture; use sqlbuild_python_base::compile_context::main::delta::capturing::capturing; use sqlbuild_python_base::compile_context::main::delta::injection::injection; use sqlbuild_python_base::compile_context::models::DeltaInjection; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::discovery::models::NativeModelFile; const MISSING_DESCRIPTION_CODE: &str = "P010"; const DESCRIPTION_LENGTH_CODE: &str = "P027"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/source_loop.rs b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/source_loop.rs index fd40d9e070..fb42efb29e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/source_loop.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/source_loop.rs @@ -17,24 +17,28 @@ use crate::bindings::_helpers::input_loops::model_loop::{ use crate::bindings::_helpers::input_loops::model_loop_macros::{ argument_references as macro_argument_references, expanded_with, }; -use crate::bindings::_helpers::model_config::config_errors::native_config_error; -use crate::bindings::_helpers::model_config::config_errors::raised_config_exception; -use crate::bindings::_helpers::model_config::config_templates::{ - PythonHost, Stop, TemplateSources, expanded, template_error, -}; use crate::bindings::_helpers::project_assembly::resources::{ syntax_error_message, syntax_error_messages, }; -use crate::bindings::_helpers::render::declaration_expansion::{ - DeclarationExpansion, ExpandedDeclarations, ExpansionClasses, ExpansionConsumer, - expand_declarations, -}; -use crate::bindings::_helpers::render::sql_macro_host::SqlMacroSource; -use crate::bindings::_helpers::scopes::declaration_contexts::NativeDeclarationContexts; -use crate::bindings::_helpers::sqltext::declaration_references::declaration_scan; -use crate::bindings::_helpers::sqltext::static_sql::{InterpolationSources, interpolated}; use sqlbuild_project::models::ReferenceRow; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::model_config::main::config::expanded::expanded; +use sqlbuild_python_front::model_config::main::config::native_config_error::native_config_error; +use sqlbuild_python_front::model_config::main::config::raised_config_exception::raised_config_exception; +use sqlbuild_python_front::model_config::main::config::template_error::template_error; +use sqlbuild_python_front::model_config::models::PythonHost; +use sqlbuild_python_front::model_config::models::Stop; +use sqlbuild_python_front::model_config::models::TemplateSources; +use sqlbuild_python_front::render::main::declarations::expand_declarations::expand_declarations; +use sqlbuild_python_front::render::models::DeclarationExpansion; +use sqlbuild_python_front::render::models::DeclarationExpansionClasses; +use sqlbuild_python_front::render::models::ExpandedDeclarations; +use sqlbuild_python_front::render::models::ExpansionConsumer; +use sqlbuild_python_front::render::models::SqlMacroSource; +use sqlbuild_python_front::scopes::models::NativeDeclarationContexts; +use sqlbuild_python_front::sqltext::main::declaration_scan::declaration_scan; +use sqlbuild_python_front::sqltext::main::interpolated::interpolated; +use sqlbuild_python_front::sqltext::models::InterpolationSources; const MACRO_TOKEN: char = '@'; const NATIVE_CONTEXTS_ATTRIBUTE: &str = "native_contexts"; @@ -233,7 +237,7 @@ pub(crate) fn expanded_authored_sql<'py>( let mut argument_references: Vec = Vec::new(); let mut expanded_sql: String = interpolated_sql.clone(); if !references.is_empty() || stop.is_some() { - let classes: ExpansionClasses<'py> = ExpansionClasses { + let classes: DeclarationExpansionClasses<'py> = DeclarationExpansionClasses { usage_record: context.classes.usage_record.clone(), compile_error: context.classes.compile_error.clone(), }; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/sql_test_loop.rs b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/sql_test_loop.rs index 7655836248..5a75d64f90 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/input_loops/sql_test_loop.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/input_loops/sql_test_loop.rs @@ -48,10 +48,10 @@ use crate::bindings::_helpers::input_loops::model_loop_calls::{ use crate::bindings::_helpers::input_loops::source_loop::{ AuthoredExpansion, expanded_authored_sql, scoped_declarations, }; -use crate::bindings::_helpers::render::sql_macro_tests::without_with_list_calls; use sqlbuild_python_base::cache::models::SqlTestScanStore; use sqlbuild_python_base::compile_context::main::delta::record_test_source_reads::record_test_source_reads; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::render::main::sql_macros::without_with_list_calls::without_with_list_calls; const MODEL_MODE: &str = "model"; const MACRO_MODE: &str = "macro"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_command.rs b/crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_command.rs index 0b9d9d3994..96bee69a6d 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_command.rs @@ -31,7 +31,6 @@ use crate::bindings::_helpers::cli::machine_output::{ }; use crate::bindings::_helpers::command_runtime::preview_target::validate_preview_target; use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_name; use crate::bindings::_helpers::diff_report::support::cli_error; use crate::bindings::_helpers::janitor::janitor_phases::{ JanitorCompiled, build_janitor_execution_plan, close_janitor_warehouse, @@ -47,6 +46,7 @@ use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_target_name::resolve_target_name; const COMMAND_NAME: &str = "janitor"; /// The code of a cleanup that needs a confirmation stdin cannot give. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_old_names.rs b/crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_old_names.rs index 90fc1ab2cc..4da294beb4 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_old_names.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_old_names.rs @@ -16,12 +16,11 @@ use crate::bindings::_helpers::janitor::janitor_facts::{ use crate::bindings::_helpers::janitor::janitor_keys::{ Folded, Key, SchemaKey, optional, record, sorted_schemas, text, tuple, }; -use crate::bindings::_helpers::state_rows::migration_io::{ - read_histories as read_view_histories, stored_columns_binding, -}; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::records::main::construct::enum_member::enum_member; +use sqlbuild_python_front::state_rows::main::migrations::read_histories::read_histories as read_view_histories; +use sqlbuild_python_front::state_rows::main::migrations::stored_columns_binding::stored_columns_binding; const IS_COMPATIBILITY_VIEW: ExecutorHost = ExecutorHost::IsCompatibilityView; use sqlbuild_core::constants::MIGRATION_TABLE_NAME; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_phases.rs b/crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_phases.rs index a37b585ab6..a484b06665 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_phases.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_phases.rs @@ -14,7 +14,6 @@ use pyo3::types::{PyBool, PyDict, PyDictMethods}; use crate::bindings::_helpers::build_progress::progress_reporters::{ ConnectionProgressReporter, PlanningProgressReporter, }; -use crate::bindings::_helpers::command_runtime::concurrency::resolve_concurrency; use crate::bindings::_helpers::command_runtime::invocation::resolve_adapter_connection_context; use crate::bindings::_helpers::janitor::janitor_facts::Warehouse; use crate::bindings::_helpers::janitor::janitor_planning::{ @@ -29,6 +28,7 @@ use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; +use sqlbuild_python_front::command_runtime::main::resolve_concurrency::resolve_concurrency; const UNKNOWN_VIEW_CODE: &str = "C503"; const UNKNOWN_VIEW_HELP: &str = diff --git a/crates/sqlbuild-python/src/bindings/_helpers/lineage/lineage_command.rs b/crates/sqlbuild-python/src/bindings/_helpers/lineage/lineage_command.rs index b23f41d303..1b11fbaa7d 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/lineage/lineage_command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/lineage/lineage_command.rs @@ -33,7 +33,6 @@ use sqlbuild_core::cli_text::models::CliStyle; use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; use crate::bindings::_helpers::compile_driver::project::build_project_graph; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; use crate::bindings::_helpers::lineage::lineage_cache::{ lineage_fingerprint, read_lineage_cache, write_lineage_cache, }; @@ -56,6 +55,7 @@ use sqlbuild_python_base::records::main::registry::native_attr::native_attr; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::NativeAttr; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; const UNKNOWN_SELECTOR_ERROR_CODE: &str = "S007"; const RICH_MODE: &str = "rich"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/load/ingestr_command.rs b/crates/sqlbuild-python/src/bindings/_helpers/load/ingestr_command.rs index acad1cfa58..6e9b4b0015 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/load/ingestr_command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/load/ingestr_command.rs @@ -17,10 +17,10 @@ use sqlbuild_core::loader_connection::models::LoaderConnection; use sqlbuild_host::entries::models::ThirdPartyHost; use sqlbuild_model_config::templates::models::TemplateOptions; -use crate::bindings::_helpers::model_config::template_data::expanded_template_data; use sqlbuild_python_base::boundary::models::Request; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::model_config::main::config::expanded_template_data::expanded_template_data; const INGESTR_ERROR: ThirdPartyHost = ThirdPartyHost::IngestrIntegrationError; const INGESTR_SOURCE_CONFIG: ThirdPartyHost = ThirdPartyHost::IngestrSourceConfig; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/load/load_command.rs b/crates/sqlbuild-python/src/bindings/_helpers/load/load_command.rs index 69dc9d3b6a..4169796e01 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/load/load_command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/load/load_command.rs @@ -20,16 +20,8 @@ use sqlbuild_host::entries::models::{AdapterHost, ExecutorHost, UserCodeHost}; use crate::bindings::_helpers::build_progress::progress_reporters::ConnectionProgressReporter; use crate::bindings::_helpers::build_progress::progress_text::write_execution_header; -use crate::bindings::_helpers::command_runtime::concurrency::resolve_concurrency; use crate::bindings::_helpers::command_runtime::connection::resolve_project_connection_config; -use crate::bindings::_helpers::compile_attachment::effective_config::build_effective_runtime_config; -use crate::bindings::_helpers::compile_attachment::effective_config::build_effective_target_config; use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; -use crate::bindings::_helpers::cursor::overrides::{cursor_integer, cursor_timestamp}; -use crate::bindings::_helpers::discovery::provider_secrets::{ - SecretPolicy, consumer_uses, require_used_secrets, sink_uses, -}; use crate::bindings::_helpers::load::load_progress::{ LoadCallbackRelay, LoadProgressReporter, load_result_text, }; @@ -52,6 +44,16 @@ use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::command_runtime::main::resolve_concurrency::resolve_concurrency; +use sqlbuild_python_front::compile_attachment::main::build_effective_runtime_config::build_effective_runtime_config; +use sqlbuild_python_front::compile_attachment::main::build_effective_target_config::build_effective_target_config; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use sqlbuild_python_front::cursor::main::overrides::cursor_integer::cursor_integer; +use sqlbuild_python_front::cursor::main::overrides::cursor_timestamp::cursor_timestamp; +use sqlbuild_python_front::discovery::main::sources::consumer_uses::consumer_uses; +use sqlbuild_python_front::discovery::main::sources::require_used_secrets::require_used_secrets; +use sqlbuild_python_front::discovery::main::sources::sink_uses::sink_uses; +use sqlbuild_python_front::discovery::models::SecretPolicy; const LOADER_NODE_KEY: &str = "sqlbuild_loader_node"; const EXECUTION_COMMAND: &str = "sqb load"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/load/load_selection.rs b/crates/sqlbuild-python/src/bindings/_helpers/load/load_selection.rs index 4fb9ffbf60..8df8b56350 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/load/load_selection.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/load/load_selection.rs @@ -17,18 +17,12 @@ use sqlbuild_core::load_command::main::select_load_entries::select_load_entries use sqlbuild_core::load_command::models::{LoadEntry, LoadGraph}; use sqlbuild_host::entries::models::AdapterHost; -use crate::bindings::_helpers::compile_attachment::effective_config::{ - build_effective_connection_config, build_effective_runtime_config, -}; use crate::bindings::_helpers::compile_attachment::target::{ connection_is_default_target, project_location, }; use crate::bindings::_helpers::compile_driver::targets::{ expanded_loader_namespace, managed_write_schema, preserved_loader_schemas, }; -use crate::bindings::_helpers::contracts::spec_resolution::loader_destination_parts; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; -use crate::bindings::_helpers::model_config::template_data::early_model_templates; use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::construct::error_class::error_class; @@ -38,6 +32,11 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_keywords; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::compile_attachment::main::build_effective_connection_config::build_effective_connection_config; +use sqlbuild_python_front::compile_attachment::main::build_effective_runtime_config::build_effective_runtime_config; +use sqlbuild_python_front::contracts::main::loader_destination_parts::loader_destination_parts; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use sqlbuild_python_front::model_config::main::config::early_model_templates::early_model_templates; const LOADER_NODE_KEY: &str = "sqlbuild_loader_node"; const COMPILE_INPUT_CODE: &str = "P001"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/location_command/snapshot.rs b/crates/sqlbuild-python/src/bindings/_helpers/location_command/snapshot.rs index 25abafa3f4..7b5c76219a 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/location_command/snapshot.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/location_command/snapshot.rs @@ -22,9 +22,6 @@ use crate::bindings::_helpers::compiled_project::snapshot_models::model_nodes; use crate::bindings::_helpers::compiled_project::snapshot_resources::resource_nodes; use crate::bindings::_helpers::compiled_project::snapshot_roles::compile_project_roles; use crate::bindings::_helpers::compiled_views::project_view::NativeProjectView; -use crate::bindings::_helpers::discovery::orchestration_files::orchestration_declarations; -use crate::bindings::_helpers::discovery::project_facts::{named_node_rows, project_facts}; -use crate::bindings::_helpers::discovery::project_validation::validation_error; use crate::bindings::_helpers::graph::python_selection::ProjectSelection; use crate::bindings::_helpers::location_command::snapshot_lineage::column_lineage_document; use crate::bindings::_helpers::location_command::snapshot_providers::providers_document; @@ -35,6 +32,10 @@ use crate::bindings::_helpers::planner_scope::values::project_graph; use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::orchestration_reads::main::environment_hash::environment_hash; use sqlbuild_python_base::records::main::fields::field::field; +use sqlbuild_python_front::discovery::main::project::named_node_rows::named_node_rows; +use sqlbuild_python_front::discovery::main::project::project_facts::project_facts; +use sqlbuild_python_front::discovery::main::project::validation_error::validation_error; +use sqlbuild_python_front::discovery::main::sources::orchestration_declarations::orchestration_declarations; /// The Python node kind whose functions load sources. const LOADER_KIND: &str = "loader"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/location_command/worker.rs b/crates/sqlbuild-python/src/bindings/_helpers/location_command/worker.rs index 2c70680a96..c1507efb2e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/location_command/worker.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/location_command/worker.rs @@ -27,13 +27,11 @@ use crate::bindings::_helpers::cli::dispatch::{Invocation, command_facts, wareho use crate::bindings::_helpers::command_runtime::warehouses::{ WarehouseInputs, configured_warehouses, }; -use crate::bindings::_helpers::compile_attachment::effective_config::build_effective_connection_config; use crate::bindings::_helpers::compiled_project::constants::SQL_TEST_KEY_PREFIX; use crate::bindings::_helpers::compiled_project::snapshot::NativeOrchestrationSnapshot; use crate::bindings::_helpers::compiled_project::snapshot_execution::{NodeKeys, WorkerBuild}; use crate::bindings::_helpers::compiled_project::snapshot_worker::NativeOrchestrationWorker; use crate::bindings::_helpers::compiled_views::project_reads::sql_tests; -use crate::bindings::_helpers::discovery::project_config::configured_changes; use crate::bindings::_helpers::freshness::freshness_command::run_freshness_command; use crate::bindings::_helpers::location_command::command::compile_snapshot; use crate::bindings::_helpers::location_command::constants::{ @@ -52,6 +50,8 @@ use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::native_host::main::host_entry::host_entry as entry; use sqlbuild_python_base::records::main::fields::field::field; use sqlbuild_python_base::records::main::fields::replaced::replaced; +use sqlbuild_python_front::compile_attachment::main::build_effective_connection_config::build_effective_connection_config; +use sqlbuild_python_front::discovery::main::project::configured_changes::configured_changes; /// Each audit and SQL test the snapshot publishes, with the node keys it checks. fn attached_nodes(snapshot: &NativeOrchestrationSnapshot) -> BTreeMap> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/mod.rs b/crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/mod.rs index 8623ff9f42..7444bd0374 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/mod.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/mod.rs @@ -1,4 +1 @@ -pub(crate) mod first_compile; -pub(crate) mod module_digests; pub(crate) mod registration; -pub(crate) mod store_keys; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/registration.rs b/crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/registration.rs index eddce4b97a..a6f2ad480b 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/registration.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/registration.rs @@ -2,10 +2,12 @@ use pyo3::prelude::{Bound, PyModule, PyResult}; -use crate::bindings::_helpers::macro_bridge::{first_compile, module_digests, store_keys}; +use sqlbuild_python_front::macro_bridge::main::register_first_compile::register_first_compile; +use sqlbuild_python_front::macro_bridge::main::register_module_digests::register_module_digests; +use sqlbuild_python_front::macro_bridge::main::register_store_keys::register_store_keys; pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { - first_compile::register(module)?; - module_digests::register(module)?; - store_keys::register(module) + register_first_compile(module)?; + register_module_digests(module)?; + register_store_keys(module) } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/microbatches/conversion.rs b/crates/sqlbuild-python/src/bindings/_helpers/microbatches/conversion.rs index ae49a505f9..a6ed3997df 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/microbatches/conversion.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/microbatches/conversion.rs @@ -10,9 +10,9 @@ use sqlbuild_cursor::algebra::models::{Scalar, SortKey}; use sqlbuild_host::entries::models::ExecutorHost; use sqlbuild_state::microbatches::models::{BoundInterval, CursorBound}; -use crate::bindings::_helpers::cursor::conversion::CursorSession; -use crate::bindings::_helpers::cursor::scalars::as_scalar; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::cursor::main::scalars::as_scalar::as_scalar; +use sqlbuild_python_front::cursor::models::CursorSession; /// `MicrobatchStateError(message)`. pub(crate) fn state_error(py: Python<'_>, message: &str) -> PyErr { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/authored_nodes.rs b/crates/sqlbuild-python/src/bindings/_helpers/model_config/authored_nodes.rs deleted file mode 100644 index c5f3c730f4..0000000000 --- a/crates/sqlbuild-python/src/bindings/_helpers/model_config/authored_nodes.rs +++ /dev/null @@ -1,127 +0,0 @@ -//! Python objects read in place as authored header values. - -use pyo3::prelude::{Bound, PyAny, PyAnyMethods}; -use pyo3::types::{ - PyBool, PyBoolMethods, PyDict, PyDictMethods, PyFloat, PyInt, PyList, PyListMethods, PyString, - PyStringMethods, PyTuple, PyTupleMethods, -}; -use sqlbuild_model_config::types::{AuthoredNode, NodeKind}; -use sqlbuild_python_base::records::main::fields::field::field as native_field; - -/// One Python object viewed as an authored value; parsed results keep the object itself. -#[derive(Clone, Debug)] -pub(crate) struct PyNode<'py>(pub(crate) Bound<'py, PyAny>); - -impl AuthoredNode for PyNode<'_> { - fn kind(&self) -> NodeKind { - let value = &self.0; - if value.is_none() { - NodeKind::Null - } else if let Ok(flag) = value.downcast::() { - NodeKind::Bool(flag.is_true()) - } else if value.is_instance_of::() { - value - .lt(0) - .map_or(NodeKind::Other, |negative| NodeKind::Int { negative }) - } else if value.is_instance_of::() { - NodeKind::Str - } else if value.is_instance_of::() { - NodeKind::List - } else if value.is_instance_of::() { - NodeKind::Tuple - } else if value.is_instance_of::() { - NodeKind::Map - } else { - NodeKind::Other - } - } - - fn integer(&self) -> Option { - if !self.0.is_instance_of::() - && self.0.is_instance_of::() - && let Ok(number) = self.0.extract::() - { - Some(number) - } else { - None - } - } - - fn number(&self) -> Option { - let value = &self.0; - let is_number: bool = value.is_instance_of::() - || (value.is_instance_of::() && !value.is_instance_of::()); - if !is_number { - return None; - } - if let Ok(number) = value.extract::() { - return Some(number); - } - let Ok(number) = self.python_str().parse::() else { - return None; - }; - Some(number) - } - - fn text(&self) -> Option { - self.with_text(str::to_owned) - } - - /// Read a string's text; lone surrogates, rejected where text enters a compile, read as U+FFFD. - fn with_text(&self, read: impl FnOnce(&str) -> R) -> Option { - match self.0.downcast::() { - Ok(value) => Some(read(&value.to_string_lossy())), - Err(_) => None, - } - } - - fn is_text(&self, text: &str) -> bool { - self.with_text(|value| value == text).unwrap_or(false) - } - - fn items(&self) -> Vec { - if let Ok(items) = self.0.downcast::() { - items.iter().map(PyNode).collect() - } else if let Ok(items) = self.0.downcast::() { - items.iter().map(PyNode).collect() - } else { - Vec::new() - } - } - - fn entries(&self) -> Vec<(Self, Self)> { - if let Ok(entries) = self.0.downcast::() { - entries.iter().map(entry_nodes).collect() - } else { - Vec::new() - } - } - - fn python_str(&self) -> String { - self.0 - .str() - .map(|text| text.to_string_lossy().into_owned()) - .unwrap_or_default() - } - - fn python_repr(&self) -> String { - self.0 - .repr() - .map(|text| text.to_string_lossy().into_owned()) - .unwrap_or_default() - } - - fn is_date_like(&self) -> bool { - let py = self.0.py(); - py.import("datetime") - .and_then(|module| native_field(&module, "date")) - .and_then(|date| self.0.is_instance(&date)) - .unwrap_or(false) - } -} - -fn entry_nodes<'py>( - (key, value): (Bound<'py, PyAny>, Bound<'py, PyAny>), -) -> (PyNode<'py>, PyNode<'py>) { - (PyNode(key), PyNode(value)) -} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/config_templates.rs b/crates/sqlbuild-python/src/bindings/_helpers/model_config/config_templates.rs deleted file mode 100644 index 462efe8530..0000000000 --- a/crates/sqlbuild-python/src/bindings/_helpers/model_config/config_templates.rs +++ /dev/null @@ -1,422 +0,0 @@ -//! `${...}` templates in authored Python config values and effective vars, expanded natively. - -use std::cell::RefCell; - -use pyo3::exceptions::{PyRuntimeError, PyValueError}; -use pyo3::prelude::{Bound, Py, PyAny, PyAnyMethods, PyModule, PyResult, Python}; -use pyo3::types::{ - PyBool, PyBoolMethods, PyDict, PyDictMethods, PyList, PyListMethods, PyString, PyStringMethods, - PyTuple, PyTupleMethods, -}; -use pyo3::{FromPyObject, PyErr}; -use sqlbuild_model_config::errors::ConfigError; -use sqlbuild_model_config::templates::errors::TemplateError; -use sqlbuild_model_config::templates::main::expand_template_string::expand_template_string; -use sqlbuild_model_config::templates::main::expand_template_text::expand_template_text; -use sqlbuild_model_config::templates::main::template_error_message::template_error_message; -use sqlbuild_model_config::templates::models::{ - ContextValue, Scalar, StringExpansion, TemplateFailure, TemplateOptions, -}; -use sqlbuild_model_config::templates::types::TemplateHost; - -use crate::bindings::_helpers::authored_values::project_vars::project_var_text; -use crate::bindings::_helpers::model_config::config_errors::native_config_error; -use crate::bindings::_helpers::model_config::errors::NativeConfigError; - -const TEMPLATE_OPEN_TOKEN: &str = "${"; -const ENVIRONMENT_READ: &str = "env"; -const CONTEXT_READ: &str = "ctx"; -const EFFECTIVE_VARS_LABEL: &str = "effective vars"; -const VALUE_PATH: &str = "its value"; -const BUILTINS_MODULE: &str = "builtins"; -const ASCII_FUNCTION: &str = "ascii"; -const ENCODE: &str = "encode"; -const UTF32_LE: &str = "utf-32-le"; -const SURROGATE_PASS: &str = "surrogatepass"; - -/// Variables, the process environment and context values, all read through Python. -pub(crate) struct PythonHost<'py> { - py: Python<'py>, - sources: TemplateSources<'py>, - label: String, - effective: Option>, - reads: RefCell>, - raised: RefCell>, -} - -/// Effective vars resolved on demand, as Python's `_EffectiveVarsResolver` resolves them. -struct EffectiveVars<'py> { - resolved: Bound<'py, PyDict>, - resolving: RefCell>, -} - -impl<'py> PythonHost<'py> { - /// Read variables, the environment and context values from these Python objects. - pub(crate) fn new(py: Python<'py>, sources: TemplateSources<'py>, label: &str) -> Self { - Self { - py, - sources, - label: label.to_owned(), - effective: None, - reads: RefCell::new(Vec::new()), - raised: RefCell::new(None), - } - } - - /// Return the `(kind, name)` reads in order. - pub(crate) fn into_reads(self) -> Vec<(&'static str, String)> { - self.reads.into_inner() - } - - /// Hold a Python error until the expansion returns, and stop evaluation. - fn hold(&self, error: PyErr) -> TemplateFailure { - self.raised.borrow_mut().get_or_insert(error); - TemplateFailure::Host - } - - /// The stop for `failure`, taking the held Python error of a host failure. - pub(crate) fn stop(&self, failure: TemplateFailure) -> Stop { - match failure { - TemplateFailure::Missing(error) | TemplateFailure::Invalid(error) => { - Stop::Failure(error) - } - TemplateFailure::Host => { - Stop::Python(self.raised.borrow_mut().take().unwrap_or_else(|| { - PyRuntimeError::new_err("template expansion stopped without an error") - })) - } - } - } - - fn text_of(&self, value: &Bound<'py, PyAny>) -> Result { - value - .downcast::() - .map_err(|error| self.hold(error.into()))? - .to_str() - .map(str::to_owned) - .map_err(|error| self.hold(error)) - } - - /// Resolve effective var `name`, keeping Python's resolving stack on errors. - fn resolve( - &self, - effective: &EffectiveVars<'py>, - name: &str, - ) -> Result>, TemplateFailure> { - let Some(raw) = self - .sources - .0 - .get_item(name) - .map_err(|error| self.hold(error))? - else { - return Ok(None); - }; - if let Some(value) = effective - .resolved - .get_item(name) - .map_err(|error| self.hold(error))? - { - return Ok(Some(value)); - } - if effective.resolving.borrow().iter().any(|key| key == name) { - let mut cycle = effective.resolving.borrow().clone(); - cycle.push(name.to_owned()); - return Err(TemplateFailure::Invalid(TemplateError::Message(format!( - "{EFFECTIVE_VARS_LABEL} contain a cyclic reference: {}", - cycle.join(" -> ") - )))); - } - effective.resolving.borrow_mut().push(name.to_owned()); - let value = if raw.is_instance_of::() { - let text = self.text_of(&raw)?; - let options = TemplateOptions { - allow_context: false, - preserve_context_tokens: false, - preserve_unknown_context: false, - }; - PyString::new(self.py, &expand_template_text(self, &text, options)?).into_any() - } else { - raw - }; - effective.resolving.borrow_mut().pop(); - effective - .resolved - .set_item(name, &value) - .map_err(|error| self.hold(error))?; - Ok(Some(value)) - } -} - -/// The variables, the `os.environ` mapping and the context values one expansion reads. -#[derive(FromPyObject)] -pub(crate) struct TemplateSources<'py>( - pub(crate) Bound<'py, PyDict>, - pub(crate) Bound<'py, PyAny>, - pub(crate) Bound<'py, PyDict>, -); - -/// A template error, or a Python error raised while reading values or building containers. -pub(crate) enum Stop { - Failure(TemplateError), - Python(PyErr), -} - -/// The `CompileInputError` Python raises for a template error in the context `label`. -pub(crate) fn template_error(error: &TemplateError, label: &str) -> ConfigError { - ConfigError::compile(template_error_message(error, label)) -} - -impl<'py> TemplateHost for PythonHost<'py> { - type Value = Bound<'py, PyAny>; - - fn variable(&self, name: &str) -> Result, TemplateFailure> { - if let Some(effective) = &self.effective { - return self.resolve(effective, name); - } - self.sources - .0 - .get_item(name) - .map_err(|error| self.hold(error)) - } - - fn environment(&self, name: &str) -> Result, TemplateFailure> { - self.reads - .borrow_mut() - .push((ENVIRONMENT_READ, name.to_owned())); - let environment: &Bound<'py, PyAny> = &self.sources.1; - if environment - .contains(name) - .map_err(|error| self.hold(error))? - { - environment - .get_item(name) - .map(Some) - .map_err(|error| self.hold(error)) - } else { - Ok(None) - } - } - - fn context(&self, name: &str) -> Result, TemplateFailure> { - self.reads - .borrow_mut() - .push((CONTEXT_READ, name.to_owned())); - match self - .sources - .2 - .get_item(name) - .map_err(|error| self.hold(error))? - { - None => Ok(ContextValue::Unknown), - Some(value) if value.is_none() => Ok(ContextValue::Unavailable), - Some(value) => Ok(ContextValue::Value(value)), - } - } - - fn text(&self, text: &str) -> Result { - Ok(PyString::new(self.py, text).into_any()) - } - - fn boolean(&self, flag: bool) -> Result { - Ok(PyBool::new(self.py, flag).to_owned().into_any()) - } - - fn null(&self) -> Self::Value { - self.py.None().into_bound(self.py) - } - - fn scalar(&self, value: &Self::Value) -> Result { - if value.is_none() { - return Ok(Scalar::Null); - } - if let Ok(flag) = value.downcast_exact::() { - return Ok(Scalar::Bool(flag.is_true())); - } - let text = value.str().map_err(|error| self.hold(error))?; - self.text_of(text.as_any()).map(Scalar::Text) - } - - fn render(&self, value: &Self::Value, label: &str) -> Result { - if value.is_exact_instance_of::() { - return self.text_of(value); - } - match project_var_text(value, label) { - Ok(text) => Ok(text), - Err(error) if error.is_instance_of::(self.py) => Err( - TemplateFailure::Invalid(TemplateError::Message(error.value(self.py).to_string())), - ), - Err(error) => Err(self.hold(error)), - } - } - - fn label(&self) -> &str { - &self.label - } -} - -/// The expanded value, or the native error expansion stopped at, and the reads in order. -pub(crate) type TemplateOutcome<'py> = ( - Result, Py>, - Vec<(&'static str, String)>, -); - -/// `value` with every template expanded under `options`, or the error, with its reads. -pub(crate) fn expand_config_templates<'py>( - py: Python<'py>, - value: &Bound<'py, PyAny>, - sources: TemplateSources<'py>, - (options, label): (TemplateOptions, &str), -) -> PyResult> { - let host = PythonHost::new(py, sources, label); - let result = expanded(&host, value, options); - outcome(py, host, result, label) -} - -/// The first `(var name, value path, UTF-8 byte offset)` of a lone surrogate in raw vars. -pub(crate) fn lone_surrogate_site<'py>( - raw_values: &Bound<'py, PyDict>, -) -> PyResult, String, usize)>> { - for (key, value) in raw_values.iter() { - if let Some((path, offset)) = surrogate_path(&value, VALUE_PATH.to_owned())? { - return Ok(Some((key.str()?, path, offset))); - } - } - Ok(None) -} - -/// Python's former `_reject_lone_surrogates` walk: dict keys then items, lists and tuples. -fn surrogate_path(value: &Bound<'_, PyAny>, path: String) -> PyResult> { - if let Ok(mapping) = value.downcast::() { - for (key, item) in mapping.iter() { - if let Some(site) = surrogate_path(&key, format!("{path} key"))? { - return Ok(Some(site)); - } - let key_ascii = PyModule::import(value.py(), BUILTINS_MODULE)? - .getattr(ASCII_FUNCTION)? - .call1((&key,))? - .str()? - .to_string_lossy() - .into_owned(); - if let Some(site) = surrogate_path(&item, format!("{path}[{key_ascii}]"))? { - return Ok(Some(site)); - } - } - return Ok(None); - } - if value.is_instance_of::() || value.is_instance_of::() { - for (index, item) in value.try_iter()?.enumerate() { - if let Some(site) = surrogate_path(&item?, format!("{path}[{index}]"))? { - return Ok(Some(site)); - } - } - return Ok(None); - } - let Ok(text) = value.downcast::() else { - return Ok(None); - }; - Ok(first_surrogate_offset(text)?.map(|offset| (path, offset))) -} - -/// The UTF-8 byte offset of the first lone surrogate in `text`. -fn first_surrogate_offset(text: &Bound<'_, PyString>) -> PyResult> { - let encoded = text.call_method1(ENCODE, (UTF32_LE, SURROGATE_PASS))?; - let mut offset = 0; - for unit in encoded.extract::>()?.as_chunks::<4>().0 { - let code_point = u32::from_le_bytes([unit[0], unit[1], unit[2], unit[3]]); - match char::from_u32(code_point) { - Some(character) => offset += character.len_utf8(), - None => return Ok(Some(offset)), - } - } - Ok(None) -} - -/// The resolved effective vars, or the native error resolution stopped at, with the reads. -pub(crate) fn resolve_effective_vars<'py>( - py: Python<'py>, - raw_values: &Bound<'py, PyDict>, - environment: Bound<'py, PyAny>, -) -> PyResult> { - let mut host = PythonHost::new( - py, - TemplateSources(raw_values.clone(), environment, PyDict::new(py)), - EFFECTIVE_VARS_LABEL, - ); - let resolved = PyDict::new(py); - host.effective = Some(EffectiveVars { - resolved: resolved.clone(), - resolving: RefCell::new(Vec::new()), - }); - let mut result: Result, Stop> = Ok(resolved.clone().into_any()); - for key in raw_values.keys() { - let name = key.str()?.to_str()?.to_owned(); - if let Err(failure) = host.variable(&name) { - result = Err(host.stop(failure)); - break; - } - } - outcome(py, host, result, EFFECTIVE_VARS_LABEL) -} - -fn outcome<'py>( - py: Python<'py>, - host: PythonHost<'py>, - result: Result, Stop>, - label: &str, -) -> PyResult> { - let value = match result { - Ok(value) => Ok(value), - Err(Stop::Failure(error)) => Err(native_config_error(py, template_error(&error, label))?), - Err(Stop::Python(error)) => return Err(error), - }; - Ok((value, host.into_reads())) -} - -/// Expand every template in `value` and the containers inside it. -pub(crate) fn expanded<'py>( - host: &PythonHost<'py>, - value: &Bound<'py, PyAny>, - options: TemplateOptions, -) -> Result, Stop> { - let py = host.py; - if let Ok(text) = value.downcast::() { - let text = text.to_str().map_err(Stop::Python)?; - if !text.contains(TEMPLATE_OPEN_TOKEN) { - return Ok(value.clone()); - } - return match expand_template_string(host, text, options) { - Ok(StringExpansion::Unchanged) => Ok(PyString::new(py, text).into_any()), - Ok(StringExpansion::Value(result)) => Ok(result), - Ok(StringExpansion::Text(result)) => Ok(PyString::new(py, &result).into_any()), - Err(failure) => Err(host.stop(failure)), - }; - } - if let Ok(mapping) = value.downcast::() { - let result = PyDict::new(py); - for (key, item) in mapping.iter() { - result - .set_item(key, expanded(host, &item, options)?) - .map_err(Stop::Python)?; - } - return Ok(result.into_any()); - } - if let Ok(items) = value.downcast::() { - let result = items - .iter() - .map(|item| expanded(host, &item, options)) - .collect::, _>>()?; - return PyList::new(py, result) - .map(Bound::into_any) - .map_err(Stop::Python); - } - if let Ok(items) = value.downcast::() { - let result = items - .iter() - .map(|item| expanded(host, &item, options)) - .collect::, _>>()?; - return PyTuple::new(py, result) - .map(Bound::into_any) - .map_err(Stop::Python); - } - Ok(value.clone()) -} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/errors.rs b/crates/sqlbuild-python/src/bindings/_helpers/model_config/errors.rs deleted file mode 100644 index 80b69f4d79..0000000000 --- a/crates/sqlbuild-python/src/bindings/_helpers/model_config/errors.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! The exact config error handed to Python. - -use pyo3::pyclass; - -/// One exact error: the Python class to raise, its message, code, help and named config key. -#[pyclass(module = "sqlbuild._native", frozen, get_all)] -pub(crate) struct NativeConfigError { - pub(crate) class_name: &'static str, - pub(crate) message: String, - pub(crate) code: Option<&'static str>, - pub(crate) help: Option, - pub(crate) key: Option, -} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/header_audits.rs b/crates/sqlbuild-python/src/bindings/_helpers/model_config/header_audits.rs deleted file mode 100644 index ac61d18106..0000000000 --- a/crates/sqlbuild-python/src/bindings/_helpers/model_config/header_audits.rs +++ /dev/null @@ -1,445 +0,0 @@ -//! Retained audit contracts; Python-authored factory results remain opaque values. - -use pyo3::IntoPyObjectExt; -use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; -use pyo3::sync::PyOnceLock; -use pyo3::types::{PyDict, PyDictMethods}; -use pyo3::types::{PyString, PyStringMethods, PyTuple}; -use sqlbuild_attachments::audits::models::ArgumentValue; -use sqlbuild_core::json::models::{JsonInteger, JsonValue}; -use sqlbuild_discovery::model_files::main::config_value::config_value; -use sqlbuild_discovery::model_files::models::NativeAudit; -use sqlbuild_model_config::config_values::models::ConfigNode; -use sqlbuild_model_config::header_metadata::constants::{ - ACCEPTED_VALUES_ARGUMENT, ACCEPTED_VALUES_AUDIT, -}; -use sqlbuild_model_config::header_metadata::models::ParsedAudit; -use sqlbuild_sqltext::compiler::models::AuthoredValue; -use std::sync::Arc; - -use crate::bindings::_helpers::attachments::argument_values::{ - argument_pairs, config_argument_value, -}; -use crate::bindings::_helpers::model_config::config_nodes::{ - PyConfigNode, config_node, config_object, -}; -use crate::bindings::_helpers::model_config::contract_classes::contract_classes; -use crate::bindings::_helpers::model_config::header_metadata::{ - ContractClasses, HeaderValue, audit_instance, thresholds, -}; -use crate::bindings::_helpers::sqltext::authored_values::authored_value_to_python; -use sqlbuild_python_base::native_host::models::AuditProjection; -use sqlbuild_python_base::records::main::fields::field::field; -use sqlbuild_python_base::result_output::main::json_value::json_value; - -/// Native-built specs never become Python audit records just to be read by attachment. -pub(crate) enum AuditInstance<'py> { - Native(Arc>, Bound<'py, PyAny>), - Python(Bound<'py, PyAny>), -} - -impl<'py> AuditInstance<'py> { - /// Equality with the builtin generated enum audit, without constructing argument containers. - pub(crate) fn accepts_enum(&self, values: &[PyConfigNode]) -> PyResult { - let Self::Native(spec, location) = self else { - return Ok(false); - }; - let py = location.py(); - if spec.definition_name.exact_text(py)? != ACCEPTED_VALUES_AUDIT - || spec.thresholds.is_some() - { - return Ok(false); - } - for name in [ - "name", - "description", - "severity", - "run_scope", - "minimum_samples", - "evidence_limit", - "meta", - ] { - if !self.field(name)?.is_none() { - return Ok(false); - } - } - if !self.field("always_run")?.eq(false)? || spec.arguments.len() != 1 { - return Ok(false); - } - let (key, authored) = &spec.arguments[0]; - let matches = match key { - ConfigNode::Str(key) => key == ACCEPTED_VALUES_ARGUMENT, - ConfigNode::Host(_) => { - let key = key.object(py)?; - key.is_instance_of::() && key.eq(ACCEPTED_VALUES_ARGUMENT)? - } - _ => false, - }; - if !matches { - return Ok(false); - } - let ConfigNode::Tuple(authored) = authored else { - return Ok(false); - }; - if authored.len() != values.len() { - return Ok(false); - } - for (left, right) in authored.iter().zip(values) { - if !left.object(py)?.eq(right.object(py)?)? { - return Ok(false); - } - } - Ok(true) - } - - pub(crate) fn meta_present(&self) -> PyResult { - match self { - Self::Native(spec, _) => Ok(spec - .meta - .as_ref() - .is_some_and(|value| !matches!(value, ConfigNode::Null))), - Self::Python(value) => Ok(!field(value, "meta")?.is_none()), - } - } - - pub(crate) fn threshold_policy(&self) -> PyResult<(bool, bool)> { - match self { - Self::Native(spec, _) => Ok(( - spec.thresholds.is_some(), - spec.thresholds.is_some_and(|value| value.error.is_some()), - )), - Self::Python(value) => { - let thresholds = field(value, "thresholds")?; - Ok(( - !thresholds.is_none(), - !thresholds.is_none() && !field(&thresholds, "error")?.is_none(), - )) - } - } - } - - pub(crate) fn field(&self, name: &str) -> PyResult> { - let (spec, location) = match self { - Self::Native(spec, location) => (spec, location), - Self::Python(value) => return field(value, name), - }; - let py = location.py(); - let value = match name { - "definition_name" => return spec.definition_name.object(py), - "name" => &spec.name, - "description" => &spec.description, - "run_scope" => &spec.run_scope, - "minimum_samples" => &spec.minimum_samples, - "evidence_limit" => &spec.evidence_limit, - "meta" => &spec.meta, - "always_run" => { - return match &spec.always_run { - Some(value) => value.object(py), - None => false.into_bound_py_any(py), - }; - } - "severity" => { - let classes = contract_classes(py)?; - let classes: ContractClasses<'_> = classes.extract()?; - return match &spec.severity { - Some(value) => Ok(classes - .severities - .get_item(value.object(py)?)? - .unwrap_or_else(|| py.None().into_bound(py))), - None => Ok(py.None().into_bound(py)), - }; - } - "thresholds" => { - let classes: ContractClasses<'_> = contract_classes(py)?.extract()?; - return thresholds(py, &classes, spec.thresholds.as_ref()); - } - "location" => return Ok(location.clone()), - _ => return Err(pyo3::exceptions::PyAttributeError::new_err(name.to_owned())), - }; - value - .as_ref() - .map(|value| value.object(py)) - .transpose() - .map(|value| value.unwrap_or_else(|| py.None().into_bound(py))) - } - - pub(crate) fn argument(&self, name: &str) -> PyResult>> { - match self { - Self::Native(spec, location) => { - for (key, value) in &spec.arguments { - let matches = match key { - ConfigNode::Str(key) => key == name, - ConfigNode::Host(_) => { - let key = key.object(location.py())?; - key.is_instance_of::() && key.eq(name)? - } - _ => false, - }; - if matches { - return value.object(location.py()).map(Some); - } - } - Ok(None) - } - Self::Python(value) => field(value, "arguments")?.cast::()?.get_item(name), - } - } - - pub(crate) fn arguments(&self) -> PyResult> { - match self { - Self::Native(spec, location) => { - let mut arguments = Vec::with_capacity(spec.arguments.len()); - for (key, value) in &spec.arguments { - let key = match key { - ConfigNode::Str(key) => key.clone(), - ConfigNode::Host(_) => { - let key = key.object(location.py())?; - let Ok(key) = key.cast::() else { - continue; - }; - key.to_string_lossy().into_owned() - } - _ => continue, - }; - arguments.push((key, config_argument_value(location.py(), value)?)); - } - Ok(arguments) - } - Self::Python(value) => argument_pairs(field(value, "arguments")?.cast()?), - } - } - - pub(crate) fn meta(&self) -> PyResult> { - match self { - Self::Native(spec, location) => spec - .meta - .as_ref() - .map(|value| config_json_value(location.py(), value)) - .transpose() - .map(Option::flatten), - Self::Python(value) => { - let meta = field(value, "meta")?; - if meta.is_none() { - Ok(None) - } else { - json_value(&meta) - } - } - } - } -} - -/// Native discovery facts keep their authored values rather than building audit records. -pub(crate) fn authored_audit( - py: Python<'_>, - spec: &NativeAudit, -) -> PyResult> { - let value = |value: &AuthoredValue| match config_value(value) { - Some(value) => Ok(value), - None => config_node(authored_value_to_python(py, value)?.bind(py)), - }; - Ok(ParsedAudit { - definition_name: ConfigNode::Str(spec.definition_name.clone()), - arguments: spec - .arguments - .iter() - .map(|(key, item)| Ok((ConfigNode::Str(key.clone()), value(item)?))) - .collect::>()?, - name: spec.name.clone().map(ConfigNode::Str), - description: spec.description.clone().map(ConfigNode::Str), - severity: spec.severity.clone().map(ConfigNode::Str), - run_scope: spec.run_scope.clone().map(ConfigNode::Str), - always_run: spec.always_run.map(ConfigNode::Bool), - thresholds: spec.thresholds, - minimum_samples: spec.minimum_samples.as_ref().map(value).transpose()?, - evidence_limit: spec.evidence_limit.as_ref().map(value).transpose()?, - meta: spec.meta.as_ref().map(value).transpose()?, - }) -} - -/// The parsed specs and genuine Python audit objects of one model or column. -pub(crate) struct HeaderAudits { - specs: Vec>, - native_generated: Vec>, - public: AuditProjection, -} - -impl HeaderAudits { - pub(crate) fn new( - py: Python<'_>, - classes: &ContractClasses<'_>, - specs: &[ParsedAudit], - location: &Bound<'_, PyAny>, - ) -> PyResult { - let custom = if classes.uses_default_classes()? { - None - } else { - Some( - specs - .iter() - .map(|spec| audit_instance(py, classes, spec, location).map(Bound::unbind)) - .collect::>()?, - ) - }; - Ok(Self { - specs: specs - .iter() - .map(|spec| retain_audit(py, spec)) - .collect::>()?, - native_generated: Vec::new(), - public: AuditProjection { - custom, - generated: Vec::new(), - location: location.clone().unbind(), - records: PyOnceLock::new(), - }, - }) - } - - pub(crate) fn extend(&mut self, generated: Vec>) { - self.public - .generated - .extend(generated.into_iter().map(Bound::unbind)); - } - - pub(crate) fn push_native(&mut self, spec: ParsedAudit) { - self.native_generated.push(spec); - } - - pub(crate) fn len(&self) -> usize { - self.specs.len() + self.public.generated.len() + self.native_generated.len() - } - - pub(crate) fn native_specs(&self) -> &[ParsedAudit] { - if self.public.custom.is_some() { - &[] - } else { - &self.specs - } - } - - pub(crate) fn python_specs<'py>(&self, py: Python<'py>) -> Vec> { - self.public - .custom - .iter() - .flatten() - .chain(&self.public.generated) - .map(|spec| spec.bind(py).clone()) - .collect() - } - - pub(crate) fn instances<'py>(&self, py: Python<'py>) -> Vec> { - self.native_specs() - .iter() - .map(|spec| { - AuditInstance::Native( - Arc::new(spec.clone()), - self.public.location.bind(py).clone(), - ) - }) - .chain(self.python_specs(py).into_iter().map(AuditInstance::Python)) - .chain(self.native_generated.iter().map(|spec| { - AuditInstance::Native(Arc::new(spec.clone()), py.None().into_bound(py)) - })) - .collect() - } - - pub(crate) fn project<'py>(&self, py: Python<'py>) -> PyResult> { - self.public - .records - .get_or_try_init(py, || { - let classes: ContractClasses<'_> = contract_classes(py)?.extract()?; - let mut audits = self - .native_specs() - .iter() - .map(|spec| audit_instance(py, &classes, spec, self.public.location.bind(py))) - .collect::>>()?; - audits.extend(self.python_specs(py)); - for spec in &self.native_generated { - audits.push(audit_instance( - py, - &classes, - spec, - &py.None().into_bound(py), - )?); - } - PyTuple::new(py, audits).map(Bound::unbind) - }) - .map(|value| value.bind(py).clone()) - } - - pub(crate) fn key_rows(&self, py: Python<'_>) -> PyResult)>> { - let mut rows = Vec::with_capacity(self.len()); - for spec in self.instances(py) { - let column = spec.argument("column")?; - rows.push(( - spec.field("definition_name")?.extract()?, - column - .filter(|value| value.is_instance_of::()) - .map(|value| value.extract()) - .transpose()?, - )); - } - Ok(rows) - } -} - -/// Preserve parsed leaves without rebuilding their public argument dictionaries. -pub(crate) fn retain_audit( - py: Python<'_>, - spec: &ParsedAudit, -) -> PyResult> { - let optional = |node: &Option| node.as_ref().map(|node| node.retained(py)).transpose(); - Ok(ParsedAudit { - definition_name: spec.definition_name.retained(py)?, - arguments: spec - .arguments - .iter() - .map(|(key, value)| Ok((key.retained(py)?, value.retained(py)?))) - .collect::>()?, - name: optional(&spec.name)?, - description: optional(&spec.description)?, - severity: optional(&spec.severity)?, - run_scope: optional(&spec.run_scope)?, - always_run: optional(&spec.always_run)?, - thresholds: spec.thresholds, - minimum_samples: optional(&spec.minimum_samples)?, - evidence_limit: optional(&spec.evidence_limit)?, - meta: optional(&spec.meta)?, - }) -} - -/// Read metadata without projecting retained containers; opaque user values keep Python semantics. -fn config_json_value(py: Python<'_>, value: &PyConfigNode) -> PyResult> { - Ok(Some(match value { - ConfigNode::Null => JsonValue::Null, - ConfigNode::Bool(value) => JsonValue::Bool(*value), - ConfigNode::Int(value) => JsonValue::Integer(JsonInteger::from(*value)), - ConfigNode::Float(value) => JsonValue::Float(*value), - ConfigNode::Str(value) => JsonValue::String(value.clone()), - ConfigNode::List(items) | ConfigNode::Tuple(items) => { - let mut result: Vec = Vec::with_capacity(items.len()); - for item in items { - let Some(value) = config_json_value(py, item)? else { - return Ok(None); - }; - result.push(value); - } - JsonValue::Array(result) - } - ConfigNode::Map(entries) => { - let mut result: Vec<(String, JsonValue)> = Vec::with_capacity(entries.len()); - for (key, item) in entries { - let ConfigNode::Str(key) = key else { - return json_value(&config_object(py, value)?); - }; - let Some(value) = config_json_value(py, item)? else { - return Ok(None); - }; - result.push((key.clone(), value)); - } - JsonValue::Object(result) - } - ConfigNode::Host(_) => return json_value(&config_object(py, value)?), - })) -} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/header_families.rs b/crates/sqlbuild-python/src/bindings/_helpers/model_config/header_families.rs deleted file mode 100644 index e3d1f1019f..0000000000 --- a/crates/sqlbuild-python/src/bindings/_helpers/model_config/header_families.rs +++ /dev/null @@ -1,65 +0,0 @@ -//! Native dynamic-column contracts with a shared, lazy public projection. - -use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; -use pyo3::types::PyTuple; -use sqlbuild_model_config::header_metadata::models::DynamicFamily; - -use sqlbuild_python_base::native_host::models::FamilyProjection; -use sqlbuild_python_base::records::main::construct::record_class::record_class; -use sqlbuild_python_base::records::main::fields::field::field; -use sqlbuild_python_base::records::types::RecordId; - -/// Parsed family specs stay native until a public schema attribute needs records. -pub(crate) struct HeaderFamilies { - pub(crate) specs: Vec, - public: FamilyProjection, -} - -impl HeaderFamilies { - pub(crate) fn new(class: &Bound<'_, PyAny>, specs: Vec) -> PyResult { - let result = Self { - specs, - public: FamilyProjection::new( - class, - !class.is(&record_class( - class.py(), - RecordId::SchemaDynamicColumnFamily, - )?), - ), - }; - if result.public.custom { - let _ = result.project(class.py())?; - } - Ok(result) - } - - pub(crate) fn read(&self, py: Python<'_>) -> PyResult> { - if self.public.custom { - family_specs(self.project(py)?.as_any()) - } else { - Ok(self.specs.clone()) - } - } - - pub(crate) fn project<'py>(&self, py: Python<'py>) -> PyResult> { - self.public.project(py, &self.specs) - } -} - -/// A Python-authored family contract crosses into native ownership once. -pub(crate) fn family_specs(families: &Bound<'_, PyAny>) -> PyResult> { - families - .try_iter()? - .map(|family| { - let family = family?; - Ok(DynamicFamily { - name: field(&family, "name")?.extract()?, - pivot_column: field(&family, "pivot_column")?.extract()?, - value_column: field(&family, "value_column")?.extract()?, - aggregate: field(&family, "aggregate")?.extract()?, - data_type: field(&family, "type")?.extract()?, - name_pattern: field(&family, "name_pattern")?.extract()?, - }) - }) - .collect() -} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/mod.rs b/crates/sqlbuild-python/src/bindings/_helpers/model_config/mod.rs index ce22851d76..7444bd0374 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/model_config/mod.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/model_config/mod.rs @@ -1,22 +1 @@ -pub(crate) mod authored_nodes; -pub(crate) mod column_migrations; -pub(crate) mod config_classes; -pub(crate) mod config_errors; -pub(crate) mod config_nodes; -pub(crate) mod config_templates; -pub(crate) mod config_values; -pub(crate) mod contract_classes; -pub(crate) mod described_models; -pub(crate) mod errors; -pub(crate) mod getters; -pub(crate) mod header_audits; -pub(crate) mod header_columns; -pub(crate) mod header_families; -pub(crate) mod header_metadata; -pub(crate) mod model_config_builder; -pub(crate) mod model_validator; -pub(crate) mod project_defaults; pub(crate) mod registration; -pub(crate) mod template_data; -pub(crate) mod typed_config; -pub(crate) mod unicode_environment; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/model_config_builder.rs b/crates/sqlbuild-python/src/bindings/_helpers/model_config/model_config_builder.rs deleted file mode 100644 index 6ff8e6da57..0000000000 --- a/crates/sqlbuild-python/src/bindings/_helpers/model_config/model_config_builder.rs +++ /dev/null @@ -1,458 +0,0 @@ -//! The native model config build handed Python inputs once, and its results projected for Python. - -use std::collections::HashMap; - -use pyo3::exceptions::{PyKeyError, PyRuntimeError, PyValueError}; -use pyo3::prelude::{Bound, Py, PyAny, PyAnyMethods, PyModule, PyModuleMethods, PyResult, Python}; -use pyo3::types::{PyDict, PyDictMethods, PyString, PyStringMethods, PyTuple}; -use pyo3::{PyErr, pyclass, pymethods}; -use sqlbuild_discovery::model_files::main::config_value::config_value; -use sqlbuild_discovery::model_files::models::{EntryFacts, HeaderFacts}; -use sqlbuild_model_config::config_presence::models::MacroPath; -use sqlbuild_model_config::config_values::models::ConfigNode; -use sqlbuild_model_config::errors::ConfigError; -use sqlbuild_model_config::model_config_build::main::build_model_config::build_model_config; -use sqlbuild_model_config::model_config_build::main::inherited_config::inherited_config; -use sqlbuild_model_config::model_config_build::main::model_context_values::model_context_values; -use sqlbuild_model_config::model_config_build::models::{ - BuiltModelConfig, ConfigBuildHalt, ConfigBuildInputs, HeaderEntryFacts, ModelHeader, -}; -use sqlbuild_model_config::model_config_build::types::ConfigBuildHost; -use sqlbuild_model_config::model_validation::models::{RetentionOverride, TableTypeOverride}; -use sqlbuild_model_config::path_defaults::main::select_path_default::select_path_default; -use sqlbuild_model_config::path_defaults::models::PathDefaultChoice; -use sqlbuild_sqltext::compiler::models::AuthoredValue; - -use crate::bindings::_helpers::authored_values::project_vars::project_var_text; -use crate::bindings::_helpers::model_config::config_classes::{ConfigClasses, built_config}; -use crate::bindings::_helpers::model_config::config_errors::config_exception; -use crate::bindings::_helpers::model_config::config_errors::native_config_error; -use crate::bindings::_helpers::model_config::config_nodes::{ - HostHandle, PyConfigEntries, PyConfigNode, carried_node, config_dict, config_entries, - config_node, config_object, hook_entry, is_exact_container, -}; -use crate::bindings::_helpers::model_config::errors::NativeConfigError; -use crate::bindings::_helpers::model_config::project_defaults::project_defaults_mapping; -use crate::bindings::_helpers::model_config::typed_config::{BuiltConfigValues, built_values}; -use sqlbuild_python_base::boundary::main::compiler_guard::compiler_guard; - -/// The config keys a model's context values read. -const CONTEXT_KEYS: [&str; 3] = ["database", "schema", "alias"]; -const BUILD_STOPPED: &str = "a config value read as text without an error"; - -/// A header's public mapping, parsed facts and native authored values. -type HeaderBuildInputs<'a, 'py> = ( - &'a Bound<'py, PyDict>, - Option<&'a HeaderFacts>, - Option<&'a [(String, AuthoredValue)]>, -); - -/// The project-wide inputs every model's config build reads, converted once per compile. -#[pyclass(module = "sqlbuild._native", frozen)] -pub(crate) struct NativeModelConfigBuilder { - inputs: ConfigBuildInputs, - path_keys: Vec, - environment: Py, -} - -/// One model's built config before Python wraps it in `CompileModelConfig`. -pub(crate) struct BuiltConfig<'py> { - pub(crate) values: Bound<'py, PyDict>, - pub(crate) nodes: Option, - pub(crate) header_keys: Vec, - pub(crate) logical_schema: Option>, - pub(crate) layer_schema_configured: bool, - pub(crate) logical_database: Option>, - pub(crate) retention: RetentionOverride, - pub(crate) table_type: TableTypeOverride, - pub(crate) reads: Vec<(&'static str, String)>, -} - -/// A native build's outcome: the built config, or the config error it raises. -pub(crate) enum ConfigBuild<'py> { - Built(BuiltConfig<'py>), - Rejected(Py), -} - -/// `((target name, run id), (database, schema) or None)` of the active target. -pub(crate) type TargetInputs<'py> = ( - (Bound<'py, PyAny>, Bound<'py, PyAny>), - Option<(Bound<'py, PyAny>, Bound<'py, PyAny>)>, -); - -/// The process environment and project-var rendering, read through Python. -struct PythonConfigHost<'py> { - environment: Bound<'py, PyAny>, -} - -impl ConfigBuildHost for PythonConfigHost<'_> { - type Handle = HostHandle; - type Error = PyErr; - - fn environment(&self, name: &str) -> PyResult> { - if !self.environment.contains(name)? { - return Ok(None); - } - Ok(Some(config_node(&self.environment.get_item(name)?)?)) - } - - fn render(&self, value: &PyConfigNode, label: &str) -> PyResult> { - let py: Python<'_> = self.environment.py(); - let object: Bound<'_, PyAny> = config_object(py, value)?; - if let Ok(text) = object.downcast_exact::() { - return Ok(Ok(text.to_str()?.to_owned())); - } - match project_var_text(&object, label) { - Ok(text) => Ok(Ok(text)), - Err(error) if error.is_instance_of::(py) => { - Ok(Err(error.value(py).to_string())) - } - Err(error) => Err(error), - } - } - - fn text_error(&self, value: &PyConfigNode) -> PyErr { - let py: Python<'_> = self.environment.py(); - let read = || -> PyResult<()> { - let object: Bound<'_, PyAny> = config_object(py, value)?; - let text: Bound<'_, PyString> = match object.downcast::() { - Ok(text) => text.clone(), - Err(_) => object.str()?, - }; - let _ = text.to_str()?; - Ok(()) - }; - match read() { - Ok(()) => PyRuntimeError::new_err(BUILD_STOPPED), - Err(error) => error, - } - } - - fn python_str(&self, value: &PyConfigNode, exact: bool) -> PyResult { - let text: Bound<'_, PyString> = config_object(self.environment.py(), value)?.str()?; - if exact { - return Ok(text.to_str()?.to_owned()); - } - Ok(text.to_string_lossy().into_owned()) - } - - fn typed_hook_entry(&self, value: &PyConfigNode) -> PyResult { - hook_entry(&config_object(self.environment.py(), value)?) - } -} - -/// Header keys whose values the build reads item by item, which are always converted. -const INSPECTED_KEYS: [&str; 7] = [ - "tags", - "row_diff_exclude_columns", - "row_diff_tolerances", - "pre_hooks", - "post_hooks", - "time_travel_retention", - "table_type", -]; - -/// Whether `key`'s container may be carried whole: no template or macro in it, items never read. -fn carried_whole(key: &str, facts: Option<&[(String, HeaderEntryFacts)]>) -> bool { - !INSPECTED_KEYS.contains(&key) - && facts - .and_then(|facts| facts.iter().find(|(name, _)| name == key)) - .is_some_and(|(_, facts)| !facts.template && facts.macro_path == MacroPath::Absent) -} - -/// A header's entries as config nodes; containers the build never looks into stay opaque. -fn header_entries( - header: &Bound<'_, PyDict>, - facts: Option<&[(String, HeaderEntryFacts)]>, - authored: Option<&[(String, AuthoredValue)]>, -) -> PyResult { - let authored: HashMap<&str, &AuthoredValue> = authored - .into_iter() - .flatten() - .map(|(key, value)| (key.as_str(), value)) - .collect(); - let mut entries: PyConfigEntries = Vec::with_capacity(header.len()); - for (key, value) in header.iter() { - let native: Option = match key.downcast_exact::() { - Ok(key) => match key.to_str() { - Ok(key) => authored.get(key).and_then(|value| config_value(value)), - Err(_) => None, - }, - Err(_) => None, - }; - if let Some(native) = native { - entries.push((config_node(&key)?, native)); - continue; - } - let whole: bool = is_exact_container(&value) - && key - .downcast_exact::() - .is_ok_and(|key| key.to_str().is_ok_and(|key| carried_whole(key, facts))); - let node: PyConfigNode = if whole { - carried_node(&value)? - } else { - config_node(&value)? - }; - entries.push((config_node(&key)?, node)); - } - Ok(entries) -} - -/// One header entry's parsed facts as the build reads them. -fn entry_facts((key, entry): &(String, EntryFacts)) -> (String, HeaderEntryFacts) { - let facts: HeaderEntryFacts = HeaderEntryFacts { - template: entry.template, - macro_path: entry.macro_path.clone(), - }; - (key.clone(), facts) -} - -fn optional_node(value: Bound<'_, PyAny>) -> PyResult> { - if value.is_none() { - return Ok(None); - } - config_node(&value).map(Some) -} - -#[pymethods] -impl NativeModelConfigBuilder { - #[new] - pub(crate) fn new( - layers: (Bound<'_, PyAny>, Bound<'_, PyDict>, Bound<'_, PyTuple>), - sources: (Bound<'_, PyDict>, Bound<'_, PyAny>), - target: TargetInputs<'_>, - ) -> PyResult { - let (run, target_namespace) = target; - let (defaults, path_defaults, _hook_entry_types) = layers; - let mut path_keys: Vec = Vec::with_capacity(path_defaults.len()); - let mut path_values: Vec<(String, PyConfigEntries)> = - Vec::with_capacity(path_defaults.len()); - for (key, values) in path_defaults.iter() { - let key: String = key.extract()?; - path_values.push((key.clone(), config_entries(values.downcast::()?)?)); - path_keys.push(key); - } - let (target_name, run_id) = run; - Ok(Self { - inputs: ConfigBuildInputs { - defaults: config_entries(&project_defaults_mapping(&defaults)?)?, - path_defaults: path_values, - variables: config_entries(&sources.0)?, - run_id: config_node(&run_id)?, - target_name: optional_node(target_name)?.unwrap_or(ConfigNode::Null), - target_namespace: target_namespace - .map(|(database, schema)| -> PyResult<_> { - Ok((config_node(&database)?, config_node(&schema)?)) - }) - .transpose()?, - }, - path_keys, - environment: sources.1.unbind(), - }) - } - - /// Return the model's `CompileModelConfig` or the first config error. - fn model_config<'py>( - &self, - py: Python<'py>, - header: Bound<'py, PyDict>, - model: (Option, String), - classes: ConfigClasses<'py>, - ) -> PyResult> { - let (matched_path_default, model_name) = model; - let matched_path_default: Option<&str> = matched_path_default.as_deref(); - compiler_guard(|| { - match self.built(py, (&header, None, None), matched_path_default, &model_name)? { - ConfigBuild::Built(built) => { - Ok(built_config(&classes, &built, matched_path_default)?.unbind()) - } - ConfigBuild::Rejected(error) => Ok(error.into_any()), - } - }) - } -} - -/// The Python error a halt raises, or the config error it is rejected with. -fn halted<'py>( - py: Python<'py>, - halt: ConfigBuildHalt, -) -> PyResult> { - Ok(match halt { - ConfigBuildHalt::Config(error) => Ok(error), - ConfigBuildHalt::Host(error) => Err(error), - ConfigBuildHalt::MissingPathDefault(key) => Err(PyKeyError::new_err(key)), - ConfigBuildHalt::KeyNotText(key) => { - Err(match config_object(py, &key)?.downcast::() { - Ok(_) => PyRuntimeError::new_err(BUILD_STOPPED), - Err(error) => error.into(), - }) - } - }) -} - -/// The built values as a new `dict`; entries still the header's own keep the header's objects. -fn own_values_dict<'py>( - header: &Bound<'py, PyDict>, - built: &BuiltModelConfig, -) -> PyResult> { - let py: Python<'py> = header.py(); - let mapping: Bound<'py, PyDict> = PyDict::new(py); - for (key, value) in &built.values { - let own: bool = own_key(key, &built.own_header_keys); - let key: Bound<'py, PyAny> = config_object(py, key)?; - let value: Bound<'py, PyAny> = match own.then(|| header.get_item(&key)).transpose()? { - Some(Some(value)) => value, - _ => config_object(py, value)?, - }; - mapping.set_item(key, value)?; - } - Ok(mapping) -} - -/// Whether `key` is a string key named among the header's own keys. -fn own_key(key: &PyConfigNode, own: &[String]) -> bool { - let text: Option<&str> = match key { - ConfigNode::Str(text) => Some(text), - ConfigNode::Host(host) if host.facts.strict_text => host.facts.text.as_deref(), - _ => None, - }; - text.is_some_and(|text| own.iter().any(|name| name == text)) -} - -/// One model's build projected for Python. -fn projected_build<'py>( - header: &Bound<'py, PyDict>, - built: BuiltModelConfig, -) -> PyResult> { - let py: Python<'py> = header.py(); - Ok(BuiltConfig { - values: own_values_dict(header, &built)?, - nodes: built_values(built.values), - header_keys: built.header_keys, - logical_schema: projected(py, built.logical_schema)?, - layer_schema_configured: built.layer_schema_configured, - logical_database: projected(py, built.logical_database)?, - retention: built.retention, - table_type: built.table_type, - reads: built.reads, - }) -} - -fn projected<'py>( - py: Python<'py>, - value: Option, -) -> PyResult>> { - value.map(|value| config_object(py, &value)).transpose() -} - -impl NativeModelConfigBuilder { - fn host<'py>(&self, py: Python<'py>) -> PythonConfigHost<'py> { - PythonConfigHost { - environment: self.environment.bind(py).clone(), - } - } - - /// The selected path-default key, or the conflict error Python raises. - pub(crate) fn selected_path_default( - &self, - py: Python<'_>, - model_path: &str, - ) -> PyResult, Py>> { - Ok(match select_path_default(model_path, &self.path_keys) { - PathDefaultChoice::Selected(key) => Ok(key), - PathDefaultChoice::Conflict(error) => Err(native_config_error(py, error)?), - }) - } - - /// Build one model's config natively. - pub(crate) fn built<'py>( - &self, - py: Python<'py>, - (header, facts, authored): HeaderBuildInputs<'_, 'py>, - matched_path_default: Option<&str>, - model_name: &str, - ) -> PyResult> { - let facts: Option> = - facts.map(|facts| facts.entries.iter().map(entry_facts).collect()); - let entries: PyConfigEntries = header_entries(header, facts.as_deref(), authored)?; - let model_header = ModelHeader { - entries: &entries, - facts: facts.as_deref(), - }; - let host: PythonConfigHost<'py> = self.host(py); - match build_model_config( - (&host, &self.inputs), - model_header, - matched_path_default, - model_name, - ) { - Ok(built) => Ok(ConfigBuild::Built(projected_build(header, built)?)), - Err(halt) => match halted(py, halt)? { - Ok(error) => Ok(ConfigBuild::Rejected(native_config_error(py, error)?)), - Err(error) => Err(error), - }, - } - } - - /// `build_layered_model_values` with an empty header: what a path default's models inherit. - pub(crate) fn inherited_values<'py>( - &self, - py: Python<'py>, - matched_path_default: Option<&str>, - ) -> PyResult, Py>> { - let host: PythonConfigHost<'py> = self.host(py); - match inherited_config((&host, &self.inputs), matched_path_default) { - Ok(values) => Ok(Ok(config_dict(py, &values)?)), - Err(halt) => match halted(py, halt)? { - Ok(error) => Ok(Err(native_config_error(py, error)?)), - Err(error) => Err(error), - }, - } - } - - /// `build_model_context_values` for a model's config values. - pub(crate) fn model_context_values<'py>( - &self, - values: &Bound<'py, PyDict>, - model_name: &str, - include_target_values: bool, - ) -> PyResult> { - let mut read: PyConfigEntries = Vec::with_capacity(CONTEXT_KEYS.len()); - for key in CONTEXT_KEYS { - if let Some(value) = values.get_item(key)? { - read.push((ConfigNode::Str(key.to_owned()), config_node(&value)?)); - } - } - let context: PyConfigEntries = - model_context_values(&self.inputs, &read, model_name, include_target_values); - config_dict(values.py(), &context) - } - - /// The active target's `(database, schema)`, or `(None, None)` without a target. - pub(crate) fn target_namespace<'py>(&self, py: Python<'py>) -> PyResult> { - match &self.inputs.target_namespace { - Some((database, schema)) => PyTuple::new( - py, - [config_object(py, database)?, config_object(py, schema)?], - ), - None => PyTuple::new(py, [py.None(), py.None()]), - } - } -} - -/// The Python exception a native config error raises as. -pub(crate) fn raised_config_error(py: Python<'_>, error: ConfigError) -> PyErr { - let raised = || -> PyResult { - let error: Py = native_config_error(py, error)?; - Ok(PyErr::from_value(config_exception( - error.bind(py).as_any(), - None, - )?)) - }; - raised().unwrap_or_else(|error| error) -} - -pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { - module.add_class::()?; - Ok(()) -} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/model_validator.rs b/crates/sqlbuild-python/src/bindings/_helpers/model_config/model_validator.rs deleted file mode 100644 index 6690095c67..0000000000 --- a/crates/sqlbuild-python/src/bindings/_helpers/model_config/model_validator.rs +++ /dev/null @@ -1,257 +0,0 @@ -//! The Python model validators, run natively up to the first error they raise. - -use sqlbuild_python_base::positional_record; -use std::collections::HashSet; - -use pyo3::prelude::{Bound, Py, PyAny, PyAnyMethods, PyModule, PyModuleMethods, PyResult, Python}; -use pyo3::types::{PyDict, PyDictMethods}; -use pyo3::{IntoPyObject, pyclass, pymethods}; -use sqlbuild_attachments::functions::models::KnownResources; -use sqlbuild_model_config::model_validation::main::validate_model_config::validate_model_config; -use sqlbuild_model_config::model_validation::main::validate_model_references::validate_model_references; -use sqlbuild_model_config::model_validation::models::{ - ModelReference, ModelValidationFacts, ProjectValidationFacts, ValidationStop, -}; - -use crate::bindings::_helpers::discovery::project_facts::{column_name, each, stem}; -use crate::bindings::_helpers::model_config::authored_nodes::PyNode; -use crate::bindings::_helpers::model_config::config_errors::native_config_error; -use sqlbuild_python_base::boundary::main::compiler_guard::compiler_guard; -use sqlbuild_python_base::records::main::fields::field::field as native_field; -use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; - -const FILE_PATH_ATTRIBUTE: &str = "file_path"; -const RETURNS_KEY: &str = "returns"; -/// The only key of a table function's `returns` mapping. -const TABLE_RETURNS_KEY: &str = "table"; - -positional_record! { - extract; - /// Model, seed, source, function and table function names. - struct ResourceNames { - models: HashSet, - seeds: HashSet, - sources: HashSet, - functions: HashSet, - table_functions: HashSet, - } -} - -positional_record! { - extract; - /// References `(kind, name, rejected)`, schema columns, unmanaged retention and table type. - struct ModelFacts { - references: Vec<(String, String, bool)>, - declared_columns: Option>, - retention_unmanaged: bool, - table_type_declared: bool, - } -} - -/// The project facts every model's validation reads, captured once per compile. -#[pyclass(module = "sqlbuild._native", frozen)] -pub(crate) struct NativeModelValidator { - project: ProjectValidationFacts, -} - -impl NativeModelValidator { - /// The project's discovered resource names, which every reference resolves against. - pub(crate) fn known_resources(&self) -> KnownResources<'_> { - KnownResources { - models: &self.project.models, - seeds: &self.project.seeds, - sources: &self.project.sources, - functions: &self.project.functions, - table_functions: &self.project.table_functions, - } - } -} - -/// Model, seed, source, function and table function names discovered in `inputs`. -fn discovered_names(inputs: &Bound<'_, PyAny>) -> PyResult { - let model_stem = |file: &Bound<'_, PyAny>| stem(file, FILE_PATH_ATTRIBUTE); - let mut models: HashSet = each(inputs, "model_files", model_stem)? - .into_iter() - .collect(); - if let Some(injection) = - sqlbuild_python_base::compile_context::main::delta::injection::injection() - { - models.extend(injection.model_names.iter().cloned()); - } - let mut seeds: HashSet = HashSet::new(); - for schema in native_field(inputs, "schema_files")?.try_iter()? { - seeds.extend(each(&schema?, "seed_entries", column_name)?); - } - let mut sources: HashSet = HashSet::new(); - for file in native_field(inputs, "source_files")?.try_iter()? { - sources.extend(each(&file?, "source_entries", column_name)?); - } - let mut functions: HashSet = HashSet::new(); - let mut table_functions: HashSet = HashSet::new(); - for file in native_field(inputs, "sql_function_files")?.try_iter()? { - let file: Bound<'_, PyAny> = file?; - let name: String = model_stem(&file)?; - if returns_table(&file)? { - table_functions.insert(name.clone()); - } - functions.insert(name); - } - functions.extend(each(inputs, "python_function_files", model_stem)?); - Ok(ResourceNames { - models, - seeds, - sources, - functions, - table_functions, - }) -} - -/// Whether a SQL function's header `returns` is a mapping whose only key is `table`. -fn returns_table(file: &Bound<'_, PyAny>) -> PyResult { - let headers: Bound<'_, PyAny> = native_field(file, "header_values")?; - let returns: Bound<'_, PyAny> = mapping_get(&headers, RETURNS_KEY)?; - let Ok(returns) = returns.downcast::() else { - return Ok(false); - }; - let keys: Vec> = returns.keys().into_iter().collect(); - Ok(keys.len() == 1 && keys[0].eq(TABLE_RETURNS_KEY)?) -} - -#[pymethods] -impl NativeModelValidator { - /// The validator for the resources and materializations `inputs` discovered. - #[staticmethod] - pub(crate) fn from_inputs( - inputs: Bound<'_, PyAny>, - microbatch_concurrency: bool, - ) -> PyResult { - let names: ResourceNames = discovered_names(&inputs)?; - let custom_materializations: HashSet = - each(&inputs, "materialization_files", |file| { - native_field(file, "name")?.extract() - })? - .into_iter() - .collect(); - Self::new(names, custom_materializations, microbatch_concurrency) - } - - /// The discovered model names references resolve against. - fn model_names(&self) -> HashSet { - self.project.models.clone() - } - - #[new] - fn new( - names: ResourceNames, - custom_materializations: HashSet, - microbatch_concurrency: bool, - ) -> PyResult { - let ResourceNames { - models, - seeds, - sources, - functions, - table_functions, - } = names; - Ok(Self { - project: ProjectValidationFacts { - custom_materializations, - microbatch_concurrency, - models, - seeds, - sources, - functions, - table_functions, - }, - }) - } - - /// `None` when accepted, the first error, or the first externally rejected reference. - fn validate( - &self, - py: Python<'_>, - values: Bound<'_, PyDict>, - model: (String, String, String), - facts: ModelFacts, - ) -> PyResult> { - compiler_guard(|| { - let (model_name, query_sql, relative_path) = model; - let ModelFacts { - references, - declared_columns, - retention_unmanaged, - table_type_declared, - } = facts; - let references: Vec = references - .into_iter() - .map(|(kind, name, externally_rejected)| ModelReference { - kind, - name, - externally_rejected, - }) - .collect(); - let entries: Vec<(PyNode<'_>, PyNode<'_>)> = values - .iter() - .map(|(key, value)| (PyNode(key), PyNode(value))) - .collect(); - let facts = ModelValidationFacts { - model_name: &model_name, - relative_path: &relative_path, - references: &references, - declared_columns: declared_columns.as_deref(), - query_sql: &query_sql, - retention_unmanaged, - table_type_declared, - }; - match validate_model_config(entries, &self.project, &facts) { - Ok(()) => Ok(py.None()), - Err(stop) => stop_object(py, stop), - } - }) - } - - /// Check references alone: `None`, the first error, or a rejected dbt reference's index. - fn references( - &self, - py: Python<'_>, - model: (String, String), - references: Vec<(String, String, bool)>, - ) -> PyResult> { - compiler_guard(|| { - let (model_name, relative_path) = model; - let references: Vec = references - .into_iter() - .map(|(kind, name, externally_rejected)| ModelReference { - kind, - name, - externally_rejected, - }) - .collect(); - let facts = ModelValidationFacts { - model_name: &model_name, - relative_path: &relative_path, - references: &references, - declared_columns: None, - query_sql: "", - retention_unmanaged: false, - table_type_declared: false, - }; - match validate_model_references(&self.project, &facts) { - Ok(()) => Ok(py.None()), - Err(stop) => stop_object(py, stop), - } - }) - } -} - -fn stop_object(py: Python<'_>, stop: ValidationStop) -> PyResult> { - match stop.into_error() { - Err(index) => Ok(index.into_pyobject(py)?.into_any().unbind()), - Ok(error) => Ok(native_config_error(py, error)?.into_any()), - } -} - -pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { - module.add_class::()?; - Ok(()) -} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/model_config/registration.rs b/crates/sqlbuild-python/src/bindings/_helpers/model_config/registration.rs index 4e9095b798..c744b3e4f1 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/model_config/registration.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/model_config/registration.rs @@ -2,18 +2,21 @@ use pyo3::prelude::{Bound, PyModule, PyResult}; -use crate::bindings::_helpers::model_config::{ - config_errors, config_values, header_columns, model_config_builder, model_validator, - template_data, unicode_environment, -}; +use sqlbuild_python_front::model_config::main::config::register_config_errors::register_config_errors; +use sqlbuild_python_front::model_config::main::config::register_config_values::register_config_values; +use sqlbuild_python_front::model_config::main::config::register_template_data::register_template_data; +use sqlbuild_python_front::model_config::main::headers::register_header_columns::register_header_columns; +use sqlbuild_python_front::model_config::main::model_nodes::register_model_config_builder::register_model_config_builder; +use sqlbuild_python_front::model_config::main::model_nodes::register_model_validator::register_model_validator; +use sqlbuild_python_front::model_config::main::model_nodes::register_unicode_environment::register_unicode_environment; pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { - config_errors::register(module)?; - config_values::register(module)?; - header_columns::register(module)?; - model_config_builder::register(module)?; - model_validator::register(module)?; - template_data::register(module)?; - unicode_environment::register(module)?; + register_config_errors(module)?; + register_config_values(module)?; + register_header_columns(module)?; + register_model_config_builder(module)?; + register_model_validator(module)?; + register_template_data(module)?; + register_unicode_environment(module)?; Ok(()) } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/native_host/mod.rs b/crates/sqlbuild-python/src/bindings/_helpers/native_host/mod.rs index 794ea5865f..a3c45ce10a 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/native_host/mod.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/native_host/mod.rs @@ -1,9 +1,6 @@ //! Permanent Python host calls and compatibility views of native-owned execution data. -pub(crate) mod audit_results_state; -pub(crate) mod consumption_state; pub(crate) mod model_lookup; -pub(crate) mod observations_state; pub(crate) mod orchestration_sensors; pub(crate) mod orchestration_triggers; pub(crate) mod registration; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/native_host/orchestration_sensors.rs b/crates/sqlbuild-python/src/bindings/_helpers/native_host/orchestration_sensors.rs index c29ee9cf82..6216853b0b 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/native_host/orchestration_sensors.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/native_host/orchestration_sensors.rs @@ -12,10 +12,6 @@ use sqlbuild_orchestration::sensors::models::{ }; use crate::bindings::_helpers::compiled_project::snapshot_declarations::python_declarations; -use crate::bindings::_helpers::discovery::imported_modules::{provider_by_name, provider_usages}; -use crate::bindings::_helpers::discovery::imported_providers::discover_provider_classes; -use crate::bindings::_helpers::discovery::orchestration_files::orchestration_declarations; -use crate::bindings::_helpers::discovery::provider_secrets::SecretPolicy; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::within::within; @@ -23,6 +19,11 @@ use sqlbuild_python_base::native_host::constants::SENSOR_CONTEXT_PARAMETER; use sqlbuild_python_base::native_host::main::host_entry::host_entry as entry; use sqlbuild_python_base::orchestration_reads::main::callback_code_hash::callback_code_hash; use sqlbuild_python_base::orchestration_reads::main::orchestration_code_hash::orchestration_code_hash; +use sqlbuild_python_front::discovery::main::python_files::discover_provider_classes::discover_provider_classes; +use sqlbuild_python_front::discovery::main::python_files::provider_by_name::provider_by_name; +use sqlbuild_python_front::discovery::main::python_files::provider_usages::provider_usages; +use sqlbuild_python_front::discovery::main::sources::orchestration_declarations::orchestration_declarations; +use sqlbuild_python_front::discovery::models::SecretPolicy; pub(crate) fn evaluate_sensor( py: Python<'_>, diff --git a/crates/sqlbuild-python/src/bindings/_helpers/native_host/orchestration_triggers.rs b/crates/sqlbuild-python/src/bindings/_helpers/native_host/orchestration_triggers.rs index ef8daac20d..5c789c7eaa 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/native_host/orchestration_triggers.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/native_host/orchestration_triggers.rs @@ -17,9 +17,6 @@ use sqlbuild_orchestration::scheduler::constants::MAX_TICKS_PER_BATCH; use sqlbuild_orchestration::sensors::models::SensorDefinition; use sqlbuild_orchestration::snapshots::models::SnapshotInput; -use crate::bindings::_helpers::discovery::imported_modules::{provider_by_name, provider_usages}; -use crate::bindings::_helpers::discovery::imported_providers::discover_provider_classes; -use crate::bindings::_helpers::discovery::provider_secrets::SecretPolicy; use crate::bindings::_helpers::graph::python_selection::ProjectSelection; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::imported::imported; @@ -32,6 +29,10 @@ use sqlbuild_python_base::orchestration_reads::main::callback_code_hash::callbac use sqlbuild_python_base::orchestration_reads::main::declared_at::declared_at; use sqlbuild_python_base::orchestration_reads::main::orchestration_code_hash::orchestration_code_hash; use sqlbuild_python_base::orchestration_reads::models::AuthoredSensor; +use sqlbuild_python_front::discovery::main::python_files::discover_provider_classes::discover_provider_classes; +use sqlbuild_python_front::discovery::main::python_files::provider_by_name::provider_by_name; +use sqlbuild_python_front::discovery::main::python_files::provider_usages::provider_usages; +use sqlbuild_python_front::discovery::models::SecretPolicy; /// A job's or group's schedule on a named calendar, as its trigger before the calendar's times fill it. pub(crate) struct CalendarRequest { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/native_host/resource_costs_state.rs b/crates/sqlbuild-python/src/bindings/_helpers/native_host/resource_costs_state.rs index d095503ec2..1b6af182fe 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/native_host/resource_costs_state.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/native_host/resource_costs_state.rs @@ -18,13 +18,17 @@ use sqlbuild_state::resource_costs::models::{ResourceCostKey, RunCostAttempt}; use sqlbuild_state::state_tables::main::values_insert_sql::values_insert_sql; use crate::bindings::_helpers::execution_history::conversion::{parsed_iso, utc}; -use crate::bindings::_helpers::native_host::consumption_state::{ - Location, ROWS_PER_STATEMENT, execute, fixed_state_table_sql, integer_literal, literal, - optional_text, state_table_name, -}; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::native_host::constants::ROWS_PER_STATEMENT; +use sqlbuild_python_front::native_host::main::execute::execute; +use sqlbuild_python_front::native_host::main::fixed_state_table_sql::fixed_state_table_sql; +use sqlbuild_python_front::native_host::main::integer_literal::integer_literal; +use sqlbuild_python_front::native_host::main::literal::literal; +use sqlbuild_python_front::native_host::main::optional_text::optional_text; +use sqlbuild_python_front::native_host::main::state_table_name::state_table_name; +use sqlbuild_python_front::native_host::models::Location; /// Rate source of a price the project configured, the only one shown as USD. const CONFIGURED_RATE_SOURCE: &str = "configured"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/native_host/warehouse_metadata.rs b/crates/sqlbuild-python/src/bindings/_helpers/native_host/warehouse_metadata.rs index 6ef103c2b3..6aebbf4d28 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/native_host/warehouse_metadata.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/native_host/warehouse_metadata.rs @@ -33,7 +33,6 @@ use sqlbuild_state::state_tables::main::event_id_index::event_id_index; use sqlbuild_state::state_tables::main::read_history_sql::read_history_sql; use sqlbuild_state::state_tables::models::HistoryRead; -use crate::bindings::_helpers::authored_values::sql_values::{SqlValueClasses, sql_value}; use crate::bindings::_helpers::command_runtime::connection::project_connection_config; use crate::bindings::_helpers::compiled_project::values::plain_value; use crate::bindings::_helpers::fingerprints::latest_rows::row_fingerprint; @@ -50,6 +49,8 @@ use sqlbuild_python_base::records::main::fields::field::field; use sqlbuild_python_base::records::types::RecordId; use sqlbuild_python_base::warehouse_access::main::read_catalog::read_catalog; use sqlbuild_python_base::warehouse_access::main::read_statistics::read_statistics; +use sqlbuild_python_front::authored_values::main::sql_value::sql_value; +use sqlbuild_python_front::authored_values::models::SqlValueClasses; /// One read-only adapter session serves every page of one synchronization. pub(crate) struct HistorySession<'py> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/observations/publication.rs b/crates/sqlbuild-python/src/bindings/_helpers/observations/publication.rs index cbb914b201..069c096f37 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/observations/publication.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/observations/publication.rs @@ -10,10 +10,6 @@ use sqlbuild_state::observations::constants::{CURSOR_MAX_KIND, SOURCE_COLUMNS_KI use crate::bindings::_helpers::compiled_views::{model_reads, project_reads}; use crate::bindings::_helpers::consumption::relation_reads::relation; -use crate::bindings::_helpers::native_host::consumption_state::{ConsumptionConnection, Location}; -use crate::bindings::_helpers::native_host::observations_state::{ - ObservationAppend, append_observations, -}; use crate::bindings::_helpers::observations::source_capture::take_source_capture; use crate::bindings::_helpers::planner_phases::objects::config_str; use crate::bindings::_helpers::planner_warehouse::constants::RUN_BOUNDED; @@ -21,6 +17,10 @@ use crate::bindings::_helpers::planner_warehouse::cursors::{adapter_cursor_sql, use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::native_host::main::append_observations::append_observations; +use sqlbuild_python_front::native_host::models::ConsumptionConnection; +use sqlbuild_python_front::native_host::models::Location; +use sqlbuild_python_front::native_host::models::ObservationAppend; /// Dependency kind of a source in a model's `dep_rows`. const SOURCE_DEPENDENCY: &str = "source"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/output_capture/values.rs b/crates/sqlbuild-python/src/bindings/_helpers/output_capture/values.rs index 7eafd8aa8d..758efed569 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/output_capture/values.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/output_capture/values.rs @@ -13,9 +13,9 @@ use sqlbuild_core::json::models::{JsonInteger, JsonValue}; use sqlbuild_host::entries::models::ExecutorHost; use sqlbuild_python_base::native_host::main::host_error::host_error; -use crate::bindings::_helpers::macro_bridge::store_keys::text; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::records::main::fields::mapping_items::mapping_items; +use sqlbuild_python_front::macro_bridge::main::text::text; const SURROGATE_PASS: &str = "surrogatepass"; const UTF8: &str = "utf-8"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/plan_command/plan.rs b/crates/sqlbuild-python/src/bindings/_helpers/plan_command/plan.rs index 9b4c92d489..2ffe94163e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/plan_command/plan.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/plan_command/plan.rs @@ -18,7 +18,6 @@ use crate::bindings::_helpers::build_progress::progress_text::with_verbose_inspe use crate::bindings::_helpers::command_runtime::invocation::resolve_adapter_connection_context; use crate::bindings::_helpers::command_runtime::preview_target::validate_preview_target; use crate::bindings::_helpers::command_runtime::runtime_errors::raised; -use crate::bindings::_helpers::compile_attachment::effective_config::build_effective_settings_config; use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; use crate::bindings::_helpers::compile_driver::plan_pipeline::run_compile_pipeline; use crate::bindings::_helpers::consumption::policy::{changed_policy, policy_line}; @@ -37,6 +36,7 @@ use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; use sqlbuild_python_base::warehouse_access::models::SyncedCopyAdapter; +use sqlbuild_python_front::compile_attachment::main::build_effective_settings_config::build_effective_settings_config; const COMMAND_NAME: &str = "plan"; const DEFAULT_SECTION_ENTRIES: i64 = 50; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/plan_command/rules.rs b/crates/sqlbuild-python/src/bindings/_helpers/plan_command/rules.rs index 40e05c5b09..b08f4227d3 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/plan_command/rules.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/plan_command/rules.rs @@ -11,7 +11,6 @@ use sqlbuild_rules::rule_catalogue::models::RuleListing; use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; use crate::bindings::_helpers::compile_driver::project::build_project_graph; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; use crate::bindings::_helpers::planner_selection::selectors::select_project_graph; use crate::bindings::_helpers::planner_selection::unit_tests::reject_unit_test_selectors; use crate::bindings::_helpers::rules::catalogue::build_rule_catalogue; @@ -28,6 +27,7 @@ use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_keywords; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; use sqlbuild_rules::rule_results::main::format_skipped_models::format_skipped_models; const LIST_ACTION: &str = "list"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/plan_output/cursor_details.rs b/crates/sqlbuild-python/src/bindings/_helpers/plan_output/cursor_details.rs index 8906c6ff58..bef1e1810a 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/plan_output/cursor_details.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/plan_output/cursor_details.rs @@ -3,7 +3,6 @@ use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; use sqlbuild_host::entries::models::ExecutorHost; -use crate::bindings::_helpers::cursor::conversion::GRAIN_NAMES; use crate::bindings::_helpers::plan_output::display::{ aligned_timestamp_bounds, resolve_effective_microbatch_batch_size, }; @@ -12,6 +11,7 @@ use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::cursor::constants::GRAIN_NAMES; const MICROBATCH_MODE: &str = "microbatch"; const TIMESTAMP_CURSOR: &str = "timestamp"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/plan_output/display.rs b/crates/sqlbuild-python/src/bindings/_helpers/plan_output/display.rs index 6dc7b553fd..4cd6d088fe 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/plan_output/display.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/plan_output/display.rs @@ -16,9 +16,6 @@ use sqlbuild_core::plan_display::main::format_waiting_on_empty_inputs::format_wa use sqlbuild_core::plan_display::main::model_materialization_label::model_materialization_label as materialization_label; use sqlbuild_core::plan_display::models::{ModelLabelFacts, ParsedBound}; -use crate::bindings::_helpers::cursor::scalars::{ - render_value, to_exclusive, to_inclusive, try_parse, -}; use crate::bindings::_helpers::plan_output::values::{optional_text, text}; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::records::main::construct::enum_from_value::enum_from_value; @@ -26,6 +23,10 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::cursor::main::scalars::render_value::render_value; +use sqlbuild_python_front::cursor::main::scalars::to_exclusive::to_exclusive; +use sqlbuild_python_front::cursor::main::scalars::to_inclusive::to_inclusive; +use sqlbuild_python_front::cursor::main::scalars::try_parse::try_parse; const DATETIME_MODULE: &str = "datetime"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/plan_output/plan_json.rs b/crates/sqlbuild-python/src/bindings/_helpers/plan_output/plan_json.rs index e1894604bc..983a0772dc 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/plan_output/plan_json.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/plan_output/plan_json.rs @@ -5,7 +5,6 @@ use pyo3::types::{PyDict, PyDictMethods, PyList, PyListMethods, PyString}; use pyo3::{pyfunction, wrap_pyfunction}; use sqlbuild_core::plan_display::constants::SYNCED_COPY_KEY; -use crate::bindings::_helpers::cursor::scalars::sentinel_to_token; use crate::bindings::_helpers::plan_output::cursor_details::{ CursorDetails, cursor_details, owner, }; @@ -20,6 +19,7 @@ use crate::bindings::_helpers::plan_output::values::{ use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::compile_outputs::main::indented_json::indented_json; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::cursor::main::scalars::sentinel_to_token::sentinel_to_token; /// The plan JSON key of what `--changed` would run, hold back and skip. pub(crate) const CHANGED_KEY: &str = "changed"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/plan_output/plan_text.rs b/crates/sqlbuild-python/src/bindings/_helpers/plan_output/plan_text.rs index 9eace562d7..d950e7e477 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/plan_output/plan_text.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/plan_output/plan_text.rs @@ -12,7 +12,6 @@ use sqlbuild_core::cli_text::models::{ }; use sqlbuild_core::plan_display::main::format_query_diff::format_query_diff; -use crate::bindings::_helpers::cursor::scalars::sentinel_to_token; use crate::bindings::_helpers::plan_output::cursor_details::{ CursorDetails, DEFERRED, RESOLVED, cursor_details, runtime_inputs_clause, }; @@ -31,6 +30,7 @@ use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::cursor::main::scalars::sentinel_to_token::sentinel_to_token; const SKIP_ACTION: &str = "skip"; const QUERY_CHANGED: &str = "query_changed"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/plan_output/safety.rs b/crates/sqlbuild-python/src/bindings/_helpers/plan_output/safety.rs index 0955e0d23e..62a673e840 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/plan_output/safety.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/plan_output/safety.rs @@ -4,9 +4,9 @@ use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyModule, PyModuleMethods, PyRes use pyo3::types::{PyDict, PyString}; use pyo3::{pyfunction, wrap_pyfunction}; -use crate::bindings::_helpers::cursor::scalars::render_value; use crate::bindings::_helpers::plan_output::values::{dict, enum_value, items}; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::cursor::main::scalars::render_value::render_value; /// `render(value=value)`. fn render<'py>(value: Bound<'py, PyAny>) -> PyResult> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_changes/detect.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_changes/detect.rs index 0e6f46fa55..149d4844fc 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_changes/detect.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_changes/detect.rs @@ -6,13 +6,14 @@ use sqlbuild_host::entries::models::{ExecutorHost, UserCodeHost}; use crate::bindings::_helpers::compiled_views::function_reads; use crate::bindings::_helpers::compiled_views::model_reads; use crate::bindings::_helpers::compiled_views::project_reads; -use crate::bindings::_helpers::contracts::spec_resolution::matching_dynamic_families; -use crate::bindings::_helpers::model_config::typed_config::{config_text, model_values}; use crate::bindings::_helpers::planner_changes::results::native_enum; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyModule, PyModuleMethods, PyResult, Python}; use pyo3::types::{PyDict, PyDictMethods, PyString, PyTuple}; use pyo3::{IntoPyObject, pyfunction, wrap_pyfunction}; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; +use sqlbuild_python_front::contracts::main::matching_dynamic_families::matching_dynamic_families; +use sqlbuild_python_front::model_config::main::config::config_text::config_text; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; use sqlbuild_analysis::planner_changes::constants::{ CASE_FOLDING_DIALECT, EMPTY_FINGERPRINT_METADATA_JSON, diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_entries/clone_plans.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_entries/clone_plans.rs index 8277a9adf2..3ecf29754a 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_entries/clone_plans.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_entries/clone_plans.rs @@ -9,7 +9,6 @@ use crate::bindings::_helpers::graph::keys::KeyCache; use crate::bindings::_helpers::graph::node_set::PyNodeSet; use crate::bindings::_helpers::graph::project_graph::NativeProjectGraph; use crate::bindings::_helpers::graph::views::edge_dict; -use crate::bindings::_helpers::model_config::typed_config::{config_node_of, model_values}; use crate::bindings::_helpers::planner_entries::models::ModelPlanContext; use crate::bindings::_helpers::planner_entries::values::{ native, planner_model, planner_type, string, @@ -40,6 +39,8 @@ use sqlbuild_python_base::records::main::construct::enum_member::enum_member; use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::model_config::main::config::config_node_of::config_node_of; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; const ENABLED_KEY: &str = "enabled"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_entries/display_plan.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_entries/display_plan.rs index dbaa7ce819..bed57d5494 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_entries/display_plan.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_entries/display_plan.rs @@ -4,7 +4,6 @@ use crate::bindings::_helpers::compiled_views::model_reads; use crate::bindings::_helpers::compiled_views::project_reads; use crate::bindings::_helpers::graph::keys::KeyCache; use crate::bindings::_helpers::graph::views::edge_dict; -use crate::bindings::_helpers::model_config::typed_config::{config_text_object, model_values}; use crate::bindings::_helpers::planner_entries::values::{ boolean, native, none, planner_model, planner_type, string, }; @@ -18,6 +17,8 @@ use pyo3::{pyfunction, wrap_pyfunction}; use sqlbuild_analysis::graph::main::downstream_edges::downstream_edges; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::model_config::main::config::config_text_object::config_text_object; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; const VIEW: &str = "view"; const INCREMENTAL: &str = "incremental"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_entries/model_entries.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_entries/model_entries.rs index 601dd8040a..908a16a460 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_entries/model_entries.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_entries/model_entries.rs @@ -3,7 +3,6 @@ use crate::bindings::_helpers::compiled_views::function_reads; use crate::bindings::_helpers::compiled_views::model_reads; use crate::bindings::_helpers::compiled_views::project_reads; -use crate::bindings::_helpers::discovery::guidance::microbatch_guidance; use crate::bindings::_helpers::planner_changes::actions::replaces_incremental_relation; use crate::bindings::_helpers::planner_changes::detect::detect_model_changes; use crate::bindings::_helpers::planner_entries::models::{ @@ -51,6 +50,7 @@ use sqlbuild_python_base::records::main::construct::enum_member::enum_member; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::discovery::main::failures::microbatch_guidance::microbatch_guidance; const MICROBATCH_COMPLEXITY_CODE: &str = "MICROBATCH_CONCURRENCY_COMPLEXITY"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_identity/metadata.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_identity/metadata.rs index 60e731100f..9508c1d437 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_identity/metadata.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_identity/metadata.rs @@ -19,9 +19,7 @@ use sqlbuild_core::fingerprint_identity::main::stable_identity_hash::stable_iden use crate::bindings::_helpers::compiled_views::function_reads; use crate::bindings::_helpers::compiled_views::model_reads; use crate::bindings::_helpers::compiled_views::seed_reads; -use crate::bindings::_helpers::discovery::hook_entries::hook_entries; use crate::bindings::_helpers::microbatches::conversion::timestamp; -use crate::bindings::_helpers::model_config::typed_config::{config_value, model_values}; use crate::bindings::_helpers::planner_identity::hashing::{ baselined_function_definition_hash, function_definition_hash, }; @@ -34,6 +32,9 @@ use sqlbuild_python_base::planner_identity::main::sorted_dumps::sorted_dumps; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::main::fields::mapping_items::mapping_items; +use sqlbuild_python_front::discovery::main::headers::hook_entries::hook_entries; +use sqlbuild_python_front::model_config::main::config::config_value::config_value; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; const LOCAL_FUNCTION_HASHES_KEY: &str = "local_function_hashes"; const DATACLASSES_MODULE: &str = "dataclasses"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/column_entries.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/column_entries.rs index 4ecc9ae781..6e6385e0df 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/column_entries.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/column_entries.rs @@ -12,7 +12,6 @@ use crate::bindings::_helpers::planner_migrations::constants::{AUTOMATIC, DONE}; use crate::bindings::_helpers::planner_migrations::models::{CheckedColumns, ColumnCandidate}; use crate::bindings::_helpers::planner_phases::objects::object; use crate::bindings::_helpers::planner_phases::runtime::runtime_field; -use crate::bindings::_helpers::state_rows::migration_projections::newest_column; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult}; use pyo3::types::{PyDict, PyDictMethods, PyFrozenSet, PyListMethods, PyTuple}; use sqlbuild_analysis::planner_migrations::main::column_decision::column_decision; @@ -23,6 +22,7 @@ use sqlbuild_python_base::records::main::construct::enum_from_value::enum_from_v use sqlbuild_python_base::records::main::construct::enum_member::enum_member; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::state_rows::main::migrations::newest_column::newest_column; pub(super) fn decide<'py>( runtime: &Bound<'py, PyAny>, diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/column_objects.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/column_objects.rs index a2d6d2b308..5c552ee897 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/column_objects.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/column_objects.rs @@ -1,7 +1,6 @@ //! Boundary conversions for the column migration planner. use crate::bindings::_helpers::compiled_views::model_reads; -use crate::bindings::_helpers::model_config::typed_config::{config_text_object, model_values}; use crate::bindings::_helpers::planner_identity::hashing::model_definition_hash; use crate::bindings::_helpers::planner_phases::objects::object; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; @@ -10,6 +9,8 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_keywords; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::model_config::main::config::config_text_object::config_text_object; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; pub(super) fn text<'py>(py: Python<'py>, value: &str) -> Bound<'py, PyAny> { PyString::new(py, value).into_any() diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/compatibility.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/compatibility.rs index dd83f32cf8..ef732eccbf 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/compatibility.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/compatibility.rs @@ -2,7 +2,6 @@ use crate::bindings::_helpers::compiled_views::model_reads; use crate::bindings::_helpers::compiled_views::model_reads::inferred_rows; -use crate::bindings::_helpers::model_config::typed_config::{config_value, model_values}; use crate::bindings::_helpers::planner_changes::detect::detect_model_changes; use crate::bindings::_helpers::planner_migrations::models::{ CompatibilityCheck, MigrationCompatibilityResult, @@ -19,6 +18,8 @@ use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::model_config::main::config::config_value::config_value; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; fn config(model: &Bound<'_, PyAny>, key: &str) -> PyResult> { config_value(model.py(), &model_values(model)?, key)?.extract() diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/discovery_events.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/discovery_events.rs index e156cd1cc0..1b93b679da 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/discovery_events.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/discovery_events.rs @@ -5,12 +5,12 @@ use sqlbuild_host::entries::models::ExecutorHost; use crate::bindings::_helpers::compiled_views::model_reads; use crate::bindings::_helpers::planner_migrations::column_objects::config; use crate::bindings::_helpers::planner_migrations::models::ModelMigrationDeclaration; -use crate::bindings::_helpers::state_rows::migration_projections::newest_move; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult}; use pyo3::types::{PyDict, PyDictMethods, PyList, PyListMethods, PyTuple}; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::state_rows::main::migrations::newest_move::newest_move; pub(super) fn identity(item: &Bound<'_, PyAny>) -> PyResult { let materialized = config(item, "materialized")?; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/model_entries.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/model_entries.rs index ac0cf2e9d8..ccafab948a 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/model_entries.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/model_entries.rs @@ -11,7 +11,6 @@ use crate::bindings::_helpers::planner_migrations::model_handover::{ use crate::bindings::_helpers::planner_migrations::models::{ CompatibilityCheck, MigrationDecisionRequest, }; -use crate::bindings::_helpers::state_rows::migration_projections::newest_move; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult}; use pyo3::types::PyBool; use sqlbuild_analysis::planner_migrations::main::model_decision::model_decision; @@ -23,6 +22,7 @@ use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::state_rows::main::migrations::newest_move::newest_move; pub(super) fn relation<'py>(location: &Bound<'py, PyAny>) -> PyResult> { host_entry(location.py(), ExecutorHost::MigrationRelationForLocation)?.call1((location,)) diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/model_handover.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/model_handover.rs index 8aee69e3e9..fdaea4ab1e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/model_handover.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/model_handover.rs @@ -5,11 +5,11 @@ use crate::bindings::_helpers::fingerprints::query_hashes::compute_query_hash; use crate::bindings::_helpers::planner_migrations::column_objects::{replace, text}; use crate::bindings::_helpers::planner_migrations::constants::MIGRATION_MODEL_NAME_METADATA_KEY; use crate::bindings::_helpers::planner_phases::objects::object; -use crate::bindings::_helpers::state_rows::timestamps::presumed_utc; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult}; use pyo3::types::{PyDict, PyDictMethods}; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::state_rows::main::event_rows::presumed_utc::presumed_utc; pub(super) fn applies( model: &Bound<'_, PyAny>, diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/model_planning.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/model_planning.rs index b736ba60e6..12d630e1e7 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/model_planning.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/model_planning.rs @@ -2,9 +2,6 @@ use crate::bindings::_helpers::compiled_views::model_reads; use crate::bindings::_helpers::compiled_views::project_reads; -use crate::bindings::_helpers::model_config::typed_config::{ - config_node_of, config_value, model_values, -}; use crate::bindings::_helpers::planner_changes::renames::plan_reference_renames; use crate::bindings::_helpers::planner_migrations::column_objects::{config, replace}; use crate::bindings::_helpers::planner_migrations::discovery::discover_model_migrations; @@ -29,6 +26,9 @@ use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get_or::mapping_get_or; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::model_config::main::config::config_node_of::config_node_of; +use sqlbuild_python_front::model_config::main::config::config_value::config_value; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; const MIGRATE_FROM_KEY: &str = "migrate_from"; const MIGRATE_FORCE_KEY: &str = "migrate_force"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/old_name_objects.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/old_name_objects.rs index cf7cc1c969..13face79d2 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/old_name_objects.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/old_name_objects.rs @@ -4,7 +4,6 @@ use sqlbuild_host::entries::models::ExecutorHost; use crate::bindings::_helpers::compiled_views::model_reads; use crate::bindings::_helpers::planner_migrations::column_objects::{config, model}; -use crate::bindings::_helpers::state_rows::migration_projections::old_name_retention; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult}; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::native_host::main::host_entry::host_entry; @@ -12,6 +11,7 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::state_rows::main::migrations::old_name_retention::old_name_retention; pub(super) fn relation<'py>(location: &Bound<'py, PyAny>) -> PyResult> { host_entry(location.py(), ExecutorHost::MigrationRelationForLocation)?.call1((location,)) diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/state_inspection.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/state_inspection.rs index a4e9bdcca7..f47da108cf 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/state_inspection.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_migrations/state_inspection.rs @@ -18,11 +18,6 @@ use crate::bindings::_helpers::planner_migrations::constants::{ GET_COLUMNS_FOR_INSPECTION, LIST_RELATIONS_FOR_INSPECTION, }; use crate::bindings::_helpers::planner_phases::runtime::runtime_field; -use crate::bindings::_helpers::state_rows::constants::{COLUMN_KIND, MODEL_KIND, OLD_NAME_KIND}; -use crate::bindings::_helpers::state_rows::migration_io::{read_events, stored_old_name_columns}; -use crate::bindings::_helpers::state_rows::migration_objects::layout; -use crate::bindings::_helpers::state_rows::migration_projections::old_name_views; -use crate::bindings::_helpers::state_rows::models::StateAccess; use sqlbuild_analysis::fingerprint_storage::constants::NODE_TYPE_MODEL; use sqlbuild_core::constants::FINGERPRINT_TABLE_NAME; use sqlbuild_python_base::boundary::main::call_with::call_with; @@ -30,6 +25,14 @@ use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::main::fields::mapping_get_or::mapping_get_or; +use sqlbuild_python_front::state_rows::constants::COLUMN_KIND; +use sqlbuild_python_front::state_rows::constants::MODEL_KIND; +use sqlbuild_python_front::state_rows::constants::OLD_NAME_KIND; +use sqlbuild_python_front::state_rows::main::migrations::layout::layout; +use sqlbuild_python_front::state_rows::main::migrations::old_name_views::old_name_views; +use sqlbuild_python_front::state_rows::main::migrations::read_events::read_events; +use sqlbuild_python_front::state_rows::main::migrations::stored_old_name_columns::stored_old_name_columns; +use sqlbuild_python_front::state_rows::models::StateAccess; /// A lowercased schema and relation name. type RelationKey = (String, String); diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/deferred_origins.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/deferred_origins.rs index 6b0802146c..9abc53ca3c 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/deferred_origins.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/deferred_origins.rs @@ -4,11 +4,12 @@ use pyo3::exceptions::PyException; use pyo3::prelude::{Bound, IntoPyObject, PyAny, PyAnyMethods, PyResult, Python}; use pyo3::types::{PyDict, PyDictMethods, PyString, PyTuple}; -use crate::bindings::_helpers::model_config::typed_config::{config_value, model_values}; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::model_config::main::config::config_value::config_value; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; const MIGRATE_FROM_KEY: &str = "migrate_from"; /// `database.schema.name`. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/execution_changes.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/execution_changes.rs index bb31c108c0..6cef425326 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/execution_changes.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/execution_changes.rs @@ -1,6 +1,5 @@ //! Write-hash reconciliation and plan entry construction. -use crate::bindings::_helpers::command_runtime::concurrency::resolve_configured_concurrency; use crate::bindings::_helpers::planner_entries::contexts::default_microbatch_limit_action; use crate::bindings::_helpers::planner_entries::model_entries::plan_entries; use crate::bindings::_helpers::planner_entries::models::{ @@ -18,6 +17,7 @@ use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult}; use pyo3::types::PyFrozenSet; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::command_runtime::main::resolve_configured_concurrency::resolve_configured_concurrency; /// The execution scope's changes with honest write hashes, and the actions merged from them. pub(crate) fn reconcile_execution_changes<'py>( diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/full_refresh.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/full_refresh.rs index 545e4ca0b1..cacbbee94f 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/full_refresh.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/full_refresh.rs @@ -2,7 +2,6 @@ use crate::bindings::_helpers::compiled_views::model_reads; use crate::bindings::_helpers::compiled_views::project_reads; -use crate::bindings::_helpers::model_config::typed_config::{config_value, model_values}; use crate::bindings::_helpers::planner_phases::constants::FULL_REFRESH_DISABLED_REBUILD_CODE; use crate::bindings::_helpers::planner_phases::objects::{frozenset, planner_error, strings}; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult}; @@ -11,6 +10,8 @@ use pyo3::types::PyBool; use sqlbuild_analysis::planner_warehouse::main::full_rebuild_cause::full_rebuild_cause; use sqlbuild_analysis::planner_warehouse::models::FullRebuildFacts; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::model_config::main::config::config_value::config_value; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; const FULL_REFRESH_KEY: &str = "full_refresh"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/objects.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/objects.rs index 58f6a1e316..de5c5ebcdf 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/objects.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/objects.rs @@ -4,7 +4,6 @@ use sqlbuild_host::entries::models::HostId; use crate::bindings::_helpers::compiled_views::project_reads; use crate::bindings::_helpers::compiled_views::resource_reads; -use crate::bindings::_helpers::model_config::typed_config::{config_text, model_values}; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult, Python}; use pyo3::types::{PyFrozenSet, PyString, PyTuple}; use pyo3::{BoundObject, IntoPyObject}; @@ -18,6 +17,8 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_keywords; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::model_config::main::config::config_text::config_text; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; /// A Python `str`. pub(crate) fn text<'py>(py: Python<'py>, value: &str) -> Bound<'py, PyAny> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/retention.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/retention.rs index b405173d37..3cf8f14a69 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/retention.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_phases/retention.rs @@ -4,8 +4,6 @@ use sqlbuild_host::entries::models::AdapterHost; use crate::bindings::_helpers::compiled_views::model_reads; use crate::bindings::_helpers::compiled_views::project_reads; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_config; -use crate::bindings::_helpers::model_config::typed_config::{config_value, typed_values}; use crate::bindings::_helpers::planner_phases::constants::{ BIGQUERY_ADAPTER, DECREASE_WARNING, DOWNGRADE_HISTORY_DAYS, PERMANENT_TABLE_TYPE, RETENTION_DECREASE, RETENTION_INCREASE, RETENTION_MATCH, SNOWFLAKE_ADAPTER, @@ -30,6 +28,9 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::types::RecordId; use sqlbuild_python_base::warehouse_access::models::SyncedCopyAdapter; +use sqlbuild_python_front::contracts::main::resolve_target_config::resolve_target_config; +use sqlbuild_python_front::model_config::main::config::config_value::config_value; +use sqlbuild_python_front::model_config::main::config::typed_values::typed_values; use std::collections::{BTreeMap, BTreeSet}; const MATERIALIZED_KEY: &str = "materialized"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_bounds.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_bounds.rs index e31243a0dd..4c686ff2ed 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_bounds.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_bounds.rs @@ -2,8 +2,6 @@ use sqlbuild_host::entries::models::ExecutorHost; -use crate::bindings::_helpers::cursor::conversion::{CursorSession, algebra_error}; -use crate::bindings::_helpers::cursor::scalars::try_parse; use crate::bindings::_helpers::planner_resolution::maximum_safety::apply_maximum_start_policy; use crate::bindings::_helpers::planner_resolution::values::string; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyModule, PyModuleMethods, PyResult, Python}; @@ -22,6 +20,9 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::cursor::main::conversion::algebra_error::algebra_error; +use sqlbuild_python_front::cursor::main::scalars::try_parse::try_parse; +use sqlbuild_python_front::cursor::models::CursorSession; pub(super) fn optional_scalar<'py>( session: &CursorSession<'py>, diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_model.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_model.rs index 35b509e3ab..30246d89b9 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_model.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_model.rs @@ -4,9 +4,6 @@ use sqlbuild_host::entries::models::{AdapterHost, ExecutorHost}; use crate::bindings::_helpers::compile_attachment::cursor_roles::resolve_cursor_input_roles; use crate::bindings::_helpers::compiled_views::model_reads; -use crate::bindings::_helpers::model_config::typed_config::{ - config_cursor_bound, config_text_object, model_values, -}; use crate::bindings::_helpers::plan_output::display::resolve_bounded_cursor_override; use crate::bindings::_helpers::planner_entries::models::ModelPlanContext; use crate::bindings::_helpers::planner_phases::contexts::class_field; @@ -34,6 +31,9 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::model_config::main::config::config_cursor_bound::config_cursor_bound; +use sqlbuild_python_front::model_config::main::config::config_text_object::config_text_object; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; fn config<'py>(model: &Bound<'py, PyAny>, key: &str) -> PyResult> { let py: Python<'py> = model.py(); diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_overrides.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_overrides.rs index 017ae15c63..428d39f17b 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_overrides.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_overrides.rs @@ -1,9 +1,6 @@ //! Selected-model inspection and untyped override conversion. use crate::bindings::_helpers::compiled_views::model_reads; -use crate::bindings::_helpers::model_config::typed_config::{ - config_text_is, config_text_object, model_values, -}; use crate::bindings::_helpers::planner_resolution::values::{method, string}; use pyo3::prelude::{ Bound, PyAny, PyAnyMethods, PyErr, PyModule, PyModuleMethods, PyResult, Python, @@ -18,6 +15,9 @@ use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::model_config::main::config::config_text_is::config_text_is; +use sqlbuild_python_front::model_config::main::config::config_text_object::config_text_object; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; const MATERIALIZED_KEY: &str = "materialized"; const CURSOR_KEY: &str = "cursor"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_policies.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_policies.rs index 04d13b095b..50a8bcd9a5 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_policies.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_policies.rs @@ -1,6 +1,5 @@ //! Model-level cursor safety policy overrides over project configuration. -use crate::bindings::_helpers::model_config::typed_config::{config_value, model_values}; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult}; use pyo3::types::PyString; use sqlbuild_python_base::boundary::main::call_with::call_with; @@ -8,6 +7,8 @@ use sqlbuild_python_base::records::main::construct::enum_from_value::enum_from_v use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::model_config::main::config::config_value::config_value; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; const POLICY_DISABLED: &str = "disabled"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_ranges.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_ranges.rs index 4df5d150db..ae4eb4b540 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_ranges.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_ranges.rs @@ -4,12 +4,6 @@ use sqlbuild_host::entries::models::ExecutorHost; use sqlbuild_python_base::records::main::construct::new_plain_error::new_plain_error; use crate::bindings::_helpers::compiled_views::model_reads; -use crate::bindings::_helpers::cursor::conversion::CursorSession; -use crate::bindings::_helpers::cursor::scalars::{parse_value, sentinel_to_token}; -use crate::bindings::_helpers::cursor::values::{local_date_time, replaced}; -use crate::bindings::_helpers::model_config::typed_config::{ - config_cursor_bound as typed_cursor_bound, config_text_object, model_values, -}; use crate::bindings::_helpers::plan_output::display::resolve_bounded_cursor_override; use crate::bindings::_helpers::planner_entries::models::ModelPlanContext; use crate::bindings::_helpers::planner_phases::contexts::class_field; @@ -44,6 +38,14 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::cursor::main::scalars::parse_value::parse_value; +use sqlbuild_python_front::cursor::main::scalars::sentinel_to_token::sentinel_to_token; +use sqlbuild_python_front::cursor::main::values::local_date_time::local_date_time; +use sqlbuild_python_front::cursor::main::values::replaced::replaced; +use sqlbuild_python_front::cursor::models::CursorSession; +use sqlbuild_python_front::model_config::main::config::config_cursor_bound::config_cursor_bound as typed_cursor_bound; +use sqlbuild_python_front::model_config::main::config::config_text_object::config_text_object; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; use std::cmp::Ordering; const INCREMENTAL: &str = "incremental"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_safety.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_safety.rs index f44d0979aa..052858c4ef 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_safety.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_safety.rs @@ -1,6 +1,5 @@ //! Shared safety horizon conversion and Python evidence construction. -use crate::bindings::_helpers::cursor::conversion::CursorSession; use crate::bindings::_helpers::planner_resolution::cursor_bounds::duration; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult, Python}; use sqlbuild_cursor::algebra::models::{DurationSpan, Grain, Scalar}; @@ -15,6 +14,7 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_keywords; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::cursor::models::CursorSession; pub(super) fn safety_error(py: Python<'_>, class: ErrorId, message: &str) -> PyErr { new_plain_error(py, class, message) diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_warnings.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_warnings.rs index 8029693977..599890d6d9 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_warnings.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_warnings.rs @@ -1,6 +1,5 @@ //! Prominent warnings for applied future-end and automatic-start cursor safety. -use crate::bindings::_helpers::cursor::scalars::render_value; use crate::bindings::_helpers::planner_resolution::values::string; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyModule, PyModuleMethods, PyResult}; use pyo3::types::{PyString, PyTuple}; @@ -9,6 +8,7 @@ use sqlbuild_python_base::records::main::construct::enum_member::enum_member; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::cursor::main::scalars::render_value::render_value; const FUTURE_CAPPED_CODE: &str = "FUTURE_CURSOR_CAPPED"; const START_CAPPED_CODE: &str = "AUTOMATIC_START_CAPPED"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_windows.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_windows.rs index 04b2818ecf..46dcb20ea1 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_windows.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/cursor_windows.rs @@ -1,7 +1,5 @@ //! Empty-window decisions and snapshot grain conversion. -use crate::bindings::_helpers::cursor::conversion::CursorSession; -use crate::bindings::_helpers::cursor::scalars::parse_value; use crate::bindings::_helpers::planner_resolution::values::string; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyModule, PyModuleMethods, PyResult, Python}; use pyo3::types::{PyDict, PyDictMethods, PyTuple}; @@ -16,6 +14,8 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_keywords; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::cursor::main::scalars::parse_value::parse_value; +use sqlbuild_python_front::cursor::models::CursorSession; #[pyfunction] #[pyo3(signature = (*, empty_input_names, waits_for_every_input, inputs_with_rows, has_window_start))] diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/future_safety.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/future_safety.rs index 1c42350546..f2dbdb5769 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/future_safety.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/future_safety.rs @@ -1,6 +1,5 @@ //! Future cursor safety evidence and exception boundary. -use crate::bindings::_helpers::cursor::conversion::CursorSession; use crate::bindings::_helpers::planner_resolution::cursor_safety::{ horizon, replace, safety_duration, safety_error, timestamp_bound, utc_clock, }; @@ -18,6 +17,7 @@ use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::cursor::models::CursorSession; use std::cmp::Ordering; #[pyfunction] diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/maximum_safety.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/maximum_safety.rs index 9a84614229..1e4e4779fc 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/maximum_safety.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/maximum_safety.rs @@ -1,7 +1,5 @@ //! Maximum automatic-start recovery and evidence boundary. -use crate::bindings::_helpers::cursor::conversion::CursorSession; -use crate::bindings::_helpers::cursor::scalars::render_value; use crate::bindings::_helpers::planner_phases::objects::object; use crate::bindings::_helpers::planner_resolution::cursor_bounds::apply_typed_cursor_replay_policy; use crate::bindings::_helpers::planner_resolution::cursor_bounds::{ @@ -28,6 +26,8 @@ use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::cursor::main::scalars::render_value::render_value; +use sqlbuild_python_front::cursor::models::CursorSession; use std::cmp::Ordering; #[pyfunction] diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/orchestration.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/orchestration.rs index 9d439d3bb5..30858a454f 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/orchestration.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/orchestration.rs @@ -1,14 +1,8 @@ //! Model, function and SQL-hook orchestration through adapter-owned rendering. -use crate::bindings::_helpers::attachments::cursor_intrinsics::resolve_cursor_intrinsics; -use crate::bindings::_helpers::attachments::reference_markers::assert_no_unresolved_sql_markers; use crate::bindings::_helpers::compile_attachment::cursor_roles::resolve_cursor_input_roles; use crate::bindings::_helpers::compiled_views::function_reads; use crate::bindings::_helpers::compiled_views::model_reads; -use crate::bindings::_helpers::cursor::scalars::sentinel_to_token; -use crate::bindings::_helpers::model_config::typed_config::{ - config_node_of, config_text_is, config_text_object, config_value, model_values, -}; use crate::bindings::_helpers::planner_entries::models::ModelPlanContext; use crate::bindings::_helpers::planner_phases::contexts::class_field; use crate::bindings::_helpers::planner_resolution::cursor_model::{ @@ -33,6 +27,14 @@ use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_key use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; use sqlbuild_python_base::warehouse_access::models::SyncedCopyAdapter; +use sqlbuild_python_front::attachments::main::assert_no_unresolved_sql_markers::assert_no_unresolved_sql_markers; +use sqlbuild_python_front::attachments::main::resolve_cursor_intrinsics::resolve_cursor_intrinsics; +use sqlbuild_python_front::cursor::main::scalars::sentinel_to_token::sentinel_to_token; +use sqlbuild_python_front::model_config::main::config::config_node_of::config_node_of; +use sqlbuild_python_front::model_config::main::config::config_text_is::config_text_is; +use sqlbuild_python_front::model_config::main::config::config_text_object::config_text_object; +use sqlbuild_python_front::model_config::main::config::config_value::config_value; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; const APPEND_STRATEGY: &str = "append"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/refs.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/refs.rs index 0bcc7bfa7c..8429bcf5ba 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/refs.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/refs.rs @@ -6,7 +6,6 @@ use crate::bindings::_helpers::planner_resolution::models::CursorFiltering; use crate::bindings::_helpers::planner_resolution::values::{ cursor_wrap, filtering_of, method, string, }; -use crate::bindings::_helpers::sqltext::code_scanner::SqlCodeScanner; use pyo3::IntoPyObject; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyModule, PyModuleMethods, PyResult, Python}; use pyo3::types::{PyDict, PyDictMethods}; @@ -16,6 +15,7 @@ use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; +use sqlbuild_python_front::sqltext::models::SqlCodeScanner; use sqlbuild_sqltext::resolution::main::{ref_alias::ref_alias, reference_spans::reference_spans}; #[pyfunction] diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/values.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/values.rs index 8baddcc5c4..d2d5e16d63 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/values.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/values.rs @@ -1,6 +1,5 @@ //! Boundary calls shared by reference and source resolution. -use crate::bindings::_helpers::cursor::scalars::sentinel_to_token; use crate::bindings::_helpers::planner_resolution::models::CursorFiltering; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; use pyo3::types::PyString; @@ -8,6 +7,7 @@ use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; +use sqlbuild_python_front::cursor::main::scalars::sentinel_to_token::sentinel_to_token; use sqlbuild_sqltext::resolution::main::cursor_subquery::cursor_subquery; use sqlbuild_sqltext::resolution::models::CursorFilter; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_scenario/execution.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_scenario/execution.rs index 409da03d00..2e69862e57 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_scenario/execution.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_scenario/execution.rs @@ -4,7 +4,6 @@ use crate::bindings::_helpers::compiled_views::model_reads; use crate::bindings::_helpers::compiled_views::project_reads; use crate::bindings::_helpers::compiled_views::records::compiled_model_record; use crate::bindings::_helpers::graph::keys::KeyCache; -use crate::bindings::_helpers::model_config::typed_config::{config_value, model_values}; use crate::bindings::_helpers::planner_entries::model_entries::plan_model; use crate::bindings::_helpers::planner_entries::models::ModelPlanContext; use crate::bindings::_helpers::planner_identity::graph::{execution_deps, execution_order}; @@ -44,6 +43,8 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_keywords; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::model_config::main::config::config_value::config_value; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; #[pyfunction] #[pyo3(signature = (**kwargs))] diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_scenario/fixtures.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_scenario/fixtures.rs index 945a0bbe8b..669fa0088e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_scenario/fixtures.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_scenario/fixtures.rs @@ -7,7 +7,6 @@ use crate::bindings::_helpers::planner_scenario::{ sql::{required_target, resolve_sql, source_label}, values::{error, string}, }; -use crate::bindings::_helpers::sqltext::lexical_syntax::LexicalSyntaxInput; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python, pyfunction}; use pyo3::types::{PyDict, PyDictMethods, PyTuple}; use sqlbuild_analysis::compiler::main::scenario_reader_ctes::scenario_reader_ctes; @@ -19,6 +18,7 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get_or::mapping_get_or; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::sqltext::models::LexicalSyntaxInput; use sqlbuild_sqltext::sql_references::main::extract_sql_references::extract_sql_references; use sqlbuild_sqltext::sql_references::models::ReferenceExtraction; use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; @@ -28,7 +28,7 @@ pub(super) fn extract_fixtures<'py>( scenario: &Bound<'py, PyAny>, prefix: &str, ) -> PyResult> { - crate::bindings::_helpers::sql_test_glue::authored_ctes::prefixed_ctes( + sqlbuild_python_front::sql_test_glue::main::prefixed_ctes::prefixed_ctes( &native_field(scenario, "authored_ctes")?, prefix, ) diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_scenario/helper_scope.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_scenario/helper_scope.rs index c11b51ea0c..3b66e666b8 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_scenario/helper_scope.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_scenario/helper_scope.rs @@ -6,9 +6,9 @@ use sqlbuild_analysis::compiler::models::{ScenarioHelperScope, ScenarioScopeInpu use crate::bindings::_helpers::planner_scenario::constants::SCENARIO_PLAN_INTERNAL; use crate::bindings::_helpers::planner_scenario::{models::SqlContext, values::error}; -use crate::bindings::_helpers::sqltext::lexical_syntax::LexicalSyntaxInput; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; +use sqlbuild_python_front::sqltext::models::LexicalSyntaxInput; const FIXTURE_LOCATIONS: [(&str, &str); 4] = [ ("__source__", "source_fixture_locations"), diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_scenario/sql.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_scenario/sql.rs index 79ed69af3f..b10b6a00fe 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_scenario/sql.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_scenario/sql.rs @@ -9,7 +9,6 @@ use crate::bindings::_helpers::planner_scenario::{ values::{error, string}, }; use crate::bindings::_helpers::references::source_relations::render_source_relation; -use crate::bindings::_helpers::sqltext::lexical_syntax::LexicalSyntaxInput; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python, pyfunction}; use pyo3::types::{PyDict, PyStringMethods}; use sqlbuild_analysis::planner_scenario::{ @@ -18,6 +17,7 @@ use sqlbuild_analysis::planner_scenario::{ use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; +use sqlbuild_python_front::sqltext::models::LexicalSyntaxInput; use sqlbuild_sqltext::sql_scan::models::Unclosed; pub(super) fn resolve_sql( diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_scope/loaders.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_scope/loaders.rs index 5701b57bd2..4d9bde263f 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_scope/loaders.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_scope/loaders.rs @@ -1,6 +1,5 @@ //! Loader dependency mapping and synthetic source boundary construction. -use crate::bindings::_helpers::contracts::spec_resolution::loader_parts; use crate::bindings::_helpers::graph::keys::KeyCache; use crate::bindings::_helpers::graph::views::edge_dict; use crate::bindings::_helpers::planner_scope::values::{ @@ -15,6 +14,7 @@ use sqlbuild_analysis::planner_scope::main::{ use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::loader_parts::loader_parts; use std::collections::HashSet; #[pyfunction] diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_selection/model_selectors.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_selection/model_selectors.rs index 9aafa335d4..136cac00ac 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_selection/model_selectors.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_selection/model_selectors.rs @@ -13,12 +13,13 @@ use sqlbuild_analysis::planner_selection::models::{ }; use crate::bindings::_helpers::compiled_views::project_reads; -use crate::bindings::_helpers::model_config::typed_config::{config_value, model_values}; use crate::bindings::_helpers::planner_selection::carrier::Carrier; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::model_config::main::config::config_value::config_value; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; const TAGS_KEY: &str = "tags"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_selection/unit_tests.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_selection/unit_tests.rs index 63317f06f4..7a8c3a69ab 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_selection/unit_tests.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_selection/unit_tests.rs @@ -13,12 +13,12 @@ use sqlbuild_analysis::planner_selection::models::{ }; use crate::bindings::_helpers::compiled_project::job_catalog::job_names; -use crate::bindings::_helpers::discovery::model_file_record::NativeModelFile; use crate::bindings::_helpers::planner_selection::carrier::{Carrier, py_strings}; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::path_stem::path_stem; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::discovery::models::NativeModelFile; /// A bare selector's kind. const NAME_SELECTOR_KIND: &str = "name"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/audit_entries.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/audit_entries.rs index 7267639344..3e331b8bbf 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/audit_entries.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/audit_entries.rs @@ -5,7 +5,6 @@ use sqlbuild_analysis::graph::main::graph_from_indexes::graph_from_indexes; use sqlbuild_analysis::graph::models::GraphIndexes; use std::collections::HashSet; -use crate::bindings::_helpers::attachments::reference_markers::assert_no_unresolved_sql_markers; use crate::bindings::_helpers::auditing::render::render_audit_sql; use crate::bindings::_helpers::compiled_views::audit_reads; use crate::bindings::_helpers::compiled_views::project_reads; @@ -23,6 +22,7 @@ use pyo3::pyfunction; use pyo3::types::{PyBool, PyDict, PyDictMethods, PyList, PyListMethods, PyString}; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::records::main::construct::new_record::new_record; +use sqlbuild_python_front::attachments::main::assert_no_unresolved_sql_markers::assert_no_unresolved_sql_markers; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::models::Request; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/cursor_inputs.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/cursor_inputs.rs index 74dcd375f8..457d7b7b85 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/cursor_inputs.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/cursor_inputs.rs @@ -9,10 +9,6 @@ use sqlbuild_analysis::planner_strategy::models::{CursorInputColumnCheck, Cursor use crate::bindings::_helpers::compile_attachment::cursor_roles::resolve_cursor_input_roles; use crate::bindings::_helpers::compiled_views::model_reads; -use crate::bindings::_helpers::cursor::scalars::parse_value; -use crate::bindings::_helpers::model_config::typed_config::{ - config_cursor_bound, config_text_object, config_value, model_values, -}; use crate::bindings::_helpers::planner_identity::metadata::or_empty; use crate::bindings::_helpers::planner_scope::retained::scope_data; use crate::bindings::_helpers::planner_strategy::constants::{ @@ -31,6 +27,11 @@ use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::main::fields::mapping_items::mapping_items; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::cursor::main::scalars::parse_value::parse_value; +use sqlbuild_python_front::model_config::main::config::config_cursor_bound::config_cursor_bound; +use sqlbuild_python_front::model_config::main::config::config_text_object::config_text_object; +use sqlbuild_python_front::model_config::main::config::config_value::config_value; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; /// Whether a model is incremental with a cursor column. fn incremental_cursor_flag( diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/fixture_metadata.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/fixture_metadata.rs index 0274eb77fe..2d15fabc57 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/fixture_metadata.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/fixture_metadata.rs @@ -6,12 +6,13 @@ use sqlbuild_analysis::planner_fixtures::models::FixtureColumn; use crate::bindings::_helpers::compiled_views::model_reads; use crate::bindings::_helpers::compiled_views::model_reads::{inferred_rows, star_flags}; -use crate::bindings::_helpers::model_config::typed_config::{config_value, model_values}; use crate::bindings::_helpers::planner_strategy::constants::ENFORCED_CONTRACT; use crate::bindings::_helpers::planner_strategy::fixture_values::{columns, folded_name}; use crate::bindings::_helpers::planner_strategy::models::FixtureRelation; use sqlbuild_project::types::InferredRow; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::model_config::main::config::config_value::config_value; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; const CONTRACT_KEY: &str = "contract"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/lineage.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/lineage.rs index 4b782d2bcc..30baee3ec5 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/lineage.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/lineage.rs @@ -12,7 +12,6 @@ use sqlbuild_analysis::planner_strategy::types::ReferenceGraph; use crate::bindings::_helpers::compile_attachment::cursor_roles::resolve_cursor_input_roles; use crate::bindings::_helpers::compiled_views::model_reads; use crate::bindings::_helpers::compiled_views::resource_reads; -use crate::bindings::_helpers::model_config::typed_config::{config_text_is, model_values}; use crate::bindings::_helpers::native_host::model_lookup::ModelLookup; use crate::bindings::_helpers::planner_strategy::microbatches::{ CAP_ACTIONS, microbatch_limit_config, @@ -21,6 +20,8 @@ use crate::bindings::_helpers::planner_strategy::values::{input_error, text}; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::types::ErrorId; +use sqlbuild_python_front::model_config::main::config::config_text_is::config_text_is; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; const MICROBATCH_MODE: &str = "microbatch"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/microbatches.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/microbatches.rs index 3072dad55b..239ab716a3 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/microbatches.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/microbatches.rs @@ -18,7 +18,6 @@ use sqlbuild_analysis::planner_strategy::types::Timeline; use sqlbuild_cursor::algebra::main::parse_duration::parse_duration; use sqlbuild_cursor::algebra::models::{DurationDigits, DurationSpan}; -use crate::bindings::_helpers::cursor::durations::shifted_moment; use crate::bindings::_helpers::plan_output::display::aligned_timestamp_bounds; use crate::bindings::_helpers::planner_strategy::values::text; use sqlbuild_python_base::records::main::construct::enum_from_value::enum_from_value; @@ -27,6 +26,7 @@ use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::cursor::main::durations::shifted_moment::shifted_moment; const INTEGER_CURSOR: &str = "integer"; const TIMESTAMP_CURSOR: &str = "timestamp"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/model_entries.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/model_entries.rs index 07244e1a41..20efc7a4c6 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/model_entries.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/model_entries.rs @@ -18,11 +18,6 @@ use sqlbuild_model_config::model_validation::constants::PHYSICAL_STORAGE_KEYS; use crate::bindings::_helpers::compiled_views::model_reads; use crate::bindings::_helpers::compiled_views::resource_reads; -use crate::bindings::_helpers::cursor::scalars::sentinel_to_token; -use crate::bindings::_helpers::model_config::typed_config::{ - ConfigValues, config_cursor_bound, config_flag, config_integer_object, config_text_object, - config_text_tuple, config_value, model_values, -}; use crate::bindings::_helpers::planner_strategy::constants::{ CUSTOM_MATERIALIZATION, DDL_SEPARATOR, ENFORCED_CONTRACT, MICROBATCH_MODE, PHYSICAL_STORAGE_DIALECT, PHYSICAL_STORAGE_UNSUPPORTED_CODE, TABLE_RECREATING_ACTIONS, @@ -48,6 +43,15 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::cursor::main::scalars::sentinel_to_token::sentinel_to_token; +use sqlbuild_python_front::model_config::main::config::config_cursor_bound::config_cursor_bound; +use sqlbuild_python_front::model_config::main::config::config_flag::config_flag; +use sqlbuild_python_front::model_config::main::config::config_integer_object::config_integer_object; +use sqlbuild_python_front::model_config::main::config::config_text_object::config_text_object; +use sqlbuild_python_front::model_config::main::config::config_text_tuple::config_text_tuple; +use sqlbuild_python_front::model_config::main::config::config_value::config_value; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; +use sqlbuild_python_front::model_config::types::ConfigValues; /// Model config keys copied to the plan entry as optional strings, with their entry fields. const STRING_FIELDS: [(&str, &str); 15] = [ diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/values.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/values.rs index 1bfcc0eed0..22e3989765 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/values.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_strategy/values.rs @@ -1,13 +1,12 @@ //! Conversions between the planner's Python models and the native strategy rows. -use crate::bindings::_helpers::model_config::typed_config::{ - config_value as typed_config_value, model_values, -}; use crate::bindings::_helpers::planner_changes::results::native_enum; use pyo3::IntoPyObject; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult, Python}; use pyo3::types::{PyDict, PyDictMethods, PyString}; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; +use sqlbuild_python_front::model_config::main::config::config_value::config_value as typed_config_value; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; use sqlbuild_analysis::planner_changes::models::{ SchemaChangeKind, SchemaColumnSource, SchemaFindingRow, diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/cursors.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/cursors.rs index 0f49154e68..c51fb8fe18 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/cursors.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/cursors.rs @@ -5,12 +5,6 @@ use crate::bindings::_helpers::compiled_views::model_reads; use crate::bindings::_helpers::compiled_views::project_reads; use crate::bindings::_helpers::compiled_views::resource_reads; use crate::bindings::_helpers::compiled_views::source_reads; -use crate::bindings::_helpers::cursor::intervals::partition; -use crate::bindings::_helpers::cursor::scalars; -use crate::bindings::_helpers::cursor::scalars::compare_values; -use crate::bindings::_helpers::cursor::scalars::render_value; -use crate::bindings::_helpers::cursor::scalars::to_inclusive; -use crate::bindings::_helpers::model_config::typed_config::{config_cursor_bound, model_values}; use crate::bindings::_helpers::planner_phases::objects::object; use crate::bindings::_helpers::planner_phases::objects::{ by_name, config_str, model_key, native_member, optional_text, planner_error, planner_model, @@ -49,6 +43,13 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_items::mapping_items; use sqlbuild_python_base::records::types::RecordId; use sqlbuild_python_base::warehouse_access::models::SyncedCopyAdapter; +use sqlbuild_python_front::cursor::main::intervals::partition::partition; +use sqlbuild_python_front::cursor::main::scalars::compare_values::compare_values; +use sqlbuild_python_front::cursor::main::scalars::render_value::render_value; +use sqlbuild_python_front::cursor::main::scalars::to_inclusive::to_inclusive; +use sqlbuild_python_front::cursor::main::scalars::try_parse::try_parse; +use sqlbuild_python_front::model_config::main::config::config_cursor_bound::config_cursor_bound; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; use std::cell::RefCell; use std::collections::{HashMap, HashSet}; use std::sync::Arc; @@ -126,7 +127,7 @@ fn parse<'py>( raw: &Bound<'py, PyAny>, cursor_type: &str, ) -> PyResult> { - scalars::parse(raw, &text(py, cursor_type)) + sqlbuild_python_front::cursor::main::scalars::parse::parse(raw, &text(py, cursor_type)) } fn render<'py>(value: &Bound<'py, PyAny>) -> PyResult> { @@ -337,7 +338,7 @@ fn floor_lifts(info: &CursorModel<'_>, observed: &Bound<'_, PyAny>) -> PyResult< let (Some(floor), Some(cursor_type)) = (&info.floor, &info.cursor_type) else { return Ok(false); }; - match scalars::try_parse(&text(py, floor), &text(py, cursor_type))? { + match try_parse(&text(py, floor), &text(py, cursor_type))? { Some(floor) => Ok(compare_values(&floor, observed)? > 0), None => Ok(false), } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/semantic_sources.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/semantic_sources.rs index f71982ea05..68d93023e6 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/semantic_sources.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/semantic_sources.rs @@ -2,7 +2,6 @@ use crate::bindings::_helpers::compiled_views::model_reads; use crate::bindings::_helpers::compiled_views::project_reads; -use crate::bindings::_helpers::model_config::typed_config::{config_node_of, model_values}; use crate::bindings::_helpers::planner_phases::objects::{text, tuple}; use crate::bindings::_helpers::planner_warehouse::constants::ACTIVE_CATALOG; use crate::bindings::_helpers::planner_warehouse::snapshot::{columns_for, list_relations}; @@ -16,6 +15,8 @@ use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; +use sqlbuild_python_front::model_config::main::config::config_node_of::config_node_of; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; use std::collections::BTreeSet; const SQL_ANALYSIS_KEY: &str = "sql_analysis"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/snapshot.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/snapshot.rs index 817166d5f3..02cf6f7df8 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/snapshot.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/snapshot.rs @@ -8,7 +8,6 @@ use crate::bindings::_helpers::compiled_views::source_reads; use crate::bindings::_helpers::fingerprints::latest_rows::select_latest_fingerprints; use crate::bindings::_helpers::fingerprints::storage_io::read_latest_fingerprints; use crate::bindings::_helpers::graph::keys::{KeyCache, native_key}; -use crate::bindings::_helpers::model_config::typed_config::{config_node_of, model_values}; use crate::bindings::_helpers::planner_identity::graph::execution_deps; use crate::bindings::_helpers::planner_phases::full_refresh::effectively_full_refreshed_model_names; use crate::bindings::_helpers::planner_phases::objects::object; @@ -42,6 +41,8 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_items::mapping_items; use sqlbuild_python_base::records::main::fields::mapping_values::mapping_values; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::model_config::main::config::config_node_of::config_node_of; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; use std::collections::{BTreeSet, HashSet}; /// Everything one snapshot gather needs. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/source_deferral.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/source_deferral.rs index 9325a8c3da..b93aaa112b 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/source_deferral.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/source_deferral.rs @@ -2,14 +2,11 @@ use sqlbuild_host::entries::models::UserCodeHost; -use crate::bindings::_helpers::authored_values::project_vars::render_project_var_text; use crate::bindings::_helpers::compiled_views::audit_reads; use crate::bindings::_helpers::compiled_views::function_reads; use crate::bindings::_helpers::compiled_views::model_reads; use crate::bindings::_helpers::compiled_views::project_reads; use crate::bindings::_helpers::compiled_views::source_reads; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_config; -use crate::bindings::_helpers::model_config::typed_config::{config_value, model_values}; use crate::bindings::_helpers::planner_phases::objects::object; use crate::bindings::_helpers::planner_phases::objects::{ optional_text, planner_error, replace, text, @@ -26,6 +23,10 @@ use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::authored_values::main::render_project_var_text::render_project_var_text; +use sqlbuild_python_front::contracts::main::resolve_target_config::resolve_target_config; +use sqlbuild_python_front::model_config::main::config::config_value::config_value; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; use std::collections::BTreeSet; fn managed_names(project: &Bound<'_, PyAny>) -> PyResult> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/source_tables.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/source_tables.rs index 49f022336a..96362f5a61 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/source_tables.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/source_tables.rs @@ -2,7 +2,6 @@ use crate::bindings::_helpers::compiled_views::project_reads; use crate::bindings::_helpers::compiled_views::source_reads; -use crate::bindings::_helpers::discovery::locations::yaml_entry_line; use crate::bindings::_helpers::planner_phases::objects::{planner_error, tuple}; use crate::bindings::_helpers::planner_scope::retained::scope_data; use crate::bindings::_helpers::planner_warehouse::constants::{ @@ -27,6 +26,7 @@ use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get_or::mapping_get_or; use sqlbuild_python_base::warehouse_access::models::SyncedCopyAdapter; +use sqlbuild_python_front::discovery::main::project::yaml_entry_line::yaml_entry_line; use std::collections::HashMap; fn selected_source_readers(scope: &Bound<'_, PyAny>) -> PyResult>> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/watermarks.rs b/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/watermarks.rs index 6164c5eca1..b1adf98e3f 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/watermarks.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/watermarks.rs @@ -3,7 +3,6 @@ use crate::bindings::_helpers::compiled_views::model_reads; use crate::bindings::_helpers::compiled_views::seed_reads; use crate::bindings::_helpers::compiled_views::source_reads; -use crate::bindings::_helpers::model_config::typed_config::{config_value, model_values}; use crate::bindings::_helpers::planner_phases::objects::object; use crate::bindings::_helpers::planner_phases::objects::{config_str, planner_error, text}; use crate::bindings::_helpers::planner_strategy::cursor_types::classify_cursor_sql_type; @@ -14,6 +13,8 @@ use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult}; use pyo3::pyfunction; use pyo3::types::{PyDict, PyDictMethods}; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::model_config::main::config::config_value::config_value; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; use std::collections::HashMap; const CONTRACT_KEY: &str = "contract"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/project_assembly/native_resources.rs b/crates/sqlbuild-python/src/bindings/_helpers/project_assembly/native_resources.rs index a920f64c24..e72461f44f 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/project_assembly/native_resources.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/project_assembly/native_resources.rs @@ -17,9 +17,7 @@ use sqlbuild_core::panics::main::native_failure::native_failure; use sqlbuild_model_config::templates::models::Scalar; use sqlbuild_python_base::positional_record; -use crate::bindings::_helpers::authored_values::project_vars::project_var_text; use crate::bindings::_helpers::compiled_views::model_input_view::input_reference_rows; -use crate::bindings::_helpers::model_config::template_data::record_reads; use crate::bindings::_helpers::project_assembly::models::{ NativeProjectResources, NativeResourceFailure, }; @@ -34,6 +32,8 @@ use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::main::fields::mapping_items::mapping_items; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::types::CompilerDetach; +use sqlbuild_python_front::authored_values::main::project_var_text::project_var_text; +use sqlbuild_python_front::model_config::main::config::record_reads::record_reads; const OS_MODULE: &str = "os"; const PROJECT_ASSEMBLY_CONTEXT: &str = "native project assembly"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/project_assembly/syntax_checks.rs b/crates/sqlbuild-python/src/bindings/_helpers/project_assembly/syntax_checks.rs index c41ed31e7d..64cb409ce9 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/project_assembly/syntax_checks.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/project_assembly/syntax_checks.rs @@ -6,10 +6,10 @@ use pyo3::{pyfunction, wrap_pyfunction}; use sqlbuild_model_config::header_metadata::models::DynamicFamily; use sqlbuild_sqltext::compiler::main::placeholder_defaults::placeholder_defaults; -use crate::bindings::_helpers::attachments::cursor_intrinsics::analysis_cursor_sql; use crate::bindings::_helpers::compiled_views::model_input_view::attached_schema; use crate::bindings::_helpers::project_assembly::syntax_validation::hook_sql_statements; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::attachments::main::analysis_cursor_sql::analysis_cursor_sql; const HOOK_NAMES: [&str; 2] = ["pre_hooks", "post_hooks"]; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/query_command/project.rs b/crates/sqlbuild-python/src/bindings/_helpers/query_command/project.rs index b137473697..95592855ca 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/query_command/project.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/query_command/project.rs @@ -3,13 +3,13 @@ use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; -use crate::bindings::_helpers::discovery::configuration::discover_connection_configuration; -use crate::bindings::_helpers::discovery::provider_secrets::SecretPolicy; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::command_runtime::main::resolve_cli_adapter::resolve_cli_adapter; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use sqlbuild_python_front::discovery::main::project::discover_connection_configuration::discover_connection_configuration; +use sqlbuild_python_front::discovery::models::SecretPolicy; /// The project directory, defaulting to the working directory, with its inputs and adapter. pub(crate) struct ProjectAdapter<'py> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/recall/events.rs b/crates/sqlbuild-python/src/bindings/_helpers/recall/events.rs index b1ef52d28f..f7960e287c 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/recall/events.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/recall/events.rs @@ -8,13 +8,13 @@ use pyo3::types::{ use serde_json::{Map, Number, Value}; use sqlbuild_host::entries::models::ExecutorHost; -use crate::bindings::_helpers::discovery::snapshot::escaped; use crate::bindings::_helpers::recall::constants::{ EVENT_OPTIONAL_TEXT_FIELDS, EVENT_TEXT_FIELDS, INVOCATION_METADATA_SCHEMA_VERSION, TIMESTAMP_PARTS, UTC_ZONE_NAME, }; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::discovery::main::snapshots::escaped::escaped; /// The text of `text`; lone surrogates, which UTF-8 cannot hold, are kept as `\\xNN` or `\\uXXXX` escapes. pub(crate) fn escaped_text(text: &Bound<'_, PyString>) -> PyResult { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/recall/registration.rs b/crates/sqlbuild-python/src/bindings/_helpers/recall/registration.rs index b703553e5f..322bb6c179 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/recall/registration.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/recall/registration.rs @@ -2,9 +2,9 @@ use pyo3::prelude::{Bound, PyModule, PyModuleMethods, PyResult}; -use crate::bindings::_helpers::discovery::imported_providers::install_recall_writer; use crate::bindings::_helpers::recall::sinks::RecallLifecycleSink; use crate::bindings::_helpers::recall::writer::RecallWriter; +use sqlbuild_python_front::discovery::main::python_files::install_recall_writer::install_recall_writer; pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { module.add_class::()?; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/constants.rs b/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/constants.rs index 3dc6eb9540..ea894c5e18 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/constants.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/constants.rs @@ -74,9 +74,8 @@ use crate::bindings::_helpers::record_behaviours::values::{ }; use crate::bindings::_helpers::{ analysis, analysis_session, build_progress, compile_command, compiled_views, compute_logs, - dbt_events, dbt_interop, discovery, event_exporting, execution_history, graph, model_config, - planner_entries, planner_migrations, planner_phases, project_assembly, result_output, rules, - scopes, + dbt_events, dbt_interop, event_exporting, execution_history, graph, planner_entries, + planner_migrations, planner_phases, project_assembly, result_output, rules, }; use sqlbuild_python_base::records::models::{GetterEntry, RecordBehaviours}; use sqlbuild_python_base::records::types::ClassMethod; @@ -365,11 +364,11 @@ pub(crate) const GETTER_TABLES: &[&[GetterEntry]] = &[ dbt_events::getters::GETTERS, dbt_interop::getters::GETTERS, sqlbuild_python_base::diagnostics::constants::GETTERS, - discovery::getters::GETTERS, + sqlbuild_python_front::discovery::constants::GETTERS, event_exporting::getters::GETTERS, execution_history::getters::GETTERS, graph::getters::GETTERS, - model_config::getters::GETTERS, + sqlbuild_python_front::model_config::constants::GETTERS, planner_entries::getters::GETTERS, planner_migrations::getters::GETTERS, planner_phases::getters::GETTERS, @@ -377,7 +376,7 @@ pub(crate) const GETTER_TABLES: &[&[GetterEntry]] = &[ project_assembly::getters::GETTERS, result_output::getters::GETTERS, rules::getters::GETTERS, - scopes::getters::GETTERS, + sqlbuild_python_front::scopes::constants::GETTERS, ]; /// Every record behaviour, installed into `records::behaviours` at registration. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/cursors.rs b/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/cursors.rs index a2ea181cf2..a3297ad4d0 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/cursors.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/cursors.rs @@ -4,13 +4,13 @@ use pyo3::prelude::{Bound, Py, PyAny, PyAnyMethods, PyResult, Python}; use pyo3::types::{PyString, PyTuple}; use sqlbuild_host::entries::models::ExecutorHost; -use crate::bindings::_helpers::cursor::scalars::parse_value; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::construct::enum_from_value::enum_from_value; use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::cursor::main::scalars::parse_value::parse_value; /// One cursor value conversion. type Conversion = for<'py> fn(&Bound<'py, PyAny>) -> PyResult>; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/durations.rs b/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/durations.rs index 3dd2e61847..02a11c2eed 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/durations.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/durations.rs @@ -4,11 +4,10 @@ use pyo3::IntoPyObjectExt; use pyo3::prelude::{Bound, Py, PyAny, PyAnyMethods, PyResult, Python}; use pyo3::types::{PyDict, PyDictMethods, PyFrozenSet, PyTuple, PyTupleMethods}; -use crate::bindings::_helpers::cursor::durations::{ - parse_cursor_duration, shift_by_cursor_duration, -}; -use crate::bindings::_helpers::cursor::intervals::interval_validation; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::cursor::main::durations::parse_cursor_duration::parse_cursor_duration; +use sqlbuild_python_front::cursor::main::durations::shift_by_cursor_duration::shift_by_cursor_duration; +use sqlbuild_python_front::cursor::main::intervals::interval_validation::interval_validation; /// `(field, unit suffix)` of each duration part, in declaration order. const DURATION_UNITS: [(&str, &str); 6] = [ diff --git a/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/lexical.rs b/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/lexical.rs index 31bce33d1d..b485186ad8 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/lexical.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/lexical.rs @@ -10,9 +10,10 @@ use sqlbuild_sqltext::sql_scan::main::reads_differently_from_generic::reads_diff use sqlbuild_sqltext::sql_scan::main::unsupported_line_comment_prefixes::unsupported_line_comment_prefixes; use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; -use crate::bindings::_helpers::sqltext::lexical_syntax::{record_syntax, sorted_texts}; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::types::ErrorId; +use sqlbuild_python_front::sqltext::main::record_syntax::record_syntax; +use sqlbuild_python_front::sqltext::main::sorted_texts::sorted_texts; /// `SqlLexicalSyntax.line_comment_prefixes` position. const LINE_COMMENT_PREFIXES_FIELD: usize = 5; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/macros.rs b/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/macros.rs index 7c55bc795e..f93c691b4e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/macros.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/macros.rs @@ -6,11 +6,10 @@ use pyo3::types::{PyDict, PyList, PyTuple, PyTupleMethods}; use crate::bindings::_helpers::graph::project_graph::{ResourceRow, project_graph}; use crate::bindings::_helpers::record_behaviours::compiled::compile_input_error; -use crate::bindings::_helpers::render::declaration_values::{ - constant_declaration_sql, render_enum_member_value, -}; use sqlbuild_python_base::boundary::main::call_argument::call_argument; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::render::main::declarations::constant_declaration_sql::constant_declaration_sql; +use sqlbuild_python_front::render::main::declarations::render_enum_member_value::render_enum_member_value; /// The parameter name through which a macro receives its context. const MACRO_CONTEXT_PARAMETER_NAME: &str = "ctx"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/planner.rs b/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/planner.rs index a31f6f8907..86338b5ad5 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/planner.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/planner.rs @@ -10,7 +10,6 @@ use sqlbuild_core::migration_values::main::model_migration_blocks_build::model_m use sqlbuild_core::migration_values::main::storage_transition::storage_transition; use sqlbuild_core::migration_values::models::{DecisionTraits, ModelMigrationFacts}; -use crate::bindings::_helpers::cursor::scalars::parse_value; use sqlbuild_python_base::boundary::main::call_argument::call_argument; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::records::main::construct::enum_from_value::enum_from_value; @@ -18,6 +17,7 @@ use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::cursor::main::scalars::parse_value::parse_value; const DECREASING_DIRECTIONS: [&str; 2] = ["decrease", "mixed"]; const STEP_ACTIONS: [&str; 2] = ["archive_and_view", "view_only"]; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/refactor/mod.rs b/crates/sqlbuild-python/src/bindings/_helpers/refactor/mod.rs index 218f3a4910..f0e246c0e0 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/refactor/mod.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/refactor/mod.rs @@ -1,7 +1,3 @@ -pub(crate) mod contract_compare; -pub(crate) mod contract_edits; pub(crate) mod offline_compile; -pub(crate) mod python_strings; pub(crate) mod refactor_command; -pub(crate) mod refactor_facts; pub(crate) mod registration; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/refactor/refactor_command.rs b/crates/sqlbuild-python/src/bindings/_helpers/refactor/refactor_command.rs index 0fa0c28a5e..f0c038c686 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/refactor/refactor_command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/refactor/refactor_command.rs @@ -38,9 +38,6 @@ use sqlbuild_refactor::refactoring::types::Originals; use crate::bindings::_helpers::lineage::lineage_index::lineage_key; use crate::bindings::_helpers::refactor::offline_compile::{OfflineCompile, compile_for_refactor}; -use crate::bindings::_helpers::refactor::refactor_facts::{ - declaration_placement, model_facts, refactor_facts, unit_test_rebindings, -}; use sqlbuild_python_base::boundary::main::compiler_guard::compiler_guard; use sqlbuild_python_base::boundary::main::native_compiler_error::native_compiler_error; use sqlbuild_python_base::build_progress::main::transient_status::status_reporter::status_reporter; @@ -49,6 +46,10 @@ use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_items::mapping_items; use sqlbuild_python_base::records::types::ErrorId; +use sqlbuild_python_front::refactor::main::declaration_placement::declaration_placement; +use sqlbuild_python_front::refactor::main::model_facts::model_facts; +use sqlbuild_python_front::refactor::main::refactor_facts::refactor_facts; +use sqlbuild_python_front::refactor::main::unit_test_rebindings::unit_test_rebindings; const STAGING_PREFIX: &str = "sqb-refactor-"; const MOVE_COMMAND: &str = "mv"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/refactor/registration.rs b/crates/sqlbuild-python/src/bindings/_helpers/refactor/registration.rs index 95663e5197..2d8ce156fb 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/refactor/registration.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/refactor/registration.rs @@ -2,13 +2,14 @@ use pyo3::prelude::{Bound, PyModule, PyResult}; -use crate::bindings::_helpers::refactor::{ - contract_compare, contract_edits, python_strings, refactor_command, -}; +use crate::bindings::_helpers::refactor::refactor_command; +use sqlbuild_python_front::refactor::main::register_contract_compare::register_contract_compare; +use sqlbuild_python_front::refactor::main::register_contract_edits::register_contract_edits; +use sqlbuild_python_front::refactor::main::register_python_strings::register_python_strings; pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { refactor_command::register(module)?; - contract_edits::register(module)?; - contract_compare::register(module)?; - python_strings::register(module) + register_contract_edits(module)?; + register_contract_compare(module)?; + register_python_strings(module) } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/mod.rs b/crates/sqlbuild-python/src/bindings/_helpers/render/mod.rs index 169a7f9d43..7444bd0374 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/render/mod.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/render/mod.rs @@ -1,20 +1 @@ -pub(crate) mod authored_sql; -pub(crate) mod declaration_expansion; -pub(crate) mod declaration_indexes; -pub(crate) mod declaration_values; -pub(crate) mod macro_arguments; -pub(crate) mod macro_call_classes; -pub(crate) mod macro_call_memo; -pub(crate) mod macro_call_rows; -pub(crate) mod macro_calls; -pub(crate) mod macro_evaluation; -pub(crate) mod macro_expansion; -pub(crate) mod macro_expansion_facts; -pub(crate) mod macro_expansion_result; -pub(crate) mod macro_generated_references; -pub(crate) mod macro_modules; pub(crate) mod registration; -pub(crate) mod sql_macro_host; -pub(crate) mod sql_macro_inventory; -pub(crate) mod sql_macro_mocks; -pub(crate) mod sql_macro_tests; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/render/registration.rs b/crates/sqlbuild-python/src/bindings/_helpers/render/registration.rs index 4362a03894..6820ff458a 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/render/registration.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/render/registration.rs @@ -2,20 +2,25 @@ use pyo3::prelude::{Bound, PyModule, PyResult}; -use crate::bindings::_helpers::render::{ - authored_sql, declaration_indexes, declaration_values, macro_arguments, macro_calls, - macro_expansion, macro_expansion_result, macro_modules, sql_macro_inventory, -}; +use sqlbuild_python_front::render::main::calls::register_macro_arguments::register_macro_arguments; +use sqlbuild_python_front::render::main::calls::register_macro_calls::register_macro_calls; +use sqlbuild_python_front::render::main::declarations::register_authored_sql::register_authored_sql; +use sqlbuild_python_front::render::main::declarations::register_declaration_indexes::register_declaration_indexes; +use sqlbuild_python_front::render::main::declarations::register_declaration_values::register_declaration_values; +use sqlbuild_python_front::render::main::expansion::register_macro_expansion::register_macro_expansion; +use sqlbuild_python_front::render::main::expansion::register_macro_expansion_result::register_macro_expansion_result; +use sqlbuild_python_front::render::main::expansion::register_macro_modules::register_macro_modules; +use sqlbuild_python_front::render::main::sql_macros::register_sql_macro_inventory::register_sql_macro_inventory; pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { - authored_sql::register(module)?; - declaration_values::register(module)?; - declaration_indexes::register(module)?; - macro_arguments::register(module)?; - macro_calls::register(module)?; - macro_expansion::register(module)?; - macro_expansion_result::register(module)?; - macro_modules::register(module)?; - sql_macro_inventory::register(module)?; + register_authored_sql(module)?; + register_declaration_values(module)?; + register_declaration_indexes(module)?; + register_macro_arguments(module)?; + register_macro_calls(module)?; + register_macro_expansion(module)?; + register_macro_expansion_result(module)?; + register_macro_modules(module)?; + register_sql_macro_inventory(module)?; Ok(()) } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/result_output/checks.rs b/crates/sqlbuild-python/src/bindings/_helpers/result_output/checks.rs index 3d0780ca6c..3b13e982ad 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/result_output/checks.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/result_output/checks.rs @@ -12,8 +12,8 @@ use sqlbuild_host::types::ResultEnum; use crate::bindings::_helpers::plan_output::values::{any, dict, items, text}; use crate::bindings::_helpers::result_output::assets::{or_none, without_none}; use crate::bindings::_helpers::result_output::projection::{Projection, ResultIdentity, rounded}; -use crate::bindings::_helpers::scopes::scope_report_objects::json_to_python; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::scopes::main::reports::json_to_python::json_to_python; const DECIMAL_KIND: &str = "decimal"; const SCALAR_KINDS: [&str; 5] = ["string", "integer", "boolean", "float", "null"]; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/result_output/integration_envelope.rs b/crates/sqlbuild-python/src/bindings/_helpers/result_output/integration_envelope.rs index 2b2705b7da..3689487c6e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/result_output/integration_envelope.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/result_output/integration_envelope.rs @@ -11,10 +11,10 @@ use sqlbuild_core::integration_results::main::normalize_integration_record::norm use sqlbuild_core::integration_results::main::strip_optional_enrichment::strip_optional_enrichment; use sqlbuild_core::json::models::JsonValue; -use crate::bindings::_helpers::scopes::scope_report_objects::json_to_python; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::result_output::main::json_value::json_value; use sqlbuild_python_base::result_output::main::validation_error::validation_error; +use sqlbuild_python_front::scopes::main::reports::json_to_python::json_to_python; /// One decoded part of a record: its fields as attributes, and as a dictionary. fn field(fields: &Py, py: Python<'_>, name: &str) -> PyResult> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/review_command/execution.rs b/crates/sqlbuild-python/src/bindings/_helpers/review_command/execution.rs index bac0a07885..ecce1d6d96 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/review_command/execution.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/review_command/execution.rs @@ -14,7 +14,6 @@ use sqlbuild_analysis::review_command::models::{IncrementalStart, ReviewGraph, V use crate::bindings::_helpers::build_command::command::run_build_command; use crate::bindings::_helpers::clone::clone_command::run_clone_command; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_config; use crate::bindings::_helpers::dagster_invocation::access::string_tuple as texts; use crate::bindings::_helpers::review_command::planning::ReviewSettings; use crate::bindings::_helpers::review_command::support::{quietly, review_error}; @@ -24,6 +23,7 @@ use sqlbuild_python_base::build_command::main::text::text; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_target_config::resolve_target_config; const FAILED_STATUS: &str = "failed"; const AUDIT_KIND: &str = "audit"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/review_command/planning.rs b/crates/sqlbuild-python/src/bindings/_helpers/review_command/planning.rs index e7dc5eeba3..0a225d96f2 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/review_command/planning.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/review_command/planning.rs @@ -27,12 +27,6 @@ use crate::bindings::_helpers::compile_driver::project::build_project_graph; use crate::bindings::_helpers::compiled_views::model_reads; use crate::bindings::_helpers::compiled_views::project_reads; use crate::bindings::_helpers::compiled_views::seed_reads; -use crate::bindings::_helpers::contracts::spec_resolution::{ - resolve_effective_adapter_name, resolve_target_name, -}; -use crate::bindings::_helpers::discovery::project_config::{ - configured_git_base_ref, configured_review, -}; use crate::bindings::_helpers::execution_history::conversion::optional_text; use crate::bindings::_helpers::graph::python_node_graph::python_node_graph; use crate::bindings::_helpers::planner_selection::selectors::select_project_graph; @@ -43,6 +37,10 @@ use sqlbuild_python_base::build_command::main::text::text; use sqlbuild_python_base::command_runtime::main::resolve_cli_adapter::resolve_cli_adapter; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use sqlbuild_python_front::contracts::main::resolve_target_name::resolve_target_name; +use sqlbuild_python_front::discovery::main::project::configured_git_base_ref::configured_git_base_ref; +use sqlbuild_python_front::discovery::main::project::configured_review::configured_review; const BASE_REF_ALIAS: &str = "@base"; const UDF_KIND: &str = "udf"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/review_command/schema.rs b/crates/sqlbuild-python/src/bindings/_helpers/review_command/schema.rs index 1f21885182..99aba3c21c 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/review_command/schema.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/review_command/schema.rs @@ -8,7 +8,6 @@ use sqlbuild_analysis::review_command::main::review_schema_name::review_schema_n use sqlbuild_host::entries::models::ExecutorHost; use crate::bindings::_helpers::command_runtime::connection::resolve_target_connection_config; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_config; use crate::bindings::_helpers::janitor::janitor_keys::utc_datetime; use crate::bindings::_helpers::review_command::planning::{ReviewProject, ReviewSettings}; use crate::bindings::_helpers::review_command::support::review_error; @@ -23,6 +22,7 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced::replaced; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_target_config::resolve_target_config; /// Where the review builds and where its ownership marker goes. pub(crate) struct ReviewSchema { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/rules/custom_host_columns.rs b/crates/sqlbuild-python/src/bindings/_helpers/rules/custom_host_columns.rs index 0101fba536..ce808b309e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/rules/custom_host_columns.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/rules/custom_host_columns.rs @@ -11,8 +11,8 @@ use sqlbuild_discovery::models::LineColumnSpan; use sqlbuild_model_config::header_metadata::models::{ParsedThresholds, ThresholdBound}; use sqlbuild_sqltext::compiler::models::AuthoredValue; -use crate::bindings::_helpers::model_config::header_metadata::native_column_record; use crate::bindings::_helpers::rules::custom_hosts::rules_error; +use sqlbuild_python_front::model_config::main::headers::native_column_record::native_column_record; /// One native header column with the text of the path its location names. #[derive(Debug, Serialize, Deserialize)] diff --git a/crates/sqlbuild-python/src/bindings/_helpers/rules/early_sql_lint.rs b/crates/sqlbuild-python/src/bindings/_helpers/rules/early_sql_lint.rs index c3d355114f..2b8ca2857c 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/rules/early_sql_lint.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/rules/early_sql_lint.rs @@ -26,7 +26,6 @@ use crate::bindings::_helpers::compiled_views::relation_keys::model_key_row; use crate::bindings::_helpers::compiled_views::relation_keys::{ RelationKeyRow, RelationKeys, one_row_seed_names, relation_keys, source_key_input, }; -use crate::bindings::_helpers::render::authored_sql::SqlExpansionInputs; use crate::bindings::_helpers::rules::lint_expansion::{ LintExpansionSources, lint_expansion_inputs, }; @@ -40,6 +39,7 @@ use sqlbuild_python_base::boundary::main::compiler_guard::compiler_guard; use sqlbuild_python_base::native_threads::main::join_interruptibly::join_interruptibly; use sqlbuild_python_base::native_threads::models::Joined; use sqlbuild_python_base::records::main::fields::field::field as record_field; +use sqlbuild_python_front::render::models::SqlExpansionInputs; /// The lint thresholds used when the project leaves them unset. const DEFAULT_MAX_LITERAL_LENGTH: i64 = 100; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/rules/fix_session.rs b/crates/sqlbuild-python/src/bindings/_helpers/rules/fix_session.rs index 8948387504..bdbb81f607 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/rules/fix_session.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/rules/fix_session.rs @@ -20,8 +20,6 @@ use crate::bindings::_helpers::compile_driver::project::build_compiled_project; use crate::bindings::_helpers::compiled_views::relation_keys::{ RelationKeys, project_relation_keys, }; -use crate::bindings::_helpers::discovery::model_file_record::NativeModelFile; -use crate::bindings::_helpers::render::authored_sql::SqlExpansionInputs; use crate::bindings::_helpers::rules::constants::SAFE_RULE_FIX_CODES; use crate::bindings::_helpers::rules::constants::SQL_RULE_PREFIX; use crate::bindings::_helpers::rules::fix_facts::compile_facts; @@ -43,6 +41,8 @@ use sqlbuild_python_base::records::main::fields::field::field; use sqlbuild_python_base::records::main::fields::replaced::replaced; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::discovery::models::NativeModelFile; +use sqlbuild_python_front::render::models::SqlExpansionInputs; const VERIFICATION_FAILURE: &str = "Compilation could not prove unchanged output columns, types, dependencies and lineage"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/rules/fixture_formatting.rs b/crates/sqlbuild-python/src/bindings/_helpers/rules/fixture_formatting.rs index bd1e587a19..67026835f7 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/rules/fixture_formatting.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/rules/fixture_formatting.rs @@ -8,13 +8,13 @@ use sqlbuild_rules::lint_text::main::format_fixture_blocks::format_fixture_block use sqlbuild_rules::lint_text::models::FixtureFormatBlock; use sqlbuild_sqltext::sql_scan::models::LexicalSyntax; -use crate::bindings::_helpers::discovery::sql_test_records::parse_sql_test_file; use crate::bindings::_helpers::rules::constants::MODEL_TEST_MODE; use crate::bindings::_helpers::rules::fixture_schemas; -use crate::bindings::_helpers::sqltext::lexical_syntax::LexicalSyntaxInput; use sqlbuild_python_base::boundary::main::compiler_guard::compiler_guard; use sqlbuild_python_base::boundary::main::value_error::value_error; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::discovery::main::records::parse_sql_test_file::parse_sql_test_file; +use sqlbuild_python_front::sqltext::models::LexicalSyntaxInput; #[pyfunction] #[pyo3(signature = (*, files, project_dir, discovered_inputs, sql_lexical_syntax))] diff --git a/crates/sqlbuild-python/src/bindings/_helpers/rules/fixture_schemas.rs b/crates/sqlbuild-python/src/bindings/_helpers/rules/fixture_schemas.rs index e591c396c5..e398733481 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/rules/fixture_schemas.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/rules/fixture_schemas.rs @@ -9,10 +9,10 @@ use sqlbuild_rules::lint_text::types::FixtureFormatColumn; use std::collections::HashMap; use std::path::Path; -use crate::bindings::_helpers::discovery::model_file_record::NativeModelFile; -use crate::bindings::_helpers::model_config::header_columns::schema_columns; -use crate::bindings::_helpers::model_config::model_config_builder::raised_config_error; use sqlbuild_python_base::records::main::fields::field::field; +use sqlbuild_python_front::discovery::models::NativeModelFile; +use sqlbuild_python_front::model_config::main::headers::schema_columns::schema_columns; +use sqlbuild_python_front::model_config::main::model_nodes::raised_config_error::raised_config_error; pub(crate) fn columns(columns: &Bound<'_, PyAny>) -> PyResult> { columns diff --git a/crates/sqlbuild-python/src/bindings/_helpers/rules/lint_expansion.rs b/crates/sqlbuild-python/src/bindings/_helpers/rules/lint_expansion.rs index f04f75f1a6..6c625c4144 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/rules/lint_expansion.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/rules/lint_expansion.rs @@ -11,8 +11,6 @@ use crate::bindings::_helpers::compile_attachment::sql_expansion_context::{ ExpansionSources, ExpansionVars, present, sql_expansion_inputs, }; use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; -use crate::bindings::_helpers::render::authored_sql::SqlExpansionInputs; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::boundary::models::KeywordArguments; @@ -20,6 +18,8 @@ use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use sqlbuild_python_front::render::models::SqlExpansionInputs; const COMPILE_FIRST_MESSAGE: &str = "compiler-integrated Rules check the SQL your project \ actually produces, so the project must compile first"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/rules/lint_inputs.rs b/crates/sqlbuild-python/src/bindings/_helpers/rules/lint_inputs.rs index 85491051e2..794d7a499b 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/rules/lint_inputs.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/rules/lint_inputs.rs @@ -10,12 +10,12 @@ use crate::bindings::_helpers::compiled_views::model_input_view::{ ModelInputRecord, NativeModelInput, }; use crate::bindings::_helpers::compiled_views::project_view::NativeProjectView; -use crate::bindings::_helpers::render::macro_call_rows::SpanRow; use crate::bindings::_helpers::rules::lint_pipeline::{ CompiledExpansion, CompiledSource, span_pass, }; use sqlbuild_project::models::ExpansionRecord; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::render::types::SpanRow; const FILE_PATH_ATTRIBUTE: &str = "file_path"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/rules/lint_pipeline.rs b/crates/sqlbuild-python/src/bindings/_helpers/rules/lint_pipeline.rs index 697ca29ddc..2f9ddf87c6 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/rules/lint_pipeline.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/rules/lint_pipeline.rs @@ -44,9 +44,6 @@ use sqlbuild_rules::project_tree::main::project_real_path::project_real_path; use sqlbuild_rules::project_tree::main::project_real_paths::project_real_paths; use sqlclean::sql_lint::main::fill_finding_path::fill_finding_path; -use crate::bindings::_helpers::render::authored_sql::SqlExpansionInputs; -use crate::bindings::_helpers::render::authored_sql::{AuthoredExpansion, expand_with_inputs}; -use crate::bindings::_helpers::render::macro_call_rows::SpanRow; use crate::bindings::_helpers::rules::dsl_headers::header_violations; use crate::bindings::_helpers::rules::native_header_parser::{ FUNCTION_KIND, HeaderFailure, NativeHeaderParser, external_identifiers, @@ -60,6 +57,10 @@ use sqlbuild_python_base::records::main::fields::field::field as record_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; use sqlbuild_python_base::types::CompilerDetach; +use sqlbuild_python_front::render::main::declarations::expand_with_inputs::expand_with_inputs; +use sqlbuild_python_front::render::models::AuthoredExpansion; +use sqlbuild_python_front::render::models::SqlExpansionInputs; +use sqlbuild_python_front::render::types::SpanRow; pub(crate) const NATIVE_ENGINE: &str = "native"; const HEADER_ENGINE: &str = "sqlbuild"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/rules/lint_preparation.rs b/crates/sqlbuild-python/src/bindings/_helpers/rules/lint_preparation.rs index bd07d782b9..c22c853333 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/rules/lint_preparation.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/rules/lint_preparation.rs @@ -5,7 +5,6 @@ use pyo3::pyfunction; use pyo3::types::{PyBool, PyDict, PyTuple}; use sqlbuild_rules::lint_text::models::{ExpansionSpan, LintSqlBody}; -use crate::bindings::_helpers::render::authored_sql::SqlExpansionInputs; use crate::bindings::_helpers::rules::lint_pipeline::{ BodyRole, SingleBody, SingleBodyRequest, prepare_single_body, }; @@ -14,6 +13,7 @@ use sqlbuild_python_base::records::main::construct::new_record_with::new_record_ use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::render::models::SqlExpansionInputs; /// `ExpansionSpan` objects of one pass. fn span_objects<'py>( diff --git a/crates/sqlbuild-python/src/bindings/_helpers/rules/native_header_parser.rs b/crates/sqlbuild-python/src/bindings/_helpers/rules/native_header_parser.rs index c90ecf9996..2568abb08e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/rules/native_header_parser.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/rules/native_header_parser.rs @@ -12,10 +12,10 @@ use sqlbuild_sqltext::compiler::models::{AuthoredValue, HeaderWord}; use sqlbuild_sqltext::header_strings::main::quote_failure::quote_failure; use sqlbuild_sqltext::header_strings::models::QuoteFailure; -use crate::bindings::_helpers::sqltext::model_headers::header_failure; use sqlbuild_python_base::boundary::main::value_error::value_error; use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::types::ErrorId; +use sqlbuild_python_front::sqltext::main::header_failure::header_failure; /// The path header rules report header syntax errors at. const SENTINEL_PATH: &str = ""; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/rules/rows.rs b/crates/sqlbuild-python/src/bindings/_helpers/rules/rows.rs index 359cb75556..94eaec521a 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/rules/rows.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/rules/rows.rs @@ -42,7 +42,6 @@ use crate::bindings::_helpers::rules::findings::{FindingClasses, finding_fault}; use crate::bindings::_helpers::rules::rule_run::bulk_cache_file; use crate::bindings::_helpers::rules::selection::rules_error; use crate::bindings::_helpers::rules::sql_test_objects::{scenario_fact, sql_test_fact}; -use crate::bindings::_helpers::scopes::scope_reports::metadata_projection_value; use sqlbuild_python_base::boundary::main::compiler_guard::compiler_guard; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::value_error::value_error; @@ -53,6 +52,7 @@ use sqlbuild_python_base::records::main::fields::field::field; use sqlbuild_python_base::records::types::RecordId; use sqlbuild_python_base::type_system::main::types_equal::types_equal; use sqlbuild_python_base::types::CompilerDetach; +use sqlbuild_python_front::scopes::main::reports::metadata_projection_value::metadata_projection_value; const DATACLASSES_MODULE: &str = "dataclasses"; const NATIVE_RULES_CACHE_FILE: &str = "native.json"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/rules/run_lint.rs b/crates/sqlbuild-python/src/bindings/_helpers/rules/run_lint.rs index 1c11cf3692..673c166fd2 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/rules/run_lint.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/rules/run_lint.rs @@ -9,7 +9,6 @@ use pyo3::{pyfunction, wrap_pyfunction}; use crate::bindings::_helpers::compile_attachment::sql_expansion_context::ExpansionVars; use crate::bindings::_helpers::compile_attachment::sql_expansion_context::present; -use crate::bindings::_helpers::render::authored_sql::SqlExpansionInputs; use crate::bindings::_helpers::rules::lint_expansion::{ LintExpansionSources, lint_expansion_inputs, }; @@ -18,6 +17,7 @@ use crate::bindings::_helpers::rules::lint_pipeline::{ lint_sources, }; use sqlbuild_python_base::boundary::models::KeywordArguments; +use sqlbuild_python_front::render::models::SqlExpansionInputs; /// The selected paths, or `None` for every file. pub(crate) fn selected_paths(selected: &Bound<'_, PyAny>) -> PyResult>> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/rules/sql_rules.rs b/crates/sqlbuild-python/src/bindings/_helpers/rules/sql_rules.rs index d5b9c70d43..c0f7a4e6fb 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/rules/sql_rules.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/rules/sql_rules.rs @@ -649,7 +649,7 @@ fn path_rows(outcome: LintOutcome) -> Vec<(PathBuf, LintViolationRow)> { /// Build lint expansion with the compiled target and vars, reusing the compiler's scope only for the same discovery. fn lint_expansion_context( run: &SqlRun<'_, '_>, -) -> PyResult { +) -> PyResult { let py: Python<'_> = run.project.py(); let reuse: Option<&ExpansionReuse> = match run .early_lint diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scenario_command/setup.rs b/crates/sqlbuild-python/src/bindings/_helpers/scenario_command/setup.rs index 243048f163..11983dd763 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scenario_command/setup.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/scenario_command/setup.rs @@ -26,10 +26,7 @@ use crate::bindings::_helpers::build_progress::progress_text::write_execution_he use crate::bindings::_helpers::command_runtime::connection::resolve_project_connection_config; use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; use crate::bindings::_helpers::compile_driver::pipeline_entries::run_compile_only_pipeline; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_scenario_config; use crate::bindings::_helpers::dbt_interop::reference_resolver::resolve_external_sql_reference_resolver; -use crate::bindings::_helpers::discovery::guidance::sql_analysis_guidance; use crate::bindings::_helpers::planner_selection::unit_tests::reject_unit_test_selectors; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::keywords::keywords; @@ -43,6 +40,9 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_keywords; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use sqlbuild_python_front::contracts::main::resolve_effective_scenario_config::resolve_effective_scenario_config; +use sqlbuild_python_front::discovery::main::failures::sql_analysis_guidance::sql_analysis_guidance; const METADATA_MODULE: &str = "importlib.metadata"; const DISTRIBUTION_NAME: &str = "sqlbuild"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scenario_command/test_command.rs b/crates/sqlbuild-python/src/bindings/_helpers/scenario_command/test_command.rs index 54a4e75a47..1422bd6b50 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scenario_command/test_command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/scenario_command/test_command.rs @@ -24,7 +24,6 @@ use crate::bindings::_helpers::change_selection::base_snapshot::{ use crate::bindings::_helpers::change_selection::selection::{ ChangedProject, changed_project, tests_and_models, with_since_section, }; -use crate::bindings::_helpers::command_runtime::concurrency::resolve_concurrency; use crate::bindings::_helpers::result_output::documents::format_scenario_execution_json_with; use crate::bindings::_helpers::result_output::documents::write_execution_json_output; use crate::bindings::_helpers::scenario_command::conversions::scenario_result_row; @@ -45,6 +44,7 @@ use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::native_host::types::ReadResult; use sqlbuild_python_base::records::main::fields::field::field as native_field; +use sqlbuild_python_front::command_runtime::main::resolve_concurrency::resolve_concurrency; const LOCAL_ADAPTER: &str = "duckdb"; const LOCAL_STATUSES: [&str; 4] = ["PASS", "FAIL", "ERROR", "SKIP"]; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/declaration_contexts.rs b/crates/sqlbuild-python/src/bindings/_helpers/scopes/declaration_contexts.rs deleted file mode 100644 index b1de60ca4b..0000000000 --- a/crates/sqlbuild-python/src/bindings/_helpers/scopes/declaration_contexts.rs +++ /dev/null @@ -1,314 +0,0 @@ -//! Declaration resolution contexts built natively from a Python scope lookup's positions. - -use std::collections::HashMap; - -use pyo3::prelude::{Bound, Py, PyAny, PyAnyMethods, PyModule, PyModuleMethods, PyResult, Python}; -use pyo3::types::{PyDict, PyDictMethods, PyTuple}; -use pyo3::{FromPyObject, intern, pyclass, pymethods}; - -use crate::bindings::_helpers::scopes::declaration_resolution::ResolutionInputs; -use sqlbuild_python_base::boundary::main::compiler_error::compiler_error; -use sqlbuild_python_base::boundary::main::compiler_guard::compiler_guard; -use sqlbuild_python_base::records::main::fields::field::field as native_field; -use sqlbuild_scopes::scope_index::main::classify_resource::classify_resource; -use sqlbuild_scopes::scope_index::models::{ - ConsumerResource, GrantEntry, VisibilityReason, VisibilityTable, VisibleEntry, -}; - -const ENUM_KIND: u8 = 0; -const CONSTANT_KIND: u8 = 1; -const MACRO_KIND: u8 = 2; - -pub(crate) type TableRow = ( - Vec, - HashMap>, - HashMap>, -); -type VisibleRow<'py> = (Bound<'py, PyAny>, VisibleEntry, Option>); - -/// One declaration position: identity, first record, name, kinds, runtime value and key. -#[derive(FromPyObject)] -pub(crate) struct PositionRow(Py, Py, Py, u8, Py, u8, u32); - -/// The Python classes and enum members the contexts are built from. -#[derive(FromPyObject)] -#[pyo3(from_item_all)] -pub(crate) struct ContextClasses { - visibility_record: Py, - pub(crate) resolution_context: Py, - reasons: Py, -} - -/// Positions, visibility table and classes of one scope lookup. -#[pyclass(frozen, module = "sqlbuild._native")] -pub(crate) struct NativeDeclarationContexts { - positions: Vec, - table: VisibilityTable, - pub(crate) classes: ContextClasses, - lookup: LookupMappings, - pub(crate) resolution: ResolutionInputs, -} - -/// The Python lookup mappings a matching resource's private positions and grants come from. -#[derive(FromPyObject)] -#[pyo3(from_item_all)] -pub(crate) struct LookupMappings { - identity_keys: Py, - private_positions: Py, - grants_by_resource: Py, -} - -/// Dictionaries one context is assembled into, in Python's insertion order. -struct ContextParts<'py> { - enums: Bound<'py, PyDict>, - constants: Bound<'py, PyDict>, - macros: Bound<'py, PyDict>, - macro_records: Bound<'py, PyDict>, - inaccessible: [Bound<'py, PyDict>; 3], - visibility: [Bound<'py, PyDict>; 3], -} - -#[pymethods] -impl NativeDeclarationContexts { - #[new] - pub(crate) fn new( - positions: Vec, - table: TableRow, - classes: ContextClasses, - lookups: (LookupMappings, ResolutionInputs), - ) -> Self { - let (lookup, resolution) = lookups; - let (global, local, inherited) = table; - let identity_keys: Vec = positions.iter().map(|row| row.6).collect(); - Self { - table: VisibilityTable { - identity_keys, - global, - local, - inherited, - }, - positions, - classes, - lookup, - resolution, - } - } - - /// `resolve_declaration_context`: the context and whether it was projected, not cached. - #[pyo3(signature = (resolver, file_path, resource=None))] - fn resolve<'py>( - &self, - resolver: Bound<'py, PyAny>, - file_path: Bound<'py, PyAny>, - resource: Option>, - ) -> PyResult<(Bound<'py, PyAny>, bool)> { - compiler_guard(|| { - let path: String = file_path.str()?.to_string(); - self.resolved_context(&resolver, &path, resource.as_ref()) - }) - } -} - -impl NativeDeclarationContexts { - pub(crate) fn classified_context<'py>( - &self, - py: Python<'py>, - matches: Vec>, - consumer: Bound<'py, PyAny>, - ) -> PyResult> { - let mut visible: Vec> = Vec::new(); - let mut inaccessible: Vec = Vec::new(); - for record in matches { - let identity: Bound<'py, PyAny> = native_field(&record, "identity")?; - let path: String = native_field(&record, "path")?.extract()?; - let private: Vec = self - .lookup - .private_positions - .bind(py) - .call_method1(intern!(py, "get"), (&identity, PyTuple::empty(py)))? - .extract()?; - if private - .iter() - .any(|position| *position >= self.positions.len()) - { - return Err(compiler_error( - "private declaration outside the scope lookup", - )); - } - let (grants, throughs) = self.grants(py, &identity)?; - let classified = classify_resource( - &self.table, - &ConsumerResource { - private, - path, - grants, - }, - ) - .map_err(|deferral| compiler_error(deferral.reason))?; - for entry in classified.visible { - let through: Option> = - entry.through.map(|slot| throughs[slot].clone()); - visible.push((identity.clone(), entry, through)); - } - inaccessible.extend(classified.inaccessible); - } - self.assemble(py, &visible, &inaccessible, consumer) - } - - /// The resource's grants of indexed declarations, with each grant's `through` value. - fn grants<'py>( - &self, - py: Python<'py>, - identity: &Bound<'py, PyAny>, - ) -> PyResult<(Vec, Vec>)> { - let records: Bound<'py, PyAny> = self - .lookup - .grants_by_resource - .bind(py) - .call_method1(intern!(py, "get"), (identity, PyTuple::empty(py)))?; - let identity_keys: &Bound<'py, PyDict> = self.lookup.identity_keys.bind(py); - let mut grants: Vec = Vec::new(); - let mut throughs: Vec> = Vec::new(); - for grant in records.try_iter()? { - let grant: Bound<'py, PyAny> = grant?; - let Some(identity_key) = - identity_keys.get_item(native_field(&grant, "declaration")?)? - else { - continue; - }; - let kind: String = native_field(&grant, "kind")? - .getattr(intern!(py, "value"))? - .extract()?; - grants.push(GrantEntry { - identity_key: identity_key.extract()?, - reason: if kind == VisibilityReason::TestedMacro.as_str() { - VisibilityReason::TestedMacro - } else { - VisibilityReason::ExpectedModel - }, - through: throughs.len(), - }); - throughs.push(native_field(&grant, "through")?); - } - Ok((grants, throughs)) - } - - fn assemble<'py>( - &self, - py: Python<'py>, - visible: &[VisibleRow<'py>], - inaccessible: &[usize], - consumer: Bound<'py, PyAny>, - ) -> PyResult> { - let parts: ContextParts<'py> = ContextParts { - enums: PyDict::new(py), - constants: PyDict::new(py), - macros: PyDict::new(py), - macro_records: PyDict::new(py), - inaccessible: [PyDict::new(py), PyDict::new(py), PyDict::new(py)], - visibility: [PyDict::new(py), PyDict::new(py), PyDict::new(py)], - }; - let mut records_by_identity: HashMap>> = HashMap::new(); - for (resource, entry, through) in visible { - let record: Bound<'py, PyAny> = self.visibility_record(py, resource, entry, through)?; - records_by_identity - .entry(self.positions[entry.position].6) - .or_default() - .push(record); - } - for (_, entry, _) in visible { - self.add_visible_value(py, &parts, entry.position)?; - } - for position in inaccessible { - let row: &PositionRow = &self.positions[*position]; - if let Some(target) = parts.inaccessible.get(usize::from(row.3)) { - target.set_item(row.2.bind(py), row.1.bind(py))?; - } - } - for (_, entry, _) in visible { - let row: &PositionRow = &self.positions[entry.position]; - if let Some(target) = parts.visibility.get(usize::from(row.3)) { - let records: &[Bound<'py, PyAny>] = - records_by_identity.get(&row.6).map_or(&[], Vec::as_slice); - target.set_item(row.2.bind(py), PyTuple::new(py, records)?)?; - } - } - let fields: Bound<'py, PyDict> = PyDict::new(py); - fields.set_item("enums", &parts.enums)?; - fields.set_item("constants", &parts.constants)?; - fields.set_item("inaccessible_enums", &parts.inaccessible[0])?; - fields.set_item("inaccessible_constants", &parts.inaccessible[1])?; - fields.set_item("enum_visibility", &parts.visibility[0])?; - fields.set_item("constant_visibility", &parts.visibility[1])?; - fields.set_item("macros", &parts.macros)?; - fields.set_item("macro_records", &parts.macro_records)?; - fields.set_item("macro_visibility", &parts.visibility[2])?; - fields.set_item("inaccessible_macros", &parts.inaccessible[2])?; - fields.set_item("consumer", consumer)?; - self.classes - .resolution_context - .bind(py) - .call((), Some(&fields)) - } - - fn add_visible_value<'py>( - &self, - py: Python<'py>, - parts: &ContextParts<'py>, - position: usize, - ) -> PyResult<()> { - let row: &PositionRow = &self.positions[position]; - let name: &Bound<'py, PyAny> = row.2.bind(py); - let value: &Bound<'py, PyAny> = row.4.bind(py); - match row.5 { - ENUM_KIND => parts.enums.set_item(name, value), - CONSTANT_KIND => parts.constants.set_item(name, value), - MACRO_KIND => { - parts.macros.set_item(name, value)?; - parts.macro_records.set_item(name, row.1.bind(py)) - } - _ => Ok(()), - } - } - - fn visibility_record<'py>( - &self, - py: Python<'py>, - resource: &Bound<'py, PyAny>, - entry: &VisibleEntry, - through: &Option>, - ) -> PyResult> { - let none: Bound<'py, PyAny> = py.None().into_bound(py); - let reason: Bound<'py, PyAny> = self - .classes - .reasons - .bind(py) - .get_item(entry.reason.as_str())? - .unwrap_or_else(|| none.clone()); - self.visibility_record_for( - resource, - self.positions[entry.position].0.bind(py), - &reason, - through.as_ref().unwrap_or(&none), - ) - } - - /// A `VisibilityRecord` of `resource`, `declaration`, `reason` and `through`. - pub(crate) fn visibility_record_for<'py>( - &self, - resource: &Bound<'py, PyAny>, - declaration: &Bound<'py, PyAny>, - reason: &Bound<'py, PyAny>, - through: &Bound<'py, PyAny>, - ) -> PyResult> { - let py: Python<'py> = resource.py(); - let class: &Bound<'py, PyAny> = self.classes.visibility_record.bind(py); - let record: Bound<'py, PyAny> = class.call1((resource, declaration, reason, through))?; - Ok(record) - } -} - -pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { - module.add_class::()?; - Ok(()) -} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/mod.rs b/crates/sqlbuild-python/src/bindings/_helpers/scopes/mod.rs index 5c1b242f57..3ab6a93648 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scopes/mod.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/scopes/mod.rs @@ -1,20 +1,3 @@ -pub(crate) mod compile_usages; -pub(crate) mod declaration_contexts; -pub(crate) mod declaration_resolution; -pub(crate) mod getters; -pub(crate) mod placement; pub(crate) mod registration; -pub(crate) mod relationship_names; -pub(crate) mod relationship_scan; -pub(crate) mod scope_cache; pub(crate) mod scope_command; -pub(crate) mod scope_errors; -pub(crate) mod scope_index; pub(crate) mod scope_loading; -pub(crate) mod scope_lookup; -pub(crate) mod scope_objects; -pub(crate) mod scope_report_objects; -pub(crate) mod scope_reports; -pub(crate) mod scope_tolerant; -pub(crate) mod scope_validation; -pub(crate) mod scope_visibility; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/registration.rs b/crates/sqlbuild-python/src/bindings/_helpers/scopes/registration.rs index 59556826ae..745c924fe0 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scopes/registration.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/scopes/registration.rs @@ -2,22 +2,28 @@ use pyo3::prelude::{Bound, PyModule, PyResult}; -use crate::bindings::_helpers::scopes::{ - compile_usages, declaration_contexts, relationship_names, scope_cache, scope_command, - scope_index, scope_loading, scope_lookup, scope_reports, scope_validation, scope_visibility, -}; +use crate::bindings::_helpers::scopes::{scope_command, scope_loading}; +use sqlbuild_python_front::scopes::main::checks::register_scope_validation::register_scope_validation; +use sqlbuild_python_front::scopes::main::checks::register_scope_visibility::register_scope_visibility; +use sqlbuild_python_front::scopes::main::declarations::register_declaration_contexts::register_declaration_contexts; +use sqlbuild_python_front::scopes::main::index::register_scope_cache::register_scope_cache; +use sqlbuild_python_front::scopes::main::index::register_scope_index::register_scope_index; +use sqlbuild_python_front::scopes::main::index::register_scope_lookup::register_scope_lookup; +use sqlbuild_python_front::scopes::main::relationships::register_compile_usages::register_compile_usages; +use sqlbuild_python_front::scopes::main::relationships::register_relationship_names::register_relationship_names; +use sqlbuild_python_front::scopes::main::reports::register_scope_reports::register_scope_reports; pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { - scope_index::register(module)?; - relationship_names::register(module)?; - declaration_contexts::register(module)?; - compile_usages::register(module)?; - scope_lookup::register(module)?; - scope_cache::register(module)?; + register_scope_index(module)?; + register_relationship_names(module)?; + register_declaration_contexts(module)?; + register_compile_usages(module)?; + register_scope_lookup(module)?; + register_scope_cache(module)?; scope_loading::register(module)?; - scope_reports::register(module)?; + register_scope_reports(module)?; scope_command::register(module)?; - scope_validation::register(module)?; - scope_visibility::register(module)?; + register_scope_validation(module)?; + register_scope_visibility(module)?; Ok(()) } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_command.rs b/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_command.rs index 52e8f26d74..69f9af83f1 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_command.rs @@ -14,13 +14,6 @@ use sqlbuild_scopes::scope_text::main::scope_result_failed::scope_result_failed; use sqlbuild_scopes::scope_text::models::ScopeTextRequest; use crate::bindings::_helpers::scopes::scope_loading::load_or_build_scope_index; -use crate::bindings::_helpers::scopes::scope_lookup::build_scope_lookup; -use crate::bindings::_helpers::scopes::scope_objects::ScopeClasses; -use crate::bindings::_helpers::scopes::scope_report_objects::read_result; -use crate::bindings::_helpers::scopes::scope_reports::{ - ExplainArguments, ListArguments, ReportArguments, scope_browse, scope_explain, scope_list, - scope_move_preview, scope_report, serialize_scope_report, -}; use sqlbuild_python_base::presentation_text::main::stdout_supports_color::stdout_supports_color; use sqlbuild_python_base::records::main::construct::enum_from_value::enum_from_value; use sqlbuild_python_base::records::main::construct::error_class::error_class; @@ -29,6 +22,18 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_keywords; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::scopes::main::index::build_scope_lookup::build_scope_lookup; +use sqlbuild_python_front::scopes::main::reports::read_result::read_result; +use sqlbuild_python_front::scopes::main::reports::scope_browse::scope_browse; +use sqlbuild_python_front::scopes::main::reports::scope_explain::scope_explain; +use sqlbuild_python_front::scopes::main::reports::scope_list::scope_list; +use sqlbuild_python_front::scopes::main::reports::scope_move_preview::scope_move_preview; +use sqlbuild_python_front::scopes::main::reports::scope_report::scope_report; +use sqlbuild_python_front::scopes::main::reports::serialize_scope_report::serialize_scope_report; +use sqlbuild_python_front::scopes::models::ExplainArguments; +use sqlbuild_python_front::scopes::models::ListArguments; +use sqlbuild_python_front::scopes::models::ReportArguments; +use sqlbuild_python_front::scopes::models::ScopeClasses; const TARGET_ERROR_CODE: &str = "C960"; const BARE_USAGE: &str = "bare names work for models, sources, seeds and functions; write macros, \ diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_loading.rs b/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_loading.rs index bbf1e815ee..8f9d283296 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_loading.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_loading.rs @@ -14,16 +14,8 @@ use sqlbuild_host::entries::models::{AdapterHost, UserCodeHost}; use crate::bindings::_helpers::compile_driver::discovery::discover_project_inputs; use crate::bindings::_helpers::compile_driver::inputs::{InputsRequest, attached_inputs}; use crate::bindings::_helpers::compile_driver::project::compile_adapter_context; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_effective_adapter_name; -use crate::bindings::_helpers::discovery::scope_snapshot::discover_scope_snapshot; use crate::bindings::_helpers::frontier::cache_directory::cache_directory; use crate::bindings::_helpers::frontier::compile_frontier::{FrontierStage, bridged, produced}; -use crate::bindings::_helpers::scopes::scope_cache::{ - project_fingerprint, read_scope_index_cache, write_scope_index_cache, -}; -use crate::bindings::_helpers::scopes::scope_index::open_native_scope_index; -use crate::bindings::_helpers::scopes::scope_tolerant::scope_tolerant_index; -use crate::bindings::_helpers::scopes::scope_validation::scope_index_with_compile_usages; use crate::bindings::_helpers::sql_test_glue::constants::SQL_TEST_EXPECTED_MODELS_SCAN_ALGORITHM; use pyo3::IntoPyObjectExt; use sqlbuild_python_base::boundary::main::call_with::call_with; @@ -31,6 +23,14 @@ use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; +use sqlbuild_python_front::discovery::main::snapshots::discover_scope_snapshot::discover_scope_snapshot; +use sqlbuild_python_front::scopes::main::checks::scope_index_with_compile_usages::scope_index_with_compile_usages; +use sqlbuild_python_front::scopes::main::checks::scope_tolerant_index::scope_tolerant_index; +use sqlbuild_python_front::scopes::main::index::open_native_scope_index::open_native_scope_index; +use sqlbuild_python_front::scopes::main::index::project_fingerprint::project_fingerprint; +use sqlbuild_python_front::scopes::main::index::read_scope_index_cache::read_scope_index_cache; +use sqlbuild_python_front::scopes::main::index::write_scope_index_cache::write_scope_index_cache; const SCOPE_CACHE_DIRECTORY_NAME: &str = "declaration-scopes-v2"; const SCOPE_CACHE_FILENAME: &str = "scope-index.json"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/seed_command/command.rs b/crates/sqlbuild-python/src/bindings/_helpers/seed_command/command.rs index 9062640ff8..74fc45deaa 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/seed_command/command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/seed_command/command.rs @@ -18,7 +18,6 @@ use sqlbuild_host::entries::models::ExecutorHost; use crate::bindings::_helpers::build_progress::progress_reporters::ConnectionProgressReporter; use crate::bindings::_helpers::build_progress::progress_text::write_execution_header; -use crate::bindings::_helpers::command_runtime::concurrency::resolve_concurrency; use crate::bindings::_helpers::command_runtime::invocation::resolve_command_invocation; use crate::bindings::_helpers::compile_driver::pipeline_entries::build_static_pipeline_result; use crate::bindings::_helpers::compile_driver::plan_result::connection_with_hooks; @@ -39,6 +38,7 @@ use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_keywords; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::command_runtime::main::resolve_concurrency::resolve_concurrency; const SUCCESS_STATUS: &str = "success"; const FAILED_STATUS: &str = "failed"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/semantic_checks/metadata.rs b/crates/sqlbuild-python/src/bindings/_helpers/semantic_checks/metadata.rs index fc4d1568a6..cbbae49101 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/semantic_checks/metadata.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/semantic_checks/metadata.rs @@ -15,9 +15,6 @@ use sqlbuild_model_config::header_metadata::constants::ACCEPTED_VALUES_ARGUMENT; use crate::bindings::_helpers::compiled_views::compiled_model_view::NativeCompiledModel; use crate::bindings::_helpers::compiled_views::model_reads::binding_validated; -use crate::bindings::_helpers::model_config::config_nodes::PyConfigNode; -use crate::bindings::_helpers::model_config::header_audits::AuditInstance; -use crate::bindings::_helpers::model_config::header_metadata::HeaderValue; use crate::bindings::_helpers::semantic_checks::failures::semantic_error; use crate::bindings::_helpers::semantic_checks::inputs::{ column_names, resource_sql_diagnostics, sql_test_columns, @@ -32,6 +29,9 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get::mapping_get; use sqlbuild_python_base::records::main::fields::mapping_items::mapping_items; use sqlbuild_python_base::types::CompilerDetach; +use sqlbuild_python_front::model_config::models::AuditInstance; +use sqlbuild_python_front::model_config::types::HeaderValue; +use sqlbuild_python_front::model_config::types::PyConfigNode; /// `SqlReferenceKind.UDF` and `SqlReferenceKind.TABLE_FUNCTION` values. const FUNCTION_REFERENCE_KINDS: [&str; 2] = ["udf", "table_fn"]; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/semantic_shapes/source_bindings.rs b/crates/sqlbuild-python/src/bindings/_helpers/semantic_shapes/source_bindings.rs index da8ce29f46..0cc5d322ae 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/semantic_shapes/source_bindings.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/semantic_shapes/source_bindings.rs @@ -13,7 +13,6 @@ use crate::bindings::_helpers::analysis::schema_request::{ SchemaRequestParts, schema_validation_request, }; use crate::bindings::_helpers::analysis_session::stage_functions::infer_native_query_columns; -use crate::bindings::_helpers::attachments::cursor_intrinsics::analysis_cursor_sql; use crate::bindings::_helpers::semantic_shapes::constants::SOURCE_REBINDING_ANALYSES; use crate::bindings::_helpers::semantic_shapes::declarations::{declared_types, function_names}; use crate::bindings::_helpers::semantic_shapes::shapes::{ @@ -30,6 +29,7 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_items::mapping_items; use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_keywords; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::attachments::main::analysis_cursor_sql::analysis_cursor_sql; use sqlbuild_sqltext::resolution::main::unquoted_column_name::unquoted_column_name; const BINDING_UNKNOWN_TABLE_INTERNAL_CODE: &str = "B000"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/test_command.rs b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/test_command.rs index cd434692d9..a721a2c9df 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/test_command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/test_command.rs @@ -36,7 +36,6 @@ use crate::bindings::_helpers::change_selection::base_snapshot::{ use crate::bindings::_helpers::change_selection::selection::{ ChangedProject, changed_project, tests_and_models, with_since_section, }; -use crate::bindings::_helpers::command_runtime::concurrency::resolve_concurrency; use crate::bindings::_helpers::command_runtime::invocation::resolve_reported_command_invocation; use crate::bindings::_helpers::compile_driver::pipeline_entries::build_static_pipeline_result; use crate::bindings::_helpers::compile_driver::static_context::compile_static_command_context; @@ -70,6 +69,7 @@ use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced::replaced; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::command_runtime::main::resolve_concurrency::resolve_concurrency; /// Why `--since` selected each test, by inspection label. type SelectionReasons = HashMap>; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/timeouts.rs b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/timeouts.rs index 99f7b4d756..ac94e0c23f 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/timeouts.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/timeouts.rs @@ -9,10 +9,10 @@ use pyo3::{pyfunction, wrap_pyfunction}; use sqlbuild_model_config::execution_limits::main::parse_execution_limit::parse_execution_limit; use sqlbuild_model_config::execution_limits::models::ExecutionLimit; -use crate::bindings::_helpers::contracts::spec_resolution::resolve_target_config; use sqlbuild_python_base::records::main::construct::new_error::new_error; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; +use sqlbuild_python_front::contracts::main::resolve_target_config::resolve_target_config; const INVALID_TIMEOUT_CODE: &str = "C418"; const LOCAL_FILE: &str = "sqlbuild_local.toml"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/assembly.rs b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/assembly.rs index cee12a05bc..477491e529 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/assembly.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/assembly.rs @@ -13,13 +13,13 @@ use sqlbuild_analysis::compiler::models::{ use sqlbuild_core::panics::main::native_failure::native_failure; use crate::bindings::_helpers::compiled_views::model_input_view::NativeModelInput; -use crate::bindings::_helpers::sqltext::lexical_syntax::LexicalSyntaxInput; use sqlbuild_project::models::ReferenceRow; use sqlbuild_python_base::boundary::main::value_error::value_error; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::path_posix_text::path_posix_text; use sqlbuild_python_base::records::main::fields::path_stem::path_stem; use sqlbuild_python_base::types::CompilerDetach; +use sqlbuild_python_front::sqltext::models::LexicalSyntaxInput; const MACRO_TOKEN: char = '@'; const INPUT_FAILURE: &str = "input"; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/cursor_window.rs b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/cursor_window.rs index 8af42fa725..b9ab6050b2 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/cursor_window.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/cursor_window.rs @@ -8,13 +8,7 @@ use sqlbuild_cursor::algebra::main::compare::compare; use sqlbuild_cursor::algebra::main::floor_to_grain::floor_to_grain; use sqlbuild_cursor::algebra::models::{Grain, Scalar}; -use crate::bindings::_helpers::attachments::cursor_intrinsics::{ - compile_input_error, resolve_cursor_intrinsics, -}; use crate::bindings::_helpers::compiled_views::model_reads; -use crate::bindings::_helpers::cursor::conversion::CursorSession; -use crate::bindings::_helpers::cursor::scalars::{parse_value, render_value}; -use crate::bindings::_helpers::model_config::typed_config::{config_text_object, model_values}; use crate::bindings::_helpers::sql_test_glue::constants::{ CURSOR_ALGEBRA_EXCEPTIONS, CURSOR_END_KEY, CURSOR_START_KEY, DEFAULT_INTEGER_END, DEFAULT_INTEGER_START, DEFAULT_TIMESTAMP_END, DEFAULT_TIMESTAMP_START, INTEGER_CURSOR_TYPE, @@ -26,6 +20,13 @@ use sqlbuild_python_base::records::main::construct::enum_from_value::enum_from_v use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::attachments::main::compile_input_error::compile_input_error; +use sqlbuild_python_front::attachments::main::resolve_cursor_intrinsics::resolve_cursor_intrinsics; +use sqlbuild_python_front::cursor::main::scalars::parse_value::parse_value; +use sqlbuild_python_front::cursor::main::scalars::render_value::render_value; +use sqlbuild_python_front::cursor::models::CursorSession; +use sqlbuild_python_front::model_config::main::config::config_text_object::config_text_object; +use sqlbuild_python_front::model_config::main::config::model_values::model_values; /// One model's cursor name, type and timestamp grain. struct ModelCursor<'py> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/mod.rs b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/mod.rs index 2ff1cb2cb8..ac3d60ae0a 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/mod.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/mod.rs @@ -1,5 +1,4 @@ pub(crate) mod assembly; -pub(crate) mod authored_ctes; pub(crate) mod compiled_tests; pub(crate) mod constants; mod cursor_window; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/plan_entries.rs b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/plan_entries.rs index 6e8c36474c..01f3019e20 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/plan_entries.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/plan_entries.rs @@ -14,9 +14,9 @@ use sqlbuild_analysis::compiler::main::missing_expected_columns::missing_expecte use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::construct::record_class::record_class; -use crate::bindings::_helpers::sql_test_glue::authored_ctes::prefixed_ctes; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::RecordId; +use sqlbuild_python_front::sql_test_glue::main::prefixed_ctes::prefixed_ctes; fn prefixed_names<'py>(test: &Bound<'py, PyAny>, prefix: &str) -> PyResult> { let py = test.py(); diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/plan_fixtures.rs b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/plan_fixtures.rs index 965cac65cf..4e5953ee77 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/plan_fixtures.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/plan_fixtures.rs @@ -4,13 +4,13 @@ use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult}; use pyo3::types::{PyDict, PyDictMethods, PyTuple}; use crate::bindings::_helpers::planner_strategy::models::RelationFixturePlanningContext; -use crate::bindings::_helpers::sql_test_glue::authored_ctes::prefixed_ctes; use crate::bindings::_helpers::sql_test_glue::fixture_validation::validated_fixtures; use crate::bindings::_helpers::sql_test_glue::plan_driver::resolve_sql_test_model_chains; use crate::bindings::_helpers::sql_test_glue::plan_values::model_payload; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_get_or::mapping_get_or; use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_keywords; +use sqlbuild_python_front::sql_test_glue::main::prefixed_ctes::prefixed_ctes; pub(super) fn validated_test<'py>( test: &Bound<'py, PyAny>, diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/planning.rs b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/planning.rs index 587de8a5e9..45a0cfcced 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/planning.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/planning.rs @@ -13,10 +13,10 @@ use sqlbuild_analysis::compiler::models::{ }; use crate::bindings::_helpers::compiled_views::model_reads; -use crate::bindings::_helpers::sqltext::lexical_syntax::LexicalSyntaxInput; use sqlbuild_python_base::boundary::main::value_error::value_error; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::types::CompilerDetach; +use sqlbuild_python_front::sqltext::models::LexicalSyntaxInput; const MODEL_RESOURCE_TYPE: &str = "model"; const PLANNING_WORKERS: usize = 4; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/registration.rs b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/registration.rs index 9b9f6f8a0d..8c7176fe72 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/registration.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/registration.rs @@ -3,7 +3,8 @@ use pyo3::prelude::{Bound, PyModule, PyModuleMethods, PyResult}; use pyo3::wrap_pyfunction; -use crate::bindings::_helpers::sql_test_glue::{authored_ctes, compiled_tests}; +use crate::bindings::_helpers::sql_test_glue::compiled_tests; +use sqlbuild_python_front::sql_test_glue::main::register_authored_ctes::register_authored_ctes; pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { module.add_function(wrap_pyfunction!( @@ -22,6 +23,6 @@ pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { super::plan_driver::sql_test_plan_error_messages, module )?)?; - authored_ctes::register(module)?; + register_authored_ctes(module)?; compiled_tests::register(module) } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sqltext/code_scanner.rs b/crates/sqlbuild-python/src/bindings/_helpers/sqltext/code_scanner.rs deleted file mode 100644 index 0e2b6ebdff..0000000000 --- a/crates/sqlbuild-python/src/bindings/_helpers/sqltext/code_scanner.rs +++ /dev/null @@ -1,67 +0,0 @@ -//! Comment, quoted-text and parenthesis boundaries at Python string offsets of one SQL text. - -use pyo3::prelude::{ - Bound, PyAny, PyAnyMethods, PyErr, PyModule, PyModuleMethods, PyResult, Python, -}; -use pyo3::{pyclass, pymethods}; -use sqlbuild_sqltext::code_scanner::main::code_scanner::code_scanner; -use sqlbuild_sqltext::code_scanner::main::scanner_matching_paren::scanner_matching_paren; -use sqlbuild_sqltext::code_scanner::main::scanner_non_code_end::scanner_non_code_end; -use sqlbuild_sqltext::code_scanner::models::CodeScanner; -use sqlbuild_sqltext::sql_scan::models::Unclosed; - -use crate::bindings::_helpers::sqltext::lexical_syntax::LexicalSyntaxInput; -use sqlbuild_python_base::records::main::construct::error_class::error_class; -use sqlbuild_python_base::records::types::ErrorId; - -/// One SQL text scanned under an adapter's lexical rules, or the generic compiler rules. -#[pyclass(module = "sqlbuild._native", frozen)] -pub(crate) struct SqlCodeScanner { - scanner: CodeScanner, - context: String, -} - -#[pymethods] -impl SqlCodeScanner { - #[new] - #[pyo3(signature = (sql, syntax, context))] - pub(crate) fn new(sql: &str, syntax: Option, context: String) -> Self { - Self { - scanner: code_scanner(sql, syntax.map(Into::into)), - context, - } - } - - /// The end of the comment or quoted text at `index`, or `None` when code starts there. - pub(crate) fn non_code_end(&self, py: Python<'_>, index: usize) -> PyResult> { - scanner_non_code_end(&self.scanner, index).map_err(|unclosed| self.error(py, unclosed)) - } - - /// The index of the parenthesis closing the one at `open`. - pub(crate) fn matching_paren(&self, py: Python<'_>, open: usize) -> PyResult { - scanner_matching_paren(&self.scanner, open).map_err(|unclosed| self.error(py, unclosed)) - } -} - -impl SqlCodeScanner { - /// `CompileInputError(" contains an unclosed ...")`. - fn error(&self, py: Python<'_>, unclosed: Unclosed) -> PyErr { - let construct: &str = match unclosed { - Unclosed::BlockComment => "block comment", - Unclosed::Quote => "quoted string", - Unclosed::Parenthesis => "parenthesis", - }; - let message: String = format!("{} contains an unclosed {construct}", self.context); - let raised = || -> PyResult { - let error: Bound<'_, PyAny> = - error_class(py, ErrorId::CompileInput)?.call1((message,))?; - Ok(PyErr::from_value(error)) - }; - raised().unwrap_or_else(|error| error) - } -} - -pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { - module.add_class::()?; - Ok(()) -} diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sqltext/mod.rs b/crates/sqlbuild-python/src/bindings/_helpers/sqltext/mod.rs index 670af7fcaa..7444bd0374 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sqltext/mod.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/sqltext/mod.rs @@ -1,10 +1 @@ -pub(crate) mod authored_values; -pub(crate) mod code_scanner; -pub(crate) mod ddl_effects; -pub(crate) mod declaration_references; -pub(crate) mod lexical_syntax; -pub(crate) mod model_headers; -pub(crate) mod placeholders; pub(crate) mod registration; -pub(crate) mod sql_references; -pub(crate) mod static_sql; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sqltext/registration.rs b/crates/sqlbuild-python/src/bindings/_helpers/sqltext/registration.rs index 655c754951..c9a5f48cf3 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sqltext/registration.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/sqltext/registration.rs @@ -2,15 +2,17 @@ use pyo3::prelude::{Bound, PyModule, PyResult}; -use crate::bindings::_helpers::sqltext::{ - code_scanner, ddl_effects, model_headers, placeholders, sql_references, -}; +use sqlbuild_python_front::sqltext::main::register_code_scanner::register_code_scanner; +use sqlbuild_python_front::sqltext::main::register_ddl_effects::register_ddl_effects; +use sqlbuild_python_front::sqltext::main::register_model_headers::register_model_headers; +use sqlbuild_python_front::sqltext::main::register_placeholders::register_placeholders; +use sqlbuild_python_front::sqltext::main::register_sql_references::register_sql_references; pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { - model_headers::register(module)?; - code_scanner::register(module)?; - sql_references::register(module)?; - placeholders::register(module)?; - ddl_effects::register(module)?; + register_model_headers(module)?; + register_code_scanner(module)?; + register_sql_references(module)?; + register_placeholders(module)?; + register_ddl_effects(module)?; Ok(()) } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/mod.rs b/crates/sqlbuild-python/src/bindings/_helpers/state_rows/mod.rs index 59acf36d54..7444bd0374 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/mod.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/state_rows/mod.rs @@ -1,11 +1 @@ -pub(crate) mod constants; -pub(crate) mod events; -pub(crate) mod freshness; -pub(crate) mod migration_io; -pub(crate) mod migration_objects; -pub(crate) mod migration_projections; -pub(crate) mod migration_rows; -pub(crate) mod models; pub(crate) mod registration; -pub(crate) mod state_tables; -pub(crate) mod timestamps; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/registration.rs b/crates/sqlbuild-python/src/bindings/_helpers/state_rows/registration.rs index cb78b58903..1137b4acb4 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/state_rows/registration.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/state_rows/registration.rs @@ -2,16 +2,19 @@ use pyo3::prelude::{Bound, PyModule, PyResult}; -use crate::bindings::_helpers::state_rows::{ - events, freshness, migration_io, migration_projections, migration_rows, state_tables, -}; +use sqlbuild_python_front::state_rows::main::event_rows::register_events::register_events; +use sqlbuild_python_front::state_rows::main::event_rows::register_freshness::register_freshness; +use sqlbuild_python_front::state_rows::main::migrations::register_migration_io::register_migration_io; +use sqlbuild_python_front::state_rows::main::migrations::register_migration_projections::register_migration_projections; +use sqlbuild_python_front::state_rows::main::migrations::register_migration_rows::register_migration_rows; +use sqlbuild_python_front::state_rows::main::tables::register_state_tables::register_state_tables; pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { - events::register(module)?; - freshness::register(module)?; - migration_rows::register(module)?; - migration_io::register(module)?; - migration_projections::register(module)?; - state_tables::register(module)?; + register_events(module)?; + register_freshness(module)?; + register_migration_rows(module)?; + register_migration_io(module)?; + register_migration_projections(module)?; + register_state_tables(module)?; Ok(()) } diff --git a/crates/sqlbuild-python/src/bindings/models.rs b/crates/sqlbuild-python/src/bindings/models.rs index ce1d809570..b48ee3ef23 100644 --- a/crates/sqlbuild-python/src/bindings/models.rs +++ b/crates/sqlbuild-python/src/bindings/models.rs @@ -98,67 +98,6 @@ impl From for validation::PositionInput { } } -/// The directory listings one discovery pass shares across its native calls. -#[pyclass(module = "sqlbuild._native", frozen)] -#[derive(Debug)] -pub(crate) struct NativeProjectTree { - pub(crate) inner: sqlbuild_discovery::tree::models::ProjectTree, -} - -/// One discovery pass of a project: the memo its native calls share, active inside its scope. -#[pyclass(module = "sqlbuild._native", frozen)] -#[derive(Debug)] -pub(crate) struct NativeDirectorySnapshot { - pub(crate) project_dir: pyo3::Py, - pub(crate) memo: pyo3::Py, -} - -/// The context manager that makes one snapshot active for a project until it exits. -#[pyclass(module = "sqlbuild._native")] -#[derive(Debug)] -pub(crate) struct NativeDirectorySnapshotScope { - pub(crate) project_dir: pyo3::Py, - /// The context-variable token of the snapshot this scope activated, if it activated one. - pub(crate) token: Option>, -} - -/// One native YAML file discovery request; `kind` is `source` or `schema`. -#[derive(FromPyObject, Debug)] -#[pyo3(from_item_all)] -pub(crate) struct YamlDiscoveryRequest { - pub(crate) project_dir: String, - pub(crate) display_prefix: String, - pub(crate) kind: String, -} - -/// One in-memory SQL model parse request; `file_path` is the path messages name. -#[derive(FromPyObject, Debug)] -#[pyo3(from_item_all)] -pub(crate) struct ModelTextRequest { - pub(crate) file_path: String, - pub(crate) supported_keys: Vec, - pub(crate) removed_keys: Vec, - pub(crate) extract_implicit_alias_columns: bool, - pub(crate) extract_output_column_locations: bool, -} - -/// The declaration collections one Python discovery pass read natively, kept for later stages. -#[pyclass(module = "sqlbuild._native", frozen)] -#[derive(Debug)] -pub(crate) struct NativeDiscoverySession { - pub(crate) inner: sqlbuild_discovery::declaration_files::models::DiscoverySession, -} - -/// One in-memory declaration file parse request; `kind` names the collection it belongs to. -#[derive(FromPyObject, Debug)] -#[pyo3(from_item_all)] -pub(crate) struct DeclarationTextRequest { - pub(crate) kind: String, - pub(crate) function_keys: Vec, - pub(crate) audit_keys: Vec, - pub(crate) hook_keys: Vec, -} - /// A record of another crate exchanged with Python as its positional tuple. #[derive(Clone, Debug)] pub(crate) struct Positional(pub(crate) T); diff --git a/fensu.toml b/fensu.toml index 0868e9b020..8e8fb2c0f1 100644 --- a/fensu.toml +++ b/fensu.toml @@ -1445,7 +1445,7 @@ paths = ["crates/sqlbuild-python/src/bindings/_helpers/execution_history/postgre reason = "PostgreSQL and SQLite execution history each read a page through their own connection, locking and cursor keys; filters and record conversion come from conversion.rs." [[dupes.allowlist]] -paths = ["crates/sqlbuild-python/src/bindings/_helpers/compile_command/prepared_artifacts.rs", "crates/sqlbuild-python/src/bindings/_helpers/cursor/scalars.rs", "crates/sqlbuild-python-base/src/diagnostics/_helpers/log_records.rs", "crates/sqlbuild-python/src/bindings/_helpers/execution_history/conversion.rs", "crates/sqlbuild-python/src/bindings/_helpers/rules/fix_session.rs", "crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_rows.rs"] +paths = ["crates/sqlbuild-python/src/bindings/_helpers/compile_command/prepared_artifacts.rs", "crates/sqlbuild-python-front/src/cursor/_helpers/scalars.rs", "crates/sqlbuild-python-base/src/diagnostics/_helpers/log_records.rs", "crates/sqlbuild-python/src/bindings/_helpers/execution_history/conversion.rs", "crates/sqlbuild-python/src/bindings/_helpers/rules/fix_session.rs", "crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_rows.rs"] reason = "Each turns the one Python exception its own call can expect into None; the calls and the exceptions they accept differ." [[dupes.allowlist]] @@ -1492,10 +1492,6 @@ reason = "Metadata sync keeps its pending page for retry and work polling drops paths = ["crates/sqlbuild-cli/src/workers/_helpers/child.rs"] reason = "terminate and kill are the two escalation steps for a worker child; each maps every child kind to its own signal." -[[dupes.allowlist]] -paths = ["crates/sqlbuild-python/src/bindings/_helpers/command_runtime/warehouse_scope.rs", "crates/sqlbuild-python-base/src/event_exporting/_helpers/scope.rs", "crates/sqlbuild-python/src/bindings/_helpers/native_host/consumption_state.rs", "crates/sqlbuild-python/src/bindings/_helpers/output_capture/context.rs", "crates/sqlbuild-python/src/bindings/_helpers/result_output/terminal_index.rs"] -reason = "Each context object takes its own resource out of its own lock and releases it the way that resource needs; only the take-under-lock shape is shared." - [[targets.python.rule_exceptions]] rule = "XSB051" path = "src/sqlbuild/executor/scenario/_helpers/lifecycle/cleanup.py" @@ -1680,9 +1676,8 @@ select = ["FPRS", "XSB072", "XSB073", "XSB075", "XSB076", "XSB077", "XSB078", "X [[targets.rust.threshold_overrides]] paths = ["crates/sqlbuild-python/Cargo.toml"] -# Raised from 197,891: SQBRPERFORMANCE102 bindings plumbing, +77 with sqlbuild-python-base. -thresholds = { max_crate_code_lines = 197963 } -reason = "The Python bindings crate is above the code-line limit; this caps it at its current size until it is split into crates by area. Lower the cap as code moves out. Set after #1514 moved the shared runtime into sqlbuild-python-base, plus 4 lines for the janitor preserve check from #1512." +thresholds = { max_crate_code_lines = 169863 } +reason = "The Python bindings crate is above the code-line limit; this caps it at its current size until it is split into crates by area. Lower the cap as code moves out." [[targets.rust.threshold_overrides]] paths = ["crates/sqlbuild-python/src/bindings/_helpers"] @@ -1705,13 +1700,16 @@ allowed = [ allowed_paths = [ "crates/sqlbuild-core/src/constants.rs=Names the observation state table.", "crates/sqlbuild-orchestration=Mirrors observations into the control store and serves them for display.", - "crates/sqlbuild-python/src/bindings/_helpers/cli/registration.rs=Registers the observation state bindings.", "crates/sqlbuild-python/src/bindings/_helpers/exported_constants=Exports the table name to Python adapters, which create it.", "crates/sqlbuild-python/src/bindings/_helpers/janitor=Prunes observation history.", - "crates/sqlbuild-python/src/bindings/_helpers/native_host/mod.rs=Declares the observation state bindings module.", - "crates/sqlbuild-python/src/bindings/_helpers/native_host/observations_state.rs=Renders observation state SQL for adapters.", + "crates/sqlbuild-python-front/src/native_host/_helpers/observations_state.rs=Renders observation state SQL for adapters.", "crates/sqlbuild-python/src/bindings/_helpers/native_host/warehouse_metadata.rs=Reads observations for the control-store mirror.", + "crates/sqlbuild-python-front/src/native_host/_helpers/mod.rs=Declares the observation state module.", + "crates/sqlbuild-python-front/src/native_host/main/append_observations.rs=Writes observations after a build.", + "crates/sqlbuild-python-front/src/native_host/main/register_observations_state.rs=Registers the observation state bindings.", + "crates/sqlbuild-python/src/bindings/_helpers/cli/registration.rs=Registers the observation state bindings.", "crates/sqlbuild-python/src/bindings/_helpers/observations=Writes observations after a build.", + "crates/sqlbuild-python-front/src/native_host/main/mod.rs=Declares the observation write and registration entries.", ] [targets.rust.rule_options.XSB079] @@ -1719,7 +1717,6 @@ allowed_paths = [ "crates/sqlbuild-cli/src/native_commands/main/_location_plan.rs=A location's requested plan names the synced copy for its sqb plan child.", "crates/sqlbuild-core/src/plan_display/constants.rs=Names the synced-copy environment variable.", "crates/sqlbuild-python/src/bindings/_helpers/freshness/planning.rs=Preview branch: a refused freshness observation leaves the source unknown.", - "crates/sqlbuild-python/src/bindings/_helpers/native_host/consumption_state.rs=Preview branch: --changed reads consumption history from the copy instead of the warehouse table.", "crates/sqlbuild-python/src/bindings/_helpers/native_host/registration.rs=Registers the synced copy's refusal error with Python.", "crates/sqlbuild-python-base/src/warehouse_access/_helpers/synced_copy.rs=Defines the synced-copy adapter.", "crates/sqlbuild-python-base/src/warehouse_access/main/register_synced_copy.rs=Registers the synced copy's refusal error with Python.", @@ -1733,6 +1730,7 @@ allowed_paths = [ "crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/source_columns.rs=Preview branch: expression columns from the copy instead of DESCRIBE.", "crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/source_freshness.rs=Preview branch: the copy has no source freshness state to read.", "crates/sqlbuild-python/src/bindings/_helpers/planner_warehouse/source_tables.rs=Preview branch: sources outside the copy are not probed.", + "crates/sqlbuild-python-front/src/native_host/models.rs=Preview branch: --changed reads consumption history from the copy instead of the warehouse table.", ] [targets.rust.rule_options.XSB077] @@ -1760,6 +1758,42 @@ path = "crates/sqlbuild-python-base/src/native_host/models.rs" symbols = ["AuditProjection", "FamilyProjection"] reason = "The header projections implement Debug manually because their cached public tuples sit in a PyOnceLock, which does not implement Debug; other models derive it." +[[targets.rust.rule_exceptions]] +rule = "FPRSS201" +path = "crates/sqlbuild-python-front/src/cursor/models.rs" +symbols = ["CursorSession"] +reason = "CursorSession implements Debug manually because it holds the interpreter token, which does not implement Debug; other models derive it." + +[[targets.rust.rule_exceptions]] +rule = "FPRSS201" +path = "crates/sqlbuild-python-front/src/discovery/models.rs" +symbols = ["NativeModelFile"] +reason = "NativeModelFile implements Debug manually because its cached Python texts sit in PyOnceLocks, which do not implement Debug; other models derive it." + +[[targets.rust.rule_exceptions]] +rule = "FPRSS201" +path = "crates/sqlbuild-python-front/src/model_config/models.rs" +symbols = ["PythonHost", "HeaderColumn", "HeaderColumns"] +reason = "PythonHost implements Debug manually because it holds the interpreter token, which does not implement Debug, and the header columns because their cached projections sit in a PyOnceLock, which does not implement Debug; other models derive it." + +[[targets.rust.rule_exceptions]] +rule = "FPRSS201" +path = "crates/sqlbuild-python-front/src/render/models.rs" +symbols = ["SqlMacroSource"] +reason = "SqlMacroSource implements Debug manually because it borrows the macro scopes as a trait object, which does not implement Debug; other models derive it." + +[[targets.rust.rule_exceptions]] +rule = "FPRSS201" +path = "crates/sqlbuild-python-front/src/scopes/models.rs" +symbols = ["ScopeClasses"] +reason = "ScopeClasses implements Debug manually because it holds the interpreter token, which does not implement Debug; other models derive it." + +[[targets.rust.rule_exceptions]] +rule = "FPRSS012" +path = "crates/sqlbuild-python-front/src/render/types.rs" +symbols = ["StateTuple"] +reason = "Python passes the expansion state as one five-item tuple; StateInput reads it in a single tuple extraction and names each position, as the positional record it replaces did." + [[targets.rust.rule_exceptions]] rule = "FPRSR307" path = "crates/sqlbuild-rules/src/scope_metadata/main.rs" @@ -1920,6 +1954,7 @@ crate_names = [ "sqlbuild-project", "sqlbuild-pysource", "sqlbuild-python-base", + "sqlbuild-python-front", "sqlbuild-python", "sqlbuild-recall", "sqlbuild-refactor", @@ -1937,7 +1972,7 @@ paths = ["src/sqlbuild/adapter/contract/classes/*", "src/sqlbuild/adapters/*/cla reason = "tests/unit/src/sqlbuild/adapter/contract/classes/strict_adapter/test_strict_adapter.py requires every first-class adapter to define each StrictAdapter method itself instead of inheriting it from BaseAdapter." [[dupes.allowlist]] -paths = ["crates/sqlbuild-python/src/bindings/_helpers/native_host/audit_results_state.rs", "crates/sqlbuild-python/src/bindings/_helpers/native_host/consumption_state.rs", "crates/sqlbuild-python/src/bindings/_helpers/native_host/observations_state.rs", "crates/sqlbuild-python/src/bindings/_helpers/native_host/resource_costs_state.rs"] +paths = ["crates/sqlbuild-python-front/src/native_host/_helpers/audit_results_state.rs", "crates/sqlbuild-python-front/src/native_host/_helpers/consumption_state.rs", "crates/sqlbuild-python-front/src/native_host/_helpers/observations_state.rs", "crates/sqlbuild-python/src/bindings/_helpers/native_host/resource_costs_state.rs"] reason = "Each state table has its own Python-facing create and prune bindings. The DDL and table naming live in the shared fixed_state_table_sql and state_table_name; each prune keeps its own retention rule." [[dupes.allowlist]] @@ -1990,6 +2025,7 @@ edge_paths = [ "crates/sqlbuild-python-base/src/records/_helpers/native_classes/registry.rs", "crates/sqlbuild-python-base/src/records/main/registry/native_attr.rs", "crates/sqlbuild-python-base/src/warehouse_access", + "crates/sqlbuild-python-front/src/native_host", "crates/sqlbuild-python/src/bindings/_helpers/native_host", ] pending_budgets = [ @@ -2030,6 +2066,98 @@ pending_budgets = [ "crates/sqlbuild-python-base/src/records/_helpers/native_classes/registration.rs=26", "crates/sqlbuild-python-base/src/records/_helpers/planner_records/constants.rs=2", "crates/sqlbuild-python-base/src/type_system/_helpers/equality.rs=3", + "crates/sqlbuild-python-front/src/attachments/_helpers/cursor_intrinsics.rs=1", + "crates/sqlbuild-python-front/src/attachments/_helpers/reference_markers.rs=3", + "crates/sqlbuild-python-front/src/authored_values/_helpers/fields.rs=1", + "crates/sqlbuild-python-front/src/authored_values/_helpers/project_vars.rs=3", + "crates/sqlbuild-python-front/src/authored_values/_helpers/python_nodes.rs=3", + "crates/sqlbuild-python-front/src/authored_values/_helpers/sql_values.rs=10", + "crates/sqlbuild-python-front/src/authored_values/models.rs=2", + "crates/sqlbuild-python-front/src/compile_attachment/_helpers/effective_config.rs=4", + "crates/sqlbuild-python-front/src/compile_driver/_helpers/config_validation.rs=2", + "crates/sqlbuild-python-front/src/contracts/_helpers/effective_config.rs=2", + "crates/sqlbuild-python-front/src/contracts/_helpers/spec_resolution.rs=9", + "crates/sqlbuild-python-front/src/cursor/_helpers/durations.rs=2", + "crates/sqlbuild-python-front/src/cursor/_helpers/intervals.rs=1", + "crates/sqlbuild-python-front/src/cursor/_helpers/overrides.rs=7", + "crates/sqlbuild-python-front/src/cursor/_helpers/scalars.rs=13", + "crates/sqlbuild-python-front/src/cursor/_helpers/values.rs=4", + "crates/sqlbuild-python-front/src/cursor/models.rs=5", + "crates/sqlbuild-python-front/src/discovery/_helpers/failures/faults.rs=2", + "crates/sqlbuild-python-front/src/discovery/_helpers/failures/raised.rs=9", + "crates/sqlbuild-python-front/src/discovery/_helpers/headers/header_declarations.rs=5", + "crates/sqlbuild-python-front/src/discovery/_helpers/headers/header_values.rs=1", + "crates/sqlbuild-python-front/src/discovery/_helpers/headers/hook_entries.rs=2", + "crates/sqlbuild-python-front/src/discovery/_helpers/project/locations.rs=4", + "crates/sqlbuild-python-front/src/discovery/_helpers/project/project_config.rs=16", + "crates/sqlbuild-python-front/src/discovery/_helpers/project/project_facts.rs=6", + "crates/sqlbuild-python-front/src/discovery/_helpers/project/project_files.rs=3", + "crates/sqlbuild-python-front/src/discovery/_helpers/project/project_validation.rs=6", + "crates/sqlbuild-python-front/src/discovery/_helpers/python_files/imported_modules.rs=3", + "crates/sqlbuild-python-front/src/discovery/_helpers/python_files/imported_providers.rs=14", + "crates/sqlbuild-python-front/src/discovery/_helpers/python_files/imported_python_nodes.rs=9", + "crates/sqlbuild-python-front/src/discovery/_helpers/python_files/python_function_files.rs=15", + "crates/sqlbuild-python-front/src/discovery/_helpers/python_files/python_hook_files.rs=1", + "crates/sqlbuild-python-front/src/discovery/_helpers/records/declaration_records.rs=8", + "crates/sqlbuild-python-front/src/discovery/_helpers/records/model_records.rs=2", + "crates/sqlbuild-python-front/src/discovery/_helpers/records/sql_test_records.rs=5", + "crates/sqlbuild-python-front/src/discovery/_helpers/records/yaml_records.rs=4", + "crates/sqlbuild-python-front/src/discovery/_helpers/snapshots/scope_snapshot.rs=1", + "crates/sqlbuild-python-front/src/discovery/_helpers/snapshots/snapshot.rs=4", + "crates/sqlbuild-python-front/src/discovery/_helpers/sources/sql_test_blocks.rs=2", + "crates/sqlbuild-python-front/src/discovery/_helpers/sources/yaml_entries.rs=14", + "crates/sqlbuild-python-front/src/macro_bridge/_helpers/module_digests.rs=2", + "crates/sqlbuild-python-front/src/macro_bridge/_helpers/store_keys.rs=26", + "crates/sqlbuild-python-front/src/model_config/_helpers/config/config_classes.rs=5", + "crates/sqlbuild-python-front/src/model_config/_helpers/config/config_errors.rs=1", + "crates/sqlbuild-python-front/src/model_config/_helpers/config/config_templates.rs=4", + "crates/sqlbuild-python-front/src/model_config/_helpers/config/config_values.rs=2", + "crates/sqlbuild-python-front/src/model_config/_helpers/config/template_data.rs=4", + "crates/sqlbuild-python-front/src/model_config/_helpers/config/typed_config.rs=1", + "crates/sqlbuild-python-front/src/model_config/_helpers/headers/header_columns.rs=1", + "crates/sqlbuild-python-front/src/model_config/_helpers/headers/header_metadata.rs=1", + "crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/described_models.rs=1", + "crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/unicode_environment.rs=3", + "crates/sqlbuild-python-front/src/model_config/models.rs=2", + "crates/sqlbuild-python-front/src/refactor/_helpers/contract_compare.rs=6", + "crates/sqlbuild-python-front/src/refactor/_helpers/python_strings.rs=1", + "crates/sqlbuild-python-front/src/refactor/_helpers/refactor_facts.rs=11", + "crates/sqlbuild-python-front/src/render/_helpers/calls/macro_arguments.rs=4", + "crates/sqlbuild-python-front/src/render/_helpers/calls/macro_call_classes.rs=1", + "crates/sqlbuild-python-front/src/render/_helpers/declarations/authored_sql.rs=2", + "crates/sqlbuild-python-front/src/render/_helpers/declarations/declaration_expansion.rs=24", + "crates/sqlbuild-python-front/src/render/_helpers/declarations/declaration_indexes.rs=1", + "crates/sqlbuild-python-front/src/render/_helpers/declarations/declaration_values.rs=12", + "crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_evaluation.rs=14", + "crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_expansion.rs=6", + "crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_expansion_result.rs=4", + "crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_generated_references.rs=9", + "crates/sqlbuild-python-front/src/render/models.rs=10", + "crates/sqlbuild-python-front/src/scopes/_helpers/checks/scope_tolerant.rs=5", + "crates/sqlbuild-python-front/src/scopes/_helpers/checks/scope_validation.rs=2", + "crates/sqlbuild-python-front/src/scopes/_helpers/checks/scope_visibility.rs=5", + "crates/sqlbuild-python-front/src/scopes/_helpers/declarations/declaration_resolution.rs=15", + "crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_cache.rs=2", + "crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_index.rs=24", + "crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_lookup.rs=8", + "crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_objects.rs=18", + "crates/sqlbuild-python-front/src/scopes/_helpers/relationships/compile_usages.rs=4", + "crates/sqlbuild-python-front/src/scopes/_helpers/reports/scope_errors.rs=3", + "crates/sqlbuild-python-front/src/scopes/_helpers/reports/scope_report_objects.rs=23", + "crates/sqlbuild-python-front/src/scopes/_helpers/reports/scope_reports.rs=2", + "crates/sqlbuild-python-front/src/scopes/models.rs=13", + "crates/sqlbuild-python-front/src/sql_test_glue/_helpers/authored_ctes.rs=2", + "crates/sqlbuild-python-front/src/sqltext/_helpers/authored_values.rs=3", + "crates/sqlbuild-python-front/src/sqltext/_helpers/sql_references.rs=1", + "crates/sqlbuild-python-front/src/sqltext/_helpers/static_sql.rs=1", + "crates/sqlbuild-python-front/src/sqltext/models.rs=1", + "crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/events.rs=1", + "crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/freshness.rs=4", + "crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/timestamps.rs=4", + "crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_io.rs=7", + "crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_projections.rs=1", + "crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_rows.rs=5", + "crates/sqlbuild-python-front/src/state_rows/_helpers/tables/state_tables.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/analysis/binding_catalog.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/analysis/sql_test_comparisons.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/analysis_session/fixture_inferences.rs=0", @@ -2038,16 +2166,10 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/analysis_session/outcome_objects.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/analysis_session/profile_inputs.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/analysis_session/session.rs=0", - "crates/sqlbuild-python/src/bindings/_helpers/attachments/cursor_intrinsics.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/attachments/reference_markers.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/audit_command/command.rs=19", "crates/sqlbuild-python/src/bindings/_helpers/auditing/identity.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/auditing/measurement.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/auditing/schema_audits.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/authored_values/fields.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/authored_values/project_vars.rs=3", - "crates/sqlbuild-python/src/bindings/_helpers/authored_values/python_nodes.rs=3", - "crates/sqlbuild-python/src/bindings/_helpers/authored_values/sql_values.rs=12", "crates/sqlbuild-python/src/bindings/_helpers/build_command/command.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/build_command/completion.rs=9", "crates/sqlbuild-python/src/bindings/_helpers/build_command/defer_clone.rs=16", @@ -2084,7 +2206,6 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/command_runtime/warehouses.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/cursor_roles.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/declaration_scope.rs=9", - "crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/effective_config.rs=4", "crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/model_inputs.rs=4", "crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/sql_expansion_context.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/storage_policies.rs=1", @@ -2108,7 +2229,6 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_project.rs=6", "crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_sql_tests.rs=6", "crates/sqlbuild-python/src/bindings/_helpers/compile_driver/command.rs=24", - "crates/sqlbuild-python/src/bindings/_helpers/compile_driver/config_validation.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/compile_driver/deferral.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/compile_driver/diff.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/compile_driver/discovery.rs=3", @@ -2144,8 +2264,6 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/contract_command/command.rs=18", "crates/sqlbuild-python/src/bindings/_helpers/contract_command/write.rs=5", "crates/sqlbuild-python/src/bindings/_helpers/contracts/contract_diagnostics.rs=6", - "crates/sqlbuild-python/src/bindings/_helpers/contracts/effective_config.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/contracts/spec_resolution.rs=9", "crates/sqlbuild-python/src/bindings/_helpers/cost_command/bounds.rs=16", "crates/sqlbuild-python/src/bindings/_helpers/cost_command/command.rs=11", "crates/sqlbuild-python/src/bindings/_helpers/cost_command/refresh.rs=10", @@ -2160,12 +2278,6 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/cost_telemetry/ledger.rs=13", "crates/sqlbuild-python/src/bindings/_helpers/cost_telemetry/snowflake.rs=23", "crates/sqlbuild-python/src/bindings/_helpers/cost_telemetry/values.rs=9", - "crates/sqlbuild-python/src/bindings/_helpers/cursor/conversion.rs=5", - "crates/sqlbuild-python/src/bindings/_helpers/cursor/durations.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/cursor/intervals.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/cursor/overrides.rs=7", - "crates/sqlbuild-python/src/bindings/_helpers/cursor/scalars.rs=13", - "crates/sqlbuild-python/src/bindings/_helpers/cursor/values.rs=4", "crates/sqlbuild-python/src/bindings/_helpers/dag_artifact/artifact.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/dag_artifact/rows.rs=8", "crates/sqlbuild-python/src/bindings/_helpers/dag_artifact/selection.rs=7", @@ -2207,30 +2319,6 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/diff_report/query.rs=19", "crates/sqlbuild-python/src/bindings/_helpers/diff_report/support.rs=6", "crates/sqlbuild-python/src/bindings/_helpers/diff_report/tolerances.rs=5", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/declaration_records.rs=8", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/faults.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/header_declarations.rs=5", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/header_values.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/hook_entries.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/imported_modules.rs=3", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/imported_providers.rs=14", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/imported_python_nodes.rs=9", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/locations.rs=4", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/model_file_record.rs=0", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/model_records.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/project_config.rs=16", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/project_facts.rs=6", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/project_files.rs=3", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/project_validation.rs=6", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/python_function_files.rs=15", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/python_hook_files.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/raised.rs=9", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/scope_snapshot.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/snapshot.rs=4", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/sql_test_blocks.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/sql_test_records.rs=5", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/yaml_entries.rs=14", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/yaml_records.rs=4", "crates/sqlbuild-python/src/bindings/_helpers/event_exporting/dispatcher.rs=28", "crates/sqlbuild-python/src/bindings/_helpers/event_exporting/registration.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/event_exporting/workers.rs=11", @@ -2311,27 +2399,11 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/load/load_command.rs=16", "crates/sqlbuild-python/src/bindings/_helpers/load/load_progress.rs=17", "crates/sqlbuild-python/src/bindings/_helpers/load/load_selection.rs=3", - "crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/module_digests.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/store_keys.rs=26", "crates/sqlbuild-python/src/bindings/_helpers/manifest/builder.rs=8", "crates/sqlbuild-python/src/bindings/_helpers/manifest/rows.rs=4", "crates/sqlbuild-python/src/bindings/_helpers/microbatches/conversion.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/microbatches/projection.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/microbatches/statements.rs=5", - "crates/sqlbuild-python/src/bindings/_helpers/model_config/authored_nodes.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/model_config/config_classes.rs=5", - "crates/sqlbuild-python/src/bindings/_helpers/model_config/config_errors.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/model_config/config_templates.rs=4", - "crates/sqlbuild-python/src/bindings/_helpers/model_config/config_values.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/model_config/described_models.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/model_config/errors.rs=0", - "crates/sqlbuild-python/src/bindings/_helpers/model_config/header_columns.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/model_config/header_metadata.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/model_config/model_config_builder.rs=0", - "crates/sqlbuild-python/src/bindings/_helpers/model_config/model_validator.rs=0", - "crates/sqlbuild-python/src/bindings/_helpers/model_config/template_data.rs=4", - "crates/sqlbuild-python/src/bindings/_helpers/model_config/typed_config.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/model_config/unicode_environment.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/output_capture/context.rs=5", "crates/sqlbuild-python/src/bindings/_helpers/output_capture/dispatcher.rs=31", "crates/sqlbuild-python/src/bindings/_helpers/output_capture/records.rs=16", @@ -2459,27 +2531,12 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/migrations.rs=8", "crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/planner.rs=7", "crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/rule_shapes.rs=5", - "crates/sqlbuild-python/src/bindings/_helpers/refactor/contract_compare.rs=6", - "crates/sqlbuild-python/src/bindings/_helpers/refactor/contract_edits.rs=0", - "crates/sqlbuild-python/src/bindings/_helpers/refactor/python_strings.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/refactor/refactor_command.rs=24", - "crates/sqlbuild-python/src/bindings/_helpers/refactor/refactor_facts.rs=11", "crates/sqlbuild-python/src/bindings/_helpers/references/explicit_references.rs=19", "crates/sqlbuild-python/src/bindings/_helpers/references/reference_facts.rs=5", "crates/sqlbuild-python/src/bindings/_helpers/references/relations.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/references/source_relations.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/relation_naming/fitting.rs=0", - "crates/sqlbuild-python/src/bindings/_helpers/render/authored_sql.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/render/declaration_expansion.rs=24", - "crates/sqlbuild-python/src/bindings/_helpers/render/declaration_indexes.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/render/declaration_values.rs=12", - "crates/sqlbuild-python/src/bindings/_helpers/render/macro_arguments.rs=4", - "crates/sqlbuild-python/src/bindings/_helpers/render/macro_call_classes.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/render/macro_call_memo.rs=0", - "crates/sqlbuild-python/src/bindings/_helpers/render/macro_evaluation.rs=14", - "crates/sqlbuild-python/src/bindings/_helpers/render/macro_expansion.rs=16", - "crates/sqlbuild-python/src/bindings/_helpers/render/macro_expansion_result.rs=4", - "crates/sqlbuild-python/src/bindings/_helpers/render/macro_generated_references.rs=9", "crates/sqlbuild-python/src/bindings/_helpers/result_output/aggregation.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/result_output/checks.rs=0", "crates/sqlbuild-python/src/bindings/_helpers/result_output/documents.rs=13", @@ -2531,21 +2588,8 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/scenario_command/setup.rs=14", "crates/sqlbuild-python/src/bindings/_helpers/scenario_command/snapshot_sync.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/scenario_command/test_command.rs=13", - "crates/sqlbuild-python/src/bindings/_helpers/scopes/compile_usages.rs=4", - "crates/sqlbuild-python/src/bindings/_helpers/scopes/declaration_contexts.rs=5", - "crates/sqlbuild-python/src/bindings/_helpers/scopes/declaration_resolution.rs=15", - "crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_cache.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_command.rs=8", - "crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_errors.rs=3", - "crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_index.rs=32", "crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_loading.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_lookup.rs=8", - "crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_objects.rs=18", - "crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_report_objects.rs=23", - "crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_reports.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_tolerant.rs=5", - "crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_validation.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_visibility.rs=5", "crates/sqlbuild-python/src/bindings/_helpers/seed_command/command.rs=14", "crates/sqlbuild-python/src/bindings/_helpers/semantic_checks/completion.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/semantic_checks/metadata.rs=6", @@ -2556,7 +2600,6 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/semantic_shapes/source_bindings.rs=13", "crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/test_command.rs=99", "crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/assembly.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/authored_ctes.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/compiled_tests.rs=4", "crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/constants.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/cursor_window.rs=2", @@ -2566,18 +2609,6 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/plan_rendering.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/plan_values.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/planning.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/sqltext/authored_values.rs=3", - "crates/sqlbuild-python/src/bindings/_helpers/sqltext/code_scanner.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/sqltext/sql_references.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/sqltext/static_sql.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/state_rows/events.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/state_rows/freshness.rs=4", - "crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_io.rs=7", - "crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_objects.rs=0", - "crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_projections.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_rows.rs=5", - "crates/sqlbuild-python/src/bindings/_helpers/state_rows/state_tables.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/state_rows/timestamps.rs=4", "crates/sqlbuild-python/src/bindings/_helpers/workspace_commands/commands.rs=5", "crates/sqlbuild-python/src/bindings/models.rs=0", ] @@ -2590,6 +2621,7 @@ edge_paths = [ "crates/sqlbuild-python-base/src/records/_helpers/native_classes/fields.rs", "crates/sqlbuild-python-base/src/records/_helpers/native_classes/registry.rs", "crates/sqlbuild-python-base/src/warehouse_access", + "crates/sqlbuild-python-front/src/native_host", "crates/sqlbuild-python/src/bindings/_helpers/native_host", ] pending_budgets = [ @@ -2610,13 +2642,51 @@ pending_budgets = [ "crates/sqlbuild-python-base/src/presentation_text/_helpers/functions.rs=1", "crates/sqlbuild-python-base/src/records/_helpers/native_classes/error_classes.rs=1", "crates/sqlbuild-python-base/src/records/models.rs=3", + "crates/sqlbuild-python-front/src/authored_values/_helpers/fields.rs=3", + "crates/sqlbuild-python-front/src/authored_values/models.rs=6", + "crates/sqlbuild-python-front/src/compile_driver/models.rs=3", + "crates/sqlbuild-python-front/src/contracts/_helpers/effective_config.rs=1", + "crates/sqlbuild-python-front/src/cursor/_helpers/intervals.rs=1", + "crates/sqlbuild-python-front/src/cursor/models.rs=4", + "crates/sqlbuild-python-front/src/discovery/_helpers/failures/faults.rs=2", + "crates/sqlbuild-python-front/src/discovery/_helpers/headers/header_declarations.rs=1", + "crates/sqlbuild-python-front/src/discovery/_helpers/project/project_config.rs=1", + "crates/sqlbuild-python-front/src/discovery/_helpers/python_files/imported_modules.rs=1", + "crates/sqlbuild-python-front/src/discovery/_helpers/python_files/imported_python_nodes.rs=4", + "crates/sqlbuild-python-front/src/discovery/_helpers/python_files/python_function_files.rs=3", + "crates/sqlbuild-python-front/src/discovery/_helpers/records/declaration_records.rs=2", + "crates/sqlbuild-python-front/src/discovery/_helpers/records/model_file_record.rs=12", + "crates/sqlbuild-python-front/src/discovery/_helpers/snapshots/native_classes.rs=2", + "crates/sqlbuild-python-front/src/discovery/_helpers/snapshots/scope_snapshot.rs=1", + "crates/sqlbuild-python-front/src/discovery/_helpers/sources/yaml_entries.rs=13", + "crates/sqlbuild-python-front/src/discovery/models.rs=7", + "crates/sqlbuild-python-front/src/macro_bridge/_helpers/store_keys.rs=9", + "crates/sqlbuild-python-front/src/model_config/_helpers/config/config_templates.rs=1", + "crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/model_config_builder.rs=1", + "crates/sqlbuild-python-front/src/model_config/models.rs=23", + "crates/sqlbuild-python-front/src/refactor/_helpers/contract_compare.rs=2", + "crates/sqlbuild-python-front/src/render/_helpers/calls/macro_arguments.rs=1", + "crates/sqlbuild-python-front/src/render/_helpers/calls/macro_call_classes.rs=4", + "crates/sqlbuild-python-front/src/render/_helpers/declarations/authored_sql.rs=10", + "crates/sqlbuild-python-front/src/render/_helpers/declarations/declaration_indexes.rs=2", + "crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_evaluation.rs=2", + "crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_expansion.rs=19", + "crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_expansion_facts.rs=2", + "crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_generated_references.rs=6", + "crates/sqlbuild-python-front/src/render/_helpers/sql_macros/sql_macro_host.rs=1", + "crates/sqlbuild-python-front/src/render/models.rs=39", + "crates/sqlbuild-python-front/src/scopes/_helpers/checks/scope_tolerant.rs=1", + "crates/sqlbuild-python-front/src/scopes/_helpers/declarations/declaration_contexts.rs=12", + "crates/sqlbuild-python-front/src/scopes/_helpers/declarations/declaration_resolution.rs=13", + "crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_index.rs=5", + "crates/sqlbuild-python-front/src/scopes/models.rs=11", + "crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_rows.rs=1", + "crates/sqlbuild-python-front/src/state_rows/models.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/analysis/binding_catalog.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/analysis/schema_request.rs=6", "crates/sqlbuild-python/src/bindings/_helpers/analysis_session/fixture_inferences.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/analysis_session/model_analyses.rs=8", "crates/sqlbuild-python/src/bindings/_helpers/audit_command/command.rs=5", - "crates/sqlbuild-python/src/bindings/_helpers/authored_values/fields.rs=3", - "crates/sqlbuild-python/src/bindings/_helpers/authored_values/sql_values.rs=6", "crates/sqlbuild-python/src/bindings/_helpers/build_command/completion.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/build_command/defer_clone.rs=6", "crates/sqlbuild-python/src/bindings/_helpers/build_command/execution.rs=6", @@ -2649,7 +2719,6 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_analysis.rs=5", "crates/sqlbuild-python/src/bindings/_helpers/compile_driver/assembly_models.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/compile_driver/command.rs=3", - "crates/sqlbuild-python/src/bindings/_helpers/compile_driver/config_validation.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/compile_driver/deferral.rs=5", "crates/sqlbuild-python/src/bindings/_helpers/compile_driver/diff.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/compile_driver/discovery.rs=2", @@ -2672,13 +2741,10 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/compiled_views/source_views.rs=9", "crates/sqlbuild-python/src/bindings/_helpers/contract_command/command.rs=4", "crates/sqlbuild-python/src/bindings/_helpers/contract_command/write.rs=5", - "crates/sqlbuild-python/src/bindings/_helpers/contracts/effective_config.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/cost_command/command.rs=0", "crates/sqlbuild-python/src/bindings/_helpers/cost_report/records.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/cost_telemetry/context.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/cost_telemetry/snowflake.rs=7", - "crates/sqlbuild-python/src/bindings/_helpers/cursor/conversion.rs=4", - "crates/sqlbuild-python/src/bindings/_helpers/cursor/intervals.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/dag_artifact/projection.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/dagster_invocation/arguments.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/dbt_command/command.rs=2", @@ -2691,17 +2757,6 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/runner.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/debug_command/run_debug.rs=4", "crates/sqlbuild-python/src/bindings/_helpers/diff_report/query.rs=4", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/declaration_records.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/faults.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/header_declarations.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/imported_modules.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/imported_python_nodes.rs=4", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/model_file_record.rs=15", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/model_records.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/project_config.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/python_function_files.rs=3", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/scope_snapshot.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/discovery/yaml_entries.rs=13", "crates/sqlbuild-python/src/bindings/_helpers/event_exporting/dispatcher.rs=14", "crates/sqlbuild-python/src/bindings/_helpers/event_exporting/workers.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/fingerprints/storage_io.rs=12", @@ -2743,12 +2798,7 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/load/load_command.rs=12", "crates/sqlbuild-python/src/bindings/_helpers/load/load_progress.rs=8", "crates/sqlbuild-python/src/bindings/_helpers/load/load_selection.rs=4", - "crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/store_keys.rs=9", "crates/sqlbuild-python/src/bindings/_helpers/microbatches/conversion.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/model_config/config_classes.rs=8", - "crates/sqlbuild-python/src/bindings/_helpers/model_config/config_templates.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/model_config/header_metadata.rs=11", - "crates/sqlbuild-python/src/bindings/_helpers/model_config/model_config_builder.rs=5", "crates/sqlbuild-python/src/bindings/_helpers/output_capture/context.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/output_capture/dispatcher.rs=9", "crates/sqlbuild-python/src/bindings/_helpers/plan_command/plan.rs=7", @@ -2788,23 +2838,10 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/project_assembly/syntax_validation.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/query_command/project.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/recall/replacements.rs=3", - "crates/sqlbuild-python/src/bindings/_helpers/refactor/contract_compare.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/refactor/offline_compile.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/refactor/refactor_command.rs=4", "crates/sqlbuild-python/src/bindings/_helpers/references/explicit_references.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/references/reference_facts.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/render/authored_sql.rs=19", - "crates/sqlbuild-python/src/bindings/_helpers/render/declaration_expansion.rs=5", - "crates/sqlbuild-python/src/bindings/_helpers/render/declaration_indexes.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/render/declaration_values.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/render/macro_arguments.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/render/macro_call_classes.rs=4", - "crates/sqlbuild-python/src/bindings/_helpers/render/macro_evaluation.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/render/macro_expansion.rs=33", - "crates/sqlbuild-python/src/bindings/_helpers/render/macro_expansion_facts.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/render/macro_expansion_result.rs=8", - "crates/sqlbuild-python/src/bindings/_helpers/render/macro_generated_references.rs=6", - "crates/sqlbuild-python/src/bindings/_helpers/render/sql_macro_host.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/result_output/documents.rs=8", "crates/sqlbuild-python/src/bindings/_helpers/result_output/event_writer.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/result_output/integration_envelope.rs=4", @@ -2829,11 +2866,6 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/scenario_command/setup.rs=7", "crates/sqlbuild-python/src/bindings/_helpers/scenario_command/snapshot_sync.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/scenario_command/test_command.rs=4", - "crates/sqlbuild-python/src/bindings/_helpers/scopes/declaration_contexts.rs=12", - "crates/sqlbuild-python/src/bindings/_helpers/scopes/declaration_resolution.rs=13", - "crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_index.rs=8", - "crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_reports.rs=8", - "crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_tolerant.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/seed_command/command.rs=5", "crates/sqlbuild-python/src/bindings/_helpers/semantic_checks/metadata.rs=4", "crates/sqlbuild-python/src/bindings/_helpers/semantic_checks/resource_sql.rs=3", @@ -2845,9 +2877,7 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/cursor_window.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/models.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/planning.rs=4", - "crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_rows.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/state_rows/models.rs=3", - "crates/sqlbuild-python/src/bindings/models.rs=4", + "crates/sqlbuild-python/src/bindings/models.rs=0", ] [targets.rust.rule_options.XSB075] @@ -2870,11 +2900,11 @@ module_layers = [ "analysis_session/query_columns=project", "analysis_session/session=project", "analysis_session/stage_functions=project", - "attachments=front", + "attachments=registry", "audit_command=commands", "auditing=compile", "auditing/render=project", - "authored_values=front", + "authored_values=registry", "build_command=commands", "build_progress=output", "cache=registry", @@ -2883,14 +2913,11 @@ module_layers = [ "cli=commands", "clone=commands", "command_runtime=commands", - "command_runtime/concurrency=front", "compile_attachment=compile", "compile_attachment/cursor_roles=project", - "compile_attachment/effective_config=front", "compile_command=compile", "compile_delta=compile", "compile_driver=compile", - "compile_driver/config_validation=front", "compile_driver/plan_pipeline=commands", "compile_driver/plan_result=commands", "compile_driver/static_context=commands", @@ -2901,14 +2928,12 @@ module_layers = [ "contract_command=commands", "consumption=plan", "contracts=project", - "contracts/effective_config=front", - "contracts/spec_resolution=front", "cost_command=commands", "cost_report=output", "cost_telemetry=output", "cost_telemetry/context=front", "cost_telemetry/values=front", - "cursor=front", + "cursor=registry", "dag_artifact=compile", "dagster_invocation=commands", "dbt_command=commands", @@ -2917,7 +2942,7 @@ module_layers = [ "debug_command=commands", "diagnostics=registry", "diff_report=commands", - "discovery=front", + "discovery=registry", "event_exporting=output", "execution_history=front", "exported_constants=registry", @@ -2938,15 +2963,12 @@ module_layers = [ "lineage/lineage_facts=project", "load=commands", "location_command=commands", - "macro_bridge=front", + "macro_bridge=registry", "manifest=compile", "microbatches=plan", - "model_config=front", + "model_config=registry", "native_host=front", - "native_host/audit_results_state=front", - "native_host/consumption_state=front", "native_host/model_lookup=project", - "native_host/observations_state=front", "native_host/orchestration_sensors=commands", "native_host/orchestration_triggers=project", "native_host/resource_costs_state=front", @@ -2996,7 +3018,7 @@ module_layers = [ "refactor/refactor_command=commands", "references=project", "relation_naming=project", - "render=front", + "render=registry", "result_output=output", "review_command=commands", "rules=compile", @@ -3009,7 +3031,6 @@ module_layers = [ "semantic_shapes=project", "sql_test_command=commands", "sql_test_glue=compile", - "sql_test_glue/authored_ctes=front", "sql_test_glue/constants=infra", "sql_test_glue/cursor_window=project", "sql_test_glue/fixture_validation=project", @@ -3023,8 +3044,8 @@ module_layers = [ "sql_test_glue/plan_rows=project", "sql_test_glue/plan_values=project", "sql_test_glue/planning=project", - "sqltext=front", - "state_rows=front", + "sqltext=registry", + "state_rows=registry", "type_system=project", "workspace_commands=commands", ] @@ -3067,11 +3088,11 @@ paths = ["crates/sqlbuild-cli/src/native_commands/_helpers/project_facts.rs", "c reason = "Field lookups on unrelated value types in different crates: project configuration takes the first matching field of a built object, while rule headers take the last entry of an authored map so a repeated key overrides earlier ones." [[dupes.allowlist]] -paths = ["crates/sqlbuild-python-base/src/event_exporting/_helpers/scope.rs", "crates/sqlbuild-python-base/src/records/_helpers/native_classes/fields.rs", "crates/sqlbuild-python/src/bindings/_helpers/contract_command/write.rs", "crates/sqlbuild-python/src/bindings/_helpers/discovery/imported_modules.rs", "crates/sqlbuild-python/src/bindings/_helpers/input_loops/attachment.rs", "crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_visibility.rs", "crates/sqlbuild-python/src/bindings/_helpers/model_config/contract_classes.rs", "crates/sqlbuild-python/src/bindings/_helpers/planner_entries/plan_output.rs", "crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/locations.rs", "crates/sqlbuild-python/src/bindings/_helpers/planner_scope/values.rs", "crates/sqlbuild-python/src/bindings/_helpers/semantic_shapes/shapes.rs"] +paths = ["crates/sqlbuild-python-base/src/event_exporting/_helpers/scope.rs", "crates/sqlbuild-python-base/src/records/_helpers/native_classes/fields.rs", "crates/sqlbuild-python/src/bindings/_helpers/contract_command/write.rs", "crates/sqlbuild-python-front/src/discovery/_helpers/python_files/imported_modules.rs", "crates/sqlbuild-python/src/bindings/_helpers/input_loops/attachment.rs", "crates/sqlbuild-python/src/bindings/_helpers/input_loops/model_loop_visibility.rs", "crates/sqlbuild-python-front/src/model_config/_helpers/model_nodes/contract_classes.rs", "crates/sqlbuild-python/src/bindings/_helpers/planner_entries/plan_output.rs", "crates/sqlbuild-python/src/bindings/_helpers/planner_resolution/locations.rs", "crates/sqlbuild-python/src/bindings/_helpers/planner_scope/values.rs", "crates/sqlbuild-python/src/bindings/_helpers/semantic_shapes/shapes.rs"] reason = "Each builds a dict keyed by a field of its own records; only the loop that fills the dict is alike." [[dupes.allowlist]] -paths = ["crates/sqlbuild-analysis/src/assembly/analysis_session/_helpers/cte_facts.rs", "crates/sqlbuild-analysis/src/manifest/_helpers/values.rs", "crates/sqlbuild-cli/src/diff_report/_helpers/payload.rs", "crates/sqlbuild-config/src/project/_helpers/fields.rs", "crates/sqlbuild-python-base/src/frontier/_helpers/encoder.rs", "crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_report_objects.rs", "crates/sqlbuild-refactor/src/refactoring/_helpers/contracts/model_edits.rs", "crates/sqlbuild-sqltext/src/compiler/_helpers/model_headers/columns.rs", "crates/sqlbuild-sqltext/src/compiler/_helpers/select_items/scanning.rs"] +paths = ["crates/sqlbuild-analysis/src/assembly/analysis_session/_helpers/cte_facts.rs", "crates/sqlbuild-analysis/src/manifest/_helpers/values.rs", "crates/sqlbuild-cli/src/diff_report/_helpers/payload.rs", "crates/sqlbuild-config/src/project/_helpers/fields.rs", "crates/sqlbuild-python-base/src/frontier/_helpers/encoder.rs", "crates/sqlbuild-python-front/src/scopes/_helpers/reports/scope_report_objects.rs", "crates/sqlbuild-refactor/src/refactoring/_helpers/contracts/model_edits.rs", "crates/sqlbuild-sqltext/src/compiler/_helpers/model_headers/columns.rs", "crates/sqlbuild-sqltext/src/compiler/_helpers/select_items/scanning.rs"] reason = "Each fills its own ordered key/value list in its own crate; a shared ordered-map helper across these crates is a separate change." [[dupes.allowlist]] @@ -3099,7 +3120,7 @@ paths = ["crates/sqlbuild-analysis/src/semantic_validation/models.rs", "crates/s reason = "Hand-written Debug implementations that each choose which of their own fields to show, so secrets, caches and large catalogs stay out of logs." [[dupes.allowlist]] -paths = ["crates/sqlbuild-python-base/src/frontier/_helpers/encoder.rs", "crates/sqlbuild-python-base/src/python_values/_helpers/values.rs", "crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/store_keys.rs"] +paths = ["crates/sqlbuild-python-base/src/frontier/_helpers/encoder.rs", "crates/sqlbuild-python-base/src/python_values/_helpers/values.rs", "crates/sqlbuild-python-front/src/macro_bridge/_helpers/store_keys.rs"] reason = "Each maps a Python `str` into its own JSON value type; the UTF-16 conversion itself is shared through `utf16_units`." [[dupes.allowlist]] @@ -3146,6 +3167,38 @@ reason = "Each public entry forwards to its own helper with the same arguments." paths = ["crates/sqlbuild-python-base/src/warehouse_access/main/read_catalog.rs", "crates/sqlbuild-python-base/src/warehouse_access/main/read_statistics.rs"] reason = "Each public entry forwards to its own helper with the same arguments." +[[dupes.allowlist]] +paths = ["crates/sqlbuild-python-front/src/discovery/_helpers/python_files/imported_python_nodes.rs", "crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/pipeline_phases.rs", "crates/sqlbuild-python/src/bindings/_helpers/lifecycle_events/envelopes.rs", "crates/sqlbuild-python/src/bindings/_helpers/planner_identity/graph.rs"] +reason = "Each bindings module registers its own functions and classes with the native module." + +[[dupes.allowlist]] +paths = ["crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_connection_config.rs", "crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_runtime_config.rs", "crates/sqlbuild-python-front/src/contracts/_helpers/spec_resolution.rs", "crates/sqlbuild-python-front/src/contracts/main/loader_destination_parts.rs", "crates/sqlbuild-python-front/src/discovery/main/records/discover_test_files.rs"] +reason = "Each public entry forwards to its own helper with the same arguments." + +[[dupes.allowlist]] +paths = ["crates/sqlbuild-python-front/src/model_config/_helpers/headers/header_families.rs", "crates/sqlbuild-python/src/bindings/_helpers/rules/dsl_headers.rs", "crates/sqlbuild-python/src/bindings/_helpers/rules/lint_sql_bodies.rs"] +reason = "Each reads its own Python record's fields into its own native record." + +[[dupes.allowlist]] +paths = ["crates/sqlbuild-python/src/bindings/_helpers/compile_attachment/registration.rs", "crates/sqlbuild-python/src/bindings/_helpers/planner_scenario/registration.rs"] +reason = "Each bindings module registers its own functions and classes with the native module." + +[[dupes.allowlist]] +paths = ["crates/sqlbuild-python-front/src/native_host/models.rs", "crates/sqlbuild-python/src/bindings/_helpers/command_runtime/warehouse_scope.rs", "crates/sqlbuild-python/src/bindings/_helpers/result_output/terminal_index.rs"] +reason = "Each context object takes its own resource out of its own lock and releases it the way that resource needs; only the take-under-lock shape is shared." + +[[dupes.allowlist]] +paths = ["crates/sqlbuild-python-base/src/warehouse_access/main/read_catalog.rs", "crates/sqlbuild-python-base/src/warehouse_access/main/read_statistics.rs", "crates/sqlbuild-python-front/src/native_host/main/state_table_name.rs"] +reason = "Each public entry forwards to its own helper with the same arguments." + +[[dupes.allowlist]] +paths = ["crates/sqlbuild-python-front/src/model_config/models.rs", "crates/sqlbuild-python-front/src/sqltext/_helpers/static_sql.rs"] +reason = "Each host keeps its own first Python error and returns its own failure type; only the string read is alike." + +[[dupes.allowlist]] +paths = ["crates/sqlbuild-python-front/src/authored_values/models.rs", "crates/sqlbuild-python-front/src/cursor/models.rs"] +reason = "SqlValueClasses::load and CursorSession::new each load the record classes their own conversions need; CursorSession's to_utc and utc_offset each turn the zone call's result into their own value." + [[dupes.allowlist]] paths = ["crates/sqlbuild-rules/src/python_rules/_helpers/units/orchestration.rs", "crates/sqlbuild-rules/src/python_rules/_helpers/units/providers.rs"] reason = "Each is one rule family's entry point: return early when no rule is selected, then run its own layout, module and import checks. Parsing, project modules and import resolution share files_naming, project_modules and rejected_import_faults." diff --git a/scripts/fensu_policy/constants.py b/scripts/fensu_policy/constants.py index f4a5d3bcbf..77f5de4f70 100644 --- a/scripts/fensu_policy/constants.py +++ b/scripts/fensu_policy/constants.py @@ -286,6 +286,7 @@ NATIVE_BINDINGS_ROOTS: tuple[str, ...] = ( "crates/sqlbuild-python/src/", "crates/sqlbuild-python-base/src/", + "crates/sqlbuild-python-front/src/", ) NATIVE_CROSSING_PATTERNS: tuple[str, ...] = ( r"\.getattr\(", @@ -487,7 +488,8 @@ ), ) OBSERVATION_STATE_PATTERN: str = ( - r"\b(?:observations_state|OBSERVATIONS_TABLE_NAME|WarehouseObservationRecord" + r"\b(?:observations_state|register_observations_state|append_observations" + r"|OBSERVATIONS_TABLE_NAME|WarehouseObservationRecord" r"|WarehouseHistoryKind::Observations|_sqlbuild_observations|sqb_warehouse_observations)\b" ) SYNCED_COPY_ALLOWED_PATHS: RuleOption[tuple[str, ...]] = RuleOption.string_list( diff --git a/scripts/native_module_paths/constants.py b/scripts/native_module_paths/constants.py index ebe33e1b7d..2c5ea422f0 100644 --- a/scripts/native_module_paths/constants.py +++ b/scripts/native_module_paths/constants.py @@ -4,6 +4,7 @@ SCANNED_SOURCE_ROOTS: tuple[str, ...] = ( "crates/sqlbuild-python-base/src", + "crates/sqlbuild-python-front/src", "crates/sqlbuild-python/src", "crates/sqlbuild-cli/src", "crates/sqlbuild-host/src", diff --git a/tests/integration/scripts/fensu_policy/test_observation_boundary.py b/tests/integration/scripts/fensu_policy/test_observation_boundary.py index 70bdb1ad5d..0b153492fd 100644 --- a/tests/integration/scripts/fensu_policy/test_observation_boundary.py +++ b/tests/integration/scripts/fensu_policy/test_observation_boundary.py @@ -39,6 +39,21 @@ expected_returncode=1, expected_faults=(" --> crates/sqlbuild-python/src/planner.rs:1:0",), ), + ObservationBoundaryTestCase( + description="planner calling the observation write and registration entry points", + rule="XSB078", + allowed=("crates/sqlbuild-python/src/observations",), + planner=( + "pub fn plan() {}\n" + "pub fn record(rows: &[Row]) { append_observations(rows); }\n" + "pub fn install(module: &Module) { register_observations_state(module); }\n" + ), + expected_returncode=1, + expected_faults=( + " --> crates/sqlbuild-python/src/planner.rs:2:0", + " --> crates/sqlbuild-python/src/planner.rs:3:0", + ), + ), ObservationBoundaryTestCase( description="allowed path that no longer names observation state", rule="XSB078", diff --git a/tests/native_field_fallbacks.txt b/tests/native_field_fallbacks.txt index 316c2ae063..4c175d640f 100644 --- a/tests/native_field_fallbacks.txt +++ b/tests/native_field_fallbacks.txt @@ -181,10 +181,10 @@ crates/sqlbuild-python/src/bindings/_helpers/debug_command/run_debug.rs Warehous crates/sqlbuild-python/src/bindings/_helpers/diff_report/support.rs CliUserError.code crates/sqlbuild-python/src/bindings/_helpers/diff_report/support.rs CliUserError.help crates/sqlbuild-python/src/bindings/_helpers/diff_report/support.rs CliUserError.message -crates/sqlbuild-python/src/bindings/_helpers/discovery/imported_modules.rs EventExporterCommandScope.cached_extensions -crates/sqlbuild-python/src/bindings/_helpers/discovery/imported_python_nodes.rs SourceWriteStrategy.value -crates/sqlbuild-python/src/bindings/_helpers/discovery/project_facts.rs DeclarationKind.value -crates/sqlbuild-python/src/bindings/_helpers/discovery/project_facts.rs ScopeKind.value +crates/sqlbuild-python-front/src/discovery/_helpers/python_files/imported_modules.rs EventExporterCommandScope.cached_extensions +crates/sqlbuild-python-front/src/discovery/_helpers/python_files/imported_python_nodes.rs SourceWriteStrategy.value +crates/sqlbuild-python-front/src/discovery/_helpers/project/project_facts.rs DeclarationKind.value +crates/sqlbuild-python-front/src/discovery/_helpers/project/project_facts.rs ScopeKind.value crates/sqlbuild-python-base/src/event_exporting/_helpers/scope.rs EventExporterCommandScope.cached_extensions crates/sqlbuild-python/src/bindings/_helpers/format_command/command.rs TransientStatusReporter.complete crates/sqlbuild-python/src/bindings/_helpers/freshness/freshness_observe.rs SourceFreshnessAgeStatus.value @@ -250,9 +250,9 @@ crates/sqlbuild-python/src/bindings/_helpers/load/load_command.rs LoadCallbackRe crates/sqlbuild-python/src/bindings/_helpers/load/load_command.rs LoadProgressReporter.on_progress crates/sqlbuild-python/src/bindings/_helpers/load/load_command.rs LoadProgressReporter.on_start crates/sqlbuild-python/src/bindings/_helpers/load/load_progress.rs TransientLineCoordinator.lock -crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/store_keys.rs CollectionRendering.value -crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/store_keys.rs DeclarationKind.value -crates/sqlbuild-python/src/bindings/_helpers/macro_bridge/store_keys.rs SqlValueKind.value +crates/sqlbuild-python-front/src/macro_bridge/_helpers/store_keys.rs CollectionRendering.value +crates/sqlbuild-python-front/src/macro_bridge/_helpers/store_keys.rs DeclarationKind.value +crates/sqlbuild-python-front/src/macro_bridge/_helpers/store_keys.rs SqlValueKind.value crates/sqlbuild-python/src/bindings/_helpers/manifest/rows.rs DeclarationKind.value crates/sqlbuild-python/src/bindings/_helpers/manifest/rows.rs ScopeKind.value crates/sqlbuild-python/src/bindings/_helpers/manifest/rows.rs SourceWriteStrategy.value @@ -380,13 +380,13 @@ crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/error_inits.rs Ma crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/error_inits.rs MacroArgumentError.relative_position crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/planner.rs ColumnMigrationDecision.blocks_build crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/values.rs SqlValueKind.value -crates/sqlbuild-python/src/bindings/_helpers/refactor/refactor_facts.rs DeclarationKind.value -crates/sqlbuild-python/src/bindings/_helpers/render/declaration_values.rs CollectionRendering.value -crates/sqlbuild-python/src/bindings/_helpers/render/declaration_values.rs VisibilityReason.value -crates/sqlbuild-python/src/bindings/_helpers/render/macro_call_classes.rs DeclarationKind.value -crates/sqlbuild-python/src/bindings/_helpers/render/macro_evaluation.rs NativeMacroExpansion.render_relation -crates/sqlbuild-python/src/bindings/_helpers/render/macro_expansion.rs ResourceKind.value -crates/sqlbuild-python/src/bindings/_helpers/render/macro_generated_references.rs ResourceKind.value +crates/sqlbuild-python-front/src/refactor/_helpers/refactor_facts.rs DeclarationKind.value +crates/sqlbuild-python-front/src/render/_helpers/declarations/declaration_values.rs CollectionRendering.value +crates/sqlbuild-python-front/src/render/_helpers/declarations/declaration_values.rs VisibilityReason.value +crates/sqlbuild-python-front/src/render/_helpers/calls/macro_call_classes.rs DeclarationKind.value +crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_evaluation.rs NativeMacroExpansion.render_relation +crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_expansion.rs ResourceKind.value +crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_generated_references.rs ResourceKind.value crates/sqlbuild-python/src/bindings/_helpers/result_output/assets.rs PlanReason.value crates/sqlbuild-python/src/bindings/_helpers/result_output/checks.rs SqlValueKind.value crates/sqlbuild-python/src/bindings/_helpers/rules/custom_evaluation.rs RuleSubject.value @@ -399,22 +399,22 @@ crates/sqlbuild-python/src/bindings/_helpers/scenario_command/presentation.rs Sc crates/sqlbuild-python/src/bindings/_helpers/scenario_command/setup.rs PlanningProgressReporter.on_progress crates/sqlbuild-python/src/bindings/_helpers/scenario_command/snapshot_sync.rs ScenarioProgressRelay.on_scenario_complete crates/sqlbuild-python/src/bindings/_helpers/scenario_command/snapshot_sync.rs ScenarioProgressRelay.on_scenario_start -crates/sqlbuild-python/src/bindings/_helpers/scopes/compile_usages.rs DeclarationKind.value -crates/sqlbuild-python/src/bindings/_helpers/scopes/compile_usages.rs ScopeKind.value -crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_errors.rs ScopeDiagnosticCode.value -crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_index.rs CollectionRendering.value -crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_index.rs ScopeKind.value -crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_index.rs SqlValueKind.value +crates/sqlbuild-python-front/src/scopes/_helpers/relationships/compile_usages.rs DeclarationKind.value +crates/sqlbuild-python-front/src/scopes/_helpers/relationships/compile_usages.rs ScopeKind.value +crates/sqlbuild-python-front/src/scopes/_helpers/reports/scope_errors.rs ScopeDiagnosticCode.value +crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_index.rs CollectionRendering.value +crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_index.rs ScopeKind.value +crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_index.rs SqlValueKind.value crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_loading.rs NativeScopeIndex.grant_relationships -crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_objects.rs DeclarationKind.value -crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_objects.rs GrantKind.value -crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_objects.rs OwnershipRootKind.value -crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_objects.rs ResourceKind.value -crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_objects.rs ScopeDiagnosticCode.value -crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_objects.rs ScopeDiagnosticSeverity.value -crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_objects.rs ScopeKind.value -crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_objects.rs UsageKind.value -crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_validation.rs ScopeDiagnosticCode.value +crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_objects.rs DeclarationKind.value +crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_objects.rs GrantKind.value +crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_objects.rs OwnershipRootKind.value +crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_objects.rs ResourceKind.value +crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_objects.rs ScopeDiagnosticCode.value +crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_objects.rs ScopeDiagnosticSeverity.value +crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_objects.rs ScopeKind.value +crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_objects.rs UsageKind.value +crates/sqlbuild-python-front/src/scopes/_helpers/checks/scope_validation.rs ScopeDiagnosticCode.value crates/sqlbuild-python/src/bindings/_helpers/seed_command/command.rs ConnectionProgressReporter.on_connection_start crates/sqlbuild-python/src/bindings/_helpers/seed_command/command.rs NativeProgressProjector.configure_resources crates/sqlbuild-python/src/bindings/_helpers/seed_command/command.rs NativeProgressProjector.consume_resource_terminal @@ -431,11 +431,11 @@ crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/cursor_window.rs Curs crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/fixture_validation.rs CompiledResourceType.value crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/plan_driver.rs WarningSeverity.value crates/sqlbuild-python/src/bindings/_helpers/sql_test_glue/plan_entries.rs CompiledResourceType.value -crates/sqlbuild-python/src/bindings/_helpers/state_rows/events.rs OldNameViewEventType.value -crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_io.rs ColumnMigrationDecision.records_event -crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_projections.rs OldNameViewEventType.value -crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_rows.rs ColumnMigrationDecision.value -crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_rows.rs MigrationDecision.value -crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_rows.rs MigrationDiscovery.value -crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_rows.rs OldNameViewDropReason.value -crates/sqlbuild-python/src/bindings/_helpers/state_rows/migration_rows.rs OldNameViewEventType.value +crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/events.rs OldNameViewEventType.value +crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_io.rs ColumnMigrationDecision.records_event +crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_projections.rs OldNameViewEventType.value +crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_rows.rs ColumnMigrationDecision.value +crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_rows.rs MigrationDecision.value +crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_rows.rs MigrationDiscovery.value +crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_rows.rs OldNameViewDropReason.value +crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_rows.rs OldNameViewEventType.value