Skip to content

Commit

Permalink
feat(poetry): add poetry_force_self_update config option
Browse files Browse the repository at this point in the history
  • Loading branch information
AThePeanut4 committed Nov 24, 2024
1 parent 40ba5b7 commit 389f840
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
4 changes: 4 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@
# enable_pipupgrade = true ###disabled by default
# pipupgrade_arguments = "-y -u --pip-path pip" ###disabled by default

# Run `poetry self update` even if poetry was not installed with the official script
# (default: false)
# poetry_force_self_update = true


[composer]
# self_update = true
Expand Down
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ pub struct Python {
enable_pip_review_local: Option<bool>,
enable_pipupgrade: Option<bool>,
pipupgrade_arguments: Option<String>,
poetry_force_self_update: Option<bool>,
}

#[derive(Deserialize, Default, Debug, Merge)]
Expand Down Expand Up @@ -1627,6 +1628,13 @@ impl Config {
.and_then(|python| python.enable_pip_review_local)
.unwrap_or(false)
}
pub fn poetry_force_self_update(&self) -> bool {
self.config_file
.python
.as_ref()
.and_then(|python| python.poetry_force_self_update)
.unwrap_or(false)
}

pub fn display_time(&self) -> bool {
self.config_file
Expand Down
42 changes: 24 additions & 18 deletions src/steps/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,28 +1077,34 @@ pub fn run_poetry(ctx: &ExecutionContext) -> Result<()> {
Ok(std::str::from_utf8(shebang)?.into())
}

let interpreter = match get_interpreter(&poetry) {
Ok(p) => p,
Err(e) => return Err(SkipStep(format!("Could not find interpreter for {}: {}", poetry.display(), e)).into()),
};
debug!("poetry interpreter: {}", interpreter.display());
if ctx.config().poetry_force_self_update() {
debug!("forcing poetry self update");
} else {
let interpreter = match get_interpreter(&poetry) {
Ok(p) => p,
Err(e) => {
return Err(SkipStep(format!("Could not find interpreter for {}: {}", poetry.display(), e)).into())
}
};
debug!("poetry interpreter: {}", interpreter.display());

let check_official_install_script =
let check_official_install_script =
"import sys; from os import path; print('Y') if path.isfile(path.join(sys.prefix, 'poetry_env')) else print('N')";
let output = Command::new(&interpreter)
.args(["-c", check_official_install_script])
.output_checked_utf8()?;
let stdout = output.stdout.trim();
let official_install = match stdout {
"N" => false,
"Y" => true,
_ => unreachable!("unexpected output from `check_official_install_script`"),
};
let output = Command::new(&interpreter)
.args(["-c", check_official_install_script])
.output_checked_utf8()?;
let stdout = output.stdout.trim();
let official_install = match stdout {
"N" => false,
"Y" => true,
_ => unreachable!("unexpected output from `check_official_install_script`"),
};

debug!("poetry is official install: {}", official_install);
debug!("poetry is official install: {}", official_install);

if !official_install {
return Err(SkipStep("Not installed with the official script".to_string()).into());
if !official_install {
return Err(SkipStep("Not installed with the official script".to_string()).into());
}
}

print_separator("Poetry");
Expand Down

0 comments on commit 389f840

Please sign in to comment.