FinceptTerminal is a modern finance application offering advanced market analytics, investment research, and economic data tools, designed for interactive exploration and data-driven decision-making in a user-friendly environment.
C++ ai-agentsalgorithmic-tradingbloomberg-terminalcppfinancefinancial-marketsfintechgood-first-issueinvestmentinvestment-researchmachine-learningopensourcepythonqtquantitative-financestock-markettrading
Fix Rust compilation errors in python_runtime.rs
tilakpatel2242638d3d1898
diff --git a/fincept-terminal-desktop/src-tauri/src/commands/peer_commands.rs b/fincept-terminal-desktop/src-tauri/src/commands/peer_commands.rsindex 457998134..0c27c7a0d 100644--- a/fincept-terminal-desktop/src-tauri/src/commands/peer_commands.rs+++ b/fincept-terminal-desktop/src-tauri/src/commands/peer_commands.rs@@ -3,7 +3,8 @@use serde::{Deserialize, Serialize};use std::collections::HashMap;-use crate::services::gics_service::{MarketCapCategory, PeerIdentificationService};+// Note: GICS service types available if needed for future peer discovery+// use crate::services::gics_service::{MarketCapCategory, PeerIdentificationService};use crate::services::comparative_service::{ComparativeService, PercentileRanking, ValuationStatus,ValuationMetrics, ProfitabilityMetrics, GrowthMetrics, LeverageMetrics,diff --git a/fincept-terminal-desktop/src-tauri/src/python_runtime.rs b/fincept-terminal-desktop/src-tauri/src/python_runtime.rsindex c26d8be38..56e615fed 100644--- a/fincept-terminal-desktop/src-tauri/src/python_runtime.rs+++ b/fincept-terminal-desktop/src-tauri/src/python_runtime.rs@@ -53,112 +53,6 @@ pub fn execute_python_script(.map_err(|e| format!("Failed to create runtime: {}", e))?;rt.block_on(execute_python_script_async(script_path, args))}- feature/peer-comparison-and-technicals-fix-- Python::with_gil(|py| {- // Preload common heavy libraries- let _ = py.import("pandas")?;- let _ = py.import("numpy")?;-- println!("Python runtime: Heavy dependencies preloaded");- self.preloaded = true;- Ok(())- })- }-- /// Execute a Python script with arguments- pub fn execute_script(- &mut self,- script_path: &PathBuf,- args: Vec<String>,- ) -> PyResult<String> {- Python::with_gil(|py| {- // Set environment variables for Python script access- // Check if FMP_API_KEY is already set, if not, try to get it from Rust environment- let os_module = py.import("os")?;- let environ = os_module.getattr("environ")?;-- // Get FMP_API_KEY from Rust environment if available- if let Ok(api_key) = std::env::var("FMP_API_KEY") {- environ.set_item("FMP_API_KEY", api_key)?;- } else {- // Try alternative environment variable names- if let Ok(api_key) = std::env::var("FINANCIAL_MODELING_PREP_API_KEY") {- environ.set_item("FMP_API_KEY", api_key)?;- }- }-- // Read the Python script- let script_code = std::fs::read_to_string(script_path)- .map_err(|e| PyErr::new::<pyo3::exceptions::PyIOError, _>(- format!("Failed to read script: {}", e)- ))?;-- // Convert paths to CString for PyO3 0.23+- let file_path_cstr = std::ffi::CString::new(script_path.to_string_lossy().as_ref())- .unwrap_or_else(|_| std::ffi::CString::new("script.py").unwrap());- let module_name_cstr = std::ffi::CString::new(- script_path.file_stem().unwrap().to_string_lossy().as_ref()- ).unwrap_or_else(|_| std::ffi::CString::new("module").unwrap());- let code_cstr = std::ffi::CString::new(script_code.as_str())- .map_err(|e| PyErr::new::<pyo3::exceptions::PyValueError, _>(- format!("Invalid Python code: {}", e)- ))?;-- // Create a new module for this script execution- let module = PyModule::from_code(- py,- &code_cstr,- &file_path_cstr,- &module_name_cstr,- )?;-- // Check if module has a 'main' function- if module.hasattr("main")? {- // Call main function with args- let main_fn = module.getattr("main")?;- let result = main_fn.call1((args,))?;-- // Extract result as string (assuming JSON output)- let output: String = result.extract()?;- Ok(output)- } else if module.hasattr("calculate_all_indicators")? {- // For technical_indicators.py, call the calculation function- // This is a temporary bridge - will be improved in next iteration- Err(PyErr::new::<pyo3::exceptions::PyAttributeError, _>(- "Script needs a 'main' function for PyO3 execution"- ))- } else {- Err(PyErr::new::<pyo3::exceptions::PyAttributeError, _>(- "Script must have a 'main' function"- ))- }- })- }-- /// Execute Python code directly (for simple calculations)- pub fn execute_code(&self, code: &str) -> PyResult<String> {- Python::with_gil(|py| {- let locals = PyDict::new(py);-- // PyO3 0.23+ requires CStr for run- let code_cstr = std::ffi::CString::new(code)- .map_err(|e| PyErr::new::<pyo3::exceptions::PyValueError, _>(- format!("Invalid code string: {}", e)- ))?;-- py.run(&code_cstr, None, Some(&locals))?;-- // Get result from locals if available- if let Ok(result) = locals.get_item("result") {- if let Some(result) = result {- return result.extract();- }- }-- Ok(String::new())- })- main}}