https://pantsbuild.org/ logo
#general
Title
# general
h

high-yak-85899

05/24/2022, 11:41 PM
Got an interesting question: When
pip install ansible
, I get a binary in my venv like
venv/bin/ansible
. When I package
ansible
into a
pex_binary
, is there a place I could still access that binary?
The context is that we're using
ansible_runner
and it has to find the executable on the system so I need to point
PATH
where that binary lives
f

fast-nail-55400

05/24/2022, 11:44 PM
You could set the pex’s entrypoint to be the ansible binary
At least, that is my hazy recollection.
h

high-yak-85899

05/24/2022, 11:45 PM
Hmm, but I need my app to be the thing that is actually getting executed
It just happens to use ansible internally
f

fast-nail-55400

05/24/2022, 11:46 PM
You could turn off zip_safe so that
pex
expands your pex onto disk in its cache.
Then the binary should be somewhere under whatever the applicable directory in the pex cache is.
probably under
PEX_ROOT
(
~/.pex
)
ah you likely want
PEX_VENV_BIN_PATH
PEX_VENV_BIN_PATH
String (false|prepend|append).
When running in PEX_VENV mode, optionally add the scripts and console scripts of
distributions in the PEX file to the $PATH.
h

high-yak-85899

05/24/2022, 11:49 PM
Sounds like what I want
So then
execution_mode
has to be set to
venv
when packaging it
And then, for my case, I want
PEX_VENV_BIN_PATH=prepend
when running the app
Actually, it looks like just setting the execution mode to
venv
is enough to get what I need
👍 1
I get the right thing when I do
subprocess.run(['which', 'ansible'])
in that mode
I continue to be amazed by how not limiting the pex way of life is
w

wide-midnight-78598

05/25/2022, 12:02 AM
@high-yak-85899 Is this ansible running from within a rule/pants? Or was it just packaged up externally?
h

high-yak-85899

05/25/2022, 12:02 AM
Just something packaged up
Shipping out to a machine that needs to execute it and ansible_runner seems to some subprocess call to
ansible
. So if it doesn't have an executable in
PATH
, things complain.
w

wide-midnight-78598

05/25/2022, 12:05 AM
Ah okay, I'm actually implementing something like this too - where i need to send ansible somewhere to, strangely, execute on itself. So bizarre.
e

enough-analyst-54434

05/25/2022, 12:12 AM
@high-yak-85899 @fast-nail-55400 has things right with the env var, but you can bake this in with:
execution_mode="venv"
https://www.pantsbuild.org/docs/reference-pex_binary#codeexecution_modecode. For a long time now that also sets the same env var - but baked into the PEX metadata: https://github.com/pantsbuild/pants/pull/12664/files
h

high-yak-85899

05/25/2022, 12:13 AM
Yeah, that aligns with what I was seeing in testing out locally. Thanks for confirming!
e

enough-analyst-54434

05/25/2022, 12:13 AM
Ah, yeah - you figured this out. I did not read enough of the thread,
@fast-nail-55400 fwiw zip_safe is long dead, all PEXes unzip or install in a venv now. I may need to cleanup some docs / options.
f

fast-nail-55400

05/25/2022, 12:16 AM
fwiw zip_safe is long dead,
The thought it was still relevant is just my bit-rotting hazy recollection
recollection updated!
e

enough-analyst-54434

05/25/2022, 12:19 AM
It was a mees even before then. It only had the meaning you expected pre-wheel when eggs were a thing. Since wheel its only meant the user-code was unzippped vs zipped, the wheels were always unzipped out of necessity of being able to load `.so`s.
7 Views