I have an application that has some files that nee...
# general
I have an application that has some files that need to follow, so I packaged them all in an 'archive'. The files are deployed in the same location as the pex binary. This works fine, and I can also tweak it to be able to run from 'dist/app.pex' by providing tha data directory as a parameter. But it doesn't work well with './pants run', because the current directory is changed to the tmp one and the data dir has to be an absolute path. This makes it a bit cumbersome to debug. Is there a simpler way that I missed?
What version of Pants?:
Copy code
$ echo $PWD
$ PEX_INTERPRETER=1 dist/scie-pants-linux-x86_64 run tools -- -c 'import os; print(f"I am here: {os.getcwd()}")'
I am here: /home/jsirois/dev/pantsbuild/jsirois-scie-pants
$ dist/scie-pants-linux-x86_64 -V
Yeah, just tried this back through to 2.11.0 and the same in each case, $CWD under
./pants run
is the repo root.
Note that you can set
on the
target, and then
./pants run
will run directly from the sources in the repo, instead of from sandboxed sources. But whether you do that or not, in either case the CWD is the repo root, not the sandbox root.
But maybe the issue is that the data dir is computed relative to the running code's
or something?
In that case
would fix this
Just as another option, are you aware of the option of packaging data directly into the PEX? This can be done via a
instead of a
and having the Python files depend on it. The data then has to be read via
. https://www.pantsbuild.org/docs/assets
It doesn't have to actually. All modes of PEX execution involve 1st extracting the PEX to disk, so
now always works and you can load the data relative to
if the data is embedded as a resource. Just another option. You still need a Pants
target as Huon suggests either way you read the file.
👍 1
Thanks all for the suggestions! ❤️ I did think about using resources, but I wasn't sure if I can use them like that (the files are ansible scripts that will be executed by an external process). If the pex is always unpacked, then it should work if I just get their exact locations. In any case, I think my problem with "pants run" was because I was running the pex binary -- if instead I just run the python module, then it should be working. I will test all the alterntives, to make sure 🙂