changed to python312
This commit is contained in:
@ -1,22 +1,60 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Resolve the project root from the executable path.
|
||||
/// In dev mode, the binary lives at: <root>/src-tauri/target/debug/<bin>
|
||||
/// So the project root is 4 levels above the binary.
|
||||
/// Resolve the project root at runtime.
|
||||
///
|
||||
/// Dev layout: <root>/src-tauri/target/debug/<bin> → walk up 4 levels
|
||||
/// Packaged: use TAURI_RESOURCE_DIR env var set by the Tauri runtime,
|
||||
/// falling back to a sibling `resources/` directory next to the exe.
|
||||
pub fn project_root() -> PathBuf {
|
||||
// Tauri sets this env var when running packaged; prefer it.
|
||||
if let Ok(res) = std::env::var("TAURI_RESOURCE_DIR") {
|
||||
return PathBuf::from(res);
|
||||
}
|
||||
let exe = std::env::current_exe().expect("Failed to get executable path");
|
||||
// exe -> debug/ -> target/ -> src-tauri/ -> root
|
||||
// Dev: exe is at <root>/src-tauri/target/debug/<bin>, walk up 4 levels.
|
||||
if let Some(root) = exe
|
||||
.parent() // debug/
|
||||
.and_then(|p| p.parent()) // target/
|
||||
.and_then(|p| p.parent()) // src-tauri/
|
||||
.and_then(|p| p.parent()) // project root
|
||||
{
|
||||
if root.join("backend").exists() {
|
||||
return root.to_path_buf();
|
||||
}
|
||||
}
|
||||
// Packaged fallback: resources/ lives next to the exe.
|
||||
exe.parent()
|
||||
.and_then(|p| p.parent())
|
||||
.and_then(|p| p.parent())
|
||||
.and_then(|p| p.parent())
|
||||
.map(|p| p.to_path_buf())
|
||||
.unwrap_or_else(|| PathBuf::from("."))
|
||||
.map(|p| p.join("resources"))
|
||||
.unwrap_or_else(|| PathBuf::from("resources"))
|
||||
}
|
||||
|
||||
/// Absolute path to the venv Python 3.10 interpreter.
|
||||
/// Absolute path to the bundled Python interpreter.
|
||||
/// Tries .venv312 first (new), falls back to .venv (legacy).
|
||||
pub fn python_exe() -> PathBuf {
|
||||
project_root().join(".venv/bin/python3.10")
|
||||
let root = project_root();
|
||||
// Packaged layout: resources/python/bin/python3
|
||||
let bundled = root.join("python").join("bin").join("python3");
|
||||
if bundled.exists() {
|
||||
return bundled;
|
||||
}
|
||||
// Dev: prefer .venv312 (Python 3.12), fall back to .venv
|
||||
let venv312 = root.join(".venv312").join("bin").join("python3.12");
|
||||
if venv312.exists() {
|
||||
return venv312;
|
||||
}
|
||||
root.join(".venv").join("bin").join("python3")
|
||||
}
|
||||
|
||||
/// Absolute path to the bundled ffmpeg binary.
|
||||
/// Uses a sidecar in resources/bin/ when packaged, otherwise expects it on PATH.
|
||||
pub fn ffmpeg_exe() -> PathBuf {
|
||||
let root = project_root();
|
||||
let bundled = root.join("bin").join("ffmpeg");
|
||||
if bundled.exists() {
|
||||
return bundled;
|
||||
}
|
||||
// Fallback to system ffmpeg during development
|
||||
PathBuf::from("ffmpeg")
|
||||
}
|
||||
|
||||
/// Absolute path to a script in the backend directory.
|
||||
|
||||
Reference in New Issue
Block a user