Hi everyone, is it possible to somehow combine the...
# general
f
Hi everyone, is it possible to somehow combine the
run
goal with
--changed-since
? When trying to, I'm faced with the error
Copy code
TooManyTargetsException: The `run` goal only works with one valid target, but was given multiple valid targets
So I am wondering whether there's any way to achieve this in a different fashion. The use case would be to run some
adhoc_tool
or script when its dependencies change
w
Are you looking for
--loop
What are you trying to do? Re-run when something changes? Or run certain items once if they are different than remote?
f
The use case would be to run some
adhoc_tool
or script when its dependencies change
loop sounds more like a polling kind of feature, right? Not exactly what I'm looking for
w
loop is based on file-watching
e.g.
pants --loop test
type of thing
f
I'm thinking more about adding a tool via
adhoc_tool
instead of writing a plugin, which I would then like to run whenever some files it depends on change.
I'm trying to understand when it makes sense to write a plugin, and when
adhoc_tool
will suffice
w
So, I still don't get this. Are you trying to no-op if nothing has changed (locally)?
f
yes correct. And by changed I'm talking about the git-level changes, like is done with the
--changed-since
flag
w
gotcha, I thought adhoc_tool has some check for that - but I might be remembering a caching function
Does your adhoc_tool have side-effects?
f
yes. It deploys infrastructure as code.
👍 1
I'm trying to understand when adhoc_tool makes sense, and when its better to create a custom target and plugin
w
Let me look through some of my code, I have a deployment tool as well - but I can't recall where I handle the determination of WHEN to call it. Re: adhoc_tool, hard to say - but in my personal opinion, I would default to
adhoc_tool
unless there's some specific reason it won't work. Writing and maintaining a plugin is more time consuming in general. For example, I have an adhoc_tool that builds my SvelteKit repo and then zips and deploys Azure to because we don't have TS support baked-in just yet, and the rest of it would otherwise be a shell command
❤️ 1
Though based on this conversation, I'm guessing we don't have a good example of "Why Use" or "When to Use" in the docs. If not, that's a great addition!
The docs have
Copy code
adhoc_tool provides you with the building blocks needed to put together a custom build process without needing to develop and maintain a plugin. The level of initial effort involved in using adhoc_tool is significantly lower than that of writing a plugin, so it's well-suited to consuming one-off scripts, or for rapidly prototyping a process before actually writing a plugin. The tradeoff is that there is more manual work involved in defining build processes that reflect your codebase's structure, and that the targets that define the tools you consume are less easy to reuse.
but I think calling out specifics in a section would be nice
f
it does have some info:
The level of initial effort involved in using
adhoc_tool
is significantly lower than that of writing a plugin, so it's well-suited to consuming one-off scripts, or for rapidly prototyping a process before actually writing a plugin. The tradeoff is that there is more manual work involved in defining build processes that reflect your codebase's structure, and that the targets that define the tools you consume are less easy to reuse.
coke 1
yeah that could definitely help
I guess for simple things like small scripts it makes a lot of sense and its okay to run it on every build
but for more involved processes (many terragrunt configurations in my case) it would be great to no-op when possible
w
In your specific case.... What about an alias or bash script that does the git checking, if we can't do it directly in pants right now (I'd need to look around my repos for a while, I have a ton of pants code floating around)
f
yeah that would work initially. It could traverse the dependencies and check for changes in git. But then it sounds like I'm reinventing the
--changed-since
feature of Pants 😄
w
Ahh, okay, so looking for specific changes for that given command - not just any changes
f
indeed, files related to that command
w
Can you show me the full command that would give you what you're expecting?
f
I don't fully understand. Do you want me to send you the Pants command I would like to run?
w
Sure
Just wondering if you could use another command, and pipe that into your run command
f
well I started with something like this
pants --changed-since=HEAD^ run
This does not work, and if it would, it would run way too much, so I would need to filter this down somehow to the
adhoc_tools
that matter here
w
Yeah, so what I mean is, using something like
pants --changed-since=HEAD list | something?
or something else more bash-y
f
hmm yeah that would actually work
awesome
w
Probably need some sort of transitive check? And then to make it easier, wrap it into a pants alias (or bash alias I guess)
f
yeah there is a
--check-dependents=transitive
option I can add
Thanks a lot for your help. Still new to Pants and exploring the feasibility within our codebase. Lots to learn 🙂
w
No prob! I'm a bit rusty, haven't had to dig into much outside of my "just works" wheelhouse in a while
❤️ 1
This whole page is good sauce (https://www.pantsbuild.org/2.19/docs/using-pants/project-introspection#peek---programmatically-inspect-a-target) - we encourage piping and bash a decent amount 🙂
👀 1
f
awesome, yeah this is the glue that I was missing in some places. Thanks for sharing 😄
👍 1