bazel-gazelle
bazel-gazelle copied to clipboard
Allow gazelle extension implementations to add arbitrary loads for generated files
Hi,
I'm working on a gazelle extension for Python and I've hit a snag. I can't find a way to cleanly add extra loads to a build file. In my case, I need the requirement
macro to resolve names of packages, as per the example:
load("@my_deps//:requirements.bzl", "requirement")
py_binary(
name = "main",
srcs = ["main.py"],
visibility = ["//visibility:public"],
deps = [
requirement("requests"),
],
)
From a quick glance at the gazelle
code it seems to me that, right now, only the loads that reference a generated rule are possible. Any help or otherwise information on how to move this towards an implementation is greatly appreciated.
I've just posted an example of the raw mechanical pieces required to support this in https://github.com/bazelbuild/bazel-gazelle/pull/1161 but would appreciate some input on the API design for how to actually expose this to language implementations.
It's possible to make this work via the plugin Load API, but it's much easier to use these aliases.
Basically if your pip repo is called my_deps
, as in your example, you can depend on packages like this:
deps = [
"@my_deps//:requests_pkg",
]
That way you don't need to add a load
at all.