Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
new: Use python-build.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Sep 8, 2023
1 parent bc58a33 commit f684a96
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 40 deletions.
134 changes: 106 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ crate-type = ['cdylib']
[dependencies]
extism-pdk = "0.3.4"
once_cell = "1.18.0"
proto_pdk = { version = "0.6.5" } # , path = "../../proto/crates/pdk" }
proto_pdk = { version = "0.6.5", path = "../../proto/crates/pdk" }
regex = "1.9.5"
serde = "1.0.188"

[dev-dependencies]
proto_pdk_test_utils = { version = "0.5.9" } # , path = "../../proto/crates/pdk-test-utils" }
starbase_sandbox = "0.1.9"
proto_pdk_test_utils = { version = "0.5.9", path = "../../proto/crates/pdk-test-utils" }
starbase_sandbox = "0.1.10"
tokio = "1.32.0"

[profile.release]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

## Caveats

This plugin only supports pre-builts via [indygreg/python-build-standalone](https://github.com/indygreg/python-build-standalone), and primarily only Python 3.
If `python-build` exists on the host machine, this will be used to install python. Otherwise, a pre-built version will be downloaded from [indygreg/python-build-standalone](https://github.com/indygreg/python-build-standalone), which doesn't support all versions, only Python 3.

Building from source (with `python-build`), and supporting Python 2, will be supported in the future.
Building from source directly (with `python-build`), and supporting Python 2, will be fully supported in the future.

## Contributing

Expand Down
40 changes: 33 additions & 7 deletions src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::fs;
#[host_fn]
extern "ExtismHost" {
fn exec_command(input: Json<ExecCommandInput>) -> Json<ExecCommandOutput>;
fn host_log(input: Json<HostLogInput>);
}

static NAME: &str = "Python";
Expand All @@ -22,6 +23,34 @@ pub fn register_tool(Json(_): Json<ToolMetadataInput>) -> FnResult<Json<ToolMeta
}))
}

#[plugin_fn]
pub fn native_install(
Json(input): Json<NativeInstallInput>,
) -> FnResult<Json<NativeInstallOutput>> {
let mut output = NativeInstallOutput::default();
let env = get_proto_environment()?;

// https://github.com/pyenv/pyenv/tree/master/plugins/python-build
if command_exists(&env, "python-build") {
host_log!("Building with `python-build` instead of downloading a pre-built");

let result = exec_command!(
inherit,
"python-build",
[
input.context.version.as_str(),
input.context.tool_dir.real_path().to_str().unwrap(),
]
);

output.installed = result.exit_code == 0;
} else {
output.skip_install = true;
}

Ok(Json(output))
}

#[derive(Deserialize)]
struct ReleaseEntry {
download: String,
Expand All @@ -39,19 +68,16 @@ pub fn download_prebuilt(
)?;

let Some(release_triples) = releases.get(&input.context.version) else {
return err!(format!(
return err!(
"No pre-built available for version {}!",
input.context.version
));
);
};

let triple = get_target_triple(&env, "Python")?;
let triple = get_target_triple(&env, NAME)?;

let Some(release) = release_triples.get(&triple) else {
return err!(format!(
"No pre-built available for architecture {}!",
triple
));
return err!("No pre-built available for architecture {}!", triple);
};

Ok(Json(DownloadPrebuiltOutput {
Expand Down

0 comments on commit f684a96

Please sign in to comment.