Skip to content

Commit 0848919

Browse files
committed
allow to enable/disable venv
1 parent fee0acc commit 0848919

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tauri-plugin-python"
3-
version = "0.3.3"
3+
version = "0.3.4"
44
authors = [ "Marco Mengelkoch" ]
55
description = "A tauri 2 plugin to use python code in the backend."
66
keywords = ["rust", "python", "tauri", "gui"]
@@ -31,5 +31,7 @@ serde_json = "1.0.136"
3131
tauri-plugin = { version = "2", features = ["build"] }
3232

3333
[features]
34-
# default = ["pyo3"] # enable to use pyo3 instead of rustpython
34+
venv = []
35+
default = ["venv"] # auto load src-python/.venv
36+
# default = ["venv", "pyo3"] # enable to use pyo3 instead of rustpython
3537
pyo3 = ["dep:pyo3"]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tauri-plugin-python-api",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"author": "Marco Mengelkoch",
55
"description": "Javascript package for tauri 2 python plugin.",
66
"type": "module",

src/lib.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,20 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
8080
}
8181

8282
fn init_python(code: String, dir: PathBuf) {
83+
#[allow(unused_mut)]
8384
let mut sys_pyth_dir = format!("sys.path.append('{}')", dir.to_str().unwrap());
84-
let venv_dir = dir.join(".venv").join("lib");
85-
if Path::exists(venv_dir.as_path()) {
86-
if let Ok(py_dir) = venv_dir.read_dir() {
87-
for entry in py_dir.flatten() {
88-
let site_packages = entry.path().join("site-packages");
89-
if Path::exists(site_packages.as_path()) { // use first site-packages found, ignoring version
90-
sys_pyth_dir += "\n";
91-
sys_pyth_dir += &format!("sys.path.append('{}')", site_packages.to_str().unwrap());
92-
break;
85+
#[cfg(feature = "venv")]
86+
{
87+
let venv_dir = dir.join(".venv").join("lib");
88+
if Path::exists(venv_dir.as_path()) {
89+
if let Ok(py_dir) = venv_dir.read_dir() {
90+
for entry in py_dir.flatten() {
91+
let site_packages = entry.path().join("site-packages");
92+
if Path::exists(site_packages.as_path()) { // use first site-packages found, ignoring version
93+
sys_pyth_dir += "\n";
94+
sys_pyth_dir += &format!("sys.path.append('{}')", site_packages.to_str().unwrap());
95+
break;
96+
}
9397
}
9498
}
9599
}

0 commit comments

Comments
 (0)