vscode-ansible icon indicating copy to clipboard operation
vscode-ansible copied to clipboard

pipenv support

Open gionn opened this issue 2 years ago • 4 comments

Summary

In my ansible project, I use pipenv to handle dependencies, that doesn't look to be supported by this extensions since I always get command not found when trying to run ansible or ansible-lint.

Extension version

v1.2.44

VS Code version

1.76.2

Ansible Version

ansible [core 2.14.3]
  config file = /Users/Giovanni.Toraldo/src/alfresco/alfresco-ansible-deployment/ansible.cfg
  configured module search path = ['/Users/Giovanni.Toraldo/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/Giovanni.Toraldo/.virtualenvs/alfresco-ansible-deployment-LdMEq9P-/lib/python3.10/site-packages/ansible
  ansible collection location = /Users/Giovanni.Toraldo/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/Giovanni.Toraldo/.virtualenvs/alfresco-ansible-deployment-LdMEq9P-/bin/ansible
  python version = 3.10.9 (main, Dec 15 2022, 18:18:30) [Clang 14.0.0 (clang-1400.0.29.202)] (/Users/Giovanni.Toraldo/.virtualenvs/alfresco-ansible-deployment-LdMEq9P-/bin/python)
  jinja version = 3.1.2
  libyaml = True

OS / Environment

MacOS Ventura

Relevant log output

Command failed: ansible-config dump /bin/sh: ansible-config: command not found

gionn avatar Mar 22 '23 16:03 gionn

Ok I've actually just discovered that if I set in the settings for my current workspace:

Ansible: Path to /Users/Giovanni.Toraldo/.virtualenvs/alfresco-ansible-deployment-LdMEq9P-/bin/ansible

Ansible › Python: Interpreter Path to /Users/Giovanni.Toraldo/.virtualenvs/alfresco-ansible-deployment-LdMEq9P-/bin/python

that is sub-optimal but still solve the issue.

vscode itself instead looks like it automatically detect I am using pipenv and when I open a terminal it automatically enter the pipenv.

Thanks!

gionn avatar Mar 22 '23 16:03 gionn

Hey @gionn, we are working on a better way of discovering interpreters. But till then, here's a quick tip: Rather than changing all these settings, you can use ansible.python.activationScript and give it the path to your activate script, which will be used instead of the setting above to run in a Python virtual environment.

priyamsahoo avatar Mar 25 '23 13:03 priyamsahoo

Hello, thanks for the feedback.

I tried with that activation script first, but with pipenv I am not aware of any script that you can source from a shell to activate it, but you need to run the pipenv binary to either launch a command from within the pipenv or spawn a pipenv-enabled shell.

https://pipenv.pypa.io/en/latest/installation/#using-installed-packages

gionn avatar Mar 25 '23 13:03 gionn

Hey @gionn, when you run pipenv shell the output tells you where the activate script is – if you pass that to ansible.python.activationScript, ansible-lint (and other binaries specific to your virtualenv handled with Pipenv) will work.

Here's more details:

> pipenv shell
Launching subshell in virtual environment...
 . /Users/me/.local/share/virtualenvs/<my project name>-4m92qzA4/bin/activate
(<my project name>) > which ansible-lint
/Users/me/.local/share/virtualenvs/<my project name>-4m92qzA4/bin/ansible-lint
(<my project name>) > 

Then on my ./vscode/settings.json:

{
  "ansible.python.activationScript": "/Users/me/.local/share/virtualenvs/<my project name>-4m92qzA4/bin/activate"
}

Now the extension can run ansible-lint.

tanjarinne avatar Apr 25 '23 18:04 tanjarinne