Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pipx): add support for specifying package extras #2510

Merged
merged 5 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 29 additions & 0 deletions e2e/backend/test_pipx_extras
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
require_cmd python3

# Create a system pipx that always fail and push it to the front of PATH
cat >"$HOME/bin/pipx" <<'EOF'
#!/usr/bin/env bash
echo "CALL TO SYSTEM pipx! args: $*" >&2
exit 1
EOF
chmod +x "$HOME"/bin/pipx
export PATH="$HOME/bin:$PATH"

# Just to be sure...
assert_fail "pipx"

# Use precompiled python
export MISE_PYTHON_COMPILE=0

# Set up a 2-step installation: [email protected] > pipx:[email protected]
cat >.mise.toml <<EOF
[tools]
pipx = "1.5.0"
"pipx:harlequin" = {version = "1.24.0", extras = "s3"}
EOF

# Install the tools
mise install

assert_contains "mise x -- harlequin --version" "1.24.0"
19 changes: 14 additions & 5 deletions src/backend/pipx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::cmd::CmdLineRunner;
use crate::config::{Config, Settings};
use crate::http::HTTP_FETCH;
use crate::install_context::InstallContext;
use crate::toolset::ToolRequest;
use crate::toolset::{ToolRequest, ToolVersionOptions};
use crate::{env, github};

#[derive(Debug)]
Expand Down Expand Up @@ -82,7 +82,7 @@ impl Backend for PIPXBackend {
let pipx_request = self
.name()
.parse::<PipxRequest>()?
.pipx_request(&ctx.tv.version);
.pipx_request(&ctx.tv.version, &ctx.tv.request.options());

if settings.pipx_uvx {
CmdLineRunner::new("uv")
Expand Down Expand Up @@ -139,16 +139,25 @@ enum PipxRequest {
}

impl PipxRequest {
fn pipx_request(&self, v: &str) -> String {
fn extras_from_opts(&self, opts: &ToolVersionOptions) -> String {
match opts.get("extras") {
Some(extras) => format!("[{}]", extras),
None => String::new(),
}
}

fn pipx_request(&self, v: &str, opts: &ToolVersionOptions) -> String {
let extras = self.extras_from_opts(opts);

if v == "latest" {
match self {
PipxRequest::Git(url) => format!("git+{url}.git"),
PipxRequest::Pypi(package) => package.to_string(),
PipxRequest::Pypi(package) => format!("{}{}", package, extras),
}
} else {
match self {
PipxRequest::Git(url) => format!("git+{}.git@{}", url, v),
PipxRequest::Pypi(package) => format!("{}=={}", package, v),
PipxRequest::Pypi(package) => format!("{}{}=={}", package, extras, v),
}
}
}
Expand Down
Loading