Skip to content

Commit

Permalink
added debug option to methods that work via queries
Browse files Browse the repository at this point in the history
  • Loading branch information
proycon committed Oct 15, 2024
1 parent ff41ed8 commit 62d61ad
Show file tree
Hide file tree
Showing 8 changed files with 382 additions and 328 deletions.
8 changes: 8 additions & 0 deletions src/annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ impl PyAnnotations {
where
F: FnOnce(Query, &AnnotationStore) -> Result<T, StamError>,
{
let debug = get_debug(kwargs);
self.map(|annotations, store| {
let query = Query::new(QueryType::Select, Some(Type::Annotation), Some("main"))
.with_constraint(Constraint::Annotations(
Expand All @@ -979,6 +980,9 @@ impl PyAnnotations {
StamError::QuerySyntaxError(format!("{}", e), "(python to query)")
})?,
);
if debug {
eprintln!("[STAM DEBUG]: {}", query.to_string()?);
}
f(query, store)
})
}
Expand Down Expand Up @@ -1070,6 +1074,7 @@ impl PyAnnotation {
where
F: FnOnce(ResultItem<Annotation>, Query) -> Result<T, StamError>,
{
let debug = get_debug(kwargs);
self.map(|annotation| {
let query = build_query(
Query::new(QueryType::Select, Some(resulttype), Some("result"))
Expand All @@ -1080,6 +1085,9 @@ impl PyAnnotation {
)
.map_err(|e| StamError::QuerySyntaxError(format!("{}", e), "(python to query)"))?
.with_annotationvar("main", &annotation);
if debug {
eprintln!("[STAM DEBUG]: {}", query.to_string()?);
}
f(annotation, query)
})
}
Expand Down
8 changes: 8 additions & 0 deletions src/annotationdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ impl PyDataKey {
where
F: FnOnce(ResultItem<DataKey>, Query) -> Result<T, StamError>,
{
let debug = get_debug(kwargs);
self.map(|key| {
let query = build_query(
Query::new(QueryType::Select, Some(resulttype), Some("result"))
Expand All @@ -201,6 +202,9 @@ impl PyDataKey {
)
.map_err(|e| StamError::QuerySyntaxError(format!("{}", e), "(python to query)"))?
.with_keyvar("main", &key);
if debug {
eprintln!("[STAM DEBUG]: {}", query.to_string()?);
}
f(key, query)
})
}
Expand Down Expand Up @@ -537,6 +541,7 @@ impl PyAnnotationData {
where
F: FnOnce(ResultItem<AnnotationData>, Query) -> Result<T, StamError>,
{
let debug = get_debug(kwargs);
self.map(|data| {
let query = build_query(
Query::new(QueryType::Select, Some(resulttype), Some("result"))
Expand All @@ -547,6 +552,9 @@ impl PyAnnotationData {
)
.map_err(|e| StamError::QuerySyntaxError(format!("{}", e), "(python to query)"))?
.with_datavar("main", &data);
if debug {
eprintln!("[STAM DEBUG]: {}", query.to_string()?);
}
f(data, query)
})
}
Expand Down
4 changes: 4 additions & 0 deletions src/annotationdataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ impl PyAnnotationDataSet {
where
F: FnOnce(ResultItem<AnnotationDataSet>, Query) -> Result<T, StamError>,
{
let debug = get_debug(kwargs);
self.map(|dataset| {
let query = build_query(
Query::new(QueryType::Select, Some(resulttype), Some("result"))
Expand All @@ -307,6 +308,9 @@ impl PyAnnotationDataSet {
)
.map_err(|e| StamError::QuerySyntaxError(format!("{}", e), "(python to query)"))?
.with_datasetvar("main", &dataset);
if debug {
eprintln!("[STAM DEBUG]: {}", query.to_string()?);
}
f(dataset, query)
})
}
Expand Down
4 changes: 4 additions & 0 deletions src/annotationstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ impl PyAnnotationStore {
where
F: FnOnce(Query, &AnnotationStore) -> Result<T, StamError>,
{
let debug = get_debug(kwargs);
self.map_store(|store| {
let query = build_query(
Query::new(QueryType::Select, Some(resulttype), None),
Expand All @@ -747,6 +748,9 @@ impl PyAnnotationStore {
store,
)
.map_err(|e| StamError::QuerySyntaxError(format!("{}", e), "(python to query)"))?;
if debug {
eprintln!("[STAM DEBUG]: {}", query.to_string()?);
}
f(query, store)
})
}
Expand Down
11 changes: 11 additions & 0 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,17 @@ pub(crate) fn get_limit(kwargs: Option<&PyDict>) -> Option<usize> {
None
}

pub(crate) fn get_debug(kwargs: Option<&PyDict>) -> bool {
if let Some(kwargs) = kwargs {
if let Ok(Some(debug)) = kwargs.get_item("debug") {
if let Ok(debug) = debug.extract::<bool>() {
return debug;
}
}
}
false
}

pub(crate) fn get_substore(kwargs: Option<&PyDict>) -> Option<bool> {
if let Some(kwargs) = kwargs {
if let Ok(Some(substore)) = kwargs.get_item("substore") {
Expand Down
4 changes: 4 additions & 0 deletions src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ impl PyTextResource {
where
F: FnOnce(ResultItem<TextResource>, Query) -> Result<T, StamError>,
{
let debug = get_debug(kwargs);
self.map(|resource| {
let query = build_query(
Query::new(QueryType::Select, Some(resulttype), Some("result"))
Expand All @@ -598,6 +599,9 @@ impl PyTextResource {
)
.map_err(|e| StamError::QuerySyntaxError(format!("{}", e), "(python to query)"))?
.with_resourcevar("main", &resource);
if debug {
eprintln!("[STAM DEBUG]: {}", query.to_string()?);
}
f(resource, query)
})
}
Expand Down
8 changes: 8 additions & 0 deletions src/textselection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ impl PyTextSelection {
where
F: FnOnce(ResultTextSelection, Query) -> Result<T, StamError>,
{
let debug = get_debug(kwargs);
self.map(|textselection| {
let query = build_query(
Query::new(QueryType::Select, Some(resulttype), Some("result"))
Expand All @@ -617,6 +618,9 @@ impl PyTextSelection {
)
.map_err(|e| StamError::QuerySyntaxError(format!("{}", e), "(python to query)"))?
.with_textvar("main", &textselection);
if debug {
eprintln!("[STAM DEBUG]: {}", query.to_string()?);
}
f(textselection, query)
})
}
Expand Down Expand Up @@ -952,6 +956,7 @@ impl PyTextSelections {
where
F: FnOnce(Query, &AnnotationStore) -> Result<T, StamError>,
{
let debug = get_debug(kwargs);
self.map(|textselections, store| {
let query = Query::new(QueryType::Select, Some(Type::Annotation), Some("main"))
.with_constraint(Constraint::TextSelections(
Expand All @@ -970,6 +975,9 @@ impl PyTextSelections {
StamError::QuerySyntaxError(format!("{}", e), "(python to query)")
})?,
);
if debug {
eprintln!("[STAM DEBUG]: {}", query.to_string()?);
}
f(query, store)
})
}
Expand Down
Loading

0 comments on commit 62d61ad

Please sign in to comment.