pyinfra-dev / pyinfra

pyinfra turns Python code into shell commands and runs them on your servers. Execute ad-hoc commands and write declarative operations. Target SSH servers, local machine and Docker containers. Fast and scales from one server to thousands.
https://pyinfra.com
MIT License
3.91k stars 382 forks source link

virtualenv: not found in pip.packages operation #872

Closed zalzac closed 2 years ago

zalzac commented 2 years ago

Describe the bug

pip.packages with virtualenv parameter returns error sh: 1: virtualenv: not found. It's similar to #567 except rerunning the deploy also results in an error.

The deploy script was working fine in my old version 1.4.1. I noticed the error after I updated pyinfra to the latest version 2.3. I investigated further which version caused the regression and 1.4.5 is the last version where I don't have this error. It appears on 1.4.6 and later.

To Reproduce

pip.packages(
    requirements="~/calc/requirements.txt",
    virtualenv="~/envs/calc",
)

Expected behavior

pyinfra installs packages from the requirements.txt into a specified environment.

Meta

pyinfra --support

System: Linux
  Platform: Linux-5.4.0-122-generic-x86_64-with-glibc2.10
  Release: 5.4.0-122-generic
  Machine: x86_64
pyinfra: v2.3
Executable: /home/user/miniconda3/envs/calc/bin/pyinfra
Python: 3.8.12 (CPython, GCC 9.4.0)

output with -vv (1.4.5)

>>> sh -c '~/envs/calc/bin/pip install -r ~/calc/requirements.txt'
Success

output with -vv (1.4.6 and 2.3)

>>> sh -c 'virtualenv ~/envs/calc'
sh: 1: virtualenv: not found
Error
Fizzadar commented 2 years ago

Interesting - not seeing any changes in 1.4.6 that would cause this (https://github.com/Fizzadar/pyinfra/compare/v1.4.5...v1.4.6#diff-e65abf13e1f9e3f55570f9ae8167cc22b6c16a48ea43ffde761f7d58095b1567).

If you re-run on 1.4.6/2.3 does the problem still remain? The operation should just check for ~/envs/calc/bin/active and if present it'll skip the virtualenv creation step.

Other useful info: is the target machine a VM/Docker container/similar? Is it possble to repro using a Docker container?

sysadmin75 commented 2 years ago

I am unable to reproduce using the latest 2.4 version.

$ pyinfra --version
pyinfra: v2.4
$ cat repro.py 
from pyinfra.operations import pip

pip.packages(
    requirements="~/ansible/requirements.txt",
    virtualenv="~/ansible/venv",
)

And the output of running pyinfra -vv @local repro.py

[@local] >>> sh -c '~/ansible/venv/bin/pip install -r ~/ansible/requirements.txt'
    [@local] Success
Fizzadar commented 2 years ago

Closing, as above this appears to work and without more info cannot debug.