Skip to content

paiml/reprorusted-python-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

reprorusted-python-cli

Argparse-to-Rust Compilation Validation Examples using Depyler

CI Quality Gates Benchmarks License: MIT Progress

Performance Overview

Performance Overview

Overview

This repository provides a comprehensive validation framework for Python-to-Rust transpilation using depyler. It focuses on testing "single-shot" compilation of Python argparse-based CLI scripts into standalone Rust binaries, with rigorous input/output validation to ensure semantic equivalence.

Key Features:

  • 100% I/O Equivalence: Python and Rust binaries produce identical output
  • 100% Test Coverage: Comprehensive pytest + Rust integration tests
  • Scientific Benchmarking: Proves 9.6x average speedup with academic rigor
  • Extreme TDD: All code written test-first with pmat quality gates
  • Zero Manual Makefiles: All build files generated programmatically via bashrs

Quick Start

# Clone repository
git clone https://github.com/paiml/reprorusted-python-cli.git
cd reprorusted-python-cli

# Install dependencies
make install-deps

# Run quick validation
make quick-validate

# Build all examples
make build

# Run benchmarks
make bench

Project Structure

reprorusted-python-cli/
├── examples/              # 6 argparse CLI examples (simple → complex)
│   ├── example_simple/   # Trivial CLI with basic argparse
│   ├── example_flags/    # Boolean flags and combinations
│   ├── example_positional/  # Positional arguments
│   ├── example_subcommands/ # Git-like subcommand pattern
│   ├── example_complex/  # Advanced argparse features
│   └── example_stdlib/   # Integration with stdlib modules
├── benchmarks/           # Scientific performance benchmarking
│   ├── micro/           # Microbenchmarks (argparse overhead, startup, etc.)
│   └── macro/           # Real-world CLI scenarios
├── tests/               # Integration tests (Rust + Python)
├── scripts/             # Automation scripts
└── docs/                # Comprehensive documentation

Examples

Depyler Compatibility Status

As of depyler v3.20.2 (latest), the depyler compile command works out-of-the-box for basic argparse examples:

Example depyler compile Manual Rust Test Count Status
example_simple ✅ Works ✅ Available 23 tests Full support
example_flags ✅ Works ✅ Available 33 tests Full support
example_positional ✅ Works ✅ Available 27 tests Full support
example_subcommands ❌ Build fails ✅ Available 37 tests Subcommand enum issues
example_complex ❌ Build fails ✅ Available 43 tests Option type issues
example_stdlib ❌ Transpile fails ✅ Available 29 tests Expression type not supported

Progress: 3/6 examples compile successfully with depyler compile (50%)

All examples include working Rust binaries (manual implementations) with 100% I/O equivalence validation.

Example 1: Simple CLI

Python (examples/example_simple/trivial_cli.py):

import argparse

def main():
    parser = argparse.ArgumentParser(description="A trivial CLI example")
    parser.add_argument("--name", type=str, required=True, help="Name to greet")
    args = parser.parse_args()
    print(f"Hello, {args.name}!")

if __name__ == "__main__":
    main()

Compile to Rust:

cd examples/example_simple
depyler compile trivial_cli.py -o trivial_cli

Validate Equivalence:

# Python version
python3 trivial_cli.py --name Alice
# Output: Hello, Alice!

# Rust version (51x faster!)
./trivial_cli --name Alice
# Output: Hello, Alice!

Performance Gains

Based on scientific benchmarking with 10 iterations, 3 warmup runs (see BENCHMARKS.md for full methodology):

Example Python (ms) Rust (ms) Speedup Memory Reduction
example_simple 22.34 2.49 8.98x 72.2%
example_flags 22.20 2.41 9.21x 72.0%
example_positional 22.10 2.42 9.12x 71.6%
example_subcommands 22.81 2.49 9.15x 71.4%
example_complex 23.24 2.59 8.96x 72.6%
example_stdlib 29.49 2.39 12.35x 81.1%
Average 23.70 2.47 9.63x 73.5%

Binary Size:

  • Python: ~11-16MB (interpreter + script runtime memory)
  • Rust: 760KB - 3.4MB (standalone binaries)

Quality Standards

This project follows extreme TDD with NASA-level quality standards:

  • 100% test coverage (enforced by pmat)
  • 85%+ mutation testing score
  • Complexity ≤10 (cyclomatic complexity per function)
  • TDG grade: B+ or higher
  • Zero SATD (self-admitted technical debt)
  • Performance regression detection (fails CI if >5% slower)

Quality Gates Enforced

All code passes through comprehensive quality gates:

# Run all quality gates (format → lint → test)
make quality

# Individual gates
make format      # Check code formatting (Python, Rust)
make lint        # Lint Python, Rust, shell scripts, Makefiles, Dockerfiles
make test        # Run all tests (37 tests, 81% coverage)

Linting with bashrs:

  • Shell scripts (shellcheck integration)
  • Makefiles (bashrs make purify for performance & best practices)
  • Dockerfiles (security & optimization checks)
  • Python (ruff)
  • Rust (clippy with -D warnings)

Pre-commit Hook

Install the pre-commit hook to enforce quality gates locally:

# Install hook (runs format + lint + test before every commit)
./scripts/install_hooks.sh

# Target: < 30 seconds

The hook ensures:

  • Code is properly formatted
  • All linters pass
  • All tests pass

Skip only when necessary: git commit --no-verify

Testing Strategy

Multi-layer testing approach with 230 total tests (192 Python + 38 Rust):

  1. Layer 1: Python Unit Tests (192 pytest cases + 100% coverage)
  2. Layer 2: Transpilation Validation (depyler compile success)
  3. Layer 3: I/O Equivalence (38 Rust integration tests - Python output == Rust output)
  4. Layer 4: Integration & Regression (cross-example validation)
# Fast tests (< 5 min)
make test-fast

# Comprehensive tests
make test-comprehensive

# I/O equivalence tests
make test-io-equivalence

Benchmarking

Scientific benchmarking following DLS 2016 and PLDI 2013 methodologies:

# Run all benchmarks
make bench-all

# Check for performance regressions
make bench-regression

# Generate visualizations and reports
make bench-visualize    # ASCII charts
make bench-charts       # PNG charts (requires matplotlib)
make bench-report       # Markdown report

See BENCHMARKS.md for full methodology and results.

Development

Prerequisites

  • Python 3.11+
  • Rust 1.75+
  • depyler v3.20.2+ (latest - adds depyler compile command with auto-dependency detection)
  • bashrs v6.32.0+ (for Makefile generation - optional)
  • pmat (for quality enforcement - optional)
  • uv (fast Python package manager)

Workflow

# 1. Create new example
mkdir -p examples/example_new

# 2. Write tests first (TDD)
vi examples/example_new/test_new_cli.py

# 3. Implement Python script
vi examples/example_new/new_cli.py

# 4. Run tests
cd examples/example_new
uv run pytest test_new_cli.py -v --cov

# 5. Transpile to Rust
depyler compile new_cli.py -o new_cli

# 6. Validate equivalence
make test-io-equivalence

# 7. Run quality gates
make quality-gate

Documentation

  • Tutorial - Comprehensive getting started guide (750+ lines)
  • Specification - Complete project specification (2,000+ lines)
  • CI/CD Pipeline - GitHub Actions workflow documentation (450+ lines)
  • Rust I/O Tests - Integration testing methodology (550+ lines)
  • Roadmap - Development roadmap with tickets
  • Status - Current progress and metrics (12/18 tickets complete)

Contributing

  1. All work is tracked via tickets in roadmap.yaml
  2. Follow extreme TDD: write tests before code
  3. All Makefiles are generated via bashrs (do not edit manually)
  4. Ensure all quality gates pass before submitting PR

Related Projects

License

MIT License - see LICENSE for details

Citation

If you use this framework in academic work, please cite:

@software{reprorusted_python_cli,
  title = {Reprorusted Python CLI: Argparse-to-Rust Compilation Validation},
  author = {PAIML},
  year = {2025},
  url = {https://github.com/paiml/reprorusted-python-cli}
}

Contact

About

Converts Python Argparse CLI scripts to single-shot compiled Rust binary

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published