bazel-gazelle icon indicating copy to clipboard operation
bazel-gazelle copied to clipboard

Allow gazelle extension implementations to add arbitrary loads for generated files

Open bogatuadrian opened this issue 3 years ago • 1 comments

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.

bogatuadrian avatar Jul 22 '21 07:07 bogatuadrian

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.

illicitonion avatar Jan 20 '22 11:01 illicitonion

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.

adzenith avatar Jan 18 '23 16:01 adzenith