Skip to content

Commit 20467ad

Browse files
committed
update version script and shim
1 parent 14d1f1f commit 20467ad

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ members = [
88
resolver = "2"
99

1010
[workspace.package]
11-
version = "0.4.0-a18"
11+
version = "0.4.0-a19"
1212
authors = ["Gabe Fierro <[email protected]>"]
1313
license = "BSD-3-Clause"
1414
edition = "2021"
@@ -39,10 +39,10 @@ memmap2 = "0.9"
3939
zstd = "0.13"
4040
rand = "0.9"
4141

42-
rdf5d = { version = "0.4.0-a18", path = "rdf5d", features = ["oxigraph", "zstd"] }
42+
rdf5d = { version = "0.4.0-a19", path = "rdf5d", features = ["oxigraph", "zstd"] }
4343

44-
ontoenv = { version = "0.4.0-a18", path = "lib" }
45-
ontoenv-cli = { version = "0.4.0-a18", path = "cli" }
44+
ontoenv = { version = "0.4.0-a19", path = "lib" }
45+
ontoenv-cli = { version = "0.4.0-a19", path = "cli" }
4646

4747
[profile.profiling]
4848
inherits = "release"

pyontoenv-shim/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "pyontoenv"
3-
dynamic = ["version"]
3+
version = "0.4.0a19"
44
description = "Compatibility wrapper that installs the ontoenv package."
55
readme = "README.md"
66
requires-python = ">=3.11"

version

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ ONTOENV_PYPROJECT = ROOT / "python" / "pyproject.toml"
2020
PYONTOENV_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+
2336
def 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

4861
def 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+
5789
def run_command(cmd: list[str], cwd: Path | None = None) -> None:
5890
display = " ".join(cmd)
5991
print(f"+ {display}", flush=True)

0 commit comments

Comments
 (0)