Skip to content

Commit eb86507

Browse files
authored
Merge pull request #22 from jqnatividad/qsv-client-0.4.0
build: qsv-client >= 0.4.0
2 parents 7665d6c + b6e6853 commit eb86507

4 files changed

Lines changed: 51 additions & 23 deletions

File tree

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ dependencies = [
4242
"httpx>=0.26.0",
4343

4444
# qsv runner (timeouts, typed errors) for the onboarding profiling passes
45-
"qsv-client>=0.3.0",
45+
"qsv-client>=0.4.0",
4646

4747
# Vector Search (Pinecone for CKAN semantic search)
4848
# Note: Use the new `pinecone` package (v5+), NOT the legacy

‎src/data_concierge/data_layer/qsv_profiling.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
QsvError,
4646
QsvNotFound,
4747
QsvTimeout,
48-
QsvVersionError,
4948
)
5049

5150
from data_concierge.data_layer.storage import storage
@@ -80,10 +79,10 @@ async def download_csv(url: str, dest: Path) -> int:
8079
"count": 120.0,
8180
}
8281

83-
# A failed run, a missing or too-old binary, or output that does not parse. QsvNotFound and
84-
# QsvVersionError are not QsvError subclasses, and the client raises QsvNotFound from its
82+
# A failed run, a missing or too-old binary, or output that does not parse. A too-old qsv
83+
# (QsvVersionError) is a QsvError; QsvNotFound is not, and the client raises it from its
8584
# constructor.
86-
_QSV_FAILURES = (QsvError, QsvNotFound, QsvVersionError, ValueError)
85+
_QSV_FAILURES = (QsvError, QsvNotFound, ValueError)
8786

8887
# Binaries whose missing describegpt has already been reported, so a portal run warns once.
8988
_describegpt_checked: set[str] = set()

‎tests/unit/test_qsv_profiling.py‎

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,34 @@
2323
posix_only = pytest.mark.skipif(sys.platform == "win32", reason="fake qsv is a POSIX script")
2424

2525

26-
def _fake_qsv(tmp_path: Path, monkeypatch: pytest.MonkeyPatch, body: str) -> Path:
27-
"""Put a Python script named ``qsv`` first on PATH, ahead of any real qsv."""
26+
QSV_CAPABILITIES = {
27+
"binary": "qsv",
28+
"version": "25.0.0",
29+
"commands": ["count", "describegpt", "frequency", "stats"],
30+
}
31+
32+
33+
def _fake_qsv(
34+
tmp_path: Path,
35+
monkeypatch: pytest.MonkeyPatch,
36+
body: str,
37+
capabilities: dict | None = QSV_CAPABILITIES,
38+
) -> Path:
39+
"""Put a Python script named ``qsv`` first on PATH, ahead of any real qsv.
40+
41+
It answers ``--capabilities`` with ``capabilities`` (qsv-client checks that before the
42+
first run); pass ``None`` to leave it to ``body``, like a qsv older than 25.0.0.
43+
"""
2844
fake = tmp_path / "bin" / "qsv"
2945
fake.parent.mkdir(exist_ok=True)
30-
fake.write_text(f"#!{sys.executable}\nimport json, os, sys, time\n{body}")
46+
caps = (
47+
""
48+
if capabilities is None
49+
else f"if sys.argv[1:] == ['--capabilities']:\n"
50+
f" print({json.dumps(capabilities)!r})\n"
51+
f" sys.exit(0)\n"
52+
)
53+
fake.write_text(f"#!{sys.executable}\nimport json, os, sys, time\n{caps}{body}")
3154
fake.chmod(0o755)
3255
monkeypatch.setenv("PATH", f"{fake.parent}:{os.environ['PATH']}")
3356
monkeypatch.delenv("QSV_BIN", raising=False)
@@ -160,22 +183,28 @@ async def test_describegpt_failure_on_a_binary_without_it_says_so(tmp_path, monk
160183
_fake_qsv(
161184
tmp_path,
162185
monkeypatch,
163-
"arg = sys.argv[1]\n"
164-
"if arg == '--version':\n"
165-
" print('qsvlite 24.0.0-standard-16-16; (aarch64-apple-darwin compiled with Rust 1.99)')\n"
166-
"elif arg == '--list':\n"
167-
" print('Installed commands (2):')\n"
168-
" print(' count Count records')\n"
169-
" print(' stats Infer data types')\n"
170-
"else:\n"
171-
" sys.stderr.write('Invalid arguments.\\n')\n"
172-
" sys.exit(1 if arg == '--capabilities' else 2)\n",
186+
"sys.stderr.write('Invalid arguments.\\n')\nsys.exit(2)\n",
187+
capabilities={"binary": "qsvlite", "version": "25.0.0", "commands": ["count", "stats"]},
173188
)
174189
out = tmp_path / "qsv_dict.json"
175190

176191
assert await run_qsv_describegpt(tmp_path / "data.csv", KEY, out) is None
177192

178193
printed = capsys.readouterr().out
179194
assert "has no describegpt" in printed
180-
assert "qsvlite 24.0.0" in printed
195+
assert "qsvlite 25.0.0" in printed
181196
assert not out.exists()
197+
198+
199+
@posix_only
200+
async def test_too_old_qsv_returns_none_instead_of_raising(tmp_path, monkeypatch, capsys):
201+
# qsv before 25.0.0 rejects --capabilities, and qsv-client refuses to run it.
202+
_fake_qsv(
203+
tmp_path,
204+
monkeypatch,
205+
"sys.stderr.write(\"Unknown flag: '--capabilities'\\n\")\nsys.exit(1)\n",
206+
capabilities=None,
207+
)
208+
209+
assert await run_qsv_count(tmp_path / "data.csv") is None
210+
assert "QsvVersionError" in capsys.readouterr().out

‎uv.lock‎

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

0 commit comments

Comments
 (0)