Skip to content

Commit 810e63b

Browse files
committed
minor version/build version issue resolved
1 parent 1724b1f commit 810e63b

1 file changed

Lines changed: 40 additions & 105 deletions

File tree

cli/scripts/util.py

Lines changed: 40 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -124,122 +124,57 @@ def get_default_spock(pgv):
124124

125125
return(DEFAULT_SPOCK)
126126

127-
128-
129127
def validate_spock_pg_compat(spock_ver: str = None, pg_ver: str = None) -> None:
130-
"""
131-
Compatibility rules:
132-
• If Spock < 5.0.0 ⇒ works with any supported PostgreSQL major.
133-
• If Spock ≥ 5.0.0 ⇒
134-
– PG15 must be ≥ 15.13
135-
– PG16 must be ≥ 16.9
136-
– PG17 must be ≥ 17.5
137-
138-
Also supports shorthand Spock strings:
139-
– "50" → "5.0.0", "40" → "4.0.0", etc.
140-
"""
141-
# 0) Fill in defaults if user didn’t pass anything
142-
if not pg_ver:
143-
pg_ver = DEFAULT_PG
144-
else:
145-
pg_ver = str(pg_ver) # ← force to string
146-
128+
# --- defaults (keep yours as-is) ---
129+
pg_ver = str(pg_ver) if pg_ver else str(DEFAULT_PG)
147130
if not spock_ver:
148-
maj = int(pg_ver.split(".", 1)[0])
131+
try:
132+
maj = int(pg_ver.split(".", 1)[0])
133+
except Exception:
134+
maj = 17
149135
spock_ver = DEFAULT_SPOCK_17 if maj == 17 else DEFAULT_SPOCK
150-
else:
151-
spock_ver = str(spock_ver) # ← force to string
152-
153-
154-
# 0.5) Normalize two-digit shorthand (e.g. "50" → "5.0.0")
155-
m = re.fullmatch(r'(\d)(\d)$', spock_ver)
156-
if m:
157-
spock_ver = f"{int(m.group(1))}.{int(m.group(2))}.0"
158-
159-
# 1) Parse Spock version (abort on bad format)
160-
try:
161-
spv = Version(spock_ver)
162-
except ValueError:
163-
exit_message(f"Invalid Spock version '{spock_ver}'. Aborting.", 1, isJSON)
164-
165-
# 2) If Spock < 5 ⇒ compatible with any PG
166-
if spv.major < 5:
136+
spock_ver = str(spock_ver)
137+
138+
# --- parse Spock major w/o 'packaging' dependency ---
139+
m_sp = re.fullmatch(r'(\d)(\d)$', spock_ver) # "50" -> "5.0.0"
140+
if m_sp:
141+
spock_ver = f"{int(m_sp.group(1))}.{int(m_sp.group(2))}.0"
142+
spock_major = int(spock_ver.split('.', 1)[0])
143+
if spock_major < 5:
167144
return
168145

169-
# — New block: handle pg_ver with “-1” or “-2” suffix
170-
rev = None
171-
rev_match = re.fullmatch(r'(\d+)\.(\d+)-(1|2)$', pg_ver)
172-
if rev_match:
173-
pg_major = int(rev_match.group(1))
174-
pg_patch = int(rev_match.group(2))
175-
rev = int(rev_match.group(3))
146+
# --- parse PG "MAJOR.MINOR-BUILD" (build 1 or 2 only) ---
147+
m = re.fullmatch(r'(\d+)\.(\d+)-(1|2)$', pg_ver)
148+
if not m:
149+
exit_message(f"Invalid PostgreSQL version '{pg_ver}'. Use 'MAJOR.MINOR-BUILD' (e.g., 17.6-1).", 1, isJSON)
150+
pg_major, pg_minor, pg_build = int(m.group(1)), int(m.group(2)), int(m.group(3))
151+
152+
# --- thresholds for 15/16/17: require -2 exactly at the min minor ---
153+
thresholds = {15: (13, 2), 16: (9, 2), 17: (5, 2)}
176154

177-
# reject revision “-1” on Spock ≥5
178-
if rev == 1:
155+
if pg_major in thresholds:
156+
min_minor, min_build = thresholds[pg_major]
157+
if pg_minor < min_minor:
179158
exit_message(
180-
f"Error: PostgreSQL {pg_major}.{pg_patch}-1 is not supported with Spock {spv}; "
181-
"please use the “-2” revision instead.",
182-
1,
183-
isJSON
159+
f"Error: Spock {spock_ver} requires PostgreSQL {pg_major}.{min_minor}-{min_build} or newer; "
160+
f"you have {pg_major}.{pg_minor}-{pg_build}.", 1, isJSON
184161
)
185-
# for “-2”, we strip suffix and proceed with pg_major/pg_patch below
186-
# end new block
187-
188-
# 3) Spock ≥ 5 ⇒ enforce minimum‐patch for each PG major
189-
minimum_patches = {
190-
15: 13,
191-
16: 9,
192-
17: 5,
193-
}
194-
195-
# 4) Extract PG major and patch (if not already set by rev_match)
196-
if rev_match:
197-
# pg_major, pg_patch are already set
198-
pass
199-
elif "." not in pg_ver:
200-
# bare-major → use its minimum patch
201-
try:
202-
pg_major = int(pg_ver)
203-
except ValueError:
204-
exit_message(f"Invalid PostgreSQL version '{pg_ver}'. Aborting.", 1, isJSON)
205-
if pg_major not in minimum_patches:
206-
allowed = ", ".join(str(m) for m in minimum_patches)
162+
if pg_minor == min_minor and pg_build < min_build:
163+
# At threshold minor, only -2 allowed
207164
exit_message(
208-
f"Error: Spock {spv} supports only PostgreSQL majors {allowed}; "
209-
f"you have {pg_major}. Aborting.",
210-
1,
211-
isJSON
165+
f"Error: Spock {spock_ver} requires PostgreSQL {pg_major}.{min_minor}-2 at the minimum; "
166+
f"you have {pg_major}.{pg_minor}-{pg_build}.", 1, isJSON
212167
)
213-
pg_patch = minimum_patches[pg_major]
214-
else:
215-
parts = pg_ver.split(".", 2)
216-
if len(parts) < 2:
217-
exit_message(f"Invalid PostgreSQL version '{pg_ver}'. Aborting.", 1, isJSON)
218-
try:
219-
pg_major = int(parts[0])
220-
pg_patch = int(parts[1])
221-
except ValueError:
222-
exit_message(f"Invalid PostgreSQL version '{pg_ver}'. Aborting.", 1, isJSON)
223-
224-
# 5) Major must be supported
225-
if pg_major not in minimum_patches:
226-
allowed = ", ".join(str(m) for m in minimum_patches)
227-
exit_message(
228-
f"Error: Spock {spv} supports only PostgreSQL majors {allowed}; "
229-
f"you have {pg_major}. Aborting.",
230-
1,
231-
isJSON
232-
)
168+
# pg_minor > min_minor → allow -1 or -2
169+
return
170+
171+
# --- future majors (≥18): allow -1 or -2, any minor ---
172+
if pg_major >= 18:
173+
return
174+
175+
# --- unsupported majors (<15) ---
176+
exit_message("Error: Supported PG majors are 15, 16, 17, and 18+.", 1, isJSON)
233177

234-
# 6) Enforce minimum‐patch
235-
required = minimum_patches[pg_major]
236-
if pg_patch < required:
237-
exit_message(
238-
f"Error: Spock {spv} requires PostgreSQL {pg_major}.{required} or newer; "
239-
f"you have {pg_major}.{pg_patch}. Aborting.",
240-
1,
241-
isJSON
242-
)
243178
def get_cpu_info():
244179
try:
245180
import cpuinfo

0 commit comments

Comments
 (0)