Skip to content

Commit cd0a2d9

Browse files
committed
feat(viz): require ggsql >= 0.5.2 for the visualize tool
The system prompt now documents ggsql 0.5.x-only syntax (hinge, aggregate, jitter, radar, rich-text labels, minor_breaks), so running the visualize tool against an older ggsql would fail at query-validation time. - pyproject.toml: viz and dev extras require ggsql>=0.5.2 (was >=0.3.2) - R DESCRIPTION: ggsql (>= 0.5.2) in Suggests - Runtime guards (Python has_viz_deps(), R check_viz_deps()) treat ggsql < 0.5.2 like a missing install: warn once and drop the visualize tool, with messages stating the 0.5.2 requirement
1 parent 5577c34 commit cd0a2d9

5 files changed

Lines changed: 33 additions & 10 deletions

File tree

‎pkg-py/src/querychat/_querychat_base.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,8 +830,8 @@ def normalize_tools(
830830
return resolved
831831
if resolved is not None and has_viz_tool(resolved) and not has_viz_deps():
832832
warnings.warn(
833-
"Visualization tools require ggsql, altair, shinywidgets, and "
834-
"vl-convert-python. Install them with: pip install querychat[viz]. "
833+
"Visualization tools require ggsql>=0.5.2, altair, shinywidgets, "
834+
"and vl-convert-python. Install them with: pip install querychat[viz]. "
835835
"Continuing without the 'visualize' tool.",
836836
stacklevel=2,
837837
)

‎pkg-py/src/querychat/_viz_utils.py‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
from __future__ import annotations
44

5+
import importlib.metadata
56
import importlib.util
67

78
from htmltools import HTMLDependency, tags
89

910
from .__version import __version__
1011

12+
MIN_GGSQL_VERSION = (0, 5, 2)
13+
1114

1215
def has_viz_tool(tools: set[str] | None) -> bool:
1316
"""Check if visualize is among the configured tools."""
@@ -16,10 +19,28 @@ def has_viz_tool(tools: set[str] | None) -> bool:
1619

1720
def has_viz_deps() -> bool:
1821
"""Check whether visualization dependencies (ggsql, altair, shinywidgets, vl-convert-python) are installed."""
19-
return all(
20-
importlib.util.find_spec(pkg) is not None
22+
if any(
23+
importlib.util.find_spec(pkg) is None
2124
for pkg in ("ggsql", "altair", "shinywidgets", "vl_convert")
22-
)
25+
):
26+
return False
27+
return ggsql_version() >= MIN_GGSQL_VERSION
28+
29+
30+
def ggsql_version() -> tuple[int, ...]:
31+
"""Installed ggsql version as a comparable tuple (e.g. ``(0, 5, 2)``)."""
32+
raw = importlib.metadata.version("ggsql")
33+
parts: list[int] = []
34+
for piece in raw.split("."):
35+
num = ""
36+
for ch in piece:
37+
if not ch.isdigit():
38+
break
39+
num += ch
40+
if not num:
41+
break
42+
parts.append(int(num))
43+
return tuple(parts)
2344

2445

2546
PRELOAD_WIDGET_ID = "__querychat_preload_viz__"

‎pkg-r/DESCRIPTION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Suggests:
4747
dplyr,
4848
DT,
4949
duckdb,
50-
ggsql,
50+
ggsql (>= 0.5.2),
5151
knitr,
5252
later,
5353
nanoparquet,

‎pkg-r/R/QueryChat.R‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,13 +1652,15 @@ normalize_tools <- function(tools) {
16521652

16531653
check_viz_deps <- function(tools) {
16541654
if (
1655-
is.null(tools) || !"visualize" %in% tools || rlang::is_installed("ggsql")
1655+
is.null(tools) ||
1656+
!"visualize" %in% tools ||
1657+
rlang::is_installed("ggsql", version = "0.5.2")
16561658
) {
16571659
return(tools)
16581660
}
16591661
rlang::warn(
16601662
c(
1661-
'The "visualize" tool requires the {.pkg ggsql} package.',
1663+
'The "visualize" tool requires {.pkg ggsql} 0.5.2 or later.',
16621664
"i" = 'Install it with `install.packages("ggsql")`; continuing without the "visualize" tool.'
16631665
),
16641666
.frequency = "once",

‎pyproject.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ gradio = ["gradio>=6.0"]
6262
dash = ["dash-ag-grid>=31.0", "dash[async]>=3.1", "dash-bootstrap-components>=2.0", "pandas"]
6363
# Visualization with ggsql
6464
viz = [
65-
"ggsql>=0.3.2",
65+
"ggsql>=0.5.2",
6666
"altair>=6.0",
6767
"shinywidgets>=0.8.0",
6868
"vl-convert-python>=1.9.0",
@@ -117,7 +117,7 @@ dev = [
117117
"ibis-framework[duckdb]>=9.0.0",
118118
# see note on the `ibis` extra above
119119
"sqlglot<30.18.0",
120-
"ggsql>=0.3.2",
120+
"ggsql>=0.5.2",
121121
"altair>=6.0",
122122
"shinywidgets>=0.8.0",
123123
"vl-convert-python>=1.9.0",

0 commit comments

Comments
 (0)