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

Commit

Permalink
new: Support proto v0.17. (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Sep 9, 2023
1 parent f684a96 commit 4bd8edf
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 14 deletions.
26 changes: 20 additions & 6 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,15 +11,15 @@ 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.7.1" } # , 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" }
proto_pdk_test_utils = { version = "0.6.2" } # , path = "../../proto/crates/pdk-test-utils" }
starbase_sandbox = "0.1.10"
tokio = "1.32.0"

[profile.release]
codegen-units = 1
lto = true
opt-level = "s"
12 changes: 7 additions & 5 deletions src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,18 @@ pub fn download_prebuilt(
Json(input): Json<DownloadPrebuiltInput>,
) -> FnResult<Json<DownloadPrebuiltOutput>> {
let env = get_proto_environment()?;
let version = input.context.version;

if version == "canary" {
return err!(PluginError::UnsupportedCanary { tool: NAME.into() }.into());
}

let releases: HashMap<String, HashMap<String, ReleaseEntry>> = fetch_url_with_cache(
"https://raw.githubusercontent.com/moonrepo/python-plugin/master/releases.json",
)?;

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

let triple = get_target_triple(&env, NAME)?;
Expand Down
3 changes: 3 additions & 0 deletions tests/download_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use proto_pdk_test_utils::*;

generate_download_install_tests!("python-test", "3.10.0");
17 changes: 17 additions & 0 deletions tests/metadata_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use proto_pdk_test_utils::*;
use starbase_sandbox::create_empty_sandbox;

#[test]
fn registers_metadata() {
let sandbox = create_empty_sandbox();
let plugin = create_plugin("python-test", sandbox.path());

assert_eq!(
plugin.register_tool(ToolMetadataInput::default()),
ToolMetadataOutput {
name: "Python".into(),
plugin_version: Some(env!("CARGO_PKG_VERSION").into()),
..ToolMetadataOutput::default()
}
);
}
4 changes: 4 additions & 0 deletions tests/shims_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use proto_pdk_test_utils::*;

#[cfg(not(windows))]
generate_global_shims_test!("python-test", ["pip"]);
13 changes: 13 additions & 0 deletions tests/snapshots/shims_test__creates_global_shims-2.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
source: tests/shims_test.rs
expression: "std::fs::read_to_string(sandbox.path().join(\".proto/bin\").join(if cfg!(windows)\n {\n format!(\"{}.cmd\", \"pip\")\n } else { \"pip\".to_string() })).unwrap()"
---
#!/usr/bin/env bash
set -e
[ -n "$PROTO_DEBUG" ] && set -x



exec proto run python-test -- -m pip "$@"


13 changes: 13 additions & 0 deletions tests/snapshots/shims_test__creates_global_shims.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
source: tests/shims_test.rs
expression: "std::fs::read_to_string(sandbox.path().join(\".proto/bin\").join(if cfg!(windows)\n {\n format!(\"{}.cmd\", \"python-test\")\n } else { \"python-test\".to_string() })).unwrap()"
---
#!/usr/bin/env bash
set -e
[ -n "$PROTO_DEBUG" ] && set -x



exec proto run python-test -- "$@"


31 changes: 31 additions & 0 deletions tests/versions_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use proto_pdk_test_utils::*;
use starbase_sandbox::create_empty_sandbox;

generate_resolve_versions_tests!("python-test", {
"2.3" => "2.3.7",
"3.10.1" => "3.10.1",
"3.10" => "3.10.13",
"3" => "3.11.5",
});

#[test]
fn loads_versions_from_git() {
let sandbox = create_empty_sandbox();
let plugin = create_plugin("python-test", sandbox.path());

let output = plugin.load_versions(LoadVersionsInput::default());

assert!(!output.versions.is_empty());
}

#[test]
fn sets_latest_alias() {
let sandbox = create_empty_sandbox();
let plugin = create_plugin("python-test", sandbox.path());

let output = plugin.load_versions(LoadVersionsInput::default());

assert!(output.latest.is_some());
assert!(output.aliases.contains_key("latest"));
assert_eq!(output.aliases.get("latest"), output.latest.as_ref());
}

0 comments on commit 4bd8edf

Please sign in to comment.