From 54301a6a17ade1837dafe2d7414e112448b6f826 Mon Sep 17 00:00:00 2001 From: MonstrousOgre Date: Sat, 20 May 2023 23:03:59 +0530 Subject: [PATCH] Adding local pip-review (#433) --- config.example.toml | 5 +++-- src/config.rs | 10 ++++++++++ src/main.rs | 3 +++ src/steps/generic.rs | 19 +++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/config.example.toml b/config.example.toml index 56042dfc..2936509f 100644 --- a/config.example.toml +++ b/config.example.toml @@ -106,8 +106,9 @@ #nix_arguments = "--flake" [python] -#enable_pip_review = true ###disabled by default -#enable_pipupgrade = true ###disabled by default +#enable_pip_review = true ###disabled by default +#enable_pip_review_local = true ###disabled by default +#enable_pipupgrade = true ###disabled by default [windows] # Manually select Windows updates diff --git a/src/config.rs b/src/config.rs index 61ccb4db..7a54dbae 100644 --- a/src/config.rs +++ b/src/config.rs @@ -130,6 +130,7 @@ pub enum Step { Pearl, Pip3, PipReview, + PipReviewLocal, Pipupgrade, Pipx, Pkg, @@ -200,6 +201,7 @@ pub struct Windows { #[serde(deny_unknown_fields)] pub struct Python { enable_pip_review: Option, + enable_pip_review_local: Option, enable_pipupgrade: Option, } @@ -1138,6 +1140,14 @@ impl Config { .and_then(|python| python.enable_pip_review) .unwrap_or(false); } + pub fn enable_pip_review_local(&self) -> bool { + return self + .config_file + .python + .as_ref() + .and_then(|python| python.enable_pip_review_local) + .unwrap_or(false); + } pub fn display_time(&self) -> bool { self.config_file.display_time.unwrap_or(true) diff --git a/src/main.rs b/src/main.rs index 53e82c74..976565c1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -384,6 +384,9 @@ For more information about this issue see https://askubuntu.com/questions/110969 runner.execute(Step::Mamba, "mamba", || generic::run_mamba_update(&ctx))?; runner.execute(Step::Pip3, "pip3", || generic::run_pip3_update(run_type))?; runner.execute(Step::PipReview, "pip-review", || generic::run_pip_review_update(&ctx))?; + runner.execute(Step::PipReviewLocal, "pip-review (local)", || { + generic::run_pip_review_local_update(&ctx) + })?; runner.execute(Step::Pipupgrade, "pipupgrade", || generic::run_pipupgrade_update(&ctx))?; runner.execute(Step::Ghcup, "ghcup", || generic::run_ghcup_update(run_type))?; runner.execute(Step::Stack, "stack", || generic::run_stack_update(run_type))?; diff --git a/src/steps/generic.rs b/src/steps/generic.rs index 851476b5..1a2ba457 100644 --- a/src/steps/generic.rs +++ b/src/steps/generic.rs @@ -414,6 +414,25 @@ pub fn run_pip_review_update(ctx: &ExecutionContext) -> Result<()> { Ok(()) } +pub fn run_pip_review_local_update(ctx: &ExecutionContext) -> Result<()> { + let pip_review = require("pip-review")?; + + print_separator("pip-review (local)"); + + if !ctx.config().enable_pip_review_local() { + print_warning( + "Pip-review (local) is disabled by default. Enable it by setting enable_pip_review_local=true in the configuration.", + ); + return Err(SkipStep(String::from("Pip-review (local) is disabled by default")).into()); + } + ctx.run_type() + .execute(pip_review) + .arg("--local") + .arg("--auto") + .status_checked_with_codes(&[1])?; + + Ok(()) +} pub fn run_pipupgrade_update(ctx: &ExecutionContext) -> Result<()> { let pipupgrade = require("pipupgrade")?;