Pants TOD (Tip Of the Day): If you ever felt like...
# general
c
Pants TOD (Tip Of the Day): If you ever felt like it would be nice if Pants had this little extra feature.. but don’t want to invest in writing a custom plugin to implement another goal? Todays tip will present an alternative approach that gives the same feel but with a very lightweight integration. Consider this UX:
Copy code
$ ./pants my-feat --help
Usage: python -m my-feat [OPTIONS]

Options:
  --feat-1
  --another
  --help
...
This is possible by using
[cli.alias]
in
pants.toml
and a
pex_binary
target some where in your first party code base (could be a utility tree living outside your regular application code, it just needs to be in a source root).
Copy code
[cli.alias]
my-feat = "run src/utils/my_feat.py --"
Then in
src/utils/BUILD
Copy code
pex_binary(.., entry_point="my_feat.py")
Then implement
my_feat.py
as any regular cli tool, using
click
or what makes most sense to you.
👍 1
🙌 5
1
h
Yes, I've used this a bunch! Great tip
🎉 1
b
Putting these in a separate resolve is also a pro-tip
👍 1
h
Fun hack!!
Actually, worth a blog post I think?
b
(I actually have a macro for the resolve+target boilerplate)
b
"Tip of the Day", I love this! Andreas, it is okay to copy this tip into a blog post? You can feel free to expand on it, or not, for the blog version.
b
Maybe we can collect these somewhere and leak them periodically. Then after some time make a blog post of the leaked ones?
I know I have a few 😛
Also back-on-topic I think your post is best compared to a tool like
pipx
which is used for sandboxing CLI tools. Pants' approach is spiritually equivalent, but can be shared across machines in the monorepo. We do this for things like
awscli
b
When a tip is conducive to bein\
(sorry, puppy crossed the keyboard hahaha) When a tip is conducive to being tweeted, that's a good way to distribute it. Then I can RT it from the Pants account, which ensures it also shows up in the slack. Then as they accumulate I can repackage into a blog post as well. Hits a bunch of media collectively, from the original person just tweeting once. It'd be good to pick a hashtag for this
#pantsbuildhints
?
#pantsbuildtip
looks wonky to me for some reason. Anything without "build", e.g.
#pantstips
risks being interpreted by twitter as a fashion topic, unfortunately.
👖 1
💵 1
🐶 2
👍 1
b
Terrific! In the future, if one namechecks the
@pantsbuild
account anywhere within the tweet I'll get notified automatically. One less step for y'all to do, plus readers can jump right to additional pants content.
b
I'm still learning Twitter
b
Everyone is. Especially the people at Twitter itself, so you're in great company!
c
hmm… I feel my tip may have been a tad long for twitter… 😛
b
No, it's good!
It's exactly what threading is for.
c
OK, so it would be a feature request for Twitter then, to automatically split up long messages like that.. but I guess they want to discourage longish messages overall to keep the majority short and succinct.
b
I think I'll retweet mine with the Pantsbuild account
wait nevermind 😛