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

Commit

Permalink
Dont use user.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Nov 22, 2023
1 parent e461664 commit 2422da0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 57 deletions.
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.1

#### 🐞 Fixes
Expand Down
20 changes: 14 additions & 6 deletions 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
Expand Up @@ -15,7 +15,7 @@ regex = { version = "1.10.2", default-features = false, features = ["std"] }
serde = "1.0.193"

[dev-dependencies]
proto_pdk_test_utils = { version = "0.11.0" } # , 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.34.0", features = ["full"] }

Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ This will install a pre-built version from [indygreg/python-build-standalone](ht

Building from source directly (with `python-build`), and supporting Python 2, will be fully supported in the future.

### Global packages

When globals are installed with `proto install-global python`, we install them using `pip --user`, which installs them to `~/.local/lib/pythonX.Y/site-packages` or `~/.local/bin` on Linux and macOS, and `~/AppData/Roaming/Python/PythonXY/Scripts` on Windows.

## Contributing

Build the plugin:
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"
50 changes: 5 additions & 45 deletions src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,53 +126,13 @@ pub fn download_prebuilt(
}))
}

// https://docs.python.org/2/library/site.html#site.USER_SITE
fn get_globals_dirs(env: &HostEnvironment, spec: &VersionSpec) -> Vec<String> {
let mut dirs = vec![];

if let VersionSpec::Version(version) = spec {
// %APPDATA% == ~/AppData/Roaming
if env.os == HostOS::Windows {
let version_stamp = format!("{}{}", version.major, version.minor);

dirs.push(format!(
"$HOME/AppData/Roaming/Python/Python{}/site-packages",
version_stamp
));
dirs.push(format!(
"$HOME/AppData/Roaming/Python/Python{}/Scripts",
version_stamp
));
} else {
let version_dot_stamp = format!("{}.{}", version.major, version.minor);

if env.os == HostOS::MacOS {
dirs.push(format!(
"$HOME/Library/Python/{}/lib/python/site-packages",
version_dot_stamp
));
}

dirs.push(format!(
"$HOME/.local/lib/python{}/site-packages",
version_dot_stamp
));
}
}

if env.os != HostOS::Windows {
dirs.push("$HOME/.local/bin".to_owned());
}

dirs
}

#[plugin_fn]
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 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");
Expand All @@ -182,7 +142,7 @@ pub fn locate_executables(
}

Ok(Json(LocateExecutablesOutput {
globals_lookup_dirs: get_globals_dirs(&env, &input.context.version),
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 @@ -203,7 +163,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 @@ -223,7 +183,7 @@ 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 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 @@ -237,7 +197,7 @@ pub fn locate_bins(Json(input): Json<LocateBinsInput>) -> FnResult<Json<LocateBi
Ok(Json(LocateBinsOutput {
bin_path: Some(bin_path.into()),
fallback_last_globals_dir: true,
globals_lookup_dirs: get_globals_dirs(&env, &input.context.version),
globals_lookup_dirs: vec![env.os.for_native("$TOOL_DIR/install/bin", "$TOOL_DIR/install/Scripts").into()],
..LocateBinsOutput::default()
}))
}
Expand Down

0 comments on commit 2422da0

Please sign in to comment.