https://pantsbuild.org/ logo
c

curved-television-6568

10/07/2022, 6:59 PM
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

high-yak-85899

10/07/2022, 7:15 PM
Yes, I've used this a bunch! Great tip
🎉 1
b

bitter-ability-32190

10/07/2022, 7:31 PM
Putting these in a separate resolve is also a pro-tip
👍 1
h

happy-kitchen-89482

10/07/2022, 8:46 PM
Fun hack!!
Actually, worth a blog post I think?
b

bitter-ability-32190

10/07/2022, 8:47 PM
(I actually have a macro for the resolve+target boilerplate)
b

busy-vase-39202

10/07/2022, 9:50 PM
"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

bitter-ability-32190

10/10/2022, 3:20 PM
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

busy-vase-39202

10/10/2022, 4:22 PM
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

busy-vase-39202

10/11/2022, 3:06 PM
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

bitter-ability-32190

10/11/2022, 3:26 PM
I'm still learning Twitter
b

busy-vase-39202

10/11/2022, 3:58 PM
Everyone is. Especially the people at Twitter itself, so you're in great company!
c

curved-television-6568

10/11/2022, 4:02 PM
hmm… I feel my tip may have been a tad long for twitter… 😛
b

busy-vase-39202

10/11/2022, 4:10 PM
No, it's good!
It's exactly what threading is for.
c

curved-television-6568

10/11/2022, 4:14 PM
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

bitter-ability-32190

10/11/2022, 4:14 PM
I think I'll retweet mine with the Pantsbuild account
wait nevermind 😛
7 Views