Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: add pipx support #637

Draft
wants to merge 2 commits into
base: 1.x
Choose a base branch
from
Draft

WIP: add pipx support #637

wants to merge 2 commits into from

Conversation

karolzlot
Copy link

@karolzlot karolzlot commented Aug 10, 2021

This is attempt to add pipx support. Pipx is is great tool to install many packages, I want to use it to install for example docker-compose and docker-auto-labels on hosts.


I have problem, which I can't understand how to fix. I can't run pipx from pyinfra, but I can run it from manual ssh session. It works ok if pipx is installed via apt, but version in apt is very outdated.

Example code below generates error:

from pyinfra.api import Config
from pyinfra.operations import apt, pip, pipx

apt.packages(
    name='Ensure python is installed',
    packages=['python3-pip', 'python3-venv'],
    latest=True,
    sudo=True,  # use sudo when installing the packages
    update=True,
    cache_time=3600,
    upgrade=True,
)

pip.packages(
    name="Ensure pipx is installed",
    packages=["pipx"],
    pip="pip3",
    latest=True,
    # sudo=True,  # If sudo is enabled here, then error vanishes, but sudo is not recommended for pip
)

pipx.packages(
    name="Ensure pycowsay is installed",
    packages=["pycowsay"],
    latest=True,
)

Error message:

--> Starting operation: Ensure pycowsay is installed
[REDACTED_IP] >>> sudo -H -n sh -c 'pipx install pycowsay'
[REDACTED_IP] sh: 1: pipx: not found
    [REDACTED_IP] Error
No hosts remaining!
--> pyinfra error: 

@karolzlot
Copy link
Author

Another issue is that pipx needs separate commands, it won't work with:

pipx install pycowsay copier docker-compose

It needs:

pipx install pycowsay 
pipx install copier
pipx install docker-compose

I'm not sure if ensure_packages is able to work this way.

@karolzlot
Copy link
Author

karolzlot commented Aug 11, 2021

Problem is pyinfra uses sh -c ' command.... ' to execute commands and $PATH is different because of it. I would like to have an option to use bash instead of sh.

Those commands give interesting, different results:

echo $PATH
sh -c 'echo $PATH'
sudo sh -c 'echo $PATH'

@Fizzadar Fizzadar marked this pull request as ready for review August 12, 2021 09:32
@karolzlot karolzlot changed the title WIP: added pipx support WIP: add pipx support Sep 18, 2021
@karolzlot karolzlot marked this pull request as draft February 6, 2022 06:37
@Fizzadar Fizzadar changed the base branch from current to 1.x March 30, 2022 09:56
@karlicoss
Copy link
Contributor

For multiple packages issue, here's the related pipx issue pypa/pipx#88

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants