Is there any kind of introspection command that ca...
# general
b
Is there any kind of introspection command that can be used to extract configuration values from
pants.toml
, particularly default ones that haven't been explicitly set or overridden? In particular, I'm looking to programmatically find out the currently-configured
protoc
version (https://www.pantsbuild.org/docs/reference-protoc#version). I know I can set a value concretely and then just process the TOML myself, but I was wondering if Pants already had some built-in capabilities along these lines. Thanks! 🙏
1
f
The
help
goal will output the current and default values for configuration options.
Although in a human-readable form and not JSON or some other form easily processed by machines.
b
Hrmm... I see a lot of the tools we're using under
pants help tools
, but not
protoc
, which we're definitely using (albeit with default configurations at the moment).
f
what about
./pants help protoc
?
b
Unknown entity: protoc
h
./pants help-all
gives a lot of info in JSON form, including the derivation of the value of every option
Is
pants.backend.codegen.protobuf.python
in your
backend_packages
in pants.toml?
If it is then
./pants help protoc
should work, and it should appear in
help-all
b
We do have
pants.backend.codegen.protobuf.python
in
backend_packages
... and I just realized I was running
./pants help protoc
in the wrong repository (🤦 ... sorry, it's one of those days). It looks like I could maybe use something like
./pants help-all | jq -r '.scope_to_help_info.protoc.advanced[0].default'
to grab the value for
protoc
🤔
Not sure yet if that's going to work if we override anything in
pants.toml
, though... I haven't quite grokked the data that's being returned.
Looks like there's some additional work to be done to extract an overridden version, but it looks doable. Thanks for the pointers!
Got sidetracked with some other work / life stuff, but this looks like it does the trick:
Copy code
./pants help-all |
    jq --raw-output \
       '.scope_to_help_info.protoc.advanced |
       .[] |
       select(.config_key == "version") |
       .value_history.ranked_values[-1].value'
🎉 1