Hello, is there a way to get the hash for a given ...
# general
Hello, is there a way to get the hash for a given target? We're building Python PEX targets and dumping them directly into Docker images; we'd like to tag these images with the hash of the inputs used to produce the PEX file, but I can't figure out how to get at that.
this is something i've been playing around with for pexes a lot in the last few weeks, so i can definitely answer this in multiple ways: (1) if you want the hash of the pants target used for the input, the
method on a
target object should be what you're looking for. targets have individual `.fingerprint()`s but i believe that doesn't take into account transitive deps. (2) if you want to hash the contents of the resulting pex and use that, you could make another (cacheable) pants task which takes that hash and writes it out to disk. let me see what we do when we build local
targets, which create python requirements tagged with the target hash
so when you get a
(which is a subclass of
) from
with self.invalidated()
in a "v1" task, you can get its cache key, which is what's used in the path to that target's output in
so not sure if you're already writing v1 tasks or if there's a more natural way for you to get what you want here
Unfortunately I'm new to pants and not well-versed in writing plugins or otherwise extending it. I was hoping for a CLI command or flag, so I'll have to learn more about plugins before continuing. Thanks for the help!
i don't think you should be blocked by that! that was just the first response :)
would a hash of the PEX file itself be sufficient for your purposes? i was thinking you might be trying to create docker images in pants already, haha. it's early in the morning for me
Yeah, I was thinking creating docker images in pants would be the next step; was hoping to tag images with the pex hash. I'd really prefer not to use a hash of the PEX file since I want the semantic to be "here is the Docker image for a given set of inputs".
yes, got it
The PEX file hash is probably close enough since the pants cache will generally make sure the same exact file is returned for a given set of inputs, but less ideal. 🙂
it shouldn't be hard to spit out a digest of the target inputs along with the pex, we have a task that does that in our monorepo at twitter is i guess also why i got ahead of myself
that's correct!
i think you might be extremely interested in the discussion that was happening in #pex yesterday -- have been having a lot of very similar thoughts recently
@cuddly-window-48195 could you create an issue at https://github.com/pantsbuild/pants/issues/new describing really quickly your use case? i can put it on my TODO list for today
Yeah, sure thing. 🙂
Having just seen this, I assume it's too late for today, but I appreciate it nevertheless.
it's only noon in california!
and also, i'd post your issue in #pex when you create it
ok, will do
was much quicker than expected :)
That was fast! Thanks for driving that through!