Hello! I'm trying to consume the output of `adhoc_...
# general
a
Hello! I'm trying to consume the output of
adhoc_tool
, which according to this generates
file
sources by default
My
adhoc_tool
is a python script that generates some files and I want to consume those in my code, I add a dependency on
adhoc_tool
and try to
open(<filepath>)
. I do specify
output_direcotries
in my
adhoc_tool
target. However, during the execution of my script that tries to find the file, it is unable to do so. As I was debugging I realized that the files are saved at
/var/tmp/pants-sandbox/...
, but my code executes with
cwd
at the root of my project, so relative path to the files doesn't work anymore. Adding
experimental_wrap_as_resources
doesn't help to open with regular
io
command like
open(filepath, "r")
It does work if I read the file with
importlib.resources
, but that's not exactly what I wanted. Is there a way to make relative open work ? Am I possibly misconfiguring something ?
b
Importlib or using
__file__
(ie source code’s current location and then manipulating that) are the best way to open these. This sort of file ends up being packaged “within” the application, so needs to be opened relative to the source code not the working directory. To make cwd-relative paths work, these generated files would have to be written into the repository itself, which sounds a bit unexpected. Can you describe more about what you’re trying to do with these generated files?
a
Thanks @broad-processor-92400. We're currently compiling some grammars, which are later consumed by our code for some text processing. Pretty much the same use-case as codegen example in documentation, except we don't produce python sources but compiled binaries that are used to accelerate some processing. I guess using importlib makes sense in this case