function verify_matlab_python_setup() % VERIFY_MATLAB_PYTHON_SETUP - Comprehensive setup verification % for MATLAB-Python-Flywheel interoperability. % % Checks MATLAB version, Python configuration, flywheel-sdk installation, % client authentication, basic operations, and helper utilities. % % Usage: % verify_matlab_python_setup() fprintf('\n'); fprintf('========================================================\n'); fprintf(' MATLAB-Python-Flywheel Setup Verification\n'); fprintf('========================================================\n'); fprintf('\n'); % Track overall success all_checks_passed = true; %% Check 1: MATLAB Version fprintf('--- Check 1: MATLAB Version ---\n'); matlab_version = version('-release'); year = str2double(matlab_version(1:4)); if year >= 2019 fprintf('[PASS] MATLAB version: R%s (>= R2019b required)\n', matlab_version); else fprintf('[FAIL] MATLAB version: R%s (too old)\n', matlab_version); fprintf(' ACTION: Upgrade to MATLAB R2019b or later\n'); all_checks_passed = false; end fprintf('\n'); %% Check 2: Python Configuration fprintf('--- Check 2: Python Configuration ---\n'); try pe = pyenv; if pe.Status == "NotLoaded" fprintf('[INFO] Python not yet loaded (will load on first use)\n'); fprintf(' Python executable: %s\n', string(pe.Executable)); elseif pe.Status == "Loaded" fprintf('[PASS] Python loaded successfully\n'); fprintf(' Version: %s\n', string(pe.Version)); fprintf(' Executable: %s\n', string(pe.Executable)); % Check Python version compatibility version_str = string(pe.Version); version_parts = split(version_str, '.'); major = str2double(version_parts(1)); minor = str2double(version_parts(2)); if major == 3 && minor >= 8 && minor <= 11 fprintf('[PASS] Python version compatible (3.8-3.11)\n'); elseif major == 3 && minor >= 12 fprintf('[WARN] Python 3.%d may have limited MATLAB support\n', minor); fprintf(' RECOMMENDED: Use Python 3.8-3.11\n'); else fprintf('[FAIL] Python version incompatible\n'); fprintf(' REQUIRED: Python 3.8-3.11\n'); all_checks_passed = false; end else fprintf('[FAIL] Python status: %s\n', string(pe.Status)); fprintf(' ACTION: Check Python installation\n'); all_checks_passed = false; end catch ME fprintf('[FAIL] Failed to check Python configuration\n'); fprintf(' Error: %s\n', ME.message); all_checks_passed = false; end fprintf('\n'); %% Check 3: flywheel-sdk Installation fprintf('--- Check 3: flywheel-sdk Installation ---\n'); try % Import flywheel module to verify it exists fw_module = py.importlib.import_module('flywheel'); % Get version using importlib.metadata (Python 3.8+) metadata_module = py.importlib.import_module('importlib.metadata'); sdk_version = string(metadata_module.version('flywheel-sdk')); fprintf('[PASS] flywheel-sdk installed: version %s\n', sdk_version); % Check if it's a recent version version_parts = split(sdk_version, '.'); major = str2double(version_parts(1)); if major >= 17 fprintf('[PASS] Version is recent\n'); else fprintf('[WARN] Version may be outdated (current: %s)\n', sdk_version); fprintf(' CONSIDER: pip install --upgrade flywheel-sdk\n'); end catch ME fprintf('[FAIL] flywheel-sdk not found\n'); fprintf(' Error: %s\n', ME.message); fprintf('\n ACTION: Install flywheel-sdk:\n'); fprintf(' pip install flywheel-sdk\n'); fprintf('\n If using virtual environment:\n'); fprintf(' python3 -m venv ~/flywheel-env\n'); fprintf(' source ~/flywheel-env/bin/activate\n'); fprintf(' pip install flywheel-sdk\n'); fprintf(' Then in MATLAB: pyenv(''Version'', ''~/flywheel-env/bin/python'')\n'); all_checks_passed = false; end fprintf('\n'); %% Check 4: Flywheel Client Creation fprintf('--- Check 4: Flywheel Client Creation ---\n'); try fw_module = py.importlib.import_module('flywheel'); fw = fw_module.Client(); fprintf('[PASS] Client created successfully\n'); % Try to get user info to verify authentication try user = fw.get_current_user(); fprintf('[PASS] Authentication successful\n'); fprintf(' User: %s %s\n', string(user.firstname), string(user.lastname)); fprintf(' Email: %s\n', string(user.email)); catch auth_ME fprintf('[WARN] Client created but authentication failed\n'); fprintf(' Error: %s\n', auth_ME.message); fprintf('\n ACTION: Configure credentials:\n'); fprintf(' Option 1: fw login (run in terminal)\n'); fprintf(' Option 2: fw = fw_module.Client(''your-api-key'')\n'); all_checks_passed = false; end catch ME fprintf('[FAIL] Failed to create client\n'); fprintf(' Error: %s\n', ME.message); fprintf('\n ACTION: Verify flywheel-sdk installation\n'); all_checks_passed = false; end fprintf('\n'); %% Check 5: Basic Operations fprintf('--- Check 5: Basic Operations ---\n'); try fw_module = py.importlib.import_module('flywheel'); fw = fw_module.Client(); % Test creating a Python dict (common operation) test_dict = py.dict(pyargs('label', 'test', 'value', 123)); fprintf('[PASS] Python dict creation works\n'); % Test list conversion test_list = py.list({'a', 'b', 'c'}); matlab_cell = cell(test_list); fprintf('[PASS] Python list conversion works\n'); % Test property access user = fw.get_current_user(); user_id = string(user.id); fprintf('[PASS] Python object property access works\n'); catch ME fprintf('[WARN] Some basic operations failed\n'); fprintf(' Error: %s\n', ME.message); fprintf(' This may affect functionality\n'); all_checks_passed = false; end fprintf('\n'); %% Check 6: Helper Utilities fprintf('--- Check 6: Helper Utilities ---\n'); if exist('flywheel_matlab_helpers.m', 'file') fprintf('[PASS] flywheel_matlab_helpers.m found\n'); % Test helper functions try fw = flywheel_matlab_helpers.create_client(); fprintf('[PASS] Helper functions operational\n'); catch fprintf('[WARN] Helper class found but has errors\n'); end else fprintf('[INFO] flywheel_matlab_helpers.m not in path\n'); fprintf(' OPTIONAL: Download and add to your MATLAB path\n'); end fprintf('\n'); %% Final Summary fprintf('========================================================\n'); fprintf(' Verification Summary\n'); fprintf('========================================================\n'); fprintf('\n'); if all_checks_passed fprintf('[PASS] ALL CHECKS PASSED\n\n'); fprintf('Your setup is ready for using flywheel-sdk from MATLAB.\n'); fprintf('\nNext steps:\n'); fprintf(' 1. Review the MATLAB SDK usage guide on the Flywheel docs site\n'); fprintf(' 2. Download flywheel_matlab_helpers.m for convenience functions\n'); fprintf(' 3. Start coding!\n'); else fprintf('[WARN] SOME CHECKS FAILED\n\n'); fprintf('Address the ACTION items above, then re-run this script.\n'); end fprintf('\n'); %% Environment Details fprintf('--- Environment Details ---\n'); fprintf('MATLAB Version: R%s\n', version('-release')); try pe = pyenv; fprintf('Python Version: %s\n', string(pe.Version)); fprintf('Python Executable: %s\n', string(pe.Executable)); fprintf('Python Status: %s\n', string(pe.Status)); catch fprintf('Python: Not configured\n'); end fprintf('Platform: %s\n', computer); fprintf('Date: %s\n', datestr(now)); fprintf('\n'); end