Hello, is there a way to get the hash for a given ...
# general
c
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.
a
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
.transitive_invalidation_hash()
method on a
PythonBinary
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
python_dist()
targets, which create python requirements tagged with the target hash
so when you get a
VersionedTarget
(which is a subclass of
VersionedTargetSet
) 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
.pants.d/
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
c
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!
a
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
c
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".
a
yes, got it
c
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. 🙂
a
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
c
Yeah, sure thing. 🙂
Having just seen this, I assume it's too late for today, but I appreciate it nevertheless.
a
it's only noon in california!
and also, i'd post your issue in #pex when you create it
c
ok, will do
a
was much quicker than expected :)
c
That was fast! Thanks for driving that through!