feat(bzlmod): expose platform-agnostic repo target for toolchain interpreter#1155
Conversation
examples/bzlmod/BUILD.bazel
Outdated
| # NOTE: we can use this flag in order to make our setup compatible with | ||
| # bzlmod. | ||
| use_pip_repository_aliases = True, |
There was a problem hiding this comment.
| # NOTE: we can use this flag in order to make our setup compatible with | |
| # bzlmod. | |
| use_pip_repository_aliases = True, | |
| use_pip_repository_aliases = True, |
Since this is a bzlmod only example, we don't need this comment
There was a problem hiding this comment.
Do we need the flag when we are not using bzlmod?
67670bc to
e5754bf
Compare
149d730 to
ba28c92
Compare
|
We are having a few flakes, but the building on Windows OS is not working. See #1163. I have recreated the problem locally. |
a9aec42 to
3c796e0
Compare
9679cae to
60818c4
Compare
|
@aignas I added a new example that includes bzlmod and gazelle. We have some issues with the sub-module, which I will file. I am not changing the build_file_generation example, and I will back out bzlmod support out of that example in another PR. |
rickeylev
left a comment
There was a problem hiding this comment.
Looking pretty good, mostly small stuff
7af481d to
3e4a140
Compare
Having both bzlmod and a WORKSPACE file confuses the user, and I have bazel-contrib#1155 which adds a new example for gazelle and bzlmod.
Having both bzlmod and a WORKSPACE file confuses the user, and I have #1155 which adds a new example for gazelle and bzlmod.
64eea9c to
4f04915
Compare
This commit includes: - adding a new bzlmod_build_file_geration demo - adding the capabilty where python.toolchain create the symlink to set the pip python interperter target - improved documentation in the pip arguments
4f04915 to
1ec8e5e
Compare
|
@linzhp, maybe I do not understand what you recommend, but this is what I did as a test: diff --git a/python/extensions.bzl b/python/extensions.bzl
index 3bcbb50..3c3d582 100644
--- a/python/extensions.bzl
+++ b/python/extensions.bzl
@@ -151,11 +151,12 @@ def _repo_mapped_label(module_label, extension_name, apparent):
name used by the extension named by `ext_name` (i.e. the value of the
`name` arg the extension passes to repository rules)
"""
- return Label("@@{module}~{extension_name}~{apparent}".format(
- module = module_label.workspace_name,
- extension_name = extension_name,
- apparent = apparent,
- ))
+ return Label("@python3_x86_64-unknown-linux-gnu")
+ #return Label("@@{module}~{extension_name}~{apparent}".format(
+ # module = module_label.workspace_name,
+ # extension_name = extension_name,
+ # apparent = apparent,
+ #))
# We are doing some bazel stuff here that could use an explanation.
# The basis of this function is that we need to create a symlink toI used We then get the error: Let me know if there is a different approach. We can always iterate to improve this, but we have already spent many hours of dev time on this. |
…d in .bazelrc (#1207) This correctly handles the integration tests and examples that are a part of the `rules_python` workspace and should not be included in the deleted packages list. This brings the changes made to the `.bazelrc` very close to what is in `main`, but I would like to update this later once #1155 and #1205 are merged. Fixes #919.
|
I think I remember why calling Label() there doesn't work: It's being called in the repo implementation function, not as part of evaluating the code generated by the repo. When Label() is called in the host_hub_impl implementation function in extensions.bzl, it's current context is the rules_python module. Since the rules_python module itself never called use_repo() on anything (it can't; the repo names are user selected), it's repo visibility mapping is empty. If host_hub generated a .bzl file with e.g. |
|
@rickeylev That's correct. This situation is especially tricky since the resolved label is needed in the implementation function of the repo rule. This may require introducing a helper extension. @Wyverald and I were discussing a |
This exposes a new repo and target,
@{name}_host_interpreter//:python, created bypython.toolchain(), that points to the host OS's Python interpreter for that particular toolchain.This solves two problems:
pip.parse()can now refer to the same interpreter used in the toolchainsfor repository rules.
The above were sort of possible for users to do already, but it required them to write much more configuration and extension code to do so. This moves that sort of boilerplate into our code so they have a simpler configuration.
Also:
with both WORKSPACE and MODULE is a pain, hence splitting them.
Closes: #1161