A comprehensive AI-powered toolkit for migrating and modernizing Python code using real industry-standard tools.
β‘ Quick StartA comprehensive AI-powered toolkit for migrating and modernizing Python code using real industry-standard tools.A comprehensive AI-powered toolkit for analyzing, migrating, and modernizing Python code. This project combines traditional analysis tools with cutting-edge AI capabilities to provide intelligent code transformation.
python run.py
```## β‘ Quick Start## π Features
That's it! The system will analyze, migrate, and modernize your Python code automatically.
## π― What It Does```bash### Core Analysis
- **Analyzes** Python projects for version compatibilitypython run.py- **Version Detection**: Automatically detect Python version requirements from code
- **Detects** Python 2.x code automatically
- **Applies** real migration tools (pyupgrade, lib2to3, modernize)```- **Compatibility Analysis**: Identify version-specific issues and requirements
- **Uses** LLM guidance for intelligent error resolution
- **Stores** final migrated files in clean OUTPUT_DIR structure- **Dependency Analysis**: Track and analyze package dependencies
## π DocumentationThat's it! The system will analyze, migrate, and modernize your Python code automatically.
π **[Complete Documentation](document/COMPREHENSIVE_DOCUMENTATION.md)** π### Direct Tool Integration + AI Analysis
Everything you need is in one comprehensive guide:## π― What It Does- **PyUpgrade Tool**: Uses actual `pyupgrade` command-line tool + AI fallback
- Quick start guide
- Technical implementation details- **Python 2 to 3 Migration**: Uses `lib2to3` engine + pattern-based migration
- Migration process explanation
- Configuration options- **Analyzes** Python projects for version compatibility- **Compatibility Modernization**: Uses `python-modernize` + smart fallbacks
- Troubleshooting guide
- Real-world examples- **Detects** Python 2.x code automatically
## π Project Structure- **Applies** real migration tools (pyupgrade, lib2to3, modernize)### Key Capabilities
```- **Uses** LLM guidance for intelligent error resolution- π§ **Direct Tool Integration**: Uses actual pyupgrade, lib2to3, and python-modernize
py-upgrade-bot/
βββ run.py # π PRIMARY LAUNCHER- **Stores** final migrated files in clean OUTPUT_DIR structure- π€ **Smart Fallbacks**: AI-powered analysis when tools unavailable
βββ src/ # Core application code
βββ document/ # π Complete documentation- π **Comprehensive Reporting**: Detailed analysis and recommendations
β βββ COMPREHENSIVE_DOCUMENTATION.md # Everything you need
βββ test-project/upgraded/ # Migration results## π Complete Documentation- π§ͺ **Extensive Testing**: Complete test coverage for all tools
βββ requirements.txt # Dependencies
```- π **Rich Documentation**: Comprehensive guides and examples
## π Ready to Migrate?π **[See Complete Documentation](document/COMPREHENSIVE_DOCUMENTATION.md)** π- β‘ **Reliable Results**: Battle-tested transformations using industry standards
```bash
python run.py
```Everything you need is in the comprehensive documentation:## π Project Structure
Check `test-project/upgraded/final_migrated_code/` for your migrated Python files!- Detailed usage guide
---- Technical implementation```
*For complete documentation: [document/COMPREHENSIVE_DOCUMENTATION.md](document/COMPREHENSIVE_DOCUMENTATION.md)*- Configuration options py-upgrade-bot/
- Troubleshootingβββ src/
- Real-world examplesβ βββ app_py_version/
β βββ __init__.py # Package exports
## π Project Structureβ βββ version_analyzer.py # Core analysis engine
β βββ prompt_library.py # Centralized AI prompts
```β βββ ai_tools/ # AI migration tools
py-upgrade-bot/β βββ __init__.py
βββ run.py # π PRIMARY LAUNCHERβ βββ pyupgrade_tool.py # Python syntax modernization
βββ src/ # Core application codeβ βββ python2to3_tool.py # Python 2 β 3 migration
βββ document/ # π Complete documentationβ βββ modernize_tool.py # 2/3 compatibility
βββ test-project/upgraded/ # Migration resultsβββ test/
βββ requirements.txt # Dependenciesβ βββ test_prompt_library.py # Prompt library tests
```β βββ test_ai_tools.py # AI tools test suite
βββ document/
## π Ready to Migrate?β βββ ai-tools-guide.md # Comprehensive documentation
βββ demo_ai_tools.py # Interactive demo script
```bashβββ requirements.txt # Project dependencies
python run.pyβββ config.py # Configuration settings
```βββ llm_manager.py # AI/LLM integration
Check test-project/upgraded/final_migrated_code/ for your migrated Python files!
- Clone the repository:
For complete documentation, configuration, and troubleshooting: document/COMPREHENSIVE_DOCUMENTATION.md ```bash git clone cd py-upgrade-bot
2. **Install dependencies**:
```bash
pip install -r requirements.txt
- Verify installation:
python -m pytest test/
from src.app_py_version.ai_tools import PyUpgradeTool, Python2To3Tool, ModernizeTool
# Modernize Python code to latest syntax
pyupgrade = PyUpgradeTool(target_version="3.11")
modern_code = pyupgrade.run("old_code_here")
# Migrate Python 2 to Python 3
migration = Python2To3Tool()
python3_code = migration.run("python2_code_here")
# Create 2/3 compatible code
compatibility = ModernizeTool()
compatible_code = compatibility.run("code_needing_compatibility")Run the comprehensive demo to see all tools in action:
python demo_ai_tools.pyPurpose: Uses the actual pyupgrade command-line tool for reliable modernization
- Converts old string formatting to f-strings
- Updates Union types to use
|operator (Python 3.10+) - Removes unnecessary
__future__imports - Optimizes for target Python version
- Falls back to pattern-based processing when tool unavailable
Example:
# Input
message = "Hello, {}!".format(name)
Union[str, int]
# Output (using real pyupgrade)
message = f"Hello, {name}!"
str | intPurpose: Uses lib2to3 engine (same as 2to3 command) for reliable migration
- Converts print statements to print functions
- Updates exception handling syntax
- Migrates import statements (urllib2 β urllib.request)
- Replaces deprecated functions (raw_input β input, xrange β range)
- Falls back to pattern-based migration when lib2to3 unavailable
Example:
# Input (Python 2)
print "Hello, World!"
import urllib2
name = raw_input("Name: ")
# Output (Python 3 using lib2to3)
print("Hello, World!")
import urllib.request
name = input("Name: ")Purpose: Uses python-modernize tool for reliable 2/3 compatibility
- Adds appropriate
from __future__imports - Handles division behavior differences
- Manages string/unicode compatibility
- Creates code that works on both Python 2.7+ and 3.x
- Falls back to pattern-based processing when tool unavailable
Example:
# Input
print "Starting..."
result = 5 / 2
# Output (using python-modernize)
from __future__ import division, print_function
print("Starting...")
result = 5 / 2 # Now behaves consistentlyThe project includes comprehensive test coverage:
# Run all tests
python -m pytest test/
# Run specific test file
python -m pytest test/test_ai_tools.py -v
# Test with coverage
python -m pytest test/ --cov=src/app_py_version- Automatically detects minimum Python version requirements
- Identifies version-specific syntax and features
- Provides detailed compatibility reports
- Identifies outdated patterns and practices
- Suggests modern alternatives
- Provides migration recommendations
All AI tools are built as LangChain BaseTool implementations:
from langchain.agents import initialize_agent
from src.app_py_version.ai_tools import PyUpgradeTool
tools = [PyUpgradeTool(target_version="3.11")]
agent = initialize_agent(tools, llm, agent="zero-shot-react-description")Tools can be easily integrated into custom analysis workflows:
# Create analysis pipeline
analyzer = VersionAnalyzer()
pyupgrade = PyUpgradeTool()
# Analyze and modernize
analysis = analyzer.analyze_code(code)
modernized = pyupgrade.run(code)- AI Tools Guide: Comprehensive tool documentation
- API Reference: Detailed code documentation
- Test Examples: Usage examples and test cases
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with LangChain for AI tool integration
- Uses pyupgrade, modernize, and other excellent Python tools
- Inspired by the Python community's commitment to code quality and maintainability
Ready to modernize your Python code? Get started with the demo!
python demo_ai_tools.py