From 61d946e0387ccc358f7ce0c580170566bcc2c3ad Mon Sep 17 00:00:00 2001 From: Will Noble Date: Mon, 16 Mar 2026 13:59:08 -0700 Subject: [PATCH 1/3] Add a test to import a dependency using an isolated extension --- .bazelrc.deleted_packages | 1 + tests/integration/BUILD.bazel | 4 ++++ tests/integration/pip_parse_isolated/.bazelrc | 8 ++++++++ .../pip_parse_isolated/BUILD.bazel | 7 +++++++ .../pip_parse_isolated/MODULE.bazel | 19 +++++++++++++++++++ .../integration/pip_parse_isolated/WORKSPACE | 0 .../pip_parse_isolated/requirements_lock.txt | 2 ++ .../pip_parse_isolated/test_isolated.py | 16 ++++++++++++++++ 8 files changed, 57 insertions(+) create mode 100644 tests/integration/pip_parse_isolated/.bazelrc create mode 100644 tests/integration/pip_parse_isolated/BUILD.bazel create mode 100644 tests/integration/pip_parse_isolated/MODULE.bazel create mode 100644 tests/integration/pip_parse_isolated/WORKSPACE create mode 100644 tests/integration/pip_parse_isolated/requirements_lock.txt create mode 100644 tests/integration/pip_parse_isolated/test_isolated.py diff --git a/.bazelrc.deleted_packages b/.bazelrc.deleted_packages index 2d8a8075fa..5fe84c4475 100644 --- a/.bazelrc.deleted_packages +++ b/.bazelrc.deleted_packages @@ -36,6 +36,7 @@ common --deleted_packages=tests/integration/custom_commands common --deleted_packages=tests/integration/local_toolchains common --deleted_packages=tests/integration/pip_parse common --deleted_packages=tests/integration/pip_parse/empty +common --deleted_packages=tests/integration/pip_parse_isolated common --deleted_packages=tests/integration/py_cc_toolchain_registered common --deleted_packages=tests/modules/another_module common --deleted_packages=tests/modules/other diff --git a/tests/integration/BUILD.bazel b/tests/integration/BUILD.bazel index f0f58daa3a..1807a30902 100644 --- a/tests/integration/BUILD.bazel +++ b/tests/integration/BUILD.bazel @@ -67,6 +67,10 @@ rules_python_integration_test( name = "pip_parse_test", ) +rules_python_integration_test( + name = "pip_parse_isolated_test", +) + rules_python_integration_test( name = "pip_parse_workspace_test", bzlmod = False, diff --git a/tests/integration/pip_parse_isolated/.bazelrc b/tests/integration/pip_parse_isolated/.bazelrc new file mode 100644 index 0000000000..227ce5a4cd --- /dev/null +++ b/tests/integration/pip_parse_isolated/.bazelrc @@ -0,0 +1,8 @@ +# Bazel configuration flags + +build --enable_runfiles + +common --experimental_isolated_extension_usages + +# https://docs.bazel.build/versions/main/best-practices.html#using-the-bazelrc-file +try-import %workspace%/user.bazelrc diff --git a/tests/integration/pip_parse_isolated/BUILD.bazel b/tests/integration/pip_parse_isolated/BUILD.bazel new file mode 100644 index 0000000000..2f825107f1 --- /dev/null +++ b/tests/integration/pip_parse_isolated/BUILD.bazel @@ -0,0 +1,7 @@ +load("@rules_python//python:py_test.bzl", "py_test") + +py_test( + name = "test_isolated", + srcs = ["test_isolated.py"], + deps = ["@pypi//six"], +) diff --git a/tests/integration/pip_parse_isolated/MODULE.bazel b/tests/integration/pip_parse_isolated/MODULE.bazel new file mode 100644 index 0000000000..6c44257acb --- /dev/null +++ b/tests/integration/pip_parse_isolated/MODULE.bazel @@ -0,0 +1,19 @@ +module(name = "pip_parse_isolated") + +bazel_dep(name = "rules_python") +local_path_override( + module_name = "rules_python", + path = "../../..", +) + +python = use_extension("@rules_python//python/extensions:python.bzl", "python") +python.toolchain(python_version = "3.13") + +# This test module verifies that dependencies can be used with `isolate = True`. +pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip", isolate = True) +pip.parse( + hub_name = "pypi", + python_version = "3.13", + requirements_lock = "//:requirements_lock.txt", +) +use_repo(pip, "pypi") diff --git a/tests/integration/pip_parse_isolated/WORKSPACE b/tests/integration/pip_parse_isolated/WORKSPACE new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/integration/pip_parse_isolated/requirements_lock.txt b/tests/integration/pip_parse_isolated/requirements_lock.txt new file mode 100644 index 0000000000..b1445a37ae --- /dev/null +++ b/tests/integration/pip_parse_isolated/requirements_lock.txt @@ -0,0 +1,2 @@ +six==1.17.0 \ + --hash=sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274 diff --git a/tests/integration/pip_parse_isolated/test_isolated.py b/tests/integration/pip_parse_isolated/test_isolated.py new file mode 100644 index 0000000000..f889f071fb --- /dev/null +++ b/tests/integration/pip_parse_isolated/test_isolated.py @@ -0,0 +1,16 @@ +""" +Verify that a dependency added using an isolated extension can be imported. +See MODULE.bazel. +""" + +import six +import unittest + + +class TestIsolated(unittest.TestCase): + def test_import(self): + self.assertTrue(hasattr(six, "PY3")) + + +if __name__ == "__main__": + unittest.main() From 0130300f8f18901bb107cd3c0beafb914249e7ca Mon Sep 17 00:00:00 2001 From: Will Noble Date: Tue, 17 Mar 2026 13:05:20 -0700 Subject: [PATCH 2/3] Draft a fix --- python/private/pypi/extension.bzl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/python/private/pypi/extension.bzl b/python/private/pypi/extension.bzl index f68596b845..50a961f38f 100644 --- a/python/private/pypi/extension.bzl +++ b/python/private/pypi/extension.bzl @@ -123,6 +123,23 @@ def build_config( # overrides, etc. Index overrides per platform could be also used here. ) + # When no platforms are configured (e.g., in isolated mode where + # rules_python's pip.default tags are not visible), provide a minimal + # host platform default so that requirements files can still be parsed. + if not defaults["platforms"]: + os_name = repo_utils.get_platforms_os_name(module_ctx) + arch_name = repo_utils.get_platforms_cpu_name(module_ctx) + platform_name = "{}_{}".format(os_name, arch_name) + defaults["platforms"][platform_name] = { + "name": platform_name.replace("-", "_").lower(), + "arch_name": arch_name, + "os_name": os_name, + "config_settings": [ + "@platforms//cpu:{}".format(arch_name), + "@platforms//os:{}".format(os_name), + ], + } + return struct( auth_patterns = defaults.get("auth_patterns", {}), netrc = defaults.get("netrc", None), From c438551b456976cc3f82a19a7bbbbf2fef49a185 Mon Sep 17 00:00:00 2001 From: Will Noble Date: Tue, 17 Mar 2026 13:36:38 -0700 Subject: [PATCH 3/3] Address buildifier issue --- python/private/pypi/extension.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/private/pypi/extension.bzl b/python/private/pypi/extension.bzl index 50a961f38f..f438263612 100644 --- a/python/private/pypi/extension.bzl +++ b/python/private/pypi/extension.bzl @@ -131,13 +131,13 @@ def build_config( arch_name = repo_utils.get_platforms_cpu_name(module_ctx) platform_name = "{}_{}".format(os_name, arch_name) defaults["platforms"][platform_name] = { - "name": platform_name.replace("-", "_").lower(), "arch_name": arch_name, - "os_name": os_name, "config_settings": [ "@platforms//cpu:{}".format(arch_name), "@platforms//os:{}".format(os_name), ], + "name": platform_name.replace("-", "_").lower(), + "os_name": os_name, } return struct(