Skip to content
Open
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
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down
30 changes: 30 additions & 0 deletions python/private/internal_dev_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
2 changes: 1 addition & 1 deletion python/private/pypi/whl_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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

if not whl_path:
if rctx.attr.urls:
Expand Down
9 changes: 9 additions & 0 deletions tests/pypi/whl_library/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Name: optional-dep
Version: 1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Wheel-Version: 1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I_AM_OPTIONAL = True
6 changes: 6 additions & 0 deletions tests/pypi/whl_library/testdata/packages.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""A list of packages that this logical testdata hub repo contains."""

packages = [
"optional_dep",
"pkg",
]
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Name: pkg
Version: 1.0
Requires-Dist: optional_dep; extra == "optional"
Provides-Extra: optional
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Wheel-Version: 1.0
6 changes: 6 additions & 0 deletions tests/pypi/whl_library/testdata/pkg/pkg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
try:
import optional_dep

WITH_EXTRAS = True
except ImportError:
WITH_EXTRAS = False
13 changes: 13 additions & 0 deletions tests/pypi/whl_library/whl_library_extras_test.py
Original file line number Diff line number Diff line change
@@ -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()