Skip to content

Commit

Permalink
CI: Patch MODULE.bazel in nanobind example
Browse files Browse the repository at this point in the history
Done via a small Python script for portability. This ensures that we test
the nanobind example build against the latest version in CI.
  • Loading branch information
nicholasjng committed Dec 10, 2024
1 parent 757096c commit b7e93d6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/lint-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ jobs:
repository: wjakob/nanobind_example
path: nanobind_example
ref: bazel
- name: Override nanobind_bazel pin in MODULE.bazel
run: python fixup_module_bazel.py
working-directory: ${{ github.workspace }}/nanobind_example

- name: Build and test nanobind_example on ${{ matrix.os }}
run: |
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/keith/pre-commit-buildifier
rev: 7.3.1
rev: 7.3.1.1
hooks:
- id: buildifier
- id: buildifier-lint
36 changes: 36 additions & 0 deletions fixup_module_bazel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
Redeclare a dependency on nanobind_bazel by overwriting the content of MODULE.bazel.
Used in nanobind-bazel CI to test against development versions in pull requests.
"""

import re
from pathlib import Path

# TODO: Support arbitrary paths in the template below
_LOCAL_NANOBIND_BAZEL = """
bazel_dep(name = "nanobind_bazel", version = "")
local_path_override(
module_name = "nanobind_bazel",
path = "../nanobind-bazel",
)
"""


def main():
# TODO: Grab the path to MODULE.bazel from sys.argv.
module_bazel = Path("MODULE.bazel")
if not module_bazel.exists():
raise FileNotFoundError(module_bazel)

content = module_bazel.read_text()
module_bazel.write_text(
re.sub(
r"bazel_dep\(name = \"nanobind_bazel\", version = [\w\".]*\)",
_LOCAL_NANOBIND_BAZEL,
content,
)
)

if __name__ == "__main__":
main()

0 comments on commit b7e93d6

Please sign in to comment.