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
Optionally infer name in use_extension
and use_repo_rule
#22168
Conversation
Following the documented best practices for [rules and extensions](https://docs.google.com/document/d/1L1JFgjpZ7SrBinb24DC_5nTIELeYDacikcme-YcA7xs/edit#heading=h.cy0m49ne5key), a symbol named `foo_deps` should be available from a `.bzl` file called `foo_deps.bzl`. This still results in pretty duplicative `MODULE.bazel` lines: ``` foo_deps = use_extension("@rules_foo//foo/extensions:foo_deps.bzl", "foo_deps") ``` Instead, Bazel now uses this convention to infer the name if not given: ``` foo_deps = use_extension("@rules_foo//foo/extensions:foo_deps.bzl") ``` This makes typos less likely and also nudges ruleset authors to adopt the new convention by providing nice syntax. RELNOTES: `use_extension` and `use_repo_rule` now infer the name from the basename of the `.bzl` file if not provided explicitly.
Note to self: Make buildozer aware of this too when accepted. |
This seems a bit too magical to me; I don't think saving the extra parameter is worth the potential confusion. Open to be convinced otherwise though. |
My own thoughts on why I personally consider this a net win:
I will try to get more eyes on this by posting about it in the #bzlmod channel. |
My two cents. I like this magic. More wizardry and unicorns, please. 🦄🧙♂️ |
@alexeagle @aherrmann @keith @illicitonion for their opinion on this idea |
I also fear that this is a bit too magical. On the pro side
On the cons side
Question
|
Bazel has existing semantics for the default label in a package, which uses the same convention for "the symbol named the same as the package"). I see that as an argument that the same concept could apply in starlark.
I had the same thought - every time I load from skylib I'm typing the same thing twice, but no one is making "default symbol to load"
I think this does matter quite a bit - it increases the cognitive burden of understanding how Bazel works.
We still have most repos with |
Very good point. AFAIK there is also no way for Bazel modules to change this without incurring a breaking change, see "extension identity" docs. So, it seems unlikely that we'll see a wider shift to the new recommendation soon. |
That's a very good point. Let's wait until Starlarkification has progressed to the point where these loads are actually found in all build files. If I will close this PR for now and revisit it later. |
Following the documented best practices for rules and extensions, a symbol named
foo_deps
should be available from a.bzl
file calledfoo_deps.bzl
. While this already reduces cognitive load during "Where do I get this extension from?", it still results in pretty repetitiveMODULE.bazel
lines:Instead, Bazel now uses this convention to infer the name if not given:
This makes typos less likely and also nudges ruleset authors to adopt the new convention by providing nicer syntax.
RELNOTES:
use_extension
anduse_repo_rule
now infer the name from the basename of the.bzl
file if not provided explicitly.