https://pantsbuild.org/ logo
g

glamorous-nail-59544

12/22/2022, 7:21 PM
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

bitter-ability-32190

12/22/2022, 7:22 PM
The asets need to be declared as targets, yes. How/where you do that is up to you šŸ™‚
g

glamorous-nail-59544

12/22/2022, 7:24 PM
a BUILD file inside assets should be enough right? also, can I used the sources path syntax mentioned up?
b

bitter-ability-32190

12/22/2022, 7:26 PM
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

curved-television-6568

12/22/2022, 7:29 PM
my best tip when unsure, is to get into a Pants sandbox and look where the files actually end up.. šŸ˜‰
šŸ’Æ 1
g

glamorous-nail-59544

12/22/2022, 7:32 PM
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

bitter-ability-32190

12/22/2022, 7:32 PM
You're welcome šŸ˜›
šŸ™Œ 1
5 Views