File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33// Licensed under MIT License, see License file for more details
44// git clone https://github.com/marcomq/tauri-plugin-python
55
6- use std:: path:: Path ;
7-
86const COMMANDS : & [ & str ] = & [
97 "run_python" ,
108 "register_function" ,
@@ -13,14 +11,6 @@ const COMMANDS: &[&str] = &[
1311] ;
1412
1513fn main ( ) {
16- let py_main = concat ! ( env!( "PWD" ) , "/src-tauri/src-python/main.py" ) ;
17- let py_main_path = Path :: new ( py_main) ;
18- if !py_main_path. exists ( ) {
19- let parent = py_main_path. parent ( ) . unwrap_or ( py_main_path) ;
20- std:: fs:: create_dir_all ( parent) . unwrap_or_default ( ) ;
21- std:: fs:: write ( py_main_path, "# auto loaded on starts" ) . unwrap_or_default ( ) ;
22- }
23-
2414 tauri_plugin:: Builder :: new ( COMMANDS )
2515 // .global_api_script_path("./api-iife.js")
2616 . android_path ( "android" )
Original file line number Diff line number Diff line change @@ -23,7 +23,8 @@ lazy_static! {
2323}
2424pub fn init_python ( ) -> PyResult < ( ) > {
2525 pyo3:: prepare_freethreaded_python ( ) ;
26- let code = py_main_import:: read_at_compile_time ( ) ;
26+ let code = py_main_import:: read_at_startup ( ) ;
27+ dbg ! ( & code) ;
2728 let c_code = CString :: new ( code) . expect ( "error loading python" ) ;
2829 marker:: Python :: with_gil ( |py| -> PyResult < ( ) > {
2930 let globals = GLOBALS . lock ( ) . unwrap ( ) . clone_ref ( py) . into_bound ( py) ;
Original file line number Diff line number Diff line change 22// © Copyright 2024, by Marco Mengelkoch
33// Licensed under MIT License, see License file for more details
44// git clone https://github.com/marcomq/tauri-plugin-python
5+ use std:: env;
56
6- pub fn read_at_compile_time < ' a > ( ) -> & ' a str {
7- // no actual error, file auto generated in build.rs, no idea how to ignore this
8- // moved to separate file to not ignore other errors
9- include_str ! ( concat!( env!( "PWD" ) , "/" , " src-tauri/src-python/main.py") )
7+ pub fn read_at_startup < ' a > ( ) -> String {
8+ let py_file_path = env :: current_dir ( ) . unwrap ( ) . join ( "src-python/main.py" ) ;
9+ std :: fs :: read_to_string ( py_file_path ) . unwrap_or_default ( )
10+ // include_str!(concat!(env!("PWD"), "/ src-tauri/src-python/main.py"))
1011}
You can’t perform that action at this time.
0 commit comments