Skip to content

Commit f346d9a

Browse files
committed
refactor: move rendered spec related struct into pymod
1 parent 15897e9 commit f346d9a

File tree

2 files changed

+23
-42
lines changed

2 files changed

+23
-42
lines changed

src/base/spec.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::prelude::*;
22

33
use super::schema::{EnrichedValueType, FieldSchema};
4-
use pyo3::prelude::*;
54
use serde::{Deserialize, Serialize};
65
use std::fmt;
76
use std::ops::Deref;
@@ -19,27 +18,6 @@ pub trait SpecFormatter {
1918
fn format(&self, mode: OutputMode) -> String;
2019
}
2120

22-
/// A single line in the rendered spec, with optional scope and children
23-
#[pyclass(get_all, set_all)]
24-
#[derive(Debug, Clone, Serialize, Deserialize)]
25-
pub struct RenderedSpecLine {
26-
/// The formatted content of the line (e.g., "Import: name=documents, source=LocalFile")
27-
pub content: String,
28-
/// The scope name, if applicable (e.g., "documents_1" for ForEach scopes)
29-
#[serde(default, skip_serializing_if = "Option::is_none")]
30-
pub scope: Option<String>,
31-
/// Child lines in the hierarchy
32-
pub children: Vec<RenderedSpecLine>,
33-
}
34-
35-
/// A rendered specification, grouped by sections
36-
#[pyclass(get_all, set_all)]
37-
#[derive(Debug, Clone, Serialize, Deserialize)]
38-
pub struct RenderedSpec {
39-
/// List of (section_name, lines) pairs
40-
pub sections: Vec<(String, Vec<RenderedSpecLine>)>,
41-
}
42-
4321
#[derive(Debug, Clone, Serialize, Deserialize)]
4422
#[serde(tag = "kind")]
4523
pub enum SpecString {

src/py/mod.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use crate::prelude::*;
22

33
use crate::base::schema::{FieldSchema, ValueType};
44
use crate::base::spec::VectorSimilarityMetric;
5-
use crate::base::spec::{NamedSpec, ReactiveOpSpec};
6-
use crate::base::spec::{OutputMode, RenderedSpec, RenderedSpecLine, SpecFormatter};
5+
use crate::base::spec::{NamedSpec, OutputMode, ReactiveOpSpec, SpecFormatter};
76
use crate::execution::query;
87
use crate::lib_context::{clear_lib_context, get_auth_registry, init_lib_context};
98
use crate::ops::interface::{QueryResult, QueryResults};
@@ -115,6 +114,24 @@ impl IndexUpdateInfo {
115114
#[pyclass]
116115
pub struct Flow(pub Arc<FlowContext>);
117116

117+
/// A single line in the rendered spec, with hierarchical children
118+
#[pyclass(get_all, set_all)]
119+
#[derive(Debug, Clone, Serialize, Deserialize)]
120+
pub struct RenderedSpecLine {
121+
/// The formatted content of the line (e.g., "Import: name=documents, source=LocalFile")
122+
pub content: String,
123+
/// Child lines in the hierarchy
124+
pub children: Vec<RenderedSpecLine>,
125+
}
126+
127+
/// A rendered specification, grouped by sections
128+
#[pyclass(get_all, set_all)]
129+
#[derive(Debug, Clone, Serialize, Deserialize)]
130+
pub struct RenderedSpec {
131+
/// List of (section_name, lines) pairs
132+
pub sections: Vec<(String, Vec<RenderedSpecLine>)>,
133+
}
134+
118135
#[pyclass]
119136
pub struct FlowLiveUpdater(pub Arc<tokio::sync::RwLock<execution::FlowLiveUpdater>>);
120137

@@ -211,43 +228,31 @@ impl Flow {
211228
.iter()
212229
.map(|op| RenderedSpecLine {
213230
content: format!("Import: name={}, {}", op.name, op.spec.format(mode)),
214-
scope: None,
215231
children: vec![],
216232
})
217233
.collect(),
218234
);
219235

220236
// Processing
221-
fn walk(
222-
op: &NamedSpec<ReactiveOpSpec>,
223-
mode: OutputMode,
224-
scope: Option<String>,
225-
) -> RenderedSpecLine {
237+
fn walk(op: &NamedSpec<ReactiveOpSpec>, mode: OutputMode) -> RenderedSpecLine {
226238
let content = format!("{}: {}", op.name, op.spec.format(mode));
227239

228240
let children = match &op.spec {
229241
ReactiveOpSpec::ForEach(fe) => fe
230242
.op_scope
231243
.ops
232244
.iter()
233-
.map(|nested| walk(nested, mode, Some(fe.op_scope.name.clone())))
245+
.map(|nested| walk(nested, mode))
234246
.collect(),
235247
_ => vec![],
236248
};
237249

238-
RenderedSpecLine {
239-
content,
240-
scope,
241-
children,
242-
}
250+
RenderedSpecLine { content, children }
243251
}
244252

245253
sections.insert(
246254
"Processing".to_string(),
247-
spec.reactive_ops
248-
.iter()
249-
.map(|op| walk(op, mode, None))
250-
.collect(),
255+
spec.reactive_ops.iter().map(|op| walk(op, mode)).collect(),
251256
);
252257

253258
// Targets
@@ -257,7 +262,6 @@ impl Flow {
257262
.iter()
258263
.map(|op| RenderedSpecLine {
259264
content: format!("Export: name={}, {}", op.name, op.spec.format(mode)),
260-
scope: None,
261265
children: vec![],
262266
})
263267
.collect(),
@@ -270,7 +274,6 @@ impl Flow {
270274
.iter()
271275
.map(|decl| RenderedSpecLine {
272276
content: format!("Declaration: {}", decl.format(mode)),
273-
scope: None,
274277
children: vec![],
275278
})
276279
.collect(),

0 commit comments

Comments
 (0)