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

Commit 76122bd

Browse files
authored
new: Include major in executable file name. (#23)
1 parent 17a6887 commit 76122bd

File tree

6 files changed

+53
-22
lines changed

6 files changed

+53
-22
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Changelog
22

3-
## 0.8.1
3+
## 0.9.0
44

55
#### 🚀 Updates
66

7+
- Will now create a secondary executable that includes the major version in the file name, for example, `python3`.
78
- Updated to support proto v0.32 release.
89

910
## 0.8.0

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "python_plugin"
3-
version = "0.8.1"
3+
version = "0.9.0"
44
edition = "2021"
55
license = "MIT"
66
publish = false

src/proto.rs

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static NAME: &str = "Python";
1717
#[derive(Deserialize)]
1818
struct PythonManifest {
1919
python_exe: String,
20-
// python_major_minor_version: String,
20+
python_major_minor_version: String,
2121
}
2222

2323
#[plugin_fn]
@@ -144,35 +144,61 @@ pub fn locate_executables(
144144
Json(input): Json<LocateExecutablesInput>,
145145
) -> FnResult<Json<LocateExecutablesOutput>> {
146146
let env = get_host_environment()?;
147-
let mut exe_path = env
148-
.os
149-
.for_native("install/bin/python3", "install/python.exe")
150-
.to_owned();
147+
let id = get_plugin_id()?;
148+
let exe_path;
149+
let mut major_version = "3".to_owned();
150+
let mut secondary = HashMap::from_iter([
151+
// pip
152+
(
153+
"pip".into(),
154+
ExecutableConfig {
155+
no_bin: true,
156+
shim_before_args: Some(StringOrVec::Vec(vec!["-m".into(), "pip".into()])),
157+
..ExecutableConfig::default()
158+
},
159+
),
160+
]);
151161

152162
// Manifest is only available for pre-builts
153163
let manifest_path = input.context.tool_dir.join("PYTHON.json");
154164

155165
if manifest_path.exists() {
156-
exe_path = json::from_slice::<PythonManifest>(&fs::read(manifest_path)?)?.python_exe;
166+
let manifest: PythonManifest = json::from_slice(&fs::read(manifest_path)?)?;
167+
168+
exe_path = manifest.python_exe;
169+
170+
if let Some(i) = manifest.python_major_minor_version.find('.') {
171+
major_version = manifest.python_major_minor_version[0..i].to_string();
172+
}
173+
}
174+
// Otherwise this was built from source
175+
else {
176+
if let VersionSpec::Version(version) = input.context.version {
177+
major_version = version.major.to_string();
178+
};
179+
180+
exe_path = env
181+
.os
182+
.for_native(
183+
format!("install/bin/python{major_version}").as_str(),
184+
"install/python.exe",
185+
)
186+
.to_owned();
157187
}
158188

189+
// Create a secondary executable that includes the major version as a suffix
190+
secondary.insert(
191+
format!("{id}{major_version}"),
192+
ExecutableConfig::new(&exe_path),
193+
);
194+
159195
Ok(Json(LocateExecutablesOutput {
160196
globals_lookup_dirs: vec![env
161197
.os
162198
.for_native("$TOOL_DIR/install/bin", "$TOOL_DIR/install/Scripts")
163199
.into()],
164200
primary: Some(ExecutableConfig::new(exe_path)),
165-
secondary: HashMap::from_iter([
166-
// pip
167-
(
168-
"pip".into(),
169-
ExecutableConfig {
170-
no_bin: true,
171-
shim_before_args: Some(StringOrVec::String("-m pip".into())),
172-
..ExecutableConfig::default()
173-
},
174-
),
175-
]),
201+
secondary,
176202
..LocateExecutablesOutput::default()
177203
}))
178204
}

tests/snapshots/shims_test__creates_shims.snap

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@ expression: "std::fs::read_to_string(sandbox.path().join(\".proto/shims/registry
1010
"pip"
1111
]
1212
},
13-
"python-test": {}
13+
"python-test": {},
14+
"python-test3": {
15+
"alt_bin": true,
16+
"parent": "python-test"
17+
}
1418
}

tests/versions_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use proto_pdk_test_utils::*;
33
generate_resolve_versions_tests!("python-test", {
44
"2.3" => "2.3.7",
55
"3.10.1" => "3.10.1",
6-
"3.10" => "3.10.13",
6+
"3.10" => "3.10.14",
77
"3" => "3.12.2",
88
});
99

0 commit comments

Comments
 (0)