background: var(--bg); padding: 0.25rem 0.5rem; border-radius: 4px; font-family: 'Courier New', monospace; font-size: 0.875em; } pre { background: var(--bg); padding: 1rem; border-radius: 6px; overflow-x: auto; font-size: 0.875rem; } .tip { background: #e8f5e9; border-left: 4px solid #4caf50; padding: 1rem; margin: 1rem 0; border-radius: 4px; } .warning { background: #fff3e0; border-left: 4px solid #ff9800; padding: 1rem; margin: 1rem 0; border-radius: 4px; } .step-number { display: inline-block; width: 2rem; height: 2rem; background: var(--primary); color: white; border-radius: 50%; text-align: center; line-height: 2rem; font-weight: bold; margin-right: 0.5rem; }

Build from Source Guide

Build and package Calcora from source code, including the desktop application and custom deployments.

Overview

This guide covers building Calcora from source for:

System Requirements

Software Requirements

  • Python: 3.10, 3.11, 3.12, or 3.13 (recommended: 3.11)
  • Git: For cloning the repository
  • pip: Python package manager (included with Python 3.4+)
  • Windows 10/11: For building desktop app (64-bit)
  • PowerShell 5.1+: For running build scripts (Windows)
💡 Quick Version Check:
python --version should show Python 3.10 or higher
git --version to verify Git is installed
pip --version to ensure pip is available

Disk Space Requirements

1 Clone the Repository

Download the Calcora source code from GitHub.

# Clone with HTTPS
git clone https://github.com/Dumbo-programmer/Calcora.git
cd Calcora

# Or clone with SSH (if you have SSH keys configured)
git clone git@github.com:Dumbo-programmer/Calcora.git
cd Calcora

Verify Repository Contents

# List important files
ls -la

# Expected files and directories:
# - api_server.py         (Flask API server)
# - calcora_desktop.py    (Desktop app entry point)
# - build-desktop.ps1     (Desktop build script)
# - pyproject.toml        (Python project metadata)
# - requirements-api.txt  (API dependencies)
# - src/                  (Source code)
# - tests/                (Test suite)
# - site/                 (Web UI files)

2 Create Virtual Environment

Isolate dependencies from system Python installation.

Windows (PowerShell)

# Create virtual environment
python -m venv .venv

# Activate virtual environment
.\.venv\Scripts\Activate.ps1

# Verify activation (should show (.venv) in prompt)
python -c "import sys; print(sys.prefix)"
⚠️ PowerShell Execution Policy: If you get an error about script execution, run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Linux / macOS (Bash/Zsh)

# Create virtual environment
python3 -m venv .venv

# Activate virtual environment
source .venv/bin/activate

# Verify activation
which python  # Should show path inside .venv/

3 Install Dependencies

Install required Python packages for development and building.

Core Dependencies

# Install API server dependencies
pip install -r requirements-api.txt

# Verify installation
pip list | grep -E "flask|sympy|numpy|pydantic"

# Expected output:
# Flask            3.0.0+
# flask-cors       4.0.0+
# sympy            1.12+
# numpy            1.26+
# pydantic         2.7+

Development Dependencies

# Install testing and build tools
pip install pytest pytest-cov pyinstaller

# Optional: Install code quality tools
pip install black flake8 mypy pylint
💡 Dependency Conflicts? If you encounter version conflicts, try:
pip install --upgrade pip setuptools wheel
Then reinstall dependencies.

4 Run Tests

Ensure everything is working correctly before building.

Basic Test Suite

# Run all tests
pytest

# Run with verbose output
pytest -v

# Run with coverage report
pytest --cov=src --cov-report=html

# Run specific test file
pytest tests/test_integration_engine.py

Expected Test Results (v0.2.0)

  • Total tests: 73
  • Passing: 69 ✅
  • Coverage: 51% (engine: 71%)
  • Benchmark accuracy: 100% (26/26)
⚠️ Known Test Issues: Some tests may fail on Windows due to path handling. This is expected and won't affect the build. Check the GitHub Issues for updates.

Manual Testing

# Test the API server locally
python api_server.py

# In another terminal/browser:
# Navigate to http://localhost:5000
# Try computing: d/dx (x^2 + 3x + 1)

5 Build Desktop Application

Create a standalone Windows executable using PyInstaller.

Using the Build Script (Recommended)

# Run the desktop build script
.\build-desktop.ps1

# Build with clean (removes previous builds)
.\build-desktop.ps1 -Clean

# Build and test immediately
.\build-desktop.ps1 -Test

What the Build Script Does

  1. Checks that virtual environment is activated
  2. Installs PyInstaller if not present
  3. Runs PyInstaller with the calcora-desktop.spec configuration
  4. Bundles Python runtime, dependencies, and web UI files
  5. Creates single-file executable in dist/Calcora.exe
  6. Reports build size and success status

Build Output

============================================================
  Calcora Desktop Builder v0.3
============================================================

Checking for PyInstaller...
PyInstaller is installed

Building Calcora Desktop executable...
This may take 2-5 minutes...

[PyInstaller build output...]

Build successful!
Executable: dist\Calcora.exe
Size: 36.8 MB

To test the executable, run:
  .\dist\Calcora.exe
💡 Build Time: First build takes 3-5 minutes. Subsequent builds (without -Clean) are faster (~1-2 minutes).

PyInstaller Configuration

Understanding the calcora-desktop.spec file.

Key Configuration Options

# calcora-desktop.spec (simplified)

a = Analysis(
    ['calcora_desktop.py'],           # Entry point script
    pathex=[],
    binaries=[],
    datas=[
        ('src/calcora/web', 'web'),    # Bundle web UI files
        ('site', 'web'),               # Alternative web files
    ],
    hiddenimports=[
        'calcora.engine_implementations.sympy_engine',
        'sympy.parsing.sympy_parser',
    ],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    noarchive=False,
)

pyz = PYZ(a.pure)

exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.datas,
    [],
    name='Calcora',                    # Executable name
    debug=False,                       # Disable debug mode
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,                          # Compress with UPX
    upx_exclude=[],
    runtime_tmpdir=None,
    console=False,                     # No console window
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
    icon='media/icon.ico',             # Application icon
)

Customizing the Build

Edit calcora-desktop.spec to customize:

Manual Build (without script)

# Build directly with PyInstaller
pyinstaller calcora-desktop.spec --clean --noconfirm

# Or create spec file from scratch
pyinstaller --onefile \
  --windowed \
  --icon=media/icon.ico \
  --name=Calcora \
  --add-data "src/calcora/web;web" \
  calcora_desktop.py

Troubleshooting Build Issues

Build fails with "Module not found"

Solution: Add missing module to hiddenimports in spec file:

hiddenimports=[
    'calcora.engine_implementations.sympy_engine',
    'your_missing_module_here',
]

Executable won't start / crashes immediately

Solution: Build with console enabled to see error messages:

# Edit calcora-desktop.spec: set console=True
# Then rebuild:
.\build-desktop.ps1 -Clean

"Virtual environment not activated" error

Solution: Activate virtual environment first:

.\.venv\Scripts\Activate.ps1  # Windows
source .venv/bin/activate      # Linux/Mac

Web UI not loading (blank page)

Solution: Verify data files are bundled correctly:

# Check datas in calcora-desktop.spec
datas=[
    ('src/calcora/web', 'web'),
    ('site', 'web'),  # Ensure this path exists
]

Build is too large (>50 MB)

Solutions:

  • Ensure UPX compression is enabled: upx=True
  • Exclude unnecessary packages in spec file: excludes=['matplotlib', 'tkinter']
  • Use --exclude-module flag with PyInstaller

PyInstaller fails on Windows Defender

Solution: Add exception for build directory:

# Add folder exclusion in Windows Security:
# Settings > Privacy & Security > Windows Security
# > Virus & threat protection > Manage settings
# > Exclusions > Add folder: B:\Development\Calcora\dist

Testing the Executable

# Test the built executable
cd dist
.\Calcora.exe

# Check if server starts properly:
# 1. Browser should open automatically to http://localhost:5000
# 2. UI should load without errors
# 3. Try a computation: d/dx (x^2)
# 4. Close browser or click "Shutdown" to exit gracefully

Creating Distribution Packages

Package your build for distribution to users.

Windows Installer (Optional)

# Use Inno Setup or NSIS to create installer
# Example Inno Setup script structure:

[Setup]
AppName=Calcora
AppVersion=0.3.0
DefaultDirName={pf}\Calcora
DefaultGroupName=Calcora
OutputBaseFilename=CalcoraSetup
Compression=lzma2
SolidCompression=yes

[Files]
Source: "dist\Calcora.exe"; DestDir: "{app}"

[Icons]
Name: "{group}\Calcora"; Filename: "{app}\Calcora.exe"

Portable ZIP Package

# Create portable package
mkdir Calcora-Portable
cp dist/Calcora.exe Calcora-Portable/
cp README.md Calcora-Portable/
cp LICENSE Calcora-Portable/

# Create ZIP archive
Compress-Archive -Path Calcora-Portable -DestinationPath Calcora-v0.3.0-Portable.zip

# Calculate checksum (for verification)
Get-FileHash Calcora-v0.3.0-Portable.zip -Algorithm SHA256

Using package-desktop.ps1

# Run the packaging script (if available)
.\package-desktop.ps1

# This creates:
# - ZIP archive with executable
# - SHA256 checksum file
# - Ready for GitHub release

Code Signing (Optional)

Sign your executable to remove Windows security warnings.

⚠️ Cost: Code signing certificates cost ~$200-400/year from Certificate Authorities (Sectigo, DigiCert, etc.).

Obtaining a Certificate

  1. Purchase from: Sectigo, DigiCert, GlobalSign, or SSL.com
  2. Complete identity verification (business or individual)
  3. Receive certificate file (.pfx or .p12)
  4. Install on Windows Certificate Store

Signing the Executable

# Using signtool.exe (Windows SDK)
signtool sign /f certificate.pfx /p password /t http://timestamp.digicert.com dist\Calcora.exe

# Verify signature
signtool verify /pa dist\Calcora.exe

See the Code Signing Guide for detailed instructions.

Contributing to Calcora

Help improve Calcora by contributing code, documentation, or bug reports.

Development Workflow

  1. Fork the repository on GitHub
  2. Clone your fork: git clone https://github.com/YOUR_USERNAME/Calcora.git
  3. Create a branch: git checkout -b feature/your-feature-name
  4. Make changes and write tests
  5. Run tests: pytest
  6. Commit: git commit -m "Add feature: your description"
  7. Push: git push origin feature/your-feature-name
  8. Create Pull Request on GitHub

Code Standards

# Format code with Black
black src/ tests/

# Check code quality
flake8 src/ tests/ --max-line-length=100

# Type checking
mypy src/

Writing Tests

# Create test file in tests/ directory
# Example: tests/test_new_feature.py

import pytest
from calcora.bootstrap import default_engine

def test_new_integration_rule():
    """Test new integration rule implementation"""
    engine = default_engine(load_entry_points=True)
    result = engine.run(
        operation='integrate',
        expression='sin(x)',
        variable='x'
    )
    assert result.output == '-cos(x)'
    assert result.success is True

Documentation

💡 First-time contributors: Check out issues labeled "good first issue" on GitHub for beginner-friendly tasks.

Guidelines

Read the full Contributing Guide for more details.

Advanced Topics

Cross-Platform Builds

PyInstaller builds for the platform you're running on:

  • Windows .exe: Build on Windows
  • Linux binary: Build on Linux
  • macOS .app: Build on macOS

Use VMs or CI/CD (GitHub Actions) for multi-platform builds.

Automated Builds with GitHub Actions

# .github/workflows/build.yml
name: Build Desktop App

on:
  push:
    tags:
      - 'v*'

jobs:
  build-windows:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: '3.11'
      - run: |
          python -m venv .venv
          .\.venv\Scripts\Activate.ps1
          pip install -r requirements-api.txt
          pip install pyinstaller
          .\build-desktop.ps1
      - uses: actions/upload-artifact@v3
        with:
          name: Calcora-Windows
          path: dist/Calcora.exe

Debugging PyInstaller Builds

# Enable debug mode in spec file
exe = EXE(
    ...,
    debug=True,  # Enable debug output
    console=True,  # Show console window
    ...
)

# Run with debug flags
pyinstaller --debug=all calcora-desktop.spec

Optimizing Build Size

  • Use --exclude-module for unused packages
  • Enable UPX compression (already enabled in spec)
  • Strip debug symbols (not recommended for production)
  • Consider lazy imports for optional dependencies

Need Help?

Build and development support resources: