@@ -20,6 +20,19 @@ ONTOENV_PYPROJECT = ROOT / "python" / "pyproject.toml"
2020PYONTOENV_PYPROJECT = ROOT / "pyontoenv-shim" / "pyproject.toml"
2121
2222
23+ def semver_to_pep440 (version : str ) -> str :
24+ """Convert workspace semver (with `-pre`) into a PEP 440 compatible form."""
25+ base , plus , build = version .partition ("+" )
26+ release , hyphen , suffix = base .partition ("-" )
27+ pep = release
28+ if hyphen :
29+ pep += suffix .replace ("-" , "." )
30+ if plus :
31+ normalized = build .replace ("-" , "." )
32+ pep += f".post{ normalized or '0' } "
33+ return pep
34+
35+
2336def read_current_version () -> str :
2437 text = (ROOT / "Cargo.toml" ).read_text (encoding = "utf-8" ).splitlines ()
2538 in_workspace = False
@@ -47,13 +60,32 @@ def write_if_contains(path: Path, old: str, new: str) -> bool:
4760
4861def update_versions (old : str , new : str ) -> None :
4962 touched = []
50- for path in (CARGO_TOML , ONTOENV_PYPROJECT , PYONTOENV_PYPROJECT ):
63+ for path in (CARGO_TOML , ONTOENV_PYPROJECT ):
5164 if write_if_contains (path , old , new ):
5265 touched .append (path )
66+ if update_pyontoenv_shim_version (new ):
67+ touched .append (PYONTOENV_PYPROJECT )
5368 if not touched :
5469 print ("warning: no files updated; version string may already be current" , file = sys .stderr )
5570
5671
72+ def update_pyontoenv_shim_version (new_version : str ) -> bool :
73+ pep_version = semver_to_pep440 (new_version )
74+ text = PYONTOENV_PYPROJECT .read_text (encoding = "utf-8" )
75+ pattern = re .compile (r'(?m)^(version\s*=\s*)"([^"]+)"' )
76+
77+ def repl (match : re .Match [str ]) -> str :
78+ return f'{ match .group (1 )} "{ pep_version } "'
79+
80+ updated , count = pattern .subn (repl , text , count = 1 )
81+ if count == 0 :
82+ raise SystemExit (f"Unable to find version field in { PYONTOENV_PYPROJECT } " )
83+ if updated != text :
84+ PYONTOENV_PYPROJECT .write_text (updated , encoding = "utf-8" )
85+ return True
86+ return False
87+
88+
5789def run_command (cmd : list [str ], cwd : Path | None = None ) -> None :
5890 display = " " .join (cmd )
5991 print (f"+ { display } " , flush = True )
0 commit comments