diff --git a/pyinfra/operations/pipx.py b/pyinfra/operations/pipx.py index 5c45237e2..e3736bdb3 100644 --- a/pyinfra/operations/pipx.py +++ b/pyinfra/operations/pipx.py @@ -3,7 +3,7 @@ """ from pyinfra import host -from pyinfra.api import operation +from pyinfra.api import operation, OperationError from pyinfra.facts.server import Path from pyinfra.facts.pipx import PipxPackages, PipxEnvironment @@ -29,7 +29,7 @@ def packages( + extra_install_args: additional arguments to the pipx install command Versions: - Package versions can be pinned like pipx: ``==``. + Package versions can be pinned like pip: ``==``. **Example:** @@ -56,6 +56,9 @@ def packages( if packages: current_packages = host.get_fact(PipxPackages, pipx=pipx) + if current_packages is None: + raise OperationError("Unable to get pipx packages") + # pipx support only one package name at a time for package in packages: yield from ensure_packages( @@ -76,7 +79,6 @@ def upgrade_all(pipx="pipx"): """ Upgrade all pipx packages. """ - yield f"{pipx} upgrade-all" @@ -93,6 +95,6 @@ def ensure_path(pipx="pipx"): # If the pipx bin dir is already in the user's PATH, we're done if pipx_env["PIPX_BIN_DIR"] in path.split(":"): - return + host.noop("pipx bin dir is already in the PATH") else: yield f"{pipx} ensurepath" diff --git a/tests/facts/pipx.PipxEnvironment/environment.json b/tests/facts/pipx.PipxEnvironment/environment.json new file mode 100644 index 000000000..aa6487019 --- /dev/null +++ b/tests/facts/pipx.PipxEnvironment/environment.json @@ -0,0 +1,22 @@ +{ + "command": "pipx environment", + "requires_command": "pipx", + "output": [ + "PIPX_HOME=/home/doodba/.local/pipx", + "PIPX_BIN_DIR=/home/doodba/.local/bin", + "PIPX_SHARED_LIBS=/home/doodba/.local/pipx/shared", + "PIPX_LOCAL_VENVS=/home/doodba/.local/pipx/venvs", + "PIPX_LOG_DIR=/home/doodba/.local/pipx/logs", + "PIPX_TRASH_DIR=/home/doodba/.local/pipx/.trash", + "PIPX_VENV_CACHEDIR=/home/doodba/.local/pipx/.cache" + ], + "fact": { + "PIPX_HOME": "/home/doodba/.local/pipx", + "PIPX_BIN_DIR": "/home/doodba/.local/bin", + "PIPX_SHARED_LIBS": "/home/doodba/.local/pipx/shared", + "PIPX_LOCAL_VENVS": "/home/doodba/.local/pipx/venvs", + "PIPX_LOG_DIR": "/home/doodba/.local/pipx/logs", + "PIPX_TRASH_DIR": "/home/doodba/.local/pipx/.trash", + "PIPX_VENV_CACHEDIR": "/home/doodba/.local/pipx/.cache" + } +} diff --git a/tests/facts/pipx.PipxEnvironment/packages.json b/tests/facts/pipx.PipxEnvironment/packages.json deleted file mode 100644 index 5ed6aa05c..000000000 --- a/tests/facts/pipx.PipxEnvironment/packages.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "command": "pipx environment", - "requires_command": "pipx", - "output": [ - "copier 9.0.1", - "invoke 2.2.0" - ], - "fact": { - "copier": ["9.0.1"], - "invoke": ["2.2.0"] - } -} diff --git a/tests/facts/pipx.PipxPackages/packages.json b/tests/facts/pipx.PipxPackages/packages.json index aa6487019..264b6fc1c 100644 --- a/tests/facts/pipx.PipxPackages/packages.json +++ b/tests/facts/pipx.PipxPackages/packages.json @@ -1,22 +1,12 @@ { - "command": "pipx environment", + "command": "pipx list --short", "requires_command": "pipx", "output": [ - "PIPX_HOME=/home/doodba/.local/pipx", - "PIPX_BIN_DIR=/home/doodba/.local/bin", - "PIPX_SHARED_LIBS=/home/doodba/.local/pipx/shared", - "PIPX_LOCAL_VENVS=/home/doodba/.local/pipx/venvs", - "PIPX_LOG_DIR=/home/doodba/.local/pipx/logs", - "PIPX_TRASH_DIR=/home/doodba/.local/pipx/.trash", - "PIPX_VENV_CACHEDIR=/home/doodba/.local/pipx/.cache" + "copier 9.0.1", + "invoke 2.2.0" ], "fact": { - "PIPX_HOME": "/home/doodba/.local/pipx", - "PIPX_BIN_DIR": "/home/doodba/.local/bin", - "PIPX_SHARED_LIBS": "/home/doodba/.local/pipx/shared", - "PIPX_LOCAL_VENVS": "/home/doodba/.local/pipx/venvs", - "PIPX_LOG_DIR": "/home/doodba/.local/pipx/logs", - "PIPX_TRASH_DIR": "/home/doodba/.local/pipx/.trash", - "PIPX_VENV_CACHEDIR": "/home/doodba/.local/pipx/.cache" - } + "copier": ["9.0.1"], + "invoke": ["2.2.0"] + } } diff --git a/tests/operations/pipx.ensure_path/ensure_path.json b/tests/operations/pipx.ensure_path/ensure_path.json index de38d43f2..9f61f9d9a 100644 --- a/tests/operations/pipx.ensure_path/ensure_path.json +++ b/tests/operations/pipx.ensure_path/ensure_path.json @@ -1,5 +1,5 @@ { - "args": [["copier==9.0.1", "invoke"]], + "args": [], "facts": { "pipx.PipxEnvironment": { "PIPX_HOME": "/home/doodba/.local/pipx", diff --git a/tests/operations/pipx.packages/add_packages.json b/tests/operations/pipx.packages/add_packages.json index 0000db894..26de23052 100644 --- a/tests/operations/pipx.packages/add_packages.json +++ b/tests/operations/pipx.packages/add_packages.json @@ -1,10 +1,10 @@ { - "args": ["copier==9.0.1", "invoke"], + "args": [["copier==0.9.1", "invoke"]], "facts": { - "pipx.PipxPackages": {} + "pipx.PipxPackages": {"ensurepath": ["0.1.1"]} }, "commands": [ - "pipx install --force copier==9.0.1", + "pipx install --force copier==0.9.1", "pipx install --force invoke" ] } diff --git a/tests/operations/pipx.packages/remove_packages.json b/tests/operations/pipx.packages/remove_packages.json index fc7e26c34..571c23d5f 100644 --- a/tests/operations/pipx.packages/remove_packages.json +++ b/tests/operations/pipx.packages/remove_packages.json @@ -1,18 +1,16 @@ { - "args": [["elasticquery==1.2", "pyinfra", "test==1.1"]], + "args": [["invoke", "copier"]], "kwargs": { "present": false }, "facts": { - "pip.PipPackages": { - "pip=pip": { - "elasticquery": ["1.0"], - "pyinfra": [""], - "test": ["1.1"] + "pipx.PipxPackages": { + "copier": ["9.0.1"], + "invoke": ["2.2.0"] } - } }, "commands": [ - "pip uninstall --yes pyinfra test==1.1" + "pipx uninstall invoke", + "pipx uninstall copier" ] } diff --git a/tests/operations/pipx.upgrade_all/upgrade_all.json b/tests/operations/pipx.upgrade_all/upgrade_all.json index 2a67cbbcd..a851d54d0 100644 --- a/tests/operations/pipx.upgrade_all/upgrade_all.json +++ b/tests/operations/pipx.upgrade_all/upgrade_all.json @@ -3,5 +3,7 @@ "facts": {}, "commands": [ "pipx upgrade-all" - ] + ], + "idempotent": false, + "disable_idempotent_warning_reason": "package upgrades are always executed" }