Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exp: multi-arch whl_library in bzlmod #1625

Closed
wants to merge 95 commits into from
Closed
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
e97a75b
add some thoughts
aignas Dec 9, 2023
ea0f2ba
wip
aignas Dec 9, 2023
bc41145
continue to spike
aignas Dec 9, 2023
e29ae54
continue experimenting, the group libraries do not work but I think i…
aignas Dec 9, 2023
393446b
hack through visibility to get tests almost passing
aignas Dec 10, 2023
3aa23a2
document analysis of the current approach and a new approach
aignas Dec 10, 2023
1e9f6fd
start implementing a new approach
aignas Dec 10, 2023
d78f282
wip
aignas Dec 11, 2023
ff2d000
work out the visibility and cleanup
aignas Dec 11, 2023
b82ac46
wip
aignas Dec 11, 2023
75be4c7
fix visibility of the group
aignas Dec 12, 2023
c01e65a
use constants instead of strings for labels
aignas Dec 12, 2023
5b637cb
do not symlink the whl and just pass along the label
aignas Dec 12, 2023
42f916d
implement patching in minihub
aignas Dec 12, 2023
825d28d
wip
aignas Dec 14, 2023
1b91882
Merge branch 'main' into exp/whl-minihub
aignas Dec 14, 2023
0401d77
remove TODOs
aignas Dec 14, 2023
f65d6ad
wip: move the downloading of all of the wheels outside whl_library macro
aignas Dec 15, 2023
0751ad8
wip: reorder code
aignas Dec 15, 2023
764d453
add index parsing
aignas Dec 15, 2023
484a061
continue refining
aignas Dec 15, 2023
242d960
wip
aignas Dec 15, 2023
6eb77fd
Merge remote-tracking branch 'upstream/main' into exp/whl-minihub
aignas Dec 15, 2023
1c0d38b
wip: use bazel 7.1 non-blocking download to get the filenames
aignas Dec 15, 2023
89b9a79
wip: remove the os_arch_dependence on extensions
aignas Dec 15, 2023
5ba4606
wip
aignas Dec 16, 2023
0db226f
cleanup
aignas Dec 16, 2023
c1eba5e
simplify and prep to support 6.2
aignas Dec 16, 2023
2871a7c
move the parsing of all req files collectively
aignas Dec 17, 2023
aff93fa
wip
aignas Dec 17, 2023
f698068
wip
aignas Dec 17, 2023
ccf6154
Ignore the MODULE.bazel.lock
aignas Dec 17, 2023
8300db1
add notes
aignas Dec 18, 2023
f8dabc1
add docs
aignas Dec 18, 2023
d484d61
Merge branch 'main' into exp/whl-minihub
aignas Dec 18, 2023
574aff6
fixup tests
aignas Dec 18, 2023
32b8d7d
tidyup
aignas Dec 18, 2023
a54873e
make it more modular
aignas Dec 18, 2023
8e4ac60
Add a feature toggle for this feature
aignas Dec 18, 2023
c4e9524
fixup! Add a feature toggle for this feature
aignas Dec 18, 2023
3cb70b2
chore: use bazel-features for non-blocking downloading feature
aignas Dec 18, 2023
ccd5d79
cleanup downloading logic
aignas Dec 18, 2023
1bd46fb
cleanup pypi_archive code
aignas Dec 18, 2023
6ad2035
move 'get_auth' to a separate file
aignas Dec 18, 2023
5fb780d
fixup the feature flag usage
aignas Dec 18, 2023
cb91638
fixup! move 'get_auth' to a separate file
aignas Dec 18, 2023
a3d6078
Merge branch 'main' into exp/whl-minihub
aignas Dec 18, 2023
b272578
revert the bazel version to the one that we can actually support
aignas Dec 18, 2023
6ce5d11
fix(whl_library): correctly handle osx universal2 wheel platform_tag …
aignas Dec 20, 2023
2b9c686
fix(whl_library): actually apply patches if specified
aignas Dec 20, 2023
241f93a
fixup! fix(whl_library): correctly handle osx universal2 wheel platfo…
aignas Dec 20, 2023
9b24bd9
fix: demote the RECORD mismatch during patching to a warning
aignas Dec 20, 2023
ea160ce
chore: re-implement the wheel platforms in starlark
aignas Dec 20, 2023
350d006
chore: hook the platform handling in starlark
aignas Dec 20, 2023
44b995e
rename the function name
aignas Dec 20, 2023
02a00bc
remove the python implementation of target_platform
aignas Dec 20, 2023
1af04ea
chore: add the bzl_library for the new code
aignas Dec 20, 2023
2dd0791
Merge branch 'fix/universal2-mac-wheel-parsing' into exp/whl-minihub
aignas Dec 20, 2023
eda65d4
Merge branch 'fix/fix-patch-application' into exp/whl-minihub
aignas Dec 20, 2023
86747f7
fix stuff
aignas Dec 20, 2023
b19e9dd
Merge branch 'main' into exp/whl-minihub
aignas Dec 20, 2023
655e400
resolve merge conflicts and improve
aignas Dec 20, 2023
1d71aae
Use stuff form #1636
aignas Dec 20, 2023
7e60f55
add more todos and test with last_green
aignas Dec 20, 2023
28d5b9d
exp: create a symlink for the host interpreter
aignas Dec 20, 2023
a82d3d7
feat(toolchain, pip.parse): introduce a new '_host' toolchain repo
aignas Dec 21, 2023
5f65e16
updated the vendored requirements example
aignas Dec 21, 2023
0afe5b3
Merge branch 'feat/setup-a-host-interpreter-for-external-repo-usage' …
aignas Dec 21, 2023
a759cf6
remove os,arch_dep
aignas Dec 21, 2023
4daddcf
wip
aignas Dec 21, 2023
636806b
Merge branch 'main' into exp/whl-minihub
aignas Dec 21, 2023
3d6e8bd
feat(toolchain, pip.parse): introduce a new '_host' toolchain repo
aignas Dec 21, 2023
4840d42
updated the vendored requirements example
aignas Dec 21, 2023
1a97810
do the interpreter symlink resolution everywhere
aignas Dec 21, 2023
169a4c1
Merge branch 'feat/setup-a-host-interpreter-for-external-repo-usage' …
aignas Dec 21, 2023
a4af2bb
disable the print
aignas Dec 21, 2023
a923fdb
Add more text about pypi_file usage
aignas Dec 24, 2023
b7e31db
rework slightly to avoid the _label helper
aignas Dec 24, 2023
2aeda3b
more cleanup
aignas Dec 24, 2023
e778402
fixup
aignas Dec 24, 2023
12a428e
Remove a TODO note
aignas Dec 24, 2023
844913a
continue experimenting with smaller requirement lines
aignas Dec 24, 2023
f8319c3
more cleanup
aignas Dec 25, 2023
79cf3a5
wip
aignas Dec 25, 2023
dd201b0
Add a trailing slash when fetching metadata
aignas Dec 29, 2023
7392dcd
Merge branch 'main' into exp/whl-minihub
aignas Jan 9, 2024
333f35f
ignore MODULE lock files
aignas Jan 10, 2024
abf60c1
revert some of the accidental changes
aignas Jan 10, 2024
5fa7077
rebase conflicts
aignas Jan 10, 2024
6fad811
Merge branch 'main' into exp/whl-minihub
aignas Jan 10, 2024
9dca6aa
more conflicts
aignas Jan 10, 2024
91a73b8
Add a note
aignas Jan 11, 2024
e32cb68
Merge branch 'main' into exp/whl-minihub
aignas Jan 22, 2024
d66b27b
use workspace_name instead of repo_name for Label
aignas Jan 22, 2024
51474e4
Merge branch 'main' into exp/whl-minihub
aignas Jan 24, 2024
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
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module(
compatibility_level = 1,
)

bazel_dep(name = "bazel_features", version = "1.1.1")
bazel_dep(name = "bazel_features", version = "1.2.0")
bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "platforms", version = "0.0.4")

Expand Down
2 changes: 1 addition & 1 deletion examples/bzlmod/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.0.0
7.0.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a new minimum version? I'm not sure we can bump to 7 -- we still need to support 6. We can bump this to 6.4, though.

1 change: 1 addition & 0 deletions examples/bzlmod/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bazel-*
MODULE.bazel.lock
9 changes: 9 additions & 0 deletions examples/bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ use_repo(python, "python_3_10", "python_3_9", "python_versions")
# You are able to set a hub name, so that you can have different modifications of the same
# wheel in different pip hubs.
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.experimental_target_platforms(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first thought: this looks like more than just configuring platforms? Looks like more general pip overrides.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll finalize the naming later.

enabled = True,
# Specify PyPI indexes in the order of preference. If the package is not found in the first
# index, it will be looked up in the next one, which means that it makes it useful to order
# the index URLs by the number of packages it contains.
extra_index_urls = [],
# Specify the main PyPI index URL to use. This is value the default.
index_url = "https://pypi.org/simple",
)

# Call whl_mods.create for the requests package.
pip.whl_mods(
Expand Down
8 changes: 6 additions & 2 deletions examples/bzlmod/whl_mods/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ exports_files(
py_test(
name = "pip_whl_mods_test",
srcs = ["pip_whl_mods_test.py"],
data = [
"@pip//requests:dist_info",
"@pip//wheel:dist_info",
],
env = {
"REQUESTS_PKG_DIR": "pip_39_requests",
"WHEEL_PKG_DIR": "pip_39_wheel",
"REQUESTS_DISTINFO": "$(rlocationpaths @pip//requests:dist_info)",
"WHEEL_DISTINFO": "$(rlocationpaths @pip//wheel:dist_info)",
},
main = "pip_whl_mods_test.py",
deps = [
Expand Down
6 changes: 1 addition & 5 deletions examples/bzlmod/whl_mods/appended_build_content.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@ write_file(

filegroup(
name = "whl_orig",
srcs = glob(
["*.whl"],
allow_empty = False,
exclude = ["*-patched-*.whl"],
),
srcs = ["_whl"],
)
81 changes: 39 additions & 42 deletions examples/bzlmod/whl_mods/pip_whl_mods_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@ class PipWhlModsTest(unittest.TestCase):
def package_path(self) -> str:
return "rules_python~override~pip~"

def wheel_pkg_dir(self) -> str:
env = os.environ.get("WHEEL_PKG_DIR")
self.assertIsNotNone(env)
return env
def wheel_pkg_dir(self) -> Path:
distinfo = os.environ.get("WHEEL_DISTINFO")
self.assertIsNotNone(distinfo)
return Path(distinfo.split(" ")[0]).parents[2]

def rlocation(self, runfiles, dir: Path, *segments):
absolute_path = dir
for segment in segments:
absolute_path = absolute_path / segment

return runfiles.Rlocation(str(absolute_path.relative_to(dir.parent)))

def test_build_content_and_data(self):
r = runfiles.Create()
rpath = r.Rlocation(
"{}{}/generated_file.txt".format(
self.package_path(),
self.wheel_pkg_dir(),
),
)
rpath = self.rlocation(r, self.wheel_pkg_dir(), "generated_file.txt")
generated_file = Path(rpath)
self.assertTrue(generated_file.exists())

Expand All @@ -51,27 +53,22 @@ def test_build_content_and_data(self):

def test_copy_files(self):
r = runfiles.Create()
rpath = r.Rlocation(
"{}{}/copied_content/file.txt".format(
self.package_path(),
self.wheel_pkg_dir(),
)
)
rpath = self.rlocation(r, self.wheel_pkg_dir(), "copied_content", "file.txt")
copied_file = Path(rpath)
self.assertTrue(copied_file.exists())

content = copied_file.read_text().rstrip()
self.assertEqual(content, "Hello world from copied file")

def test_copy_executables(self):
executable_name = (
"executable.exe" if platform.system() == "windows" else "executable.py"
)

r = runfiles.Create()
rpath = r.Rlocation(
"{}{}/copied_content/executable{}".format(
self.package_path(),
self.wheel_pkg_dir(),
".exe" if platform.system() == "windows" else ".py",
)
)
rpath = self.rlocation(
r, self.wheel_pkg_dir(), "copied_content", executable_name
)
executable = Path(rpath)
self.assertTrue(executable.exists())

Expand All @@ -88,37 +85,37 @@ def test_data_exclude_glob(self):
current_wheel_version = "0.40.0"

r = runfiles.Create()
dist_info_dir = "{}{}/site-packages/wheel-{}.dist-info".format(
self.package_path(),
self.wheel_pkg_dir(),
current_wheel_version,
)
wheel_pkg_dir = self.wheel_pkg_dir()
dist_info_dir = f"wheel-{current_wheel_version}.dist-info"

# Note: `METADATA` is important as it's consumed by https://docs.python.org/3/library/importlib.metadata.html
# `METADATA` is expected to be there to show dist-info files are included in the runfiles.
metadata_path = r.Rlocation("{}/METADATA".format(dist_info_dir))
metadata_path = Path(
self.rlocation(r, wheel_pkg_dir, "site-packages", dist_info_dir, "METADATA")
)

# However, `WHEEL` was explicitly excluded, so it should be missing
wheel_path = r.Rlocation("{}/WHEEL".format(dist_info_dir))
wheel_path = Path(
self.rlocation(r, wheel_pkg_dir, "site-packages", dist_info_dir, "WHEEL")
)

self.assertTrue(Path(metadata_path).exists())
self.assertFalse(Path(wheel_path).exists())
self.assertTrue(
metadata_path.exists(), f"METADATA was not found in {metadata_path}"
)
self.assertTrue(wheel_path.exists(), f"WHEEL was not found in {wheel_path}")

def requests_pkg_dir(self) -> str:
env = os.environ.get("REQUESTS_PKG_DIR")
self.assertIsNotNone(env)
return env
def requests_pkg_dir(self) -> Path:
distinfo = os.environ.get("REQUESTS_DISTINFO")
self.assertIsNotNone(distinfo)
pkgdir = Path(distinfo.split(" ")[0]).parents[2]
return pkgdir

def test_extra(self):
# This test verifies that annotations work correctly for pip packages with extras
# specified, in this case requests[security].
r = runfiles.Create()
rpath = r.Rlocation(
"{}{}/generated_file.txt".format(
self.package_path(),
self.requests_pkg_dir(),
),
)
rpath = self.rlocation(r, self.requests_pkg_dir(), "generated_file.txt")

generated_file = Path(rpath)
self.assertTrue(generated_file.exists())

Expand Down
1 change: 1 addition & 0 deletions python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ bzl_library(
srcs = ["repositories.bzl"],
deps = [
":versions_bzl",
"//python/private:auth_bzl",
"//python/private:bazel_tools_bzl",
"//python/private:bzlmod_enabled_bzl",
"//python/private:coverage_deps_bzl",
Expand Down
52 changes: 40 additions & 12 deletions python/pip_install/pip_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -714,18 +714,28 @@ def _whl_library_impl(rctx):
# Manually construct the PYTHONPATH since we cannot use the toolchain here
environment = _create_repository_execution_environment(rctx, python_interpreter)

result = rctx.execute(
args,
environment = environment,
quiet = rctx.attr.quiet,
timeout = rctx.attr.timeout,
)
if result.return_code:
fail("whl_library %s failed: %s (%s) error code: '%s'" % (rctx.attr.name, result.stdout, result.stderr, result.return_code))
whl_path = None
whl_label = None
if rctx.attr.experimental_whl_file:
whl_label = rctx.attr.experimental_whl_file
whl_path = rctx.path(whl_label).realpath
if whl_path.basename.endswith("tar.gz"):
whl_path = None
whl_label = None

if whl_path == None:
result = rctx.execute(
args,
environment = environment,
quiet = rctx.attr.quiet,
timeout = rctx.attr.timeout,
)
if result.return_code:
fail("whl_library %s failed: %s (%s) error code: '%s'" % (rctx.attr.name, result.stdout, result.stderr, result.return_code))

whl_path = rctx.path(json.decode(rctx.read("whl_file.json"))["whl_file"])
if not rctx.delete("whl_file.json"):
fail("failed to delete the whl_file.json file")
whl_path = rctx.path(json.decode(rctx.read("whl_file.json"))["whl_file"])
if not rctx.delete("whl_file.json"):
fail("failed to delete the whl_file.json file")

if rctx.attr.whl_patches:
patches = {}
Expand Down Expand Up @@ -781,7 +791,7 @@ def _whl_library_impl(rctx):

build_file_contents = generate_whl_library_build_bazel(
repo_prefix = rctx.attr.repo_prefix,
whl_name = whl_path.basename,
whl_name = whl_label or whl_path.basename,
dependencies = metadata["deps"],
dependencies_by_platform = metadata["deps_by_platform"],
group_name = rctx.attr.group_name,
Expand All @@ -793,6 +803,10 @@ def _whl_library_impl(rctx):
],
entry_points = entry_points,
annotation = None if not rctx.attr.annotation else struct(**json.decode(rctx.read(rctx.attr.annotation))),
impl_vis = None if not rctx.attr.experimental_whl_file else "@{}{}//:__pkg__".format(
rctx.attr.repo_prefix,
normalize_name(metadata["name"]),
),
)
rctx.file("BUILD.bazel", build_file_contents)

Expand Down Expand Up @@ -834,6 +848,20 @@ whl_library_attrs = {
),
allow_files = True,
),
"experimental_whl_file": attr.label(
doc = """\
The label of the whl file to use. This allows one to pass a whl file to be used, but at the same
time it changes the assumed whl_library layout. With this parameter set, the pip repository layout
becomes as following:
* pip has aliases to wheel libraries based on the version of the toolchain in use.
* downloaded whls and sdists are in separate `pypi_file` repos.
* per each downloaded `whl` or `sdist` there is a `whl_library` that creates a `py_library` target.
* there is a alias `whl_library` repo that allows selecting which implementation `whl_library` repo to use.

In the future the `whl_library` alias repo might be merged into the main `pip` repo but for that to
happen, the `dependency` closures need to be generated for the selected target python versions.
""",
),
"group_deps": attr.string_list(
doc = "List of dependencies to skip in order to break the cycles within a dependency group.",
default = [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ def generate_whl_library_build_bazel(
entry_points,
annotation = None,
group_name = None,
group_deps = []):
group_deps = [],
impl_vis = None):
"""Generate a BUILD file for an unzipped Wheel

Args:
Expand All @@ -155,6 +156,7 @@ def generate_whl_library_build_bazel(
group_deps: List[str]; names of fellow members of the group (if any). These will be excluded
from generated deps lists so as to avoid direct cycles. These dependencies will be provided
at runtime by the group rules which wrap this library and its fellows together.
impl_vis: str; override the visibility of the implementation labels.

Returns:
A complete BUILD file as a string
Expand Down Expand Up @@ -267,12 +269,12 @@ config_setting(
group_repo = repo_prefix + "_groups"
library_impl_label = "@%s//:%s_%s" % (group_repo, normalize_name(group_name), PY_LIBRARY_PUBLIC_LABEL)
whl_impl_label = "@%s//:%s_%s" % (group_repo, normalize_name(group_name), WHEEL_FILE_PUBLIC_LABEL)
impl_vis = "@%s//:__pkg__" % (group_repo,)
impl_vis = impl_vis or "@%s//:__pkg__" % (group_repo,)

else:
library_impl_label = PY_LIBRARY_IMPL_LABEL
whl_impl_label = WHEEL_FILE_IMPL_LABEL
impl_vis = "//visibility:private"
impl_vis = impl_vis or "//visibility:private"

contents = "\n".join(
[
Expand Down
8 changes: 8 additions & 0 deletions python/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ filegroup(
visibility = ["//python:__pkg__"],
)

bzl_library(
name = "auth_bzl",
srcs = ["auth.bzl"],
deps = [
"//python:py_runtime_bzl",
],
)

bzl_library(
name = "autodetecting_toolchain_bzl",
srcs = ["autodetecting_toolchain.bzl"],
Expand Down
42 changes: 42 additions & 0 deletions python/private/auth.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2022 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Helpers copied from http_file source to be reused here.

The implementation below is copied directly from Bazel's implementation of `http_archive`.
Accordingly, the return value of this function should be used identically as the `auth` parameter of `http_archive`.
Reference: https://github.com/bazelbuild/bazel/blob/6.3.2/tools/build_defs/repo/http.bzl#L109
"""

# TODO @aignas 2023-12-18: use the following instead when available.
# load("@bazel_tools//tools/build_defs/repo:utils.bzl", "get_auth")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "read_netrc", "read_user_netrc", "use_netrc")

def get_auth(rctx, urls):
"""Utility for retrieving netrc-based authentication parameters for repository download rules used in python_repository.

Args:
rctx (repository_ctx): The repository rule's context object.
urls: A list of URLs from which assets will be downloaded.

Returns:
dict: A map of authentication parameters by URL.
"""
if rctx.attr.netrc:
netrc = read_netrc(rctx, rctx.attr.netrc)
elif "NETRC" in rctx.os.environ:
netrc = read_netrc(rctx, rctx.os.environ["NETRC"])
else:
netrc = read_user_netrc(rctx)
return use_netrc(netrc, urls, rctx.attr.auth_patterns)
23 changes: 23 additions & 0 deletions python/private/bzlmod/label.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2023 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"A small utility to create a label usable internally"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er, huh? What's this?

It looks like its trying to...get a reference to...@rules_python?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is one of the ways for us to construct a label that we can pass to repositories created by pip. This would be unneeded if bazelbuild/bazel#19055 was fixed in 7.1.0 and we used it.


_this = str(Label("//:unknown"))

def label(label):
"""This function allows us to construct labels to pass to rules."""
prefix, _, _ = _this.partition("//")
prefix = prefix + "~pip~"
return Label(label.replace("@", prefix))
Loading