From 4bd8edfb2d785d2761cb66e798644b55b7240bbb Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Fri, 8 Sep 2023 22:19:16 -0700 Subject: [PATCH] new: Support proto v0.17. (#1) --- Cargo.lock | 26 ++++++++++++---- Cargo.toml | 6 ++-- src/proto.rs | 12 ++++--- tests/download_test.rs | 3 ++ tests/metadata_test.rs | 17 ++++++++++ tests/shims_test.rs | 4 +++ .../shims_test__creates_global_shims-2.snap | 13 ++++++++ .../shims_test__creates_global_shims.snap | 13 ++++++++ tests/versions_test.rs | 31 +++++++++++++++++++ 9 files changed, 111 insertions(+), 14 deletions(-) create mode 100644 tests/download_test.rs create mode 100644 tests/metadata_test.rs create mode 100644 tests/shims_test.rs create mode 100644 tests/snapshots/shims_test__creates_global_shims-2.snap create mode 100644 tests/snapshots/shims_test__creates_global_shims.snap create mode 100644 tests/versions_test.rs diff --git a/Cargo.lock b/Cargo.lock index c7cfcee..f2e5f78 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2055,7 +2055,9 @@ dependencies = [ [[package]] name = "proto_core" -version = "0.16.4" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9d66bf857561212ef611c073ce1f83f09a3bc70ee8b5edbdf1dff433f8e71d" dependencies = [ "cached", "extism", @@ -2083,7 +2085,9 @@ dependencies = [ [[package]] name = "proto_pdk" -version = "0.6.5" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2e7ee5ae588b5cda3bcbd90c87f2875292bba9ce846569f4ed427fc520ba96d" dependencies = [ "anyhow", "extism-pdk", @@ -2095,7 +2099,9 @@ dependencies = [ [[package]] name = "proto_pdk_api" -version = "0.6.3" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33aee2bcc06bc3f8d0033e2c733e0ddaf8e1fcd141e151064ef7f73867e123cd" dependencies = [ "anyhow", "semver", @@ -2107,7 +2113,9 @@ dependencies = [ [[package]] name = "proto_pdk_test_utils" -version = "0.5.9" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b799a8c37613832e1129d7a52887406a1e2aabf1565484b1925d4ad3d3dac98" dependencies = [ "extism", "proto_core", @@ -2118,7 +2126,9 @@ dependencies = [ [[package]] name = "proto_wasm_plugin" -version = "0.6.3" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a377902a50bcfd6658744b43c416b18088921d6c52db0de2be0e8f7a76ec4aed" dependencies = [ "extism", "proto_pdk_api", @@ -3231,7 +3241,9 @@ dependencies = [ [[package]] name = "warpgate" -version = "0.5.3" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e105ab7fd178b2fc6b59439046418278b478e761549658a41eb48c97a9944a" dependencies = [ "extism", "miette", @@ -3253,6 +3265,8 @@ dependencies = [ [[package]] name = "warpgate_api" version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c87f4f62fa42fa715ce697387b4c5c66ae0380723b841b1e0ff9fd285c78ab5f" dependencies = [ "serde", ] diff --git a/Cargo.toml b/Cargo.toml index b5e4edc..2801e55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/proto.rs b/src/proto.rs index 6ab7d38..6acd17c 100644 --- a/src/proto.rs +++ b/src/proto.rs @@ -62,16 +62,18 @@ pub fn download_prebuilt( Json(input): Json, ) -> FnResult> { let env = get_proto_environment()?; + let version = input.context.version; + + if version == "canary" { + return err!(PluginError::UnsupportedCanary { tool: NAME.into() }.into()); + } let releases: HashMap> = 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)?; diff --git a/tests/download_test.rs b/tests/download_test.rs new file mode 100644 index 0000000..cb3fedb --- /dev/null +++ b/tests/download_test.rs @@ -0,0 +1,3 @@ +use proto_pdk_test_utils::*; + +generate_download_install_tests!("python-test", "3.10.0"); diff --git a/tests/metadata_test.rs b/tests/metadata_test.rs new file mode 100644 index 0000000..87ae6c1 --- /dev/null +++ b/tests/metadata_test.rs @@ -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() + } + ); +} diff --git a/tests/shims_test.rs b/tests/shims_test.rs new file mode 100644 index 0000000..24580ef --- /dev/null +++ b/tests/shims_test.rs @@ -0,0 +1,4 @@ +use proto_pdk_test_utils::*; + +#[cfg(not(windows))] +generate_global_shims_test!("python-test", ["pip"]); diff --git a/tests/snapshots/shims_test__creates_global_shims-2.snap b/tests/snapshots/shims_test__creates_global_shims-2.snap new file mode 100644 index 0000000..e166aeb --- /dev/null +++ b/tests/snapshots/shims_test__creates_global_shims-2.snap @@ -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 "$@" + + diff --git a/tests/snapshots/shims_test__creates_global_shims.snap b/tests/snapshots/shims_test__creates_global_shims.snap new file mode 100644 index 0000000..c314d27 --- /dev/null +++ b/tests/snapshots/shims_test__creates_global_shims.snap @@ -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 -- "$@" + + diff --git a/tests/versions_test.rs b/tests/versions_test.rs new file mode 100644 index 0000000..a74aeeb --- /dev/null +++ b/tests/versions_test.rs @@ -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()); +}