Skip to content

Commit 87f0c34

Browse files
authored
Extend src/version.py script to nanobind_bazel docs (#1164)
This relieves the need to update the nanobind_bazel documentation entry by hand after each stable release. Technically, there is a brief period(until the subsequent BCR release of nanobind_bazel) during which the documentation contains non-working MODULE.bazel code. However, this risk is probably acceptable, since I release nanobind_bazel typically in short order after each nanobind release, and the command to override nanobind_bazel from GitHub can be found directly below. No other changes intended - specifically, no print statements or other logging were added to preserve stdout behavior expected by Meson.
1 parent b748ac8 commit 87f0c34

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/version.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def get_version(root):
3131
else:
3232
print(version_core)
3333

34-
# Write the semantic version to nanobind.h, pyproject.toml, and __init__.py.
34+
# Write the semantic version to nanobind.h, pyproject.toml, __init__.py,
35+
# and docs/bazel.rst.
3536
# The semver string must be either 'X.Y.Z' or 'X.Y.Z-devN', where X, Y, Z are
3637
# non-negative integers and N is a positive integer.
3738
def write_version(root, semver):
@@ -92,6 +93,27 @@ def write_version(root, semver):
9293
f.truncate()
9394
f.write(contents)
9495

96+
# write to docs/bazel.rst, but only if `semver` is not a dev release.
97+
# This is because documentation is scoped only to the latest stable release.
98+
if "dev" not in semver:
99+
with open(os.path.join(root, "docs/bazel.rst"), "r+") as f:
100+
contents = f.read()
101+
contents = re.sub(
102+
r"nanobind\s+v\d+(\.\d+)+",
103+
r"nanobind v" + semver,
104+
contents,
105+
count=1,
106+
)
107+
contents = re.sub(
108+
r'"nanobind_bazel", version = "\d+(\.\d+)+"',
109+
r'"nanobind_bazel", version = "' + semver + '"',
110+
contents,
111+
count=1,
112+
)
113+
f.seek(0)
114+
f.truncate()
115+
f.write(contents)
116+
95117

96118
def main():
97119
root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
@@ -107,4 +129,3 @@ def main():
107129

108130
if __name__ == '__main__':
109131
main()
110-

0 commit comments

Comments
 (0)