Skip to content

Commit 893e5a5

Browse files
authored
refactor: move the front layer of the Python bindings into sqlbuild-python-front (#1516)
* refactor: move the front layer of the Python bindings into sqlbuild-python-front 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 consumption, observation and audit result state tables move into a new crate between sqlbuild-python-base and sqlbuild-python, one area per helper bucket. sqlbuild-python imports their entry points directly; the extension module surface is unchanged. * fix: keep the observation write and registration entries under the observation boundary The observation boundary matched `observations_state` as a whole word, so the `append_observations` and `register_observations_state` entries the front crate exports, and the files that call them, fell outside it after the move. The pattern now names both entries, and their callers are listed again.
1 parent 929101c commit 893e5a5

872 files changed

Lines changed: 12255 additions & 5836 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Cargo.lock‎

Lines changed: 31 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ members = [
2424
"crates/sqlbuild-project",
2525
"crates/sqlbuild-cli",
2626
"crates/sqlbuild-python-base",
27+
"crates/sqlbuild-python-front",
2728
"crates/sqlbuild-python",
2829
]
2930
resolver = "2"
@@ -57,9 +58,10 @@ order = [
5758
"sqlbuild-project",
5859
"sqlbuild-cli",
5960
"sqlbuild-python-base",
61+
"sqlbuild-python-front",
6062
"sqlbuild-python",
6163
]
62-
python-boundary = ["sqlbuild-python-base", "sqlbuild-python"]
64+
python-boundary = ["sqlbuild-python-base", "sqlbuild-python-front", "sqlbuild-python"]
6365
polyglot-floor = "sqlbuild-analysis"
6466

6567
[workspace.package]
@@ -180,6 +182,7 @@ sqlbuild-orchestration = { path = "crates/sqlbuild-orchestration" }
180182
sqlbuild-process-ownership = { path = "crates/sqlbuild-process-ownership" }
181183
sqlbuild-project = { path = "crates/sqlbuild-project" }
182184
sqlbuild-python-base = { path = "crates/sqlbuild-python-base" }
185+
sqlbuild-python-front = { path = "crates/sqlbuild-python-front" }
183186
sqlbuild-pysource = { path = "crates/sqlbuild-pysource" }
184187
sqlbuild-recall = { path = "crates/sqlbuild-recall" }
185188
sqlbuild-scopes = { path = "crates/sqlbuild-scopes" }

‎crates/README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ tested and benchmarked with `cargo test` alone.
2929
| `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. |
3030
| `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`). |
3131
| `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. |
32-
| `sqlbuild-python` | The `_native` module: its Python classes and functions and the conversions from Python objects, on top of `sqlbuild-python-base`. |
32+
| `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. |
33+
| `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`. |
3334

3435
## Layering
3536

3637
Dependencies point one way, from the top of this graph to the bottom:
3738

3839
```text
39-
sqlbuild-python -> sqlbuild-python-base
40+
sqlbuild-python -> sqlbuild-python-front -> sqlbuild-python-base
4041
-> sqlbuild-project -> sqlbuild-refactor -> sqlbuild-rules -> sqlbuild-analysis -> sqlbuild-attachments
4142
-> sqlbuild-model-config -> sqlbuild-scopes -> sqlbuild-render -> sqlbuild-discovery -> sqlbuild-host
4243
-> sqlbuild-config -> sqlbuild-sqltext -> sqlbuild-cache -> sqlbuild-pysource -> sqlbuild-state -> sqlbuild-cursor -> sqlbuild-core
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[package]
2+
name = "sqlbuild-python-front"
3+
description = "The front layer of the sqlbuild._native bindings: discovery, model configuration, scopes, rendering and SQL text."
4+
version.workspace = true
5+
edition.workspace = true
6+
license.workspace = true
7+
publish.workspace = true
8+
rust-version.workspace = true
9+
10+
[dependencies]
11+
chrono.workspace = true
12+
chrono-tz.workspace = true
13+
pyo3.workspace = true
14+
serde_json.workspace = true
15+
sqlbuild-analysis.workspace = true
16+
sqlbuild-attachments.workspace = true
17+
sqlbuild-cache.workspace = true
18+
sqlbuild-cli.workspace = true
19+
sqlbuild-config.workspace = true
20+
sqlbuild-core.workspace = true
21+
sqlbuild-cursor.workspace = true
22+
sqlbuild-discovery.workspace = true
23+
sqlbuild-host.workspace = true
24+
sqlbuild-model-config.workspace = true
25+
sqlbuild-orchestration.workspace = true
26+
sqlbuild-pysource.workspace = true
27+
sqlbuild-python-base.workspace = true
28+
sqlbuild-refactor.workspace = true
29+
sqlbuild-render.workspace = true
30+
sqlbuild-scopes.workspace = true
31+
sqlbuild-sqltext.workspace = true
32+
sqlbuild-state.workspace = true
33+
stacker.workspace = true
34+
uuid.workspace = true
35+
36+
[lints]
37+
workspace = true

crates/sqlbuild-python/src/bindings/_helpers/attachments/argument_values.rs renamed to crates/sqlbuild-python-front/src/attachments/_helpers/argument_values.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Python audit argument values read as plain argument values.
22
3-
use crate::bindings::_helpers::model_config::config_nodes::{PyConfigNode, config_object};
3+
use crate::model_config::main::config::config_object::config_object;
4+
use crate::model_config::types::PyConfigNode;
45
use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python};
56
use pyo3::types::{
67
PyBool, PyDict, PyDictMethods, PyFloat, PyInt, PyList, PyListMethods, PyString,

crates/sqlbuild-python/src/bindings/_helpers/attachments/ceremonial_select.rs renamed to crates/sqlbuild-python-front/src/attachments/_helpers/ceremonial_select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use sqlbuild_attachments::ceremonial_select::main::omitted_select_offset::omitte
66
use sqlbuild_attachments::ceremonial_select::models::OmittedSelect;
77
use sqlbuild_sqltext::sql_scan::models::LexicalSyntax;
88

9-
use crate::bindings::_helpers::sqltext::lexical_syntax::LexicalSyntaxInput;
9+
use crate::sqltext::models::LexicalSyntaxInput;
1010
use sqlbuild_python_base::boundary::main::compiler_guard::compiler_guard;
1111

1212
/// The code-point offset to insert `SELECT 1` at, or `None`.

crates/sqlbuild-python/src/bindings/_helpers/attachments/cursor_intrinsics.rs renamed to crates/sqlbuild-python-front/src/attachments/_helpers/cursor_intrinsics.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Cursor intrinsic validation, rejection and rendering.
22
3+
use crate::attachments::constants::MICROBATCH_END_SENTINEL;
4+
use crate::attachments::constants::MICROBATCH_START_SENTINEL;
35
use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyModule, PyModuleMethods, PyResult};
46
use pyo3::types::{PyString, PyStringMethods};
57
use pyo3::{Python, pyfunction, wrap_pyfunction};
@@ -23,10 +25,7 @@ const INTEGER_ANALYSIS_BOUND: &str = "CAST(0 AS BIGINT)";
2325
const TIMESTAMP_ANALYSIS_BOUND: &str = "CAST('2000-01-01 00:00:00' AS TIMESTAMP)";
2426
const MODEL_SQL_CONTEXT: &str = "Model SQL";
2527
const SQL_CONTEXT: &str = "SQL";
26-
/// Executor placeholder replaced with a microbatch's start bound.
27-
pub(crate) const MICROBATCH_START_SENTINEL: &str = "__SQB_CURSOR_START__";
28-
/// Executor placeholder replaced with a microbatch's end bound.
29-
pub(crate) const MICROBATCH_END_SENTINEL: &str = "__SQB_CURSOR_END__";
28+
3029
const RESERVED_CURSOR_MARKERS: [&str; 2] = [MICROBATCH_START_SENTINEL, MICROBATCH_END_SENTINEL];
3130

3231
/// The reserved executor bound markers no authored SQL may contain.
@@ -53,7 +52,7 @@ fn text_value(value: &Bound<'_, PyAny>) -> Option<String> {
5352
}
5453

5554
/// `sql` with each intrinsic replaced by its bound and whether any was, raising for `context`.
56-
fn replaced(
55+
pub(crate) fn replaced(
5756
py: Python<'_>,
5857
sql: &str,
5958
context: &str,

crates/sqlbuild-python/src/bindings/_helpers/attachments/function_headers.rs renamed to crates/sqlbuild-python-front/src/attachments/_helpers/function_headers.rs

File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub(crate) mod argument_values;
2+
pub(crate) mod ceremonial_select;
3+
pub(crate) mod cursor_intrinsics;
4+
pub(crate) mod function_headers;
5+
pub(crate) mod reference_markers;

crates/sqlbuild-python/src/bindings/_helpers/attachments/reference_markers.rs renamed to crates/sqlbuild-python-front/src/attachments/_helpers/reference_markers.rs

File renamed without changes.

0 commit comments

Comments
 (0)