feat(pipx-update): add quiet flag for pipx upgrade-all on version 1.4.0+ (#635)

This commit introduces conditional logic to the `run_pipx_update` function that checks the installed version of pipx. If the version is 1.4.0 or higher, the `--quiet` argument is added to the `pipx upgrade-all` command to suppress non-critical output during the upgrade process, adhering to the new feature introduced in pipx 1.4.0 as per the documentation (https://pipx.pypa.io/stable/docs/#pipx-upgrade-all). This change aims to make the upgrade process less verbose and more manageable in automated scripts or CI/CD pipelines where log brevity is beneficial.
This commit is contained in:
Carrol Cox
2023-12-31 04:38:39 +01:00
committed by GitHub
parent 15f4ad7cd1
commit ab35cd7b10

View File

@@ -8,6 +8,7 @@ use std::{fs, io::Write};
use color_eyre::eyre::eyre;
use color_eyre::eyre::Context;
use color_eyre::eyre::Result;
use semver::Version;
use tempfile::tempfile_in;
use tracing::{debug, error};
@@ -352,7 +353,20 @@ pub fn run_pipx_update(ctx: &ExecutionContext) -> Result<()> {
let pipx = require("pipx")?;
print_separator("pipx");
ctx.run_type().execute(pipx).arg("upgrade-all").status_checked()
let mut command_args = vec!["upgrade-all"];
// pipx version 1.4.0 introduced a new command argument `pipx upgrade-all --quiet`
// (see https://pipx.pypa.io/stable/docs/#pipx-upgrade-all)
let version_str = Command::new("pipx")
.args(["--version"])
.output_checked_utf8()
.map(|s| s.stdout.trim().to_owned());
let version = Version::parse(&version_str?);
if matches!(version, Ok(version) if version >= Version::new(1, 4, 0)) {
command_args.push("--quiet")
}
ctx.run_type().execute(pipx).args(command_args).status_checked()
}
pub fn run_conda_update(ctx: &ExecutionContext) -> Result<()> {