Trying to use the buf backend for linting proto fi...
# general
p
Trying to use the buf backend for linting proto files, and I'm having a hard time wiring up my config file ("buf.yaml"). Ideally I would put it in "build-support/proto/buf.yaml" and have
[buf].config = "build-support/proto/buf.yaml"
but I see that's not an option just yet. I tried
[buf].lint_args = ["--config", "build-support/proto/buf.yaml"]
but that didn't work as it seems buf is not running from the build root. Anyone have any suggestions?
h
Usually Pants can auto-discover config in its normal location, or you can explicitly point to a config file. However perusing the code for buf (which is new) it looks like it doesn't support config files yet. @narrow-vegetable-37489 is that correct?
If so, and you feel like adding it, I think it would be pretty straightforward and a good first issue!
p
I'll take a look! 🌟 Haven't used buf before, seems like it's more than just a formatter / linter, but yeah -- seems like it should have a config option like the others.
n
It's not supported just yet - for now you'll sadly have to specify config options directly in
[buf].lint_args
. I can take a look at adding support for config files when work is less hectic, but as @happy-kitchen-89482 said it shouldn't be too hard to implement if you wanna give it a go :)
p
Got it, thanks!
h
FYI the reason it is not enough to set
[buf].lint_args = ["--config", "build-support/proto/buf.yaml"]
is Pants won't know to include the file in the sandbox @prehistoric-afternoon-67621 would you mind opening an issue w/ this feature request? I would be happy to add some instructions on how to implement this - I think it's literally like 10 lines of code. Hardest part is figuring out what Buf's config autodiscovery mechanism looks like
h
I think what Jonas meant was that you can pass config directly to buf, but Eric correctly points out that you can't use that to pass the config file path...
h
(edited above to make that more clear)
n
Looking more closely at it,
--config
actually expects the config itself and not a path, so you could do
--config='$(cat path/to/buf.yml)'
and it should work :)
hoping that there are no single quotes that needs to be escaped and so on 🤞
h
Ha neat. that would work if you did
./pants --buf-args="--config='$(cat path/to/buf/yml)'" fmt ::
on the CLI, but
cat
interpolation won't work in config file
n
Yeah. I can't find an option to specify config file path though, which could make adding a Pants config for it less straight-forward.
👀 1
Ah, no.
If the value ends in json or .yaml it is interpreted as a path. Otherwise as an actual config string.
👍 1
p
Thanks for the thoughts all! I have the desired functionality I wanted right now by using
[buf].lint_args="--config='{\"version\":\"v1\", ...}'"
I will open a feature request when I have some time.
👍 2
@hundreds-father-404 I opened up an issue for this. https://github.com/pantsbuild/pants/issues/15354 I took a quick look at spiking out a solution and, yeah, as suspected it looks pretty straightforward, but if you have any additional tips I'm all for 'em. It probably makes sense to test out autodiscovery too just to make sure that works as expected.
❤️ 1
h
Added some thoughts 🙂 lmk if you have questions!
p
Ah thanks! Definitely would have missed the input digests bit. Cheers.
❤️ 1