From da32ffe3108c499302f17eb252039df764c4458e Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Wed, 20 Mar 2024 12:23:44 -0700 Subject: [PATCH] Include major in exe name. --- CHANGELOG.md | 3 +- Cargo.lock | 2 +- Cargo.toml | 2 +- src/proto.rs | 60 +++++++++++++------ .../snapshots/shims_test__creates_shims.snap | 6 +- tests/versions_test.rs | 2 +- 6 files changed, 53 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44d2e76..8c8508d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,10 @@ # Changelog -## 0.8.1 +## 0.9.0 #### 🚀 Updates +- Will now create a secondary executable that includes the major version in the file name, for example, `python3`. - Updated to support proto v0.32 release. ## 0.8.0 diff --git a/Cargo.lock b/Cargo.lock index 6fb38ed..da95699 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2137,7 +2137,7 @@ dependencies = [ [[package]] name = "python_plugin" -version = "0.8.1" +version = "0.9.0" dependencies = [ "extism-pdk", "proto_pdk", diff --git a/Cargo.toml b/Cargo.toml index 74794fd..9aa4944 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "python_plugin" -version = "0.8.1" +version = "0.9.0" edition = "2021" license = "MIT" publish = false diff --git a/src/proto.rs b/src/proto.rs index 50d621c..27288b0 100644 --- a/src/proto.rs +++ b/src/proto.rs @@ -17,7 +17,7 @@ static NAME: &str = "Python"; #[derive(Deserialize)] struct PythonManifest { python_exe: String, - // python_major_minor_version: String, + python_major_minor_version: String, } #[plugin_fn] @@ -144,35 +144,61 @@ pub fn locate_executables( Json(input): Json, ) -> FnResult> { let env = get_host_environment()?; - let mut exe_path = env - .os - .for_native("install/bin/python3", "install/python.exe") - .to_owned(); + let id = get_plugin_id()?; + let exe_path; + let mut major_version = "3".to_owned(); + let mut secondary = HashMap::from_iter([ + // pip + ( + "pip".into(), + ExecutableConfig { + no_bin: true, + shim_before_args: Some(StringOrVec::Vec(vec!["-m".into(), "pip".into()])), + ..ExecutableConfig::default() + }, + ), + ]); // Manifest is only available for pre-builts let manifest_path = input.context.tool_dir.join("PYTHON.json"); if manifest_path.exists() { - exe_path = json::from_slice::(&fs::read(manifest_path)?)?.python_exe; + let manifest: PythonManifest = json::from_slice(&fs::read(manifest_path)?)?; + + exe_path = manifest.python_exe; + + if let Some(i) = manifest.python_major_minor_version.find('.') { + major_version = manifest.python_major_minor_version[0..i].to_string(); + } + } + // Otherwise this was built from source + else { + if let VersionSpec::Version(version) = input.context.version { + major_version = version.major.to_string(); + }; + + exe_path = env + .os + .for_native( + format!("install/bin/python{major_version}").as_str(), + "install/python.exe", + ) + .to_owned(); } + // Create a secondary executable that includes the major version as a suffix + secondary.insert( + format!("{id}{major_version}"), + ExecutableConfig::new(&exe_path), + ); + Ok(Json(LocateExecutablesOutput { globals_lookup_dirs: vec![env .os .for_native("$TOOL_DIR/install/bin", "$TOOL_DIR/install/Scripts") .into()], primary: Some(ExecutableConfig::new(exe_path)), - secondary: HashMap::from_iter([ - // pip - ( - "pip".into(), - ExecutableConfig { - no_bin: true, - shim_before_args: Some(StringOrVec::String("-m pip".into())), - ..ExecutableConfig::default() - }, - ), - ]), + secondary, ..LocateExecutablesOutput::default() })) } diff --git a/tests/snapshots/shims_test__creates_shims.snap b/tests/snapshots/shims_test__creates_shims.snap index 93d3092..e4c452f 100644 --- a/tests/snapshots/shims_test__creates_shims.snap +++ b/tests/snapshots/shims_test__creates_shims.snap @@ -10,5 +10,9 @@ expression: "std::fs::read_to_string(sandbox.path().join(\".proto/shims/registry "pip" ] }, - "python-test": {} + "python-test": {}, + "python-test3": { + "alt_bin": true, + "parent": "python-test" + } } diff --git a/tests/versions_test.rs b/tests/versions_test.rs index 3230da4..3a14d22 100644 --- a/tests/versions_test.rs +++ b/tests/versions_test.rs @@ -3,7 +3,7 @@ use proto_pdk_test_utils::*; generate_resolve_versions_tests!("python-test", { "2.3" => "2.3.7", "3.10.1" => "3.10.1", - "3.10" => "3.10.13", + "3.10" => "3.10.14", "3" => "3.12.2", });