Skip to content

Commit 142f7a0

Browse files
committed
Get RUNFILES_DIR via rules_python
1 parent 5f135fe commit 142f7a0

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ bazel_dep(name = "rules_pkg", version = "1.1.0")
2929
# Python version
3030
#
3131
###############################################################################
32-
bazel_dep(name = "rules_python", version = "1.4.1")
32+
bazel_dep(name = "rules_python", version = "1.5.0")
3333

3434
PYTHON_VERSION = "3.12"
3535

src/extensions/BUILD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ py_library(
2020
srcs = ["@score_docs_as_code//src/extensions:score_plantuml.py"],
2121
imports = ["."],
2222
visibility = ["//visibility:public"],
23+
deps = [
24+
"@rules_python//python/runfiles",
25+
"@score_docs_as_code//src:plantuml_for_python",
26+
],
2327
)

src/extensions/score_plantuml.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,21 @@
2828
import sys
2929
from pathlib import Path
3030

31+
from python.runfiles import Runfiles
3132
from sphinx.application import Sphinx
3233
from sphinx.util import logging
3334

3435
logger = logging.getLogger(__name__)
3536

3637

3738
def get_runfiles_dir() -> Path:
38-
if r := os.getenv("RUNFILES_DIR"):
39+
if (r := Runfiles.Create()) and (rd := r.EnvVars().get("RUNFILES_DIR")):
3940
# Runfiles are only available when running in Bazel.
4041
# bazel build and bazel run are both supported.
4142
# i.e. `bazel build //:docs` and `bazel run //:docs`.
4243
logger.debug("Using runfiles to determine plantuml path.")
4344

44-
runfiles_dir = Path(r)
45+
runfiles_dir = Path(rd)
4546

4647
else:
4748
# The only way to land here is when running from within the virtual

0 commit comments

Comments
 (0)