Hey again, I enabled `[python-infer].assets = tru...
# general
g
Hey again, I enabled
[python-infer].assets = true
and have an assets dir located in
src/python/service/assets
I am trying to access these assets from python using the path
service/assets/file_name.extension
but getting not such file or directory. So I am wondering, ā€¢ am I accessing the files correctly using module instead of root? ā€¢ do I need to create BUILD file inside the assets dir? ā€¢ if yes, can I define sources using asterisk symbol
**/*.extension
to void adding new source for every file.
b
The asets need to be declared as targets, yes. How/where you do that is up to you šŸ™‚
g
a BUILD file inside assets should be enough right? also, can I used the sources path syntax mentioned up?
b
It depends.
file
targets are assumed to loaded relative to the build root (so
src/python/service/...
)
resource
targets are assumed to be loaded relative to the file loading them (e.g. you might be doing
importlib.resources.path(__name_, "assets/...")
)
c
my best tip when unsure, is to get into a Pants sandbox and look where the files actually end up.. šŸ˜‰
šŸ’Æ 1
g
damn, this BUILD file and using a root path was everything I needed!
Copy code
files(
    name="assets",
    sources=["**/*"],
)
This feels like magic!
šŸ’Æ 1
šŸ’Ŗ 1
b
You're welcome šŸ˜›
šŸ™Œ 1