From fb143bdcb80385009e9af06ff6b89ea7bc3b49db Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Fri, 3 Nov 2023 16:28:38 -0700 Subject: [PATCH 1/2] Update. --- Cargo.lock | 28 ++------- Cargo.toml | 4 +- src/proto.rs | 139 +++++++++++++++++++++++++++++--------------- tests/shims_test.rs | 2 +- 4 files changed, 102 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6e683f4..01f6e91 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1579,9 +1579,9 @@ dependencies = [ [[package]] name = "json_comments" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41ee439ee368ba4a77ac70d04f14015415af8600d6c894dc1f11bd79758c57d5" +checksum = "9dbbfed4e59ba9750e15ba154fdfd9329cee16ff3df539c2666b70f58cc32105" [[package]] name = "lazy_static" @@ -2018,8 +2018,6 @@ dependencies = [ [[package]] name = "proto_core" version = "0.21.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea826b40e2682f5eb5ee90d1065e09a710ec74807f5c7db85aa3c5fb397623e" dependencies = [ "cached", "extism", @@ -2049,8 +2047,6 @@ dependencies = [ [[package]] name = "proto_pdk" version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce0b4fe64801579bbf1c341db7c6bf9b67cd2d58e3bf32d28b6fd69908cfe102" dependencies = [ "anyhow", "extism-pdk", @@ -2061,8 +2057,6 @@ dependencies = [ [[package]] name = "proto_pdk_api" version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0d49bf81e0c2033a4660270a2c8ff6f331ba0cb61500c6d3dc41d8f18cd5ce3" dependencies = [ "anyhow", "semver", @@ -2077,8 +2071,6 @@ dependencies = [ [[package]] name = "proto_pdk_test_utils" version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb47a6bf9be024ae8690f62e6e9c3e0c2537e9071c1562a74564bf70378b8a80" dependencies = [ "extism", "proto_core", @@ -2538,9 +2530,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.107" +version = "1.0.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" dependencies = [ "itoa", "ryu", @@ -2746,9 +2738,9 @@ dependencies = [ [[package]] name = "starbase_utils" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9faf731068b919569efae7f6c7c6c3d2e29411c1cba666ef0c6fe20b82f50a1" +checksum = "d948dcd63f1dd11f2b7a9ab15c53e7866faa11ccd31377dca1625c106d40fcee" dependencies = [ "dirs 5.0.1", "fs4", @@ -2845,8 +2837,6 @@ dependencies = [ [[package]] name = "system_env" version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9eb72230d28d8116aab631232e98675a7fd3e69b81b046d54205bd21e16d5" dependencies = [ "serde", "serde_json", @@ -3280,8 +3270,6 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "version_spec" version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5e3bdf3e63b4025522cf6a324e3c4f8f0f29a9148de2392d980c10f22b134c7" dependencies = [ "human-sort", "once_cell", @@ -3321,8 +3309,6 @@ dependencies = [ [[package]] name = "warpgate" version = "0.5.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31378533107129c8dcc2cc8b2333768a21374ccecc735d33c468b4ebe747b225" dependencies = [ "extism", "miette", @@ -3344,8 +3330,6 @@ dependencies = [ [[package]] name = "warpgate_api" version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d55e21fc85ba24a15b008acf53638354e81d14ba966bb909918271b1f0138d" dependencies = [ "serde", ] diff --git a/Cargo.toml b/Cargo.toml index b9b612e..84e219a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,12 +10,12 @@ crate-type = ['cdylib'] [dependencies] extism-pdk = "0.3.4" -proto_pdk = { version = "0.9.0" } # , path = "../../proto/crates/pdk" } +proto_pdk = { version = "0.9.0", path = "../../proto/crates/pdk" } regex = { version = "1.10.2", default-features = false, features = ["std"] } serde = "1.0.190" [dev-dependencies] -proto_pdk_test_utils = { version = "0.9.1" } # , path = "../../proto/crates/pdk-test-utils" } +proto_pdk_test_utils = { version = "0.9.1", path = "../../proto/crates/pdk-test-utils" } starbase_sandbox = "0.1.12" tokio = { version = "1.33.0", features = ["full"] } diff --git a/src/proto.rs b/src/proto.rs index 0230d11..8d3cd55 100644 --- a/src/proto.rs +++ b/src/proto.rs @@ -14,6 +14,12 @@ extern "ExtismHost" { static NAME: &str = "Python"; +#[derive(Deserialize)] +struct PythonManifest { + python_exe: String, + python_major_minor_version: String, +} + #[plugin_fn] pub fn register_tool(Json(_): Json) -> FnResult> { Ok(Json(ToolMetadataOutput { @@ -24,6 +30,30 @@ pub fn register_tool(Json(_): Json) -> FnResult FnResult> { + Ok(Json(DetectVersionOutput { + files: vec![".python-version".into()], + })) +} + +#[plugin_fn] +pub fn load_versions(Json(_): Json) -> FnResult> { + let tags = load_git_tags("https://github.com/python/cpython")?; + let regex = Regex::new( + r"v?(?[0-9]+)\.(?[0-9]+)(?:\.(?[0-9]+))?(?:(?
a|b|c|rc)(?[0-9]+))?",
+    )
+    .unwrap();
+
+    let tags = tags
+        .into_iter()
+        .filter(|t| t != "legacy-trunk")
+        .filter_map(|t| from_python_version(t, ®ex))
+        .collect::>();
+
+    Ok(Json(LoadVersionsOutput::from(tags)?))
+}
+
 // #[plugin_fn]
 // pub fn native_install(
 //     Json(input): Json,
@@ -95,12 +125,71 @@ pub fn download_prebuilt(
     }))
 }
 
-#[derive(Deserialize)]
-struct PythonManifest {
-    python_exe: String,
-    python_major_minor_version: String,
+#[plugin_fn]
+pub fn locate_executables(
+    Json(input): Json,
+) -> FnResult> {
+    let env = get_proto_environment()?;
+    let mut exe_path = format_bin_name("install/bin/python3", env.os);
+    let mut globals_lookup_dirs = vec!["$HOME/.local/bin".to_owned()];
+
+    // Manifest is only available for pre-builts
+    let manifest_path = input.context.tool_dir.join("PYTHON.json");
+
+    if manifest_path.exists() {
+        let manifest: PythonManifest = json::from_slice(&fs::read(manifest_path)?)?;
+        exe_path = manifest.python_exe;
+
+        if env.os == HostOS::Windows {
+            let formatted_version = manifest.python_major_minor_version.replace('.', "");
+
+            globals_lookup_dirs.push(format!(
+                "$APPDATA/Roaming/Python{}/Scripts",
+                formatted_version
+            ));
+            globals_lookup_dirs.push(format!("$APPDATA/Python{}/Scripts", formatted_version));
+        }
+    }
+
+    Ok(Json(LocateExecutablesOutput {
+        globals_lookup_dirs,
+        primary: Some(ExecutableConfig::new(exe_path)),
+        secondary: HashMap::from_iter([
+            // pip
+            (
+                "pip".into(),
+                ExecutableConfig {
+                    no_bin: true,
+                    shim_before_args: Some("-m pip".into()),
+                    ..ExecutableConfig::default()
+                },
+            ),
+        ]),
+        ..LocateExecutablesOutput::default()
+    }))
+}
+
+#[plugin_fn]
+pub fn install_global(
+    Json(input): Json,
+) -> FnResult> {
+    let result = exec_command!(inherit, "pip", ["install", "--user", &input.dependency]);
+
+    Ok(Json(InstallGlobalOutput::from_exec_command(result)))
+}
+
+#[plugin_fn]
+pub fn uninstall_global(
+    Json(input): Json,
+) -> FnResult> {
+    let result = exec_command!(inherit, "pip", ["uninstall", "--yes", &input.dependency]);
+
+    Ok(Json(UninstallGlobalOutput::from_exec_command(result)))
 }
 
+// DEPRECATED
+// Removed in v0.23!
+
 #[plugin_fn]
 pub fn locate_bins(Json(input): Json) -> FnResult> {
     let env = get_proto_environment()?;
@@ -135,30 +224,6 @@ pub fn locate_bins(Json(input): Json) -> FnResult) -> FnResult> {
-    let tags = load_git_tags("https://github.com/python/cpython")?;
-    let regex = Regex::new(
-        r"v?(?[0-9]+)\.(?[0-9]+)(?:\.(?[0-9]+))?(?:(?
a|b|c|rc)(?[0-9]+))?",
-    )
-    .unwrap();
-
-    let tags = tags
-        .into_iter()
-        .filter(|t| t != "legacy-trunk")
-        .filter_map(|t| from_python_version(t, ®ex))
-        .collect::>();
-
-    Ok(Json(LoadVersionsOutput::from(tags)?))
-}
-
-#[plugin_fn]
-pub fn detect_version_files(_: ()) -> FnResult> {
-    Ok(Json(DetectVersionOutput {
-        files: vec![".python-version".into()],
-    }))
-}
-
 #[plugin_fn]
 pub fn create_shims(Json(_): Json) -> FnResult> {
     let mut global_shims = HashMap::new();
@@ -170,21 +235,3 @@ pub fn create_shims(Json(_): Json) -> FnResult,
-) -> FnResult> {
-    let result = exec_command!(inherit, "pip", ["install", "--user", &input.dependency]);
-
-    Ok(Json(InstallGlobalOutput::from_exec_command(result)))
-}
-
-#[plugin_fn]
-pub fn uninstall_global(
-    Json(input): Json,
-) -> FnResult> {
-    let result = exec_command!(inherit, "pip", ["uninstall", "--yes", &input.dependency]);
-
-    Ok(Json(UninstallGlobalOutput::from_exec_command(result)))
-}
diff --git a/tests/shims_test.rs b/tests/shims_test.rs
index 24580ef..a586251 100644
--- a/tests/shims_test.rs
+++ b/tests/shims_test.rs
@@ -1,4 +1,4 @@
 use proto_pdk_test_utils::*;
 
 #[cfg(not(windows))]
-generate_global_shims_test!("python-test", ["pip"]);
+generate_shims_test!("python-test", ["pip"]);

From 58c4b2683b16727423ab0e4e46c0456f1923d11c Mon Sep 17 00:00:00 2001
From: Miles Johnson 
Date: Sat, 4 Nov 2023 12:52:24 -0700
Subject: [PATCH 2/2] Update deps.

---
 CHANGELOG.md | 10 ++++++++++
 Cargo.lock   | 28 ++++++++++++++++++++++------
 Cargo.toml   |  6 +++---
 src/proto.rs |  4 ++--
 4 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 87dfa81..bea1024 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,15 @@
 # Changelog
 
+## 0.2.0
+
+#### 🚀 Updates
+
+- Updated to support proto v0.22 release.
+
+#### ⚙️ Internal
+
+- Updated dependencies.
+
 ## 0.1.2
 
 #### ⚙️ Internal
diff --git a/Cargo.lock b/Cargo.lock
index 01f6e91..55a3493 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2017,7 +2017,9 @@ dependencies = [
 
 [[package]]
 name = "proto_core"
-version = "0.21.2"
+version = "0.22.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "857645ab2fe78d570056938494f135a33edd8788a6ec898188325b385d29671e"
 dependencies = [
  "cached",
  "extism",
@@ -2046,7 +2048,9 @@ dependencies = [
 
 [[package]]
 name = "proto_pdk"
-version = "0.9.0"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a67a488f4dfb26b6fc53378526de346d09ba2b511883204992fdf3acebb24d16"
 dependencies = [
  "anyhow",
  "extism-pdk",
@@ -2056,7 +2060,9 @@ dependencies = [
 
 [[package]]
 name = "proto_pdk_api"
-version = "0.9.0"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2c4cafcba5b79560a3bfba87ac7fe6fca1e7970e7459a2b60989dc41e152a9ad"
 dependencies = [
  "anyhow",
  "semver",
@@ -2070,7 +2076,9 @@ dependencies = [
 
 [[package]]
 name = "proto_pdk_test_utils"
-version = "0.9.1"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2e6c0a69d1302bd65f95043434d90b6e5cb9ff0aeb7bef7cd91f7fc49b9973ad"
 dependencies = [
  "extism",
  "proto_core",
@@ -2100,7 +2108,7 @@ dependencies = [
 
 [[package]]
 name = "python_plugin"
-version = "0.1.2"
+version = "0.2.0"
 dependencies = [
  "extism-pdk",
  "proto_pdk",
@@ -2836,7 +2844,9 @@ dependencies = [
 
 [[package]]
 name = "system_env"
-version = "0.1.2"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c1545ee71941615742defd942059f99d35bfd6e1e079d0f6502e020c4b60a928"
 dependencies = [
  "serde",
  "serde_json",
@@ -3270,6 +3280,8 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
 [[package]]
 name = "version_spec"
 version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e5e3bdf3e63b4025522cf6a324e3c4f8f0f29a9148de2392d980c10f22b134c7"
 dependencies = [
  "human-sort",
  "once_cell",
@@ -3309,6 +3321,8 @@ dependencies = [
 [[package]]
 name = "warpgate"
 version = "0.5.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "31378533107129c8dcc2cc8b2333768a21374ccecc735d33c468b4ebe747b225"
 dependencies = [
  "extism",
  "miette",
@@ -3330,6 +3344,8 @@ dependencies = [
 [[package]]
 name = "warpgate_api"
 version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "88d55e21fc85ba24a15b008acf53638354e81d14ba966bb909918271b1f0138d"
 dependencies = [
  "serde",
 ]
diff --git a/Cargo.toml b/Cargo.toml
index 84e219a..0e1f528 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "python_plugin"
-version = "0.1.2"
+version = "0.2.0"
 edition = "2021"
 license = "MIT"
 publish = false
@@ -10,12 +10,12 @@ crate-type = ['cdylib']
 
 [dependencies]
 extism-pdk = "0.3.4"
-proto_pdk = { version = "0.9.0", path = "../../proto/crates/pdk" }
+proto_pdk = { version = "0.10.0" }                                           # , path = "../../proto/crates/pdk" }
 regex = { version = "1.10.2", default-features = false, features = ["std"] }
 serde = "1.0.190"
 
 [dev-dependencies]
-proto_pdk_test_utils = { version = "0.9.1", path = "../../proto/crates/pdk-test-utils" }
+proto_pdk_test_utils = { version = "0.10.0" }       # , path = "../../proto/crates/pdk-test-utils" }
 starbase_sandbox = "0.1.12"
 tokio = { version = "1.33.0", features = ["full"] }
 
diff --git a/src/proto.rs b/src/proto.rs
index 8d3cd55..e956961 100644
--- a/src/proto.rs
+++ b/src/proto.rs
@@ -130,7 +130,7 @@ pub fn locate_executables(
     Json(input): Json,
 ) -> FnResult> {
     let env = get_proto_environment()?;
-    let mut exe_path = format_bin_name("install/bin/python3", env.os);
+    let mut exe_path = env.os.get_exe_name("install/bin/python3");
     let mut globals_lookup_dirs = vec!["$HOME/.local/bin".to_owned()];
 
     // Manifest is only available for pre-builts
@@ -193,7 +193,7 @@ pub fn uninstall_global(
 #[plugin_fn]
 pub fn locate_bins(Json(input): Json) -> FnResult> {
     let env = get_proto_environment()?;
-    let mut bin_path = format_bin_name("install/bin/python3", env.os);
+    let mut bin_path = env.os.get_exe_name("install/bin/python3");
     let mut globals_lookup_dirs = vec!["$HOME/.local/bin".to_owned()];
 
     // Manifest is only available for pre-builts