Skip to content

VenkateshSrini/python-upgrader-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Python Upgrader Bot# πŸš€ Python Upgrader Bot# Python Migration & Modernization Toolkit

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!

πŸ› οΈ Installation


  1. 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
  1. Verify installation:
    python -m pytest test/

🎯 Quick Start

Basic Usage

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")

Interactive Demo

Run the comprehensive demo to see all tools in action:

python demo_ai_tools.py

πŸ”§ AI Tools Details

PyUpgradeTool

Purpose: 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 | int

Python2To3Tool

Purpose: 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: ")

ModernizeTool

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 consistently

πŸ§ͺ Testing

The 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

πŸ“Š Analysis Capabilities

Version Detection

  • Automatically detects minimum Python version requirements
  • Identifies version-specific syntax and features
  • Provides detailed compatibility reports

Code Pattern Recognition

  • Identifies outdated patterns and practices
  • Suggests modern alternatives
  • Provides migration recommendations

πŸ”Œ Integration

LangChain Compatibility

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")

Custom Workflows

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)

πŸ“š Documentation

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all tests pass
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published