careful-address-89803
02/23/2022, 8:51 PMansible-lint
, which requires the ansible
script to be there too. I tried subclassing PythonToolBase and adding 'ansible==5.3.0' to the extra requirements, but it looks like it's not included in the PEX as I get "No such file or directory: 'ansible'" when running .ansible-lint
.
I'm not sure what question to ask. Is it possible to have a PEX with multiple binaries? Can I have a PythonToolBase depend/include another PythonToolBase? Is there a better way to do this?
Any help is appreciated :)hundreds-father-404
02/23/2022, 8:54 PMdefault_main = ConsoleScript("ansible")
careful-address-89803
02/23/2022, 8:57 PMansible-lint
, which then `subprocess.run`s ansible
.careful-address-89803
02/23/2022, 8:59 PMansible-lint
is actually a separate python package with a separate entrypoint (ansible-lint
), which eventually invokes the ansible
command from the ansible-core
python package.enough-analyst-54434
02/23/2022, 9:03 PMenough-analyst-54434
02/23/2022, 9:04 PMbin_names=["ansible", "ansible-lint"]
you need exposed there.careful-address-89803
02/23/2022, 9:05 PMenough-analyst-54434
02/23/2022, 9:06 PMenough-analyst-54434
02/23/2022, 9:11 PM--venv {prepend,append}
instead of just --venv
there. So, you'd need to plumb a prepend/append option through VenvPexRequest to go that route or else we could just default to prepend
which the package rules do for pex_binary(execution_mode="venv")
targets: https://github.com/pantsbuild/pants/blob/12d56a388c1d0ee02523d19c7e7ad6b2b9550c33/src/python/pants/backend/python/goals/package_pex_binary.py#L[…]92
That'd be simpler and I'm not able to concoct how that might be harmful off the top of my head.enough-analyst-54434
02/23/2022, 9:14 PMcareful-address-89803
02/23/2022, 9:15 PMenough-analyst-54434
02/23/2022, 9:15 PMenough-analyst-54434
02/23/2022, 9:15 PMcareful-address-89803
02/23/2022, 9:15 PMcareful-address-89803
02/23/2022, 9:16 PMenough-analyst-54434
02/23/2022, 9:18 PMenough-analyst-54434
02/23/2022, 9:19 PMcareful-address-89803
02/23/2022, 9:29 PMsubprocess.run(args=["ansible", "--version"], ...)
. I can't find it monkeying around with the sys.path anywhere. Is there a quick way to test this, maybe with another command?enough-analyst-54434
02/23/2022, 10:02 PM--no-process-cleanup
is your friend when testing rule sandboxed processes. That will print out the paths to all the sandboxes Pants creates. Grab the path of the relevant rule fro the Pants run output, then cd there and poke around. Everything is exactly as executed by the Rust code except:
1. There is a __run.sh
script that encodes how Rust will execute this sandbox.
2. That script is buggy in 1 way, it does not mask env vars like the rust code does, it lets your ambient environment through.
You should be able to use this knowledge to hack on the __run.sh
script and run it to see what happens. I'd 1st have it echo the $PATH
and see if there are CWD (`:rest`or .:rest
) style entries. If there are, I'd try running PATH=... ./__run.sh
to exclude CWD and see if things still work.enough-analyst-54434
02/23/2022, 10:03 PM--no-process-execution-local-cleanup
.careful-address-89803
02/23/2022, 10:56 PMansible
executable because python is adding the CWD to the path. ansible-lint
is invoked directly via path to "${venv_dir}/bin/ansible-lint" with a shebang of a pex-venv-based python, it gets the CWD of "${venv_dir}/bin" added to its path, and that's the same place as ansible and other binaries are installed (including bins from other python dependencies!).careful-address-89803
02/23/2022, 10:56 PMwide-midnight-78598
02/23/2022, 11:08 PMcareful-address-89803
02/23/2022, 11:14 PMcareful-address-89803
02/23/2022, 11:16 PMcareful-address-89803
02/23/2022, 11:18 PMcareful-address-89803
02/23/2022, 11:36 PMproud-dentist-22844
02/23/2022, 11:53 PMtransform
to fix (or at least improve) the issues the rule identified.proud-dentist-22844
02/23/2022, 11:53 PMproud-dentist-22844
02/24/2022, 12:03 AMansible-lint
loads its rules from the filesystem, not via python imports. The default rules (python files) are indirectly identified using a __file__
and then importlib
. see:
https://github.com/ansible-community/ansible-lint/blob/main/src/ansiblelint/constants.py#L12
https://github.com/ansible-community/ansible-lint/blob/main/src/ansiblelint/rules/__init__.py#L181-L197proud-dentist-22844
02/24/2022, 12:03 AMproud-dentist-22844
02/24/2022, 12:06 AMansible
bin next to the sys.executable
bin and adds that to PATH if it exists. This was added so people could call ansible-lint
without activating a venv, and still pick up the ansible
binary from that venv instead of some other random version. https://github.com/ansible-community/ansible-lint/blob/main/src/ansiblelint/__main__.py#L274-L292proud-dentist-22844
02/24/2022, 12:11 AMansible-lint
can mess with the PATH
for v5.4.0+, giving preference to ansible
installed in the same venv as ansible-lint
.wide-midnight-78598
02/24/2022, 12:35 AMwide-midnight-78598
02/24/2022, 12:36 AMcareful-address-89803
02/24/2022, 1:11 AMcareful-address-89803
02/24/2022, 1:16 AMproud-dentist-22844
02/24/2022, 1:26 AMcareful-address-89803
03/06/2022, 2:15 AMsys.path
, which is the python module path. Not, as I thought, the system path for looking up commands (with shutils
or subprocess
). That's still the os.environ
path variable, which is unmodified. So now I'm no longer confused about why things didn't work. I've going to try the other suggestions for getting multiple binaries playing together.proud-dentist-22844
03/06/2022, 5:50 AMansible-lint-6.0.0a0
pre release was released today. It includes the ability to reformat YAML files using ansible-lint --write
. I would love feedback. So, if you find any issues with that or the PATH manipulation or whatever, we can get changes in before 6.0 final is released, prob in a couple weeks.careful-address-89803
03/07/2022, 5:33 AM--venv prepend
a shot. I hotwired it with a normal PexRequest with additional_args=("--venv", "append")
, so it looks like plumbing that in to VenvPexRequest would work. I'm open to contributing, but I'm still getting around how Pants works, so I think I'd need guidance.careful-address-89803
03/07/2022, 5:36 AMenough-analyst-54434
03/07/2022, 5:37 PM$ git grep -n "\"\--venv\"" src/python/
src/python/pants/backend/python/goals/package_pex_binary.py:92: args.extend(("--venv", "prepend"))
src/python/pants/backend/python/util_rules/pex.py:786: "--venv",
You're interested in the 2nd hit. One option is to do like the 1st hit and just hard code "prepend"
- I can't see any problems with this. The other option is the plumb. Looking at that line 786 there is a VenvPexRequest
in scope (https://github.com/pantsbuild/pants/blob/94921a8edb9b142dff471784aef9da22b58cd0ab/src/python/pants/backend/python/util_rules/pex.py#L751-L786); so, if VenvPexRequest
grew a new field carrying a prepend, append or None, you'd be done.