Skip to content

Commit 62d61ad

Browse files
committed
added debug option to methods that work via queries
1 parent ff41ed8 commit 62d61ad

File tree

8 files changed

+382
-328
lines changed

8 files changed

+382
-328
lines changed

src/annotation.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,7 @@ impl PyAnnotations {
960960
where
961961
F: FnOnce(Query, &AnnotationStore) -> Result<T, StamError>,
962962
{
963+
let debug = get_debug(kwargs);
963964
self.map(|annotations, store| {
964965
let query = Query::new(QueryType::Select, Some(Type::Annotation), Some("main"))
965966
.with_constraint(Constraint::Annotations(
@@ -979,6 +980,9 @@ impl PyAnnotations {
979980
StamError::QuerySyntaxError(format!("{}", e), "(python to query)")
980981
})?,
981982
);
983+
if debug {
984+
eprintln!("[STAM DEBUG]: {}", query.to_string()?);
985+
}
982986
f(query, store)
983987
})
984988
}
@@ -1070,6 +1074,7 @@ impl PyAnnotation {
10701074
where
10711075
F: FnOnce(ResultItem<Annotation>, Query) -> Result<T, StamError>,
10721076
{
1077+
let debug = get_debug(kwargs);
10731078
self.map(|annotation| {
10741079
let query = build_query(
10751080
Query::new(QueryType::Select, Some(resulttype), Some("result"))
@@ -1080,6 +1085,9 @@ impl PyAnnotation {
10801085
)
10811086
.map_err(|e| StamError::QuerySyntaxError(format!("{}", e), "(python to query)"))?
10821087
.with_annotationvar("main", &annotation);
1088+
if debug {
1089+
eprintln!("[STAM DEBUG]: {}", query.to_string()?);
1090+
}
10831091
f(annotation, query)
10841092
})
10851093
}

src/annotationdata.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ impl PyDataKey {
191191
where
192192
F: FnOnce(ResultItem<DataKey>, Query) -> Result<T, StamError>,
193193
{
194+
let debug = get_debug(kwargs);
194195
self.map(|key| {
195196
let query = build_query(
196197
Query::new(QueryType::Select, Some(resulttype), Some("result"))
@@ -201,6 +202,9 @@ impl PyDataKey {
201202
)
202203
.map_err(|e| StamError::QuerySyntaxError(format!("{}", e), "(python to query)"))?
203204
.with_keyvar("main", &key);
205+
if debug {
206+
eprintln!("[STAM DEBUG]: {}", query.to_string()?);
207+
}
204208
f(key, query)
205209
})
206210
}
@@ -537,6 +541,7 @@ impl PyAnnotationData {
537541
where
538542
F: FnOnce(ResultItem<AnnotationData>, Query) -> Result<T, StamError>,
539543
{
544+
let debug = get_debug(kwargs);
540545
self.map(|data| {
541546
let query = build_query(
542547
Query::new(QueryType::Select, Some(resulttype), Some("result"))
@@ -547,6 +552,9 @@ impl PyAnnotationData {
547552
)
548553
.map_err(|e| StamError::QuerySyntaxError(format!("{}", e), "(python to query)"))?
549554
.with_datavar("main", &data);
555+
if debug {
556+
eprintln!("[STAM DEBUG]: {}", query.to_string()?);
557+
}
550558
f(data, query)
551559
})
552560
}

src/annotationdataset.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ impl PyAnnotationDataSet {
297297
where
298298
F: FnOnce(ResultItem<AnnotationDataSet>, Query) -> Result<T, StamError>,
299299
{
300+
let debug = get_debug(kwargs);
300301
self.map(|dataset| {
301302
let query = build_query(
302303
Query::new(QueryType::Select, Some(resulttype), Some("result"))
@@ -307,6 +308,9 @@ impl PyAnnotationDataSet {
307308
)
308309
.map_err(|e| StamError::QuerySyntaxError(format!("{}", e), "(python to query)"))?
309310
.with_datasetvar("main", &dataset);
311+
if debug {
312+
eprintln!("[STAM DEBUG]: {}", query.to_string()?);
313+
}
310314
f(dataset, query)
311315
})
312316
}

src/annotationstore.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ impl PyAnnotationStore {
739739
where
740740
F: FnOnce(Query, &AnnotationStore) -> Result<T, StamError>,
741741
{
742+
let debug = get_debug(kwargs);
742743
self.map_store(|store| {
743744
let query = build_query(
744745
Query::new(QueryType::Select, Some(resulttype), None),
@@ -747,6 +748,9 @@ impl PyAnnotationStore {
747748
store,
748749
)
749750
.map_err(|e| StamError::QuerySyntaxError(format!("{}", e), "(python to query)"))?;
751+
if debug {
752+
eprintln!("[STAM DEBUG]: {}", query.to_string()?);
753+
}
750754
f(query, store)
751755
})
752756
}

src/query.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,17 @@ pub(crate) fn get_limit(kwargs: Option<&PyDict>) -> Option<usize> {
421421
None
422422
}
423423

424+
pub(crate) fn get_debug(kwargs: Option<&PyDict>) -> bool {
425+
if let Some(kwargs) = kwargs {
426+
if let Ok(Some(debug)) = kwargs.get_item("debug") {
427+
if let Ok(debug) = debug.extract::<bool>() {
428+
return debug;
429+
}
430+
}
431+
}
432+
false
433+
}
434+
424435
pub(crate) fn get_substore(kwargs: Option<&PyDict>) -> Option<bool> {
425436
if let Some(kwargs) = kwargs {
426437
if let Ok(Some(substore)) = kwargs.get_item("substore") {

src/resources.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ impl PyTextResource {
588588
where
589589
F: FnOnce(ResultItem<TextResource>, Query) -> Result<T, StamError>,
590590
{
591+
let debug = get_debug(kwargs);
591592
self.map(|resource| {
592593
let query = build_query(
593594
Query::new(QueryType::Select, Some(resulttype), Some("result"))
@@ -598,6 +599,9 @@ impl PyTextResource {
598599
)
599600
.map_err(|e| StamError::QuerySyntaxError(format!("{}", e), "(python to query)"))?
600601
.with_resourcevar("main", &resource);
602+
if debug {
603+
eprintln!("[STAM DEBUG]: {}", query.to_string()?);
604+
}
601605
f(resource, query)
602606
})
603607
}

src/textselection.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ impl PyTextSelection {
607607
where
608608
F: FnOnce(ResultTextSelection, Query) -> Result<T, StamError>,
609609
{
610+
let debug = get_debug(kwargs);
610611
self.map(|textselection| {
611612
let query = build_query(
612613
Query::new(QueryType::Select, Some(resulttype), Some("result"))
@@ -617,6 +618,9 @@ impl PyTextSelection {
617618
)
618619
.map_err(|e| StamError::QuerySyntaxError(format!("{}", e), "(python to query)"))?
619620
.with_textvar("main", &textselection);
621+
if debug {
622+
eprintln!("[STAM DEBUG]: {}", query.to_string()?);
623+
}
620624
f(textselection, query)
621625
})
622626
}
@@ -952,6 +956,7 @@ impl PyTextSelections {
952956
where
953957
F: FnOnce(Query, &AnnotationStore) -> Result<T, StamError>,
954958
{
959+
let debug = get_debug(kwargs);
955960
self.map(|textselections, store| {
956961
let query = Query::new(QueryType::Select, Some(Type::Annotation), Some("main"))
957962
.with_constraint(Constraint::TextSelections(
@@ -970,6 +975,9 @@ impl PyTextSelections {
970975
StamError::QuerySyntaxError(format!("{}", e), "(python to query)")
971976
})?,
972977
);
978+
if debug {
979+
eprintln!("[STAM DEBUG]: {}", query.to_string()?);
980+
}
973981
f(query, store)
974982
})
975983
}

0 commit comments

Comments
 (0)