Skip to content

Commit 2842244

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

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,24 @@
2424
In addition it sets common PlantUML options, like output to svg_obj.
2525
"""
2626

27-
import os
2827
import sys
2928
from pathlib import Path
3029

30+
from python.runfiles import Runfiles
3131
from sphinx.application import Sphinx
3232
from sphinx.util import logging
3333

3434
logger = logging.getLogger(__name__)
3535

3636

3737
def get_runfiles_dir() -> Path:
38-
if r := os.getenv("RUNFILES_DIR"):
38+
if (r := Runfiles.Create()) and (rd := r.EnvVars().get("RUNFILES_DIR")):
3939
# Runfiles are only available when running in Bazel.
4040
# bazel build and bazel run are both supported.
4141
# i.e. `bazel build //:docs` and `bazel run //:docs`.
4242
logger.debug("Using runfiles to determine plantuml path.")
4343

44-
runfiles_dir = Path(r)
44+
runfiles_dir = Path(rd)
4545

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

0 commit comments

Comments
 (0)