I think this is related to <https://github.com/pan...
# plugins
w
I think this is related to https://github.com/pantsbuild/pants/pull/14049 (which I just saw) - but I was looking for examples on using files or resources with a list of assets. For some reason, this part of Pants is still rather murky to me. I just can't grok it for some reason. 2 use cases I'm trying to determine, and was wondering if I'm on the correct path (I'll be working on these tonight): 1. Creating a sample QT app for my pyoxidizer examples - so first off, I want a working standalone pex, and then a fully packaged pyox'd file - so I can see how the two relate (other than the embedded Python, naturally). I'm using
resources
so that my files get packaged within my
pex
, and then I think I need to use
pkgutil
to access those
.qml
and
.svg
files? Or, is there any way I can make those files available using "normal" references from within my application ie.
Copy code
engine = QQmlApplicationEngine()
engine.load("app.qml") # Can I make this relative "app.qml" work with resources?
2. Finishing up my
ansible
plugin - I'm not sure if I should be using a
files
or
resources
dependency into the
ansible
target, OR, if bundling my playbook + roles should be part of the target itself. My gut feel is that the target should specify directly all the source files it needs and can use (the latter option), but I'm not sure if there are other use cases and workflows I'm not considering properly (like, if we're pulling in files not nested in the target's directory).
h
Re 1. AFAICT QQmlApplicationEngine.load takes a file path and loads it using filesystem APIs, not Python-specific package resource loading APIs. so the file has to be a real path on disk. So if you want to bundle the file in a pex then you'll have to use some magic to find the path relative to the
__file__
of the running module (and note that
__file__
may not be set, depending on how the pex was packaged and run)
This is hackery, and not theoretically robust, but it might work
One thing you can do of course is use pkgutil to extract the resource to a tmpfile and run
load
on that
That seems to be the safer course of action
2. I don't know much about ansible, but intuitively it seems like the playbook should be a source for the target, similarly to how a Dockerfile is a source for a docker_image target?
w
@happy-kitchen-89482 Re 2. I agree, and that was the vibe I was going with - just wanted to make sure I wasn't doing something completely whack - like what happens when I get too deep into the weeds Re 1: Okay, so this is what I thought I might have to do. Was hoping to not need to do it, but I'm pretty sure it's completely fine in the grand scheme