1- #!/usr/bin/env python3
21"""
3- Check compatibility between sqlalchemy-paradedb's api.json and a released pg_search schema.
2+ Check compatibility between sqlalchemy-paradedb's api.json5 and a released pg_search schema.
43
54The schema is downloaded from the corresponding ParadeDB GitHub release and
65checked in both directions:
76
8- Forward: every symbol in api.json is present in the schema (detects removals/renames).
9- Reverse: every pdb.* symbol in the schema is either in api.json or in apiignore.json
7+ Forward: every symbol in api.json5 is present in the schema (detects removals/renames).
8+ Reverse: every pdb.* symbol in the schema is either in api.json5 or in apiignore.json5
109 (surfaces new paradedb APIs that haven't been wrapped yet).
1110
1211Example:
1312 python scripts/check_schema_compat.py 0.22.0
1413
15- The ignore list is read automatically from apiignore.json (repo root) if it exists.
14+ The ignore list is read automatically from apiignore.json5 (repo root) if it exists.
1615"""
1716
1817import argparse
19- import json
2018import re
2119import shutil
2220import subprocess
2321import sys
2422import tempfile
2523from pathlib import Path
2624
25+ import json5
26+
2727_ROOT_DIR = Path (__file__ ).resolve ().parent .parent
28- _API_FILE = _ROOT_DIR / "api.json "
29- _IGNORE_FILE = _ROOT_DIR / "apiignore.json "
28+ _API_FILE = _ROOT_DIR / "api.json5 "
29+ _IGNORE_FILE = _ROOT_DIR / "apiignore.json5 "
3030_SCHEMA_FILE_NAME = "pg_search.schema.sql"
3131
3232
@@ -36,8 +36,8 @@ def normalize(sql: str) -> str:
3636
3737
3838def extract_from_api (path : Path ) -> dict :
39- """Read api.json and return {functions: [...], operators: [...], types: [...]}."""
40- data = json .loads (path .read_text ())
39+ """Read api.json5 and return {functions: [...], operators: [...], types: [...]}."""
40+ data = json5 .loads (path .read_text ())
4141 return {
4242 "functions" : sorted (set (data ["functions" ].values ())),
4343 "operators" : sorted (set (data ["operators" ].values ())),
@@ -104,7 +104,7 @@ def normalize_version(version: str) -> str:
104104
105105def parse_args (argv : list [str ]) -> argparse .Namespace :
106106 parser = argparse .ArgumentParser (
107- description = ("Download pg_search.schema.sql for a ParadeDB release and check it against this repo's api.json ." )
107+ description = ("Download pg_search.schema.sql for a ParadeDB release and check it against this repo's api.json5 ." )
108108 )
109109 parser .add_argument ("version" , help = "ParadeDB version to check, for example 0.22.0" )
110110 return parser .parse_args (argv )
@@ -164,17 +164,17 @@ def run_checks(schema_path: Path, api_path: Path) -> int:
164164 print (f"❌ Schema file not found: { schema_path } " , file = sys .stderr )
165165 return 1
166166 if not api_path .exists ():
167- print (f"❌ api.json not found: { api_path } " , file = sys .stderr )
167+ print (f"❌ api.json5 not found: { api_path } " , file = sys .stderr )
168168 return 1
169169
170170 schema = normalize (schema_path .read_text ())
171171 deps = extract_from_api (api_path )
172- ignored = json .loads (_IGNORE_FILE .read_text ()) if _IGNORE_FILE .exists () else {}
172+ ignored = json5 .loads (_IGNORE_FILE .read_text ()) if _IGNORE_FILE .exists () else {}
173173
174174 rc = 0
175175
176176 # ------------------------------------------------------------------
177- # Forward check: every symbol in api.json must exist in the schema.
177+ # Forward check: every symbol in api.json5 must exist in the schema.
178178 # ------------------------------------------------------------------
179179 missing : list [tuple [str , str ]] = []
180180 for fn in deps .get ("functions" , []):
@@ -189,20 +189,20 @@ def run_checks(schema_path: Path, api_path: Path) -> int:
189189
190190 total_api = sum (len (v ) for v in deps .values () if isinstance (v , list ))
191191 if missing :
192- print (f"❌ Forward check: { len (missing )} /{ total_api } api.json symbols missing from schema:" )
192+ print (f"❌ Forward check: { len (missing )} /{ total_api } api.json5 symbols missing from schema:" )
193193 for kind , name in missing :
194194 print (f" { kind } : { name } " )
195195 print (
196196 "\n These symbols were removed or renamed in this version of pg_search.\n "
197- "Update sqlalchemy-paradedb to handle the API change, then update api.json ."
197+ "Update sqlalchemy-paradedb to handle the API change, then update api.json5 ."
198198 )
199199 rc = 1
200200 else :
201- print (f"✅ Forward check: all { total_api } api.json symbols present in schema." )
201+ print (f"✅ Forward check: all { total_api } api.json5 symbols present in schema." )
202202
203203 # ------------------------------------------------------------------
204- # Reverse check: every pdb.* symbol in the schema must be in api.json
205- # or explicitly ignored in apiignore.json .
204+ # Reverse check: every pdb.* symbol in the schema must be in api.json5
205+ # or explicitly ignored in apiignore.json5 .
206206 # ------------------------------------------------------------------
207207 schema_symbols = scan_schema_symbols (schema )
208208 uncovered : list [tuple [str , str ]] = []
@@ -215,12 +215,12 @@ def run_checks(schema_path: Path, api_path: Path) -> int:
215215
216216 total_schema = sum (len (v ) for v in schema_symbols .values ())
217217 if uncovered :
218- print (f"\n ⚠️ Reverse check: { len (uncovered )} schema symbols not covered by api.json :" )
218+ print (f"\n ⚠️ Reverse check: { len (uncovered )} schema symbols not covered by api.json5 :" )
219219 for kind , name in uncovered :
220220 print (f" { kind } : { name } " )
221221 print (
222222 "\n These are paradedb APIs not yet wrapped by sqlalchemy-paradedb.\n "
223- "Either add them to api.json or add them to apiignore.json ."
223+ "Either add them to api.json5 or add them to apiignore.json5 ."
224224 )
225225 rc = 1
226226 else :
0 commit comments