wide-midnight-78598
03/19/2023, 5:49 AMpants help-all
time is just too slow.
Instead, for those who have jq
installed, I've tried yet more slightly different. I call pants help-all
and cache the resulting JSON using the md5 of the pants.toml file. I then check that md5 on completion, and pull the giant json file back in to use jq
to parse. This won't work for nested pants
usage, unfortunately. Also, this ends up being too slow to use for parsing all the scoped options from all the keys in the JSON (at least, using a naive for loop approach - I think jq
has a syntax for what I'm trying to do, but I haven't dug into the manual yet). Either way, for this approach, it's probably worth just doing a one-time parse and caching all the results somewhere, until the pants.toml MD5 changes, and then it would be super fast (rather than re-parsing a huge JSON file all the time).
https://gist.github.com/sureshjoshi/cbe50559eb85f21f079e45681d9b486bwide-midnight-78598
03/19/2023, 5:52 AM--pants-completion-helper
call or something, which could dynamically return appropriate values back to the completions.
Another option is keeping this generic-style completion file, and when Pants runs, it automatically exports a parsed help-all json to a Pants-controlled location per repo, and the bash script would know by convention to look there 🤷fast-nail-55400
03/19/2023, 10:04 AMEither way, for this approach, it's probably worth just doing a one-time parse and caching all the results somewhere, until the pants.toml MD5 changes, and then it would be super fast (rather than re-parsing a huge JSON file all the time).Which was the approach taken by the Pants v1 shell completion support. The options config was converted to be shell code and then the shell completion function could just consult shell variables to determine what the completions were.
wide-midnight-78598
03/19/2023, 1:29 PMpants-completion-handler
idea. I think that would be slick, and extensible, and not require any 3rd party toolingwide-midnight-78598
03/19/2023, 1:29 PMpants
at some pointproud-dentist-22844
03/20/2023, 5:37 PMwide-midnight-78598
03/20/2023, 6:08 PMwide-midnight-78598
03/20/2023, 6:08 PMwitty-crayon-22786
03/20/2023, 6:14 PMIs there an API the completions stuff could use to query pantsd?`pantsd`’s only interface at the moment is CLI invokes. the actual runtime of: 1. starting the native client from https://github.com/pantsbuild/pants/pull/11922 2. connecting to a server … should be sub 50 ms though. most of the overhead when using 11922 is in options parsing and bootstrapping.
witty-crayon-22786
03/20/2023, 6:14 PMwitty-crayon-22786
03/20/2023, 6:16 PMfast-nail-55400
03/20/2023, 7:45 PM`pantsd`’s only interface at the moment is CLI invokes.It need not be given the Build Server Protocol support demonstrates Pants can function as a request/response server as well.
witty-crayon-22786
03/20/2023, 7:46 PMfast-nail-55400
03/20/2023, 7:46 PMpantsd
listens on a UNIX domain socket under BUILDROOT/.pants.d for requests and then invokes an uncached rule to get the result.fast-nail-55400
03/20/2023, 7:46 PMfast-nail-55400
03/20/2023, 7:48 PMfast-nail-55400
03/20/2023, 7:48 PMwitty-crayon-22786
03/20/2023, 7:48 PMfast-nail-55400
03/20/2023, 7:49 PMfast-nail-55400
03/20/2023, 7:50 PMdirenv
and similar tools dofast-nail-55400
03/20/2023, 7:51 PM.pants.d
and completion support could just pick it up directly without any API or other extra stufffast-nail-55400
03/20/2023, 7:51 PMfast-nail-55400
03/20/2023, 7:52 PMfast-nail-55400
03/20/2023, 7:53 PMwide-midnight-78598
03/20/2023, 8:49 PMjq
- performance was perfectly adequate. The ideal world for that would be as you described, where pantsd
(or whatever) automatically writes out the completions, or caches help, whenever the pants.toml changes. I think that was the hope in one of the more recent tickets on this topic. I think back in the day, I also talked about the idea of the ./pants
script auto-sourcing a completions script as well - which was a bit more 🤷 .