Skip to content

Commit f07f0bd

Browse files
authored
Merge pull request #221 from QuantStrategyLab/codex/sync-qsl-compat-pin-20260710
fix(qpk): sync QSL compatibility pin metadata
2 parents 65efff9 + 8fe78f8 commit f07f0bd

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

scripts/open_downstream_qpk_pin_prs.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import argparse
77
import os
8+
import re
89
import subprocess
910
import sys
1011
import tempfile
@@ -18,6 +19,11 @@
1819
from check_qpk_pin_consistency import get_qpk_pin_sha
1920

2021

22+
QSL_QPK_REQUIREMENT_RE = re.compile(
23+
r"(quant-platform-kit\s*@\s*git\+https://github\.com/QuantStrategyLab/QuantPlatformKit\.git@)[a-f0-9]{40}"
24+
)
25+
26+
2127
@dataclass(frozen=True)
2228
class RepoSpec:
2329
name: str
@@ -53,13 +59,28 @@ def maybe_run_uv_lock(repo_dir: Path) -> bool:
5359
return True
5460

5561

62+
def update_qsl_compat_qpk_pin(repo_dir: Path, qpk_sha: str) -> bool:
63+
qsl_path = repo_dir / "qsl.toml"
64+
if not qsl_path.is_file():
65+
return False
66+
67+
original = qsl_path.read_text(encoding="utf-8")
68+
updated, replacements = QSL_QPK_REQUIREMENT_RE.subn(rf"\g<1>{qpk_sha}", original)
69+
if replacements == 0 or updated == original:
70+
return False
71+
72+
qsl_path.write_text(updated, encoding="utf-8")
73+
return True
74+
75+
5676
def update_repo(repo_dir: Path, qpk_pin: Path) -> bool:
5777
script = SCRIPT_ROOT / "check_qpk_pin_consistency.py"
5878
run(
5979
["python3", str(script), "--root", str(repo_dir), "--pin-file", str(qpk_pin), "--fix"],
6080
cwd=repo_dir,
6181
)
6282
maybe_run_uv_lock(repo_dir)
83+
update_qsl_compat_qpk_pin(repo_dir, get_qpk_pin_sha(pin_file=qpk_pin))
6384
return has_changes(repo_dir)
6485

6586

tests/test_qpk_pin_consistency.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
extract_qpk_shas,
1010
extract_override_qpk_sha,
1111
)
12+
from scripts.open_downstream_qpk_pin_prs import update_qsl_compat_qpk_pin
1213

1314

1415
TARGET = "8378e939d9324ea63a0f45c9f21ba0e2eeb1cfff"
@@ -61,6 +62,25 @@ def test_override_must_match_pin(self) -> None:
6162
override = extract_override_qpk_sha(pyproject)
6263
self.assertEqual("1111111111111111111111111111111111111111", override)
6364

65+
def test_update_qsl_compat_qpk_pin_rewrites_only_qpk_requirement(self) -> None:
66+
with tempfile.TemporaryDirectory() as tmp:
67+
qsl_path = Path(tmp) / "qsl.toml"
68+
qsl_path.write_text(
69+
"[compat]\n"
70+
"requires = [\n"
71+
f' "pandas>=2.0",\n'
72+
f' "quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@{STALE}",\n'
73+
f' "us-equity-strategies @ git+https://github.com/QuantStrategyLab/UsEquityStrategies.git@{STALE}",\n'
74+
"]\n",
75+
encoding="utf-8",
76+
)
77+
78+
self.assertTrue(update_qsl_compat_qpk_pin(Path(tmp), TARGET))
79+
updated = qsl_path.read_text(encoding="utf-8")
80+
81+
self.assertIn(f"QuantPlatformKit.git@{TARGET}", updated)
82+
self.assertIn(f"UsEquityStrategies.git@{STALE}", updated)
83+
6484

6585
if __name__ == "__main__":
6686
unittest.main()

0 commit comments

Comments
 (0)