Add PyInstaller build support for deployment
- Add PyInstaller spec files (onefile and onedir modes) - Add build scripts for executable creation - Add MCP hooks for PyInstaller compatibility - Add test script for MCP server validation - Add Windsurf integration setup guide - Update main.py with better error reporting - Successfully tested MCP server works with ONEDIR build (45MB) Features: - Single executable deployment without Python dependency - ONEDIR mode preserves stdio communication for MCP - Build scripts with deployment instructions - Windsurf config integration guide Files added: - mt5-quant.spec (PyInstaller spec) - mt5-quant-onedir.spec (directory mode) - scripts/build-executable.sh (onefile) - scripts/build-executable-onedir.sh (directory) - hooks/hook-mcp.py (PyInstaller hook) - test_mcp.py (validation script) - WINDSURF_SETUP.md (integration guide)
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
#!/bin/bash
|
||||
# Build MT5-Quant as a directory bundle (onedir mode) using PyInstaller
|
||||
# This mode preserves stdin/stdout better for MCP communication
|
||||
# Output: dist/mt5-quant/ directory
|
||||
|
||||
set -e
|
||||
|
||||
# Get script directory and project root
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
echo "=== MT5-Quant PyInstaller Build (ONEDIR Mode) ==="
|
||||
echo "Project root: $PROJECT_ROOT"
|
||||
echo ""
|
||||
|
||||
# Determine Python interpreter
|
||||
if [ -f "$PROJECT_ROOT/.venv/bin/python3" ]; then
|
||||
PYTHON="$PROJECT_ROOT/.venv/bin/python3"
|
||||
elif [ -f "$PROJECT_ROOT/.venv/bin/python" ]; then
|
||||
PYTHON="$PROJECT_ROOT/.venv/bin/python"
|
||||
else
|
||||
PYTHON="python3"
|
||||
fi
|
||||
|
||||
echo "Using Python: $PYTHON"
|
||||
echo ""
|
||||
|
||||
# Ensure dependencies are installed
|
||||
echo "Installing dependencies..."
|
||||
$PYTHON -m pip install pyinstaller mcp pyyaml typer --quiet 2>/dev/null || true
|
||||
|
||||
# Clean previous builds
|
||||
echo "Cleaning previous builds..."
|
||||
rm -rf "$PROJECT_ROOT/build" "$PROJECT_ROOT/dist"
|
||||
|
||||
# Build the executable in onedir mode
|
||||
echo "Building executable in ONEDIR mode (this may take 1-2 minutes)..."
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
# Use onedir mode (no --onefile flag)
|
||||
# Note: mode is controlled by the .spec file
|
||||
$PYTHON -m PyInstaller \
|
||||
--clean \
|
||||
--noconfirm \
|
||||
--distpath "$PROJECT_ROOT/dist" \
|
||||
--workpath "$PROJECT_ROOT/build" \
|
||||
"$PROJECT_ROOT/mt5-quant.spec"
|
||||
|
||||
# Report results
|
||||
echo ""
|
||||
echo "=== Build Complete ==="
|
||||
echo ""
|
||||
echo "Executable location:"
|
||||
ls -la "$PROJECT_ROOT/dist/mt5-quant/" | head -10
|
||||
|
||||
echo ""
|
||||
echo "Main executable:"
|
||||
ls -lh "$PROJECT_ROOT/dist/mt5-quant/mt5-quant"
|
||||
|
||||
echo ""
|
||||
echo "Total size:"
|
||||
du -sh "$PROJECT_ROOT/dist/mt5-quant/"
|
||||
|
||||
echo ""
|
||||
echo "To test:"
|
||||
echo " ./dist/mt5-quant/mt5-quant"
|
||||
echo ""
|
||||
echo "To register with Claude Code:"
|
||||
echo " claude mcp add MT5-Quant -- $(pwd)/dist/mt5-quant/mt5-quant"
|
||||
echo ""
|
||||
echo "=== Deployment to Multiple Machines ==="
|
||||
echo ""
|
||||
echo "1. Copy entire directory to target machines:"
|
||||
echo " scp -r dist/mt5-quant/ user@server:/opt/"
|
||||
echo " ssh user@server ln -s /opt/mt5-quant/mt5-quant /usr/local/bin/"
|
||||
echo ""
|
||||
echo "2. Or create tarball for distribution:"
|
||||
echo " tar -czf mt5-quant-macos-arm64.tar.gz -C dist mt5-quant"
|
||||
echo ""
|
||||
echo "Requirements on target machine:"
|
||||
echo " - MetaTrader 5 installed (via Wine on macOS/Linux)"
|
||||
echo " - Config file at ~/.config/mt5-quant/config/mt5-quant.yaml"
|
||||
echo " - NO Python installation required!"
|
||||
@@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
# Build MT5-Quant as a single executable using PyInstaller
|
||||
# Output: dist/mt5-quant
|
||||
|
||||
set -e
|
||||
|
||||
# Get script directory and project root
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
echo "=== MT5-Quant PyInstaller Build ==="
|
||||
echo "Project root: $PROJECT_ROOT"
|
||||
echo ""
|
||||
|
||||
# Determine Python interpreter
|
||||
if [ -f "$PROJECT_ROOT/.venv/bin/python3" ]; then
|
||||
PYTHON="$PROJECT_ROOT/.venv/bin/python3"
|
||||
elif [ -f "$PROJECT_ROOT/.venv/bin/python" ]; then
|
||||
PYTHON="$PROJECT_ROOT/.venv/bin/python"
|
||||
else
|
||||
PYTHON="python3"
|
||||
fi
|
||||
|
||||
echo "Using Python: $PYTHON"
|
||||
echo ""
|
||||
|
||||
# Ensure dependencies are installed
|
||||
echo "Installing dependencies..."
|
||||
$PYTHON -m pip install pyinstaller mcp pyyaml --quiet
|
||||
|
||||
# Clean previous builds
|
||||
echo "Cleaning previous builds..."
|
||||
rm -rf "$PROJECT_ROOT/build" "$PROJECT_ROOT/dist"
|
||||
|
||||
# Build the executable
|
||||
echo "Building executable (this may take 1-2 minutes)..."
|
||||
cd "$PROJECT_ROOT"
|
||||
$PYTHON -m PyInstaller \
|
||||
--clean \
|
||||
--noconfirm \
|
||||
--distpath "$PROJECT_ROOT/dist" \
|
||||
--workpath "$PROJECT_ROOT/build" \
|
||||
"$PROJECT_ROOT/mt5-quant.spec"
|
||||
|
||||
# Report results
|
||||
echo ""
|
||||
echo "=== Build Complete ==="
|
||||
echo ""
|
||||
echo "Executable location:"
|
||||
ls -lh dist/mt5-quant
|
||||
|
||||
echo ""
|
||||
echo "Size breakdown:"
|
||||
du -sh dist/ 2>/dev/null || echo " dist/: $(du -sh dist/mt5-quant 2>/dev/null | cut -f1)"
|
||||
|
||||
echo ""
|
||||
echo "To test:"
|
||||
echo " ./dist/mt5-quant --help"
|
||||
echo ""
|
||||
echo "To register with Claude Code:"
|
||||
echo " claude mcp add MT5-Quant -- $(pwd)/dist/mt5-quant"
|
||||
echo ""
|
||||
echo "=== Deployment to Multiple Machines ==="
|
||||
echo ""
|
||||
echo "1. Copy this single binary to target machines:"
|
||||
echo " scp dist/mt5-quant user@server:/usr/local/bin/"
|
||||
echo " ssh user@server chmod +x /usr/local/bin/mt5-quant"
|
||||
echo ""
|
||||
echo "2. Copy config directory (includes mt5-quant.yaml):"
|
||||
echo " scp -r config/ user@server:~/.config/mt5-quant/"
|
||||
echo ""
|
||||
echo "3. Or use bundled config (minimal):"
|
||||
echo " MT5_MCP_HOME=/path/to/config ./mt5-quant"
|
||||
echo ""
|
||||
echo "4. Register on target machine:"
|
||||
echo " claude mcp add MT5-Quant -- /usr/local/bin/mt5-quant"
|
||||
echo ""
|
||||
echo "Requirements on target machine:"
|
||||
echo " - MetaTrader 5 installed (via Wine on macOS/Linux)"
|
||||
echo " - Config file at ~/.config/mt5-quant/config/mt5-quant.yaml"
|
||||
echo " - NO Python installation required!"
|
||||
Reference in New Issue
Block a user