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

Commit

Permalink
new: Include major in executable file name. (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Mar 20, 2024
1 parent 17a6887 commit 76122bd
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 22 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "python_plugin"
version = "0.8.1"
version = "0.9.0"
edition = "2021"
license = "MIT"
publish = false
Expand Down
60 changes: 43 additions & 17 deletions src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -144,35 +144,61 @@ pub fn locate_executables(
Json(input): Json<LocateExecutablesInput>,
) -> FnResult<Json<LocateExecutablesOutput>> {
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::<PythonManifest>(&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()
}))
}
6 changes: 5 additions & 1 deletion tests/snapshots/shims_test__creates_shims.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion tests/versions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});

Expand Down

0 comments on commit 76122bd

Please sign in to comment.