projg2 / python-exec

Wrapper for multi-implementation install of Python scripts and executables
BSD 2-Clause "Simplified" License
13 stars 6 forks source link

python-exec triggers a warning when starting ansible-lint #12

Open pva opened 2 months ago

pva commented 2 months ago

Whenever I run ansible-lint on Gentoo system, I get a warning:

WARNING: PATH altered to include /usr/lib/python-exec/python3.10 :: This is usually a sign of broken local setup, which can cause unexpected behaviors.

This is because ansible-lint adds a binary path into system $PATH and the path binary has (/usr/lib/python-exec/python3.10/) is not in system PATH: https://github.com/ansible/ansible-lint/blob/main/src/ansiblelint/__main__.py#L468

I think python-exec should add a binary path to PATH. Something like this (before exec()) fixed issue for me:

os.environ["PATH"] += os.pathsep + os.path.join('/usr/lib/python-exec', EPYTHON)
mgorny commented 2 months ago

I'm not convinced this is generally a good idea, and it is definitely a change in behavior.

Currently, if direct executable doesn't support preferred impl, other programs will still run through python-exec and run with preferred impl. With this change, the non-preferred impl will be forced for everything.

pva commented 2 months ago

I'm not convinced as well. It's possible to patch ansible-lint but I failed to think of a good way to detect that program was running with the help of python-exec.

eli-schwartz commented 2 months ago

It has never been entirely clear to me why python-exec supports its own use as a shebang to smartly detect the preferred EPYTHON but then uses that facility to execute a launcher script which reads and exec()'s the real script in combination with argv mangling.

One possible solution to this reported case would be to stop doing that, and simply inject itself into the existing script's shebang directly in /usr/bin. What would be the downside of such an approach? (I assume that this must have been considered at some point and rejected, but I haven't seen any documentation on why.)

mgorny commented 2 months ago

Please ask in plain English.