Pants "subcmd" running use case notes #22692
Replies: 5 comments 5 replies
-
|
A historical note of perhaps interest. In Pants v1 when I built out better support for go for Medium, I heavily leveraged the go CLI internally (go list, go build, go test, etc). I only had two weeks contracted on the project though and knew I couldn't cover all use cases; so I made sure to add support for # Here the cache sub-command works because Pex is at the version Pants uses and its PEX_ROOT has been adjusted to match the one Pants sets up.
pants tool pex -- cache ...
# This would only work sanely and in an easy to grok way for the user if Pants stopped abusing user files to store its own state - there is a Pants issue about this.
pants tool pex3 -- lock update -Pcowsay 3rdparty/python/my-lock-hopefully-pants-no-longer-adds-invalid-header-to.jsonThe short of it is, even if you do want to concoct more baroque layerings for whatever reason, at the end of the day, always having an escape hatch to the underlying tool, minimally configured to work with Pants, is super useful for users, tool maintainers and Pants maintainers (who will get rung up less). |
Beta Was this translation helpful? Give feedback.
-
|
Quite a ways back, I had the idea of having some "helper" CLIs which could even operate interactively. I think the first could be a So, everything is pants - without shelling out to an external tool. Similar to how I'd be interested in seeing where the sub-command idea goes in terms of robustness to options and whatnot. A big value add to me, would be compacting a number of goals into a hierarchy (namespace) to help new users out - so they don't see a wall of goals, but get some sort of progressive disclosure. For the external tools, having an easy way to escape hatch down to their command lines could be helpful for whenever one of them adds/changes something - and Pants isn't a limiting factor. I did think we already had some sort of |
Beta Was this translation helpful? Give feedback.
-
|
How would the options scoping interact with this? Today subcmds add a potential layer of scoping, or at least scoping confusion. I think the sanest and most expected thing to do is get rid of the long scoped flags entirely, so that each cmd (when there are no subcmds) or each subcmd (when there are) is its own thing with its own options that have to be specified in the right position, and its own help. This also has the advantage of avoiding the rare-in-practice-thankfully but potentially very irritating name collisions that this scheme can cause. And it will also simplify options parsing. |
Beta Was this translation helpful? Give feedback.
-
|
I wonder if we should have an experimental mode for the pants cli. We could have multiple CLI entry points, similar to |
Beta Was this translation helpful? Give feedback.
-
|
Here is a new CLI entry point to kick around and experiment with: #22808 Right now it doesn't actually do anything, future PRs will wire it up to stuff, ideally new stuff at least at first. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Pants "subcmd" running use case notes
The typical Pants cli invocation looks like:
This allows one to express multiple actions on the same set of targets (ex:
pants fix test src::and this is among the most common use cases. However, it makes it difficult to express optionally that may be specific to only some "targets" (or not even apply to targets). This document outlines 3 use cases that are challenging with the existing pattern, the first two of which are likely more tractable. I have some idea how to implement the "meat" of the change, and how I would do it with click, but not how to hook it up to the existing goals/options system.The intent is to provide concrete examples to illustrate the current limitations to inform possible paths forward for implementation. (There is not an obvious way to do these today with the existing goal system.) But not to completely flesh out a design for all of them at once.
Cases
cache tooling (no target)
#11167
Pants maintains several different caches, including ones both internal to Pants (lmdb) and cases where pants Pants is orchestrating "named" caches for other tools. Users have reasonable requests like "tell me how big my cache is" and "prune it so it doesn't grow without bounds". The size of these caches vary greatly so some of these are more valuable than others. For example on my workstation
named_caches/pex_rootis 350 GiB,lmdb_store/is 36 GiB, and third place is 3 GiB.Some of the tools -- notably Pex -- have their own tools for pruning or otherwise managing their cache. Unlike goals, these commands would act on the specific caches, but not targets.
reference: pex --help
example cli
(assume these launch as
experimental-cache)pants cache named pex prunepants cache pex prunepants cache prune pex,lmdb,mypypants cache named pex -- prune(raw cli passthru)pants cache pex -- prune(raw cli passthru)Questions
namedvslmdbhelpful future proofing?pants cache tool ...vspants cache future-all-cache-cmds?Future Questions:
lockfile manipulation (usually ~one resolve, or resolve ecosystem)
#15704
#15568
#12880
There are a lot of different things people would like to do with lockfiles besides generating the whole thing from scratch:
The details of all of these are pretty specific to the given ecosystems. For example, it would not make sense to say "update pytest to x.y.z" to both java and Python resolves. It might make sense to say "update pytest to x.y.z" to multiple Python resolves. But, I wearly of trying to support identical operations similar but different ecoystehsms by creating semenatics to "update pytest to x.y.z" that apply to Pex, Poetry, and UV, but are different from each.
example cli
pants lock update pex [resolve-name] --pex-specific-flagspants lock update pex --resolve=foo --resolve=bar --pex-specific-flagspants lock update --resolve=foo --dynamic-flags-based-on-type-of-resolve(--resolveis mandatory?)pants generate-lockfiles --not-actually-generate-operation=update --resolve=foo --dynamic-flags-based-on-operation(today; not a real proposal)pants lock direct-op --tool=pex --resolve=foo -- raw-pass-thruREMINDER: This is illustrative of things that are hard to address with the goal system today. Pex/Poetry/UV have a lot of prior art here on the details.
Unlike the cache case, these operate on things existing Pants goals know about (resolves), but are not targets.
Questions
pants help lintandpants help generate-lockfilesthat one operates on targets and the other does not. Should we have a name for this that shows up inhelp?TargetGoal?targeting
#15012
For example, consider the case where a repository has multiple "types" of tests and has tagged all the unit tests with
unitone can dopants fmt lint test ::to run those goals on everything, orpants --tag=unit fmt lint test ::to run on allunittargets, but not "fmt fix linteverything and also run all the unit tests".Hey what about help
An existing "goal" that already follows this pattern is
helppants help toolspants help ruffAwkward but more composable
The examples above were generally in the form
pants goal sub subsub. This looks "natural" but would not be posible to compose with other goals. Given that neither the cache nor lockfile use case operates on targets tha thist is probably an okay tradeoff, but it might be possible to have spaces or-in the "goal name. Sopants fmt cache-named-pex-prune test ::pants fmt 'cache named pex prune' test ::I'm not sure of a real use case where one would want to do this. (You can't do this with
helptoday.)Other Refernces
Beta Was this translation helpful? Give feedback.
All reactions