From 2842244c0a9a54216ca4d7469fdb07c4478d2bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20T=C3=A4nzer?= Date: Fri, 9 Jan 2026 09:56:21 +0100 Subject: [PATCH] Get RUNFILES_DIR via rules_python --- MODULE.bazel | 2 +- src/extensions/BUILD | 4 ++++ src/extensions/score_plantuml.py | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 72e8ae14a..81c886852 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -29,7 +29,7 @@ bazel_dep(name = "rules_pkg", version = "1.1.0") # Python version # ############################################################################### -bazel_dep(name = "rules_python", version = "1.4.1") +bazel_dep(name = "rules_python", version = "1.5.0") PYTHON_VERSION = "3.12" diff --git a/src/extensions/BUILD b/src/extensions/BUILD index d4db4293c..77ab9c608 100644 --- a/src/extensions/BUILD +++ b/src/extensions/BUILD @@ -20,4 +20,8 @@ py_library( srcs = ["@score_docs_as_code//src/extensions:score_plantuml.py"], imports = ["."], visibility = ["//visibility:public"], + deps = [ + "@rules_python//python/runfiles", + "@score_docs_as_code//src:plantuml_for_python", + ], ) diff --git a/src/extensions/score_plantuml.py b/src/extensions/score_plantuml.py index c452315e5..0e887e158 100644 --- a/src/extensions/score_plantuml.py +++ b/src/extensions/score_plantuml.py @@ -24,10 +24,10 @@ In addition it sets common PlantUML options, like output to svg_obj. """ -import os import sys from pathlib import Path +from python.runfiles import Runfiles from sphinx.application import Sphinx from sphinx.util import logging @@ -35,13 +35,13 @@ def get_runfiles_dir() -> Path: - if r := os.getenv("RUNFILES_DIR"): + if (r := Runfiles.Create()) and (rd := r.EnvVars().get("RUNFILES_DIR")): # Runfiles are only available when running in Bazel. # bazel build and bazel run are both supported. # i.e. `bazel build //:docs` and `bazel run //:docs`. logger.debug("Using runfiles to determine plantuml path.") - runfiles_dir = Path(r) + runfiles_dir = Path(rd) else: # The only way to land here is when running from within the virtual