From a37924a00f14bd5f3537cfb43ad3f57cf1bb21ce Mon Sep 17 00:00:00 2001 From: Jonathan Woodbury Date: Thu, 17 Jul 2025 17:27:31 -0400 Subject: [PATCH 1/3] fix #3101 - Normalize stub_path in repl.bzl When a REPL target is run from an external Bazel module, the `stub_path` can have path components in it (e.g. "/..") which get rejected by the `Rlocation()` in `runfiles.py`. This commit normalizes the path before it's passed to `Rlocation()`. --- python/private/repl.bzl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/private/repl.bzl b/python/private/repl.bzl index 838166a187..34d75070e0 100644 --- a/python/private/repl.bzl +++ b/python/private/repl.bzl @@ -1,10 +1,12 @@ """Implementation of the rules to expose a REPL.""" load("//python:py_binary.bzl", _py_binary = "py_binary") +load("@bazel_skylib//lib:paths.bzl", "paths") def _generate_repl_main_impl(ctx): stub_repo = ctx.attr.stub.label.repo_name or ctx.workspace_name - stub_path = "/".join([stub_repo, ctx.file.stub.short_path]) + unnormalized_path = "/".join([stub_repo, ctx.file.stub.short_path]) + stub_path = paths.normalize(unnormalized_path) out = ctx.actions.declare_file(ctx.label.name + ".py") From 7f642ea8a5f2c46d5ed8f1c86277e23fd7382b40 Mon Sep 17 00:00:00 2001 From: Jonathan Woodbury Date: Sun, 20 Jul 2025 17:38:44 -0400 Subject: [PATCH 2/3] Use Python's normpath() Windows paths had mixed separators when using the path normalizer from skylib which appeared to cause some tests to fail. --- python/private/repl.bzl | 4 +--- python/private/repl_template.py | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/private/repl.bzl b/python/private/repl.bzl index 34d75070e0..838166a187 100644 --- a/python/private/repl.bzl +++ b/python/private/repl.bzl @@ -1,12 +1,10 @@ """Implementation of the rules to expose a REPL.""" load("//python:py_binary.bzl", _py_binary = "py_binary") -load("@bazel_skylib//lib:paths.bzl", "paths") def _generate_repl_main_impl(ctx): stub_repo = ctx.attr.stub.label.repo_name or ctx.workspace_name - unnormalized_path = "/".join([stub_repo, ctx.file.stub.short_path]) - stub_path = paths.normalize(unnormalized_path) + stub_path = "/".join([stub_repo, ctx.file.stub.short_path]) out = ctx.actions.declare_file(ctx.label.name + ".py") diff --git a/python/private/repl_template.py b/python/private/repl_template.py index 37f4529fbe..dd8beb9784 100644 --- a/python/private/repl_template.py +++ b/python/private/repl_template.py @@ -5,7 +5,9 @@ from python.runfiles import runfiles -STUB_PATH = "%stub_path%" +# runfiles.py will reject paths which aren't normalized, which can happen when the REPL rules are +# used from a remote module. +STUB_PATH = os.path.normpath("%stub_path%") def start_repl(): From 0e1faff541359d99c604f5e89e3d9f9c409b1ead Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Tue, 22 Jul 2025 09:07:04 +0900 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74a4409cbb..5ad48bee3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -93,6 +93,8 @@ END_UNRELEASED_TEMPLATE ([#3099](https://github.com/bazel-contrib/rules_python/issues/3099)). * (pypi) Expose pypi packages only common to all Python versions in `all_requirements` ([#2921](https://github.com/bazel-contrib/rules_python/issues/2921)). +* (repl) Normalize the path for the `REPL` stub to make it possible to use the + default stub template from outside `rules_python` ({gh-issue}`3101`). {#v0-0-0-added} ### Added