Skip to content

Commit 36f5257

Browse files
committed
Use the which crate to figure out sys.executable
1 parent fbbf242 commit 36f5257

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

Cargo.lock

Lines changed: 14 additions & 3 deletions
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
@@ -33,7 +33,7 @@ rustpython-vm = { path = "vm", version = "0.1.1", default-features = false, feat
3333
pylib = { package = "rustpython-pylib", path = "vm/pylib-crate", version = "0.1.0", default-features = false, optional = true }
3434
dirs = { package = "dirs-next", version = "1.0" }
3535
num-traits = "0.2.8"
36-
cfg-if = "0.1"
36+
cfg-if = "1.0"
3737
libc = "0.2"
3838

3939
flame = { version = "0.2", optional = true }

common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ num-complex = "0.3"
1515
num-bigint = "0.3"
1616
lexical-core = "0.7"
1717
hexf-parse = "0.1.0"
18-
cfg-if = "0.1"
18+
cfg-if = "1.0"
1919
once_cell = "1.4.1"
2020
siphasher = "0.3"
2121
rand = "0.8"

vm/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ bstr = "0.2.12"
7878
crossbeam-utils = "0.8"
7979
parking_lot = "0.11"
8080
thread_local = "1.0"
81-
cfg-if = "0.1.10"
81+
cfg-if = "1.0"
8282
timsort = "0.1"
8383
thiserror = "1.0"
8484
atty = "0.2"
@@ -117,6 +117,7 @@ openssl = { version = "0.10", features = ["vendored"], optional = true }
117117
openssl-sys = { version = "0.9", optional = true }
118118
openssl-probe = { version = "0.1", optional = true }
119119
utime = "0.3"
120+
which = "4.0"
120121

121122
[target.'cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))'.dependencies]
122123
num_cpus = "1"

vm/src/sysmodule.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ fn argv(vm: &VirtualMachine) -> PyObjectRef {
2929
}
3030

3131
fn executable(ctx: &PyContext) -> PyObjectRef {
32+
#[cfg(not(target_arch = "wasm32"))]
33+
{
34+
if let Some(exec_path) = env::args_os().next() {
35+
if let Ok(path) = which::which(exec_path) {
36+
return ctx.new_str(
37+
path.into_os_string()
38+
.into_string()
39+
.unwrap_or_else(|p| p.to_string_lossy().into_owned()),
40+
);
41+
}
42+
}
43+
}
3244
if let Some(exec_path) = env::args().next() {
3345
let path = path::Path::new(&exec_path);
3446
if !path.exists() {

0 commit comments

Comments
 (0)