Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 .bazelrc.deleted_packages
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions python/private/pypi/extension.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],
}
Comment thread
ouillie marked this conversation as resolved.
Outdated

return struct(
auth_patterns = defaults.get("auth_patterns", {}),
netrc = defaults.get("netrc", None),
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/pip_parse_isolated/.bazelrc
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions tests/integration/pip_parse_isolated/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)
19 changes: 19 additions & 0 deletions tests/integration/pip_parse_isolated/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -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")
Empty file.
2 changes: 2 additions & 0 deletions tests/integration/pip_parse_isolated/requirements_lock.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
six==1.17.0 \
--hash=sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274
16 changes: 16 additions & 0 deletions tests/integration/pip_parse_isolated/test_isolated.py
Original file line number Diff line number Diff line change
@@ -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()