Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/sqltide-python/src/project_discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ fn immutable_config_value<'py>(

/// Freeze nested configuration values while preserving authored key order.
#[pyfunction]
fn immutable_config_pairs<'py>(
pub(crate) fn immutable_config_pairs<'py>(
py: Python<'py>,
values: Bound<'py, PyAny>,
) -> PyResult<Bound<'py, PyTuple>> {
Expand Down
543 changes: 543 additions & 0 deletions crates/sqltide-python/src/shapes/discovery_models.rs

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions crates/sqltide-python/src/shapes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use pyo3::types::{
mod cli_service;
mod compiler_analysis;
mod compiler_project;
mod discovery_models;
mod executor_ops;
mod planner_execution;
mod sensors_dev;
Expand Down Expand Up @@ -86,6 +87,8 @@ pub(crate) type PostInit = for<'py> fn(&mut [Bound<'py, PyAny>]) -> PyResult<()>

/// One shape: its class name, fields in declaration order and optional post-init hook.
pub(crate) struct ShapeSpec {
/// The public module path, which with the class name identifies the shape.
pub(crate) module: &'static str,
pub(crate) qualname: &'static str,
pub(crate) fields: &'static [FieldSpec],
pub(crate) post_init: Option<PostInit>,
Expand Down Expand Up @@ -151,6 +154,7 @@ macro_rules! shapes {

impl $name {
pub(crate) const SPEC: $crate::shapes::ShapeSpec = $crate::shapes::ShapeSpec {
module: $module,
qualname: stringify!($name),
fields: &[$($crate::shapes::FieldSpec {
name: $crate::shapes::unraw(stringify!($field)),
Expand Down Expand Up @@ -394,8 +398,9 @@ pub(crate) fn bind<'py>(
Ok(values)
}

/// Each shape's plain default values by class name, built once so every instance and the
/// `dataclasses` field table share one default object, as a dataclass's defaults are shared.
/// Each shape's plain default values by module path and class name, built once so every
/// instance and the `dataclasses` field table share one default object, as a dataclass's
/// defaults are shared.
static DEFAULTS: PyOnceLock<Py<PyDict>> = PyOnceLock::new();

/// The shape's default values in field order, `None` where a field is required or has a
Expand All @@ -404,7 +409,8 @@ fn shared_defaults<'py>(py: Python<'py>, spec: &ShapeSpec) -> PyResult<Bound<'py
let table: &Bound<'py, PyDict> = DEFAULTS
.get_or_init(py, || PyDict::new(py).unbind())
.bind(py);
if let Some(found) = table.get_item(spec.qualname)? {
let key: (&str, &str) = (spec.module, spec.qualname);
if let Some(found) = table.get_item(key)? {
return Ok(found.cast_into()?);
}
let mut values: Vec<Bound<'py, PyAny>> = Vec::with_capacity(spec.fields.len());
Expand All @@ -415,7 +421,7 @@ fn shared_defaults<'py>(py: Python<'py>, spec: &ShapeSpec) -> PyResult<Bound<'py
});
}
let defaults: Bound<'py, PyTuple> = PyTuple::new(py, values)?;
table.set_item(spec.qualname, &defaults)?;
table.set_item(key, &defaults)?;
Ok(defaults)
}

Expand Down Expand Up @@ -870,6 +876,7 @@ pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
executor_ops::register(module)?;
cli_service::register(module)?;
sensors_dev::register(module)?;
discovery_models::register(module)?;
lazy_constants(
module,
&[
Expand Down
2 changes: 1 addition & 1 deletion python-boundary.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# still carries planning, validation, rendering or other movable logic counts as movable until
# that logic moves to Rust.
# Native failures must surface as errors; `handled_native_errors` lists the reviewed exceptions.
remaining_lines = 1774
remaining_lines = 1080

[[stays]]
path = "adapter/classes/adapter.py"
Expand Down
1 change: 1 addition & 0 deletions scripts/python_boundary/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
NATIVE_ALIASES: dict[str, tuple[str, str]] = {
"DiscoveryRefType": ("RefType", "compiler/discovery/types.py"),
"DiscoverySqlRelationType": ("SqlRelationType", "compiler/discovery/types.py"),
"DiscoveryKafkaSettings": ("KafkaSettings", "compiler/discovery/models.py"),
}
Loading
Loading