- versions: require entire normalized string to be numeric so dates and hotfix suffixes compare as incomparable instead of eq/gt - hosts: exact host or dot-suffix match rejects lookalikes like notmediafire.com and evilmega.nz; GitHub stays exact-set - census: lazy extractor loop so a later OSError no longer discards an earlier sidecar changelog hit - jobs: watchlist parses only table rows whose vault-note cell is a bare wikilink (skips parenthetical related/complete notes); wanted also matches bold names in Wanted.md tables with Pokemon prefix stripped and casefolded - cli: validate-scouts and judge raise SystemExit when jobs.json has jobs but scouts/ has zero valid files - fetch: download forwards timeout=60 to urlopen and writes to a .part file then os.replace, removing the partial on any failure
34 lines
973 B
Python
34 lines
973 B
Python
from __future__ import annotations
|
|
import re
|
|
|
|
_LANG = re.compile(r"\s*\((EN|ES|FR|DE|IT|PT|JP)\)\s*", re.I)
|
|
_LEADING_V = re.compile(r"^\s*v", re.I)
|
|
_NUMERIC = re.compile(r"^(\d+(?:\.\d+)*)\s*$")
|
|
|
|
def normalize_version(s: str) -> str:
|
|
s = _LANG.sub(" ", s or "")
|
|
s = _LEADING_V.sub("", s)
|
|
return re.sub(r"\s+", " ", s).strip()
|
|
|
|
def _tuple(s: str) -> tuple[int, ...] | None:
|
|
m = _NUMERIC.match(normalize_version(s))
|
|
if not m:
|
|
return None
|
|
return tuple(int(p) for p in m.group(1).split("."))
|
|
|
|
def compare_versions(a: str, b: str) -> str:
|
|
na, nb = normalize_version(a), normalize_version(b)
|
|
if na.lower() == nb.lower() and na != "":
|
|
return "eq"
|
|
ta, tb = _tuple(a), _tuple(b)
|
|
if ta is None or tb is None:
|
|
return "incomparable"
|
|
n = max(len(ta), len(tb))
|
|
ta = ta + (0,) * (n - len(ta))
|
|
tb = tb + (0,) * (n - len(tb))
|
|
if ta < tb:
|
|
return "lt"
|
|
if ta > tb:
|
|
return "gt"
|
|
return "eq"
|