From 1345c8887ebb5723aee1acd69ce25c2e32df7f05 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Thu, 18 Dec 2025 19:20:48 +0900 Subject: [PATCH 1/4] test(whl_library): test a recent fix for pipstar Test for #3352 #3468 --- MODULE.bazel | 1 + python/private/internal_dev_deps.bzl | 30 +++++++++++++++++++ tests/pypi/whl_library/BUILD.bazel | 9 ++++++ tests/pypi/whl_library/testdata/BUILD.bazel | 0 .../testdata/optional_dep/BUILD.bazel | 0 .../optional-dep-1.0.dist-info/METADATA | 2 ++ .../optional-dep-1.0.dist-info/RECORD | 0 .../optional-dep-1.0.dist-info/WHEEL | 1 + .../testdata/optional_dep/optional_dep.py | 1 + tests/pypi/whl_library/testdata/packages.bzl | 6 ++++ .../pypi/whl_library/testdata/pkg/BUILD.bazel | 0 .../testdata/pkg/pkg-1.0.dist-info/METADATA | 4 +++ .../testdata/pkg/pkg-1.0.dist-info/RECORD | 0 .../testdata/pkg/pkg-1.0.dist-info/WHEEL | 1 + tests/pypi/whl_library/testdata/pkg/pkg.py | 6 ++++ .../whl_library/whl_library_extras_test.py | 13 ++++++++ 16 files changed, 74 insertions(+) create mode 100644 tests/pypi/whl_library/BUILD.bazel create mode 100644 tests/pypi/whl_library/testdata/BUILD.bazel create mode 100644 tests/pypi/whl_library/testdata/optional_dep/BUILD.bazel create mode 100644 tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/METADATA create mode 100644 tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/RECORD create mode 100644 tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/WHEEL create mode 100644 tests/pypi/whl_library/testdata/optional_dep/optional_dep.py create mode 100644 tests/pypi/whl_library/testdata/packages.bzl create mode 100644 tests/pypi/whl_library/testdata/pkg/BUILD.bazel create mode 100644 tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/METADATA create mode 100644 tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/RECORD create mode 100644 tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/WHEEL create mode 100644 tests/pypi/whl_library/testdata/pkg/pkg.py create mode 100644 tests/pypi/whl_library/whl_library_extras_test.py diff --git a/MODULE.bazel b/MODULE.bazel index 80c7ab1d99..6486634370 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -242,6 +242,7 @@ use_repo( "pkgutil_nspkg2", "rules_python_runtime_env_tc_info", "somepkg_with_build_files", + "whl_library_extras_direct_dep", "whl_with_build_files", ) diff --git a/python/private/internal_dev_deps.bzl b/python/private/internal_dev_deps.bzl index 0e21d8b8a5..47af65bcce 100644 --- a/python/private/internal_dev_deps.bzl +++ b/python/private/internal_dev_deps.bzl @@ -91,6 +91,36 @@ def _internal_dev_deps_impl(mctx): enable_implicit_namespace_pkgs = False, ) + _whl_library_from_dir( + name = "whl_library_extras_direct_dep", + root = "//tests/pypi/whl_library/testdata/pkg:BUILD.bazel", + output = "pkg-1.0-any-none-any.whl", + requirement = "pkg[optional]", + # The following is necessary to enable pipstar and make tests faster + config_load = "@rules_python//tests/pypi/whl_library/testdata:packages.bzl", + dep_template = "@whl_library_extras_{name}//:{target}", + ) + _whl_library_from_dir( + name = "whl_library_extras_optional_dep", + root = "//tests/pypi/whl_library/testdata/optional_dep:BUILD.bazel", + output = "optional-dep-1.0-any-none-any.whl", + requirement = "optional_dep", + # The following is necessary to enable pipstar and make tests faster + config_load = "@rules_python//tests/pypi/whl_library/testdata:packages.bzl", + ) + +def _whl_library_from_dir(*, name, output, root, **kwargs): + whl_from_dir_repo( + name = "{}_whl".format(name), + root = root, + output = output, + ) + whl_library( + name = name, + whl_file = "@{}_whl//:{}".format(name, output), + **kwargs + ) + internal_dev_deps = module_extension( implementation = _internal_dev_deps_impl, doc = "This extension creates internal rules_python dev dependencies.", diff --git a/tests/pypi/whl_library/BUILD.bazel b/tests/pypi/whl_library/BUILD.bazel new file mode 100644 index 0000000000..7f3f284d9b --- /dev/null +++ b/tests/pypi/whl_library/BUILD.bazel @@ -0,0 +1,9 @@ +load("//python:py_test.bzl", "py_test") + +py_test( + name = "whl_library_extras_test", + srcs = ["whl_library_extras_test.py"], + deps = [ + "@whl_library_extras_direct_dep//:pkg", + ], +) diff --git a/tests/pypi/whl_library/testdata/BUILD.bazel b/tests/pypi/whl_library/testdata/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/pypi/whl_library/testdata/optional_dep/BUILD.bazel b/tests/pypi/whl_library/testdata/optional_dep/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/METADATA b/tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/METADATA new file mode 100644 index 0000000000..6495d1ba36 --- /dev/null +++ b/tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/METADATA @@ -0,0 +1,2 @@ +Name: optional-dep +Version: 1.0 diff --git a/tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/RECORD b/tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/RECORD new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/WHEEL b/tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/WHEEL new file mode 100644 index 0000000000..a64521a1cc --- /dev/null +++ b/tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/WHEEL @@ -0,0 +1 @@ +Wheel-Version: 1.0 diff --git a/tests/pypi/whl_library/testdata/optional_dep/optional_dep.py b/tests/pypi/whl_library/testdata/optional_dep/optional_dep.py new file mode 100644 index 0000000000..4af2718944 --- /dev/null +++ b/tests/pypi/whl_library/testdata/optional_dep/optional_dep.py @@ -0,0 +1 @@ +I_AM_OPTIONAL = True diff --git a/tests/pypi/whl_library/testdata/packages.bzl b/tests/pypi/whl_library/testdata/packages.bzl new file mode 100644 index 0000000000..e4a9b0af4c --- /dev/null +++ b/tests/pypi/whl_library/testdata/packages.bzl @@ -0,0 +1,6 @@ +"""A list of packages that this logical testdata hub repo contains.""" + +packages = [ + "optional_dep", + "pkg", +] diff --git a/tests/pypi/whl_library/testdata/pkg/BUILD.bazel b/tests/pypi/whl_library/testdata/pkg/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/METADATA b/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/METADATA new file mode 100644 index 0000000000..730180bc1e --- /dev/null +++ b/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/METADATA @@ -0,0 +1,4 @@ +Name: ns-sub1 +Version: 1.0 +Requires-Dist: optional_dep; extra == "optional" +Provides-Extra: optional diff --git a/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/RECORD b/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/RECORD new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/WHEEL b/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/WHEEL new file mode 100644 index 0000000000..a64521a1cc --- /dev/null +++ b/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/WHEEL @@ -0,0 +1 @@ +Wheel-Version: 1.0 diff --git a/tests/pypi/whl_library/testdata/pkg/pkg.py b/tests/pypi/whl_library/testdata/pkg/pkg.py new file mode 100644 index 0000000000..c5aca099c4 --- /dev/null +++ b/tests/pypi/whl_library/testdata/pkg/pkg.py @@ -0,0 +1,6 @@ +try: + import optional_dep + + WITH_EXTRAS = True +except ImportError: + WITH_EXTRAS = False diff --git a/tests/pypi/whl_library/whl_library_extras_test.py b/tests/pypi/whl_library/whl_library_extras_test.py new file mode 100644 index 0000000000..4fe344470a --- /dev/null +++ b/tests/pypi/whl_library/whl_library_extras_test.py @@ -0,0 +1,13 @@ +import unittest + + +class NamespacePackagesTest(unittest.TestCase): + + def test_extras_propagated(self): + import pkg + + self.assertEqual(pkg.WITH_EXTRAS, True) + + +if __name__ == "__main__": + unittest.main() From 2db5b84896e9a474617c546e9e8120008aba106d Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Thu, 18 Dec 2025 19:29:55 +0900 Subject: [PATCH 2/4] fixup --- python/private/pypi/whl_library.bzl | 2 +- tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/METADATA | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/private/pypi/whl_library.bzl b/python/private/pypi/whl_library.bzl index c368dea733..ab0492b244 100644 --- a/python/private/pypi/whl_library.bzl +++ b/python/private/pypi/whl_library.bzl @@ -400,7 +400,7 @@ def _whl_library_impl(rctx): # also enable pipstar for any whls that are downloaded without `pip` enable_pipstar = (rp_config.enable_pipstar or whl_path) and rctx.attr.config_load - enable_pipstar_extract = (rp_config.enable_pipstar and rp_config.bazel_8_or_later) and rctx.attr.config_load + enable_pipstar_extract = (enable_pipstar and rp_config.bazel_8_or_later) and rctx.attr.config_load if not whl_path: if rctx.attr.urls: diff --git a/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/METADATA b/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/METADATA index 730180bc1e..712b44edbf 100644 --- a/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/METADATA +++ b/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/METADATA @@ -1,4 +1,4 @@ -Name: ns-sub1 +Name: pkg Version: 1.0 Requires-Dist: optional_dep; extra == "optional" Provides-Extra: optional From ab5ed594bf1fc305f34e54d44847e32ce89d941e Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Thu, 18 Dec 2025 19:31:58 +0900 Subject: [PATCH 3/4] simplify the bool expression further --- python/private/pypi/whl_library.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/private/pypi/whl_library.bzl b/python/private/pypi/whl_library.bzl index ab0492b244..bed33fb49d 100644 --- a/python/private/pypi/whl_library.bzl +++ b/python/private/pypi/whl_library.bzl @@ -400,7 +400,7 @@ def _whl_library_impl(rctx): # also enable pipstar for any whls that are downloaded without `pip` enable_pipstar = (rp_config.enable_pipstar or whl_path) and rctx.attr.config_load - enable_pipstar_extract = (enable_pipstar and rp_config.bazel_8_or_later) and rctx.attr.config_load + enable_pipstar_extract = enable_pipstar and rp_config.bazel_8_or_later if not whl_path: if rctx.attr.urls: From 844fb548d2c9f364cb684f86115cea178c6496bf Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Thu, 18 Dec 2025 22:44:05 +0900 Subject: [PATCH 4/4] fixup --- python/private/internal_dev_deps.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/private/internal_dev_deps.bzl b/python/private/internal_dev_deps.bzl index 47af65bcce..fbdd5711b1 100644 --- a/python/private/internal_dev_deps.bzl +++ b/python/private/internal_dev_deps.bzl @@ -103,7 +103,7 @@ def _internal_dev_deps_impl(mctx): _whl_library_from_dir( name = "whl_library_extras_optional_dep", root = "//tests/pypi/whl_library/testdata/optional_dep:BUILD.bazel", - output = "optional-dep-1.0-any-none-any.whl", + output = "optional_dep-1.0-any-none-any.whl", requirement = "optional_dep", # The following is necessary to enable pipstar and make tests faster config_load = "@rules_python//tests/pypi/whl_library/testdata:packages.bzl",