Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions src/backend/pipx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use async_trait::async_trait;
use eyre::{Result, eyre};
use indexmap::IndexMap;
use itertools::Itertools;
use jiff::Timestamp;
use regex::Regex;
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -229,6 +230,7 @@ impl Backend for PIPXBackend {
ctx.pr.as_ref(),
)
.await?;
cmd = Self::apply_transitive_install_before(cmd, PipxInstaller::Uvx, ctx.before_date);
if let Some(args) = tv.request.options().get("uvx_args") {
cmd = cmd.args(shell_words::split(args)?);
}
Expand All @@ -244,6 +246,7 @@ impl Backend for PIPXBackend {
ctx.pr.as_ref(),
)
.await?;
cmd = Self::apply_transitive_install_before(cmd, PipxInstaller::Pipx, ctx.before_date);
if let Some(args) = tv.request.options().get("pipx_args") {
cmd = cmd.args(shell_words::split(args)?);
}
Expand Down Expand Up @@ -288,6 +291,32 @@ pub fn install_time_option_keys() -> Vec<String> {
}

impl PIPXBackend {
fn transitive_install_before_env(
installer: PipxInstaller,
before_date: Option<Timestamp>,
) -> Option<(&'static str, String)> {
before_date.map(|before_date| {
let env_key = match installer {
PipxInstaller::Uvx => "UV_EXCLUDE_NEWER",
PipxInstaller::Pipx => "PIP_EXCLUDE_NEWER",
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Outdated
};
(env_key, before_date.to_string())
})
}

fn apply_transitive_install_before<'a>(
mut cmd: CmdLineRunner<'a>,
installer: PipxInstaller,
before_date: Option<Timestamp>,
) -> CmdLineRunner<'a> {
if let Some((env_key, env_value)) =
Self::transitive_install_before_env(installer, before_date)
{
cmd = cmd.env(env_key, env_value);
}
cmd
}

pub fn from_arg(ba: BackendArg) -> Self {
Self {
latest_version_cache: CacheManagerBuilder::new(
Expand Down Expand Up @@ -640,3 +669,42 @@ fn fix_venv_python_symlink(install_path: &Path, pkg_name: &str) -> Result<()> {
fn fix_venv_python_symlink(_install_path: &Path, _pkg_name: &str) -> Result<()> {
Ok(())
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum PipxInstaller {
Uvx,
Pipx,
}

#[cfg(test)]
mod tests {
use super::{PIPXBackend, PipxInstaller};
use pretty_assertions::assert_eq;

#[test]
fn test_transitive_install_before_env_for_uvx() {
let before_date = "2024-01-02T03:04:05Z".parse().unwrap();
let env = PIPXBackend::transitive_install_before_env(PipxInstaller::Uvx, Some(before_date));
assert_eq!(
env,
Some(("UV_EXCLUDE_NEWER", "2024-01-02T03:04:05Z".to_string()))
);
}

#[test]
fn test_transitive_install_before_env_for_pipx() {
let before_date = "2024-01-02T03:04:05Z".parse().unwrap();
let env =
PIPXBackend::transitive_install_before_env(PipxInstaller::Pipx, Some(before_date));
assert_eq!(
env,
Some(("PIP_EXCLUDE_NEWER", "2024-01-02T03:04:05Z".to_string()))
);
}

#[test]
fn test_transitive_install_before_env_without_cutoff() {
let env = PIPXBackend::transitive_install_before_env(PipxInstaller::Pipx, None);
assert_eq!(env, None);
}
}
Loading