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
feat: implement PyOxidizer sidecar bundling with platform-specific builds
tilakpatel22b3de8617de16
diff --git a/.github/workflows/build-with-updater.yml b/.github/workflows/build-with-updater.ymlindex 218820e77..7fbe9909f 100644--- a/.github/workflows/build-with-updater.yml+++ b/.github/workflows/build-with-updater.yml@@ -84,6 +84,27 @@ jobs:run: npm installworking-directory: ./fincept-terminal-desktop+ - name: Setup Python for dependency scanning+ uses: actions/setup-python@v5+ with:+ python-version: '3.12'++ - name: Scan and update Python dependencies+ run: python3 src-tauri/scan_dependencies.py+ working-directory: ./fincept-terminal-desktop++ - name: Install PyOxidizer+ run: cargo install pyoxidizer --locked++ - name: Build Python interpreter with PyOxidizer+ run: |+ cd fincept-terminal-desktop/src-tauri+ pyoxidizer build --release --target-triple ${{ matrix.target }}+ mkdir -p binaries+ find build -name "python-interpreter*" -type f -executable -exec cp {} binaries/ \;+ ls -lh binaries/+ shell: bash+- name: Build the app with updateruses: tauri-apps/tauri-action@v0env:diff --git a/.gitignore b/.gitignoreindex 1e54a947a..d38df71d7 100644--- a/.gitignore+++ b/.gitignore@@ -58,6 +58,10 @@ python!fincept-terminal-desktop/src-tauri/resources/bun/!fincept-terminal-desktop/src-tauri/resources/bun/**+# Exclude PyOxidizer generated binaries (built in CI)+fincept-terminal-desktop/src-tauri/binaries/python-interpreter-*+fincept-terminal-desktop/src-tauri/python-interpreter-*.tar.gz+# Exclude large executables and binaries EXCEPT for resources*.exe!fincept-terminal-desktop/src-tauri/resources/**/*.exediff --git a/fincept-terminal-desktop/.gitignore b/fincept-terminal-desktop/.gitignoreindex fc3a2ff34..ed8106d5f 100644--- a/fincept-terminal-desktop/.gitignore+++ b/fincept-terminal-desktop/.gitignore@@ -26,18 +26,15 @@ dist-ssrsrc/services/node_modulessrc-tauri/target-# Python site-packages - installed via pip during CI/CD-src-tauri/resources/python-windows/Lib/site-packages/*-src-tauri/resources/python-macos/lib/python3.12/site-packages/*-src-tauri/resources/python-linux/lib/python3.12/site-packages/*+# PyOxidizer executables - platform specific, only bundle matching platform+src-tauri/binaries/python-interpreter-*+!src-tauri/binaries/.gitkeep-# Keep site-packages directory structure but not packages-!src-tauri/resources/python-windows/Lib/site-packages/-!src-tauri/resources/python-macos/lib/python3.12/site-packages/-!src-tauri/resources/python-linux/lib/python3.12/site-packages/+# PyOxidizer tar files+src-tauri/python-interpreter-*.tar.gz-# Bun executable - always include-!src-tauri/resources/bun/bun.exe+# Bun and Python are kept in repo for PyOxidizer builds+# Only exclude generated binaries# Scripts should always be included!src-tauri/resources/scripts/diff --git a/fincept-terminal-desktop/src-tauri/build.rs b/fincept-terminal-desktop/src-tauri/build.rsindex d860e1e6a..ab34c272b 100644--- a/fincept-terminal-desktop/src-tauri/build.rs+++ b/fincept-terminal-desktop/src-tauri/build.rs@@ -1,3 +1,39 @@fn main() {+ // Build platform-specific PyOxidizer executable during CI+ // This runs pyoxidizer against the local python-{platform} directory+ use std::path::Path;+ use std::process::Command;++ let binaries_dir = Path::new("binaries");+ std::fs::create_dir_all(binaries_dir).ok();++ // Determine target triple+ let target = std::env::var("TARGET").unwrap_or_else(|_| {+ if cfg!(target_os = "windows") {+ "x86_64-pc-windows-msvc".to_string()+ } else if cfg!(target_os = "linux") {+ "x86_64-unknown-linux-gnu".to_string()+ } else if cfg!(target_os = "macos") {+ "x86_64-apple-darwin".to_string()+ } else {+ "unknown".to_string()+ }+ });++ let binary_name = format!("python-interpreter-{}{}", target, if target.contains("windows") { ".exe" } else { "" });+ let binary_path = binaries_dir.join(&binary_name);++ // Only build if binary doesn't exist+ if !binary_path.exists() {+ println!("cargo:warning=Building PyOxidizer Python for {}", target);++ // Check if we're in CI and should build from local python folder+ if std::env::var("CI").is_ok() || std::env::var("GITHUB_ACTIONS").is_ok() {+ // Run pyoxidizer build command here+ // For now, just warn - implement actual build in CI workflow+ println!("cargo:warning=PyOxidizer build should happen in CI workflow before this step");+ }+ }+tauri_build::build()}diff --git a/fincept-terminal-desktop/src-tauri/pyoxidizer.bzl b/fincept-terminal-desktop/src-tauri/pyoxidizer.bzlnew file mode 100644index 000000000..25e7ddcf2--- /dev/null+++ b/fincept-terminal-desktop/src-tauri/pyoxidizer.bzl@@ -0,0 +1,36 @@+def make_exe():+ dist = default_python_distribution()++ policy = dist.make_python_packaging_policy()+ policy.resources_location_fallback = "filesystem-relative:lib"++ python_config = dist.make_python_interpreter_config()+ python_config.run_mode = "repl"+ python_config.module_search_paths = ["$ORIGIN/lib"]++ exe = dist.to_python_executable(+ name="python-interpreter",+ packaging_policy=policy,+ config=python_config,+ )++ # Add all packages from requirements.txt (relative to src-tauri/)+ exe.add_python_resources(exe.pip_install([+ "-r", "../resources/requirements.txt"+ ]))++ return exe++def make_embedded_resources(exe):+ return exe.to_embedded_resources()++def make_install(exe):+ files = FileManifest()+ files.add_python_resource(".", exe)+ return files++register_target("exe", make_exe)+register_target("resources", make_embedded_resources, depends=["exe"], default_build_script=True)+register_target("install", make_install, depends=["exe"], default=True)++resolve_targets()diff --git a/fincept-terminal-desktop/src-tauri/resources/requirements.txt b/fincept-terminal-desktop/src-tauri/resources/requirements.txtindex caf7225b1..6b1d01025 100644--- a/fincept-terminal-desktop/src-tauri/resources/requirements.txt+++ b/fincept-terminal-desktop/src-tauri/resources/requirements.txt@@ -1,8 +1,45 @@-yfinance==0.2.66-pandas==2.3.3-numpy==2.3.5+aiohappyeyeballs==2.6.1+aiohttp==3.13.2+aiosignal==1.4.0+attrs==25.4.0+beautifulsoup4==4.14.2+certifi==2025.11.12+cffi==2.0.0+charset-normalizer==3.4.4+curl_cffi==0.13.0databento==0.66.0+databento-dbn==0.44.0+dnspython==2.8.0+feedparser==6.0.12+frozendict==2.4.7+frozenlist==1.8.0+gnews==0.4.2+idna==3.11+multidict==6.7.0+multitasking==0.0.12+numpy==2.3.5+pandas==2.3.3+peewee==3.18.3+pip_system_certs==5.3+platformdirs==4.5.0+propcache==0.4.1+protobuf==6.33.1+pyarrow==22.0.0+pycparser==2.23+python-dateutil==2.9.0.post0+pytz==2025.2+requests==2.32.5+sgmllib3k==1.0.0+six==1.17.0+soupsieve==2.8ta==0.11.0+typing_extensions==4.15.0+tzdata==2025.2+urllib3==2.5.0+websockets==15.0.1+yarl==1.22.0+yfinance==0.2.66+zstandard==0.25.0jinja2==3.1.3weasyprint==62.3matplotlib==3.9.3diff --git a/fincept-terminal-desktop/src-tauri/scan_dependencies.py b/fincept-terminal-desktop/src-tauri/scan_dependencies.pynew file mode 100644index 000000000..5658123c8--- /dev/null+++ b/fincept-terminal-desktop/src-tauri/scan_dependencies.py@@ -0,0 +1,109 @@+#!/usr/bin/env python3+"""Scan Python scripts and update requirements.txt with missing packages."""+import ast+import os+import re+from pathlib import Path++SCRIPTS_DIR = Path("resources/scripts")+REQUIREMENTS_FILE = Path("resources/requirements.txt")+STDLIB_MODULES = set([+ 'abc', 'aifc', 'argparse', 'array', 'ast', 'asynchat', 'asyncio', 'asyncore',+ 'base64', 'bdb', 'binascii', 'binhex', 'bisect', 'builtins', 'bz2',+ 'calendar', 'cgi', 'cgitb', 'chunk', 'cmath', 'cmd', 'code', 'codecs',+ 'codeop', 'collections', 'colorsys', 'compileall', 'concurrent', 'configparser',+ 'contextlib', 'copy', 'copyreg', 'cProfile', 'csv', 'ctypes', 'curses',+ 'dataclasses', 'datetime', 'dbm', 'decimal', 'difflib', 'dis', 'distutils',+ 'doctest', 'email', 'encodings', 'enum', 'errno', 'faulthandler', 'fcntl',+ 'filecmp', 'fileinput', 'fnmatch', 'formatter', 'fractions', 'ftplib',+ 'functools', 'gc', 'getopt', 'getpass', 'gettext', 'glob', 'gzip',+ 'hashlib', 'heapq', 'hmac', 'html', 'http', 'imaplib', 'imghdr', 'imp',+ 'importlib', 'inspect', 'io', 'ipaddress', 'itertools', 'json', 'keyword',+ 'lib2to3', 'linecache', 'locale', 'logging', 'lzma', 'mailbox', 'mailcap',+ 'marshal', 'math', 'mimetypes', 'mmap', 'modulefinder', 'multiprocessing',+ 'netrc', 'numbers', 'operator', 'optparse', 'os', 'ossaudiodev', 'parser',+ 'pathlib', 'pdb', 'pickle', 'pickletools', 'pipes', 'pkgutil', 'platform',+ 'plistlib', 'poplib', 'posix', 'posixpath', 'pprint', 'profile', 'pstats',+ 'pty', 'pwd', 'py_compile', 'pyclbr', 'pydoc', 'queue', 'quopri', 'random',+ 're', 'readline', 'reprlib', 'resource', 'rlcompleter', 'runpy', 'sched',+ 'secrets', 'select', 'selectors', 'shelve', 'shlex', 'shutil', 'signal',+ 'site', 'smtpd', 'smtplib', 'sndhdr', 'socket', 'socketserver', 'sqlite3',+ 'ssl', 'stat', 'statistics', 'string', 'stringprep', 'struct', 'subprocess',+ 'sunau', 'symbol', 'symtable', 'sys', 'sysconfig', 'syslog', 'tabnanny',+ 'tarfile', 'telnetlib', 'tempfile', 'termios', 'test', 'textwrap', 'threading',+ 'time', 'timeit', 'token', 'tokenize', 'trace', 'traceback', 'tracemalloc',+ 'tty', 'turtle', 'turtledemo', 'types', 'typing', 'unicodedata', 'unittest',+ 'urllib', 'uu', 'uuid', 'venv', 'warnings', 'wave', 'weakref', 'webbrowser',+ 'winreg', 'winsound', 'wsgiref', 'xdrlib', 'xml', 'xmlrpc', 'zipapp',+ 'zipfile', 'zipimport', 'zlib'+])++def extract_imports(file_path):+ """Extract all import statements from a Python file."""+ imports = set()+ try:+ with open(file_path, 'r', encoding='utf-8') as f:+ tree = ast.parse(f.read(), filename=str(file_path))++ for node in ast.walk(tree):+ if isinstance(node, ast.Import):+ for alias in node.names:+ imports.add(alias.name.split('.')[0])+ elif isinstance(node, ast.ImportFrom):+ if node.module:+ imports.add(node.module.split('.')[0])+ except Exception as e:+ print(f"Warning: Could not parse {file_path}: {e}")++ return imports++def scan_all_scripts():+ """Scan all Python scripts in resources/scripts directory."""+ all_imports = set()++ for py_file in SCRIPTS_DIR.rglob("*.py"):+ imports = extract_imports(py_file)+ all_imports.update(imports)++ # Filter out standard library modules+ third_party = {imp for imp in all_imports if imp not in STDLIB_MODULES}++ return sorted(third_party)++def read_requirements():+ """Read existing requirements.txt."""+ if not REQUIREMENTS_FILE.exists():+ return set()++ packages = set()+ with open(REQUIREMENTS_FILE, 'r') as f:+ for line in f:+ line = line.strip()+ if line and not line.startswith('#'):+ # Extract package name (before ==, >=, etc.)+ pkg = re.split(r'[=<>!]', line)[0].strip()+ packages.add(pkg.lower())++ return packages++def update_requirements(new_packages):+ """Update requirements.txt with new packages."""+ existing = read_requirements()+ to_add = [pkg for pkg in new_packages if pkg.lower() not in existing]++ if to_add:+ print(f"Adding {len(to_add)} new packages to requirements.txt:")+ for pkg in to_add:+ print(f" - {pkg}")++ with open(REQUIREMENTS_FILE, 'a') as f:+ for pkg in to_add:+ f.write(f"{pkg}\n")+ else:+ print("✓ All packages already in requirements.txt")++if __name__ == "__main__":+ print("Scanning Python scripts for dependencies...")+ packages = scan_all_scripts()+ print(f"Found {len(packages)} third-party packages")+ update_requirements(packages)diff --git a/fincept-terminal-desktop/src-tauri/src/utils/python.rs b/fincept-terminal-desktop/src-tauri/src/utils/python.rsindex dd94498bc..78cb458ff 100644--- a/fincept-terminal-desktop/src-tauri/src/utils/python.rs+++ b/fincept-terminal-desktop/src-tauri/src/utils/python.rs@@ -11,122 +11,46 @@ use std::os::windows::process::CommandExt;#[cfg(target_os = "windows")]const CREATE_NO_WINDOW: u32 = 0x08000000;-/// Get the Python executable path at runtime+/// Get the Python executable path at runtime using Tauri sidecarpub fn get_python_path(app: &tauri::AppHandle) -> Result<PathBuf, String> {- use std::process::Command;-- // Strategy for all platforms:- // 1. Try bundled Python first (ensures consistency)- // 2. Fall back to system Python (for compatibility)- // This ensures users don't need to install Python separately-- #[cfg(target_os = "windows")]- {- // Try bundled Python first on Windows- let resource_dir = app- .path()- .resource_dir()- .map_err(|e| format!("Failed to get resource directory: {}", e))?;-- let bundled_python = resource_dir- .join("python-windows")- .join("python.exe");-- if bundled_python.exists() {- return Ok(bundled_python);- }-- // Fallback to system Python- if let Ok(output) = Command::new("python").arg("--version").output() {- if output.status.success() {- if let Ok(python_path) = which::which("python") {- return Ok(python_path);- }- }- }-- return Err("Python not found. Please install Python 3.x from python.org".to_string());- }-- #[cfg(target_os = "macos")]- {- // Try bundled Python first on macOS- let resource_dir = app- .path()- .resource_dir()- .map_err(|e| format!("Failed to get resource directory: {}", e))?;-- let bundled_python = resource_dir- .join("python-macos")- .join("bin")- .join("python3");-- if bundled_python.exists() {- return Ok(bundled_python);- }-- // Fallback to system python3- if let Ok(output) = Command::new("python3").arg("--version").output() {- if output.status.success() {- if let Ok(python_path) = which::which("python3") {- return Ok(python_path);- }- }- }-- // Try python as last resort- if let Ok(output) = Command::new("python").arg("--version").output() {- if output.status.success() {- if let Ok(python_path) = which::which("python") {- return Ok(python_path);- }- }- }-- return Err("Python not found. Please install Python 3.x:\n brew install python3".to_string());- }-- #[cfg(target_os = "linux")]- {- // Try bundled Python first on Linux- let resource_dir = app- .path()- .resource_dir()- .map_err(|e| format!("Failed to get resource directory: {}", e))?;-- let bundled_python = resource_dir- .join("python-linux")- .join("bin")- .join("python3");+ // Get sidecar binary path - Tauri places sidecars next to the executable+ let resource_dir = app+ .path()+ .resource_dir()+ .map_err(|e| format!("Failed to get resource directory: {}", e))?;- if bundled_python.exists() {- return Ok(bundled_python);+ // Determine the platform-specific binary name+ let binary_name = if cfg!(target_os = "windows") {+ if cfg!(target_arch = "x86_64") {+ "python-interpreter-x86_64-pc-windows-msvc.exe"+ } else {+ "python-interpreter.exe" // fallback}-- // Fallback to system python3- if let Ok(output) = Command::new("python3").arg("--version").output() {- if output.status.success() {- if let Ok(python_path) = which::which("python3") {- return Ok(python_path);- }- }+ } else if cfg!(target_os = "linux") {+ if cfg!(target_arch = "aarch64") {+ "python-interpreter-aarch64-unknown-linux-gnu"+ } else {+ "python-interpreter-x86_64-unknown-linux-gnu"}-- // Try python as last resort- if let Ok(output) = Command::new("python").arg("--version").output() {- if output.status.success() {- if let Ok(python_path) = which::which("python") {- return Ok(python_path);- }- }+ } else if cfg!(target_os = "macos") {+ if cfg!(target_arch = "aarch64") {+ "python-interpreter-aarch64-apple-darwin"+ } else {+ "python-interpreter-x86_64-apple-darwin"}+ } else {+ return Err("Unsupported platform".to_string());+ };- return Err("Python not found. Please install Python 3.x:\n sudo apt install python3 python3-pip\n OR\n sudo yum install python3 python3-pip".to_string());- }+ // Sidecar binaries are placed in parent directory of resources+ let python_path = resource_dir.parent()+ .ok_or("Failed to get parent directory")?+ .join(binary_name);- #[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]- {- Err("Unsupported operating system".to_string())+ if python_path.exists() {+ Ok(python_path)+ } else {+ Err(format!("Python interpreter not found at: {}. Please ensure the binary is bundled correctly.", python_path.display()))}}@@ -137,20 +61,18 @@ pub fn get_bundled_bun_path(app: &tauri::AppHandle) -> Result<PathBuf, String> {.resource_dir().map_err(|e| format!("Failed to get resource directory: {}", e))?;- // Determine platform-specific directory and executable name- let (bun_dir, bun_exe) = if cfg!(target_os = "windows") {- ("bun-windows", "bun.exe")+ // Platform-specific Bun directory (only current platform is bundled)+ let bun_dir = if cfg!(target_os = "windows") {+ "bun-windows"} else if cfg!(target_os = "macos") {- ("bun-macos", "bun")+ "bun-macos"} else {- ("bun-linux", "bun")+ "bun-linux"};- let bun_path = resource_dir- .join(bun_dir)- .join(bun_exe);+ let bun_exe = if cfg!(target_os = "windows") { "bun.exe" } else { "bun" };+ let bun_path = resource_dir.join(bun_dir).join(bun_exe);- // Verify Bun existsif !bun_path.exists() {return Err(format!("Bundled Bun not found at: {}", bun_path.display()));}diff --git a/fincept-terminal-desktop/src-tauri/tauri.conf.json b/fincept-terminal-desktop/src-tauri/tauri.conf.jsonindex a189a4ab5..54ccc711f 100644--- a/fincept-terminal-desktop/src-tauri/tauri.conf.json+++ b/fincept-terminal-desktop/src-tauri/tauri.conf.json@@ -47,7 +47,9 @@"resources": ["resources/scripts"],- "externalBin": [],+ "externalBin": [+ "binaries/python-interpreter"+ ],"windows": {"digestAlgorithm": "sha256","timestampUrl": "http://timestamp.digicert.com",