Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023-2025 Google LLC
# Copyright 2023-2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,7 +32,7 @@ bazel_dep(name = "protobuf", version = "33.5")
# Development-only module dependencies
bazel_dep(name = "stardoc", version = "0.8.1", dev_dependency = True)
bazel_dep(name = "rules_go", version = "0.60.0", dev_dependency = True)
bazel_dep(name = "rules_python", version = "1.7.0", dev_dependency = True)
bazel_dep(name = "rules_python", version = "1.8.4", dev_dependency = True)
bazel_dep(name = "gazelle", version = "0.47.0", dev_dependency = True)
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.9.0", dev_dependency = True)
bazel_dep(name = "bazel_features", version = "1.41.0", dev_dependency = True)
Expand All @@ -43,6 +43,15 @@ bazel_dep(name = "googletest", version = "1.17.0.bcr.2", dev_dependency = True)
cc_configure = use_extension("@rules_cc//cc:extensions.bzl", "cc_configure_extension")
use_repo(cc_configure, "local_config_cc", "local_config_cc_toolchains")

# FIXME: Remove rules_python.patch once
# https://github.com/bazel-contrib/rules_python/pull/3086#issuecomment-3765803662
# is isolated and fixed.
single_version_override(
module_name = "rules_python",
patch_strip = 1,
patches = ["rules_python.patch"],
)

# Non-module dependencies
emacs_repository = use_repo_rule("//elisp/private:emacs_repository.bzl", "emacs_repository")

Expand Down
9 changes: 5 additions & 4 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 104 additions & 0 deletions rules_python.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
From c61f3cc8251abef63646587630203a024a1bd575 Mon Sep 17 00:00:00 2001
From: Joel Sing <jsing@canva.com>
Date: Mon, 14 Jul 2025 14:15:41 +1000
Subject: [PATCH 1/5] fix(runfiles): correct Python runfiles path assumption

The current _FindPythonRunfilesRoot() implementation assumes that
the Python module has been unpacked four levels below the runfiles
directory. This is not the case in multiple situations, for example when
rules_pycross is in use and has installed the module via pypi (in which
case it is five levels below runfiles).

Both strategies already know where the runfiles directory exists -
implement _GetRunfilesDir() on the _DirectoryBased strategy, then call
_GetRunfilesDir() in order to populate self._python_runfiles_dir.

Stop passing a bogus path to runfiles.Create() in testCurrentRepository(),
such that the test actually uses the appropriate runfiles path.

Fixes #3085
---
CHANGELOG.md | 4 ++++
python/runfiles/runfiles.py | 17 ++++-------------
tests/runfiles/runfiles_test.py | 2 +-
3 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/python/runfiles/runfiles.py b/python/runfiles/runfiles.py
index fc794272c9..bfa9d0d053 100644
--- b/python/runfiles/runfiles.py
+++ a/python/runfiles/runfiles.py
@@ -229,9 +229,6 @@
# runfiles strategy on those platforms.
return posixpath.join(self._runfiles_root, path)

- def _GetRunfilesDir(self) -> str:
- return self._runfiles_root
-
def EnvVars(self) -> Dict[str, str]:
return {
"RUNFILES_DIR": self._runfiles_root,
@@ -249,7 +246,7 @@

def __init__(self, strategy: Union[_ManifestBased, _DirectoryBased]) -> None:
self._strategy = strategy
- self._python_runfiles_root = strategy._GetRunfilesDir()
+ self._python_runfiles_root = _FindPythonRunfilesRoot()
self._repo_mapping = _RepositoryMapping.create_from_file(
strategy.RlocationChecked("_repo_mapping")
)
@@ -472,6 +469,18 @@
_Runfiles = Runfiles


+def _FindPythonRunfilesRoot() -> str:
+ """Finds the root of the Python runfiles tree."""
+ root = __file__
+ # Walk up our own runfiles path to the root of the runfiles tree from which
+ # the current file is being run. This path coincides with what the Bazel
+ # Python stub sets up as sys.path[0]. Since that entry can be changed at
+ # runtime, we rederive it here.
+ for _ in range("rules_python/python/runfiles/runfiles.py".count("/") + 1):
+ root = os.path.dirname(root)
+ return root
+
+
def CreateManifestBased(manifest_path: str) -> Runfiles:
return Runfiles.CreateManifestBased(manifest_path)

From d86b9e943b1cd2db4387843c1b72531301ea5fc1 Mon Sep 17 00:00:00 2001
From: Joel Sing <jsing@canva.com>
Date: Thu, 23 Oct 2025 13:29:45 +1100
Subject: [PATCH 2/5] Add test that ensures we can correctly locate and open a
data file.

---
tests/runfiles/BUILD.bazel | 3 +++
tests/runfiles/runfiles_test.py | 10 ++++++++++
2 files changed, 13 insertions(+)

From d63226877520b20a0aa4dd10f040a316975f7773 Mon Sep 17 00:00:00 2001
From: Joel Sing <jsing@canva.com>
Date: Thu, 23 Oct 2025 13:30:08 +1100
Subject: [PATCH 3/5] Add workaround for buggy zip file bootstrap.

---
.../runtime_env_toolchain/toolchain_runs_test.py | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

From 6166d66a3672648fd9178d2031c9030922b2026e Mon Sep 17 00:00:00 2001
From: Ignas Anikevicius <240938+aignas@users.noreply.github.com>
Date: Wed, 5 Nov 2025 17:47:58 +0900
Subject: [PATCH 4/5] doc: move changelog to the unreleased section.

---
CHANGELOG.md | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

From 7e48c4e89f233ef43f15b993ceafc12e90ae0e40 Mon Sep 17 00:00:00 2001
From: Joel Sing <jsing@canva.com>
Date: Thu, 6 Nov 2025 14:15:02 +1100
Subject: [PATCH 5/5] Appease mypy

---
tests/runfiles/runfiles_test.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)