Skip to content

Commit

Permalink
feat(pipx): add support for specifying package extras (#2510)
Browse files Browse the repository at this point in the history
* feat(pipx): add support for specifying extras

* chore: fix linting erros

* tests: add e2e tests for pipx with extras
  • Loading branch information
antoniomdk committed Aug 31, 2024
1 parent d341e4e commit 6730416
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
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: pipx@1.5.0 > pipx:mkdocs@1.6.0
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

0 comments on commit 6730416

Please sign in to comment.