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

fix: Fix Windows globals lookup dirs. #7

Merged
merged 6 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 0.3.0

#### 💥 Breaking

- Removed `--user` from global package installation via `proto install-global`. Packages are now installed into the tool directory for the current Python version: `.proto/tools/python/3.12.0/install/bin`.

#### ⚙️ Internal

- Updated dependencies.

## 0.2.0

#### 🚀 Updates
Expand Down
76 changes: 42 additions & 34 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "python_plugin"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
license = "MIT"
publish = false
Expand All @@ -10,14 +10,14 @@ crate-type = ['cdylib']

[dependencies]
extism-pdk = "0.3.4"
proto_pdk = { version = "0.10.2" } # , path = "../../proto/crates/pdk" }
proto_pdk = { version = "0.10.3" } # , path = "../../proto/crates/pdk" }
regex = { version = "1.10.2", default-features = false, features = ["std"] }
serde = "1.0.190"
serde = "1.0.193"

[dev-dependencies]
proto_pdk_test_utils = { version = "0.10.2" } # , path = "../../proto/crates/pdk-test-utils" }
proto_pdk_test_utils = { version = "0.11.1" } # , path = "../../proto/crates/pdk-test-utils" }
starbase_sandbox = "0.1.12"
tokio = { version = "1.33.0", features = ["full"] }
tokio = { version = "1.34.0", features = ["full"] }

[profile.release]
codegen-units = 1
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
profile = "default"
channel = "1.73.0"
channel = "1.74.0"
51 changes: 20 additions & 31 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 All @@ -34,6 +34,7 @@ pub fn register_tool(Json(_): Json<ToolMetadataInput>) -> FnResult<Json<ToolMeta
pub fn detect_version_files(_: ()) -> FnResult<Json<DetectVersionOutput>> {
Ok(Json(DetectVersionOutput {
files: vec![".python-version".into()],
ignore: vec![],
}))
}

Expand Down Expand Up @@ -130,29 +131,23 @@ pub fn locate_executables(
Json(input): Json<LocateExecutablesInput>,
) -> FnResult<Json<LocateExecutablesOutput>> {
let env = get_proto_environment()?;
let mut exe_path = env.os.get_exe_name("install/bin/python3");
let mut globals_lookup_dirs = vec!["$HOME/.local/bin".to_owned()];
let mut exe_path = env
.os
.for_native("install/bin/python3", "install/python.exe")
.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));
}
exe_path = json::from_slice::<PythonManifest>(&fs::read(manifest_path)?)?.python_exe;
}

Ok(Json(LocateExecutablesOutput {
globals_lookup_dirs,
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
Expand All @@ -173,7 +168,7 @@ pub fn locate_executables(
pub fn install_global(
Json(input): Json<InstallGlobalInput>,
) -> FnResult<Json<InstallGlobalOutput>> {
let result = exec_command!(inherit, "pip", ["install", "--user", &input.dependency]);
let result = exec_command!(inherit, "pip", ["install", &input.dependency]);

Ok(Json(InstallGlobalOutput::from_exec_command(result)))
}
Expand All @@ -193,8 +188,10 @@ pub fn uninstall_global(
#[plugin_fn]
pub fn locate_bins(Json(input): Json<LocateBinsInput>) -> FnResult<Json<LocateBinsOutput>> {
let env = get_proto_environment()?;
let mut bin_path = env.os.get_exe_name("install/bin/python3");
let mut globals_lookup_dirs = vec!["$HOME/.local/bin".to_owned()];
let mut bin_path = env
.os
.for_native("install/bin/python3", "install/python.exe")
.to_owned();

// Manifest is only available for pre-builts
let manifest_path = input.context.tool_dir.join("PYTHON.json");
Expand All @@ -203,23 +200,15 @@ pub fn locate_bins(Json(input): Json<LocateBinsInput>) -> FnResult<Json<LocateBi
let manifest: PythonManifest = json::from_slice(&fs::read(manifest_path)?)?;

bin_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(LocateBinsOutput {
bin_path: Some(bin_path.into()),
fallback_last_globals_dir: true,
globals_lookup_dirs,
globals_lookup_dirs: vec![env
.os
.for_native("$TOOL_DIR/install/bin", "$TOOL_DIR/install/Scripts")
.into()],
..LocateBinsOutput::default()
}))
}
Expand Down
Loading