Skip to content

velo4705/polyglot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Polyglot - Universal Compiler Wrapper

CI License: MIT Go Version Version

A universal compiler and interpreter wrapper that detects programming languages by file extension and executes them with the appropriate toolchain.

🎉 Version 1.1.0 - Improved UX!

✨ Features

  • 🌍 30+ Languages - Python, JavaScript, Go, Java, C, C++, Rust, Ruby, PHP, and more
  • 🔍 Auto-Detection - Automatically detects language from file extension
  • 📦 Auto-Install - Installs missing toolchains via system package manager
  • ⚙️ Configurable - Global and per-project configuration
  • 👀 Watch Mode - Auto-rerun on file changes
  • 🎨 Colored Output - Beautiful terminal output with progress indicators
  • 🔧 Custom Extensions - Map any extension to any language
  • 🚀 Fast - Minimal overhead, efficient execution
  • 🐳 Docker Ready - Pre-built images with common runtimes
  • 📚 Well Documented - Comprehensive guides and examples

🚀 Quick Start

Installation

Quick Install (one-liner):

curl -sSL https://raw.githubusercontent.com/velo4705/polyglot/main/scripts/install.sh | bash

Or install from source:

git clone https://github.com/velo4705/polyglot.git
cd polyglot
make build
sudo make install

Docker:

git clone https://github.com/velo4705/polyglot.git
cd polyglot
docker build -t polyglot .

# Run a file
docker run -v $(pwd):/workspace polyglot -h

Usage

# Run any supported file
polyglot run hello.py
polyglot run main.go
polyglot run app.js

# Watch mode (auto-rerun on changes)
polyglot watch hello.py

# Dry run (see what would execute)
polyglot run --dry-run hello.c

# List supported languages
polyglot list

# Check installed toolchains
polyglot check

# Update to latest version
polyglot update

# Show version
polyglot version

📖 Documentation

🌟 Supported Languages

Interpreted (16)

Python • JavaScript • Ruby • PHP • Perl • Lua • Shell • Elixir • Erlang • Groovy • R • Julia • Haskell • OCaml • TypeScript • Dart

Compiled (14)

Go • Java • C • C++ • Rust • Zig • Nim • Crystal • D • Haskell • OCaml • F# • Kotlin • Scala • Swift

Esoteric (1)

Brainfuck

Total: 30 languages with 45+ file extensions

💡 Examples

Basic Usage

# Python
$ polyglot run hello.py
ℹ Detected: Python
→ Executing: python3 hello.py
Hello from Python!

# Go
$ polyglot run main.go
ℹ Detected: Go
→ Executing: go run main.go
Hello from Go!

# C (with compilation)
$ polyglot run hello.c
ℹ Detected: C
→ Compiling hello.c...
✓ Compilation successful
→ Executing: ./hello
Hello from C!

Watch Mode

$ polyglot watch app.js
👀 Watching app.js for changes...

→ Executing: node app.js
Server running on port 3000

# Edit file and save...

🔄 File changed: app.js
──────────
→ Executing: node app.js
Server running on port 3000
✓ Completed in 45ms

Configuration

# .polyglot.yaml
languages:
  python:
    command: python3.11
    flags:
      - "-O"
    environment:
      PYTHONPATH: "./lib"

custom_extensions:
  .pyx: Python
  .jsx: JavaScript

environment:
  NODE_ENV: "development"

🎯 Use Cases

Development

  • Rapid Prototyping - Test code in any language instantly
  • Learning - Experiment with new languages easily
  • Polyglot Projects - Work with multiple languages seamlessly

DevOps

  • CI/CD - Run tests in any language
  • Automation - Script in your preferred language
  • Deployment - Execute deployment scripts

Education

  • Teaching - Support students using different languages
  • Assignments - Grade code in any language
  • Workshops - Quick setup for participants

🔧 Configuration

Global Configuration

# Initialize config
polyglot config init

# Enable auto-install
polyglot config set auto_install.enabled true

# Set Python version
polyglot config set languages.python.version 3.11

Project Configuration

Create .polyglot.yaml in your project:

auto_install:
  enabled: true
  prompt: false

languages:
  python:
    enabled: true
    version: "3.11"
  
  javascript:
    enabled: true
    environment:
      NODE_ENV: "development"

custom_extensions:
  .pyx: Python
  .jsx: JavaScript

🐳 Docker

Polyglot comes with Docker support including common language runtimes.

Build Image

# Clone the repository first
git clone https://github.com/velo4705/polyglot.git
cd polyglot

# Build the image
docker build -t polyglot .

Usage Examples

Run files from your current directory:

# Create a test file
echo 'print("Hello from Docker!")' > hello.py

# Run it with polyglot in Docker
docker run -v $(pwd):/workspace polyglot run hello.py

# Run JavaScript
echo 'console.log("Hello from Docker!");' > hello.js
docker run -v $(pwd):/workspace polyglot run hello.js

# Run with arguments
docker run -v $(pwd):/workspace polyglot run script.py arg1 arg2

Interactive shell with all languages:

# Start development container
docker-compose up -d polyglot-dev
docker-compose exec polyglot-dev bash

# Now you're inside the container with all languages available
polyglot list
polyglot run hello.py
exit

Quick commands:

# List supported languages
docker run polyglot list

# Check version
docker run polyglot version

# Get help
docker run polyglot --help

Included Languages

The Docker image includes: Python, Node.js, Ruby, PHP, Perl, Lua, Bash, GCC, G++, and Go.

📊 Performance

  • Detection: <1ms
  • Python Execution: ~50ms
  • Go Execution: ~200ms (includes compilation)
  • Config Load: <5ms
  • Memory: ~10MB base

🧪 Testing

# Run all tests
./scripts/run-tests.sh

# Unit tests only
go test ./internal/... ./pkg/... -v

# Integration tests
go test ./test/... -v

# Benchmarks
go test ./test/... -bench=. -benchmem

Test Coverage: 85%+

🤝 Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

Quick Contribution Guide

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests
  5. Run tests (./scripts/run-tests.sh)
  6. Commit (git commit -m 'Add amazing feature')
  7. Push (git push origin feature/amazing-feature)
  8. Open a Pull Request

Adding a New Language

See CONTRIBUTING.md for detailed instructions.

📜 License

MIT License - see LICENSE file for details.

🙏 Acknowledgments

  • Built with Go
  • CLI powered by Cobra
  • Configuration with YAML

⭐ Star History

If you find Polyglot useful, please consider giving it a star! ⭐


Made with ❤️ by the Polyglot community

Version: 1.0.0 | Status: Production Ready | License: MIT

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors