|
| 1 | +# Python-mode Ruff Migration Plan |
| 2 | + |
| 3 | +## Executive Summary |
| 4 | + |
| 5 | +This document outlines a comprehensive plan to replace most of the python-mode submodules with Ruff, a blazingly fast Python linter and formatter written in Rust. The migration will reduce complexity, improve performance, and modernize the codebase while preserving essential functionality. |
| 6 | + |
| 7 | +## Current State Analysis |
| 8 | + |
| 9 | +### Submodules to be Replaced by Ruff (7 total): |
| 10 | +- **pyflakes** - Syntax errors and undefined names detection |
| 11 | +- **pycodestyle** - PEP 8 style guide enforcement |
| 12 | +- **mccabe** - Cyclomatic complexity checking |
| 13 | +- **pylint** - Comprehensive static analysis |
| 14 | +- **pydocstyle** - Docstring style checking |
| 15 | +- **pylama** - Multi-tool linting wrapper |
| 16 | +- **autopep8** - Automatic PEP 8 formatting |
| 17 | + |
| 18 | +### Submodules to Keep (7 total): |
| 19 | +- **rope** - Refactoring, completion, and code intelligence *(essential for IDE features)* |
| 20 | +- **astroid** - Abstract syntax tree library *(dependency of rope)* |
| 21 | +- **toml** / **tomli** - TOML configuration parsing *(may be needed)* |
| 22 | +- **pytoolconfig** - Tool configuration management *(evaluate necessity)* |
| 23 | +- **appdirs** - Application directory paths *(evaluate necessity)* |
| 24 | +- **snowballstemmer** - Text stemming *(used by pydocstyle, may remove)* |
| 25 | + |
| 26 | +## Migration Plan |
| 27 | + |
| 28 | +### Phase 1: Replace Core Linting Infrastructure |
| 29 | +**Timeline: 2-3 weeks** |
| 30 | + |
| 31 | +#### Task 1.1: Create Ruff Integration Module |
| 32 | +- [x] Create `pymode/ruff_integration.py` |
| 33 | +- [x] Implement `run_ruff_check()` function |
| 34 | +- [x] Implement `run_ruff_format()` function |
| 35 | +- [x] Handle ruff subprocess execution and error parsing |
| 36 | +- [x] Convert ruff JSON output to vim-compatible format |
| 37 | + |
| 38 | +#### Task 1.2: Update Configuration System |
| 39 | +- [x] Map existing `g:pymode_lint_checkers` to ruff rule selection |
| 40 | +- [x] Convert `g:pymode_lint_ignore` patterns to ruff ignore rules |
| 41 | +- [x] Convert `g:pymode_lint_select` patterns to ruff select rules |
| 42 | +- [x] Handle tool-specific options (mccabe complexity, etc.) |
| 43 | +- [x] Create configuration validation |
| 44 | + |
| 45 | +#### Task 1.3: Modify Core Files |
| 46 | +- [x] Update `pymode/lint.py` - replace pylama integration |
| 47 | +- [x] Update `pymode/__init__.py` - replace autopep8 import |
| 48 | +- [x] Update `autoload/pymode/lint.vim` - modify VimScript functions |
| 49 | +- [x] Ensure async linting compatibility |
| 50 | +- [x] Preserve error reporting format |
| 51 | + |
| 52 | +### Phase 2: Update Build and Distribution |
| 53 | +**Timeline: 1 week** |
| 54 | + |
| 55 | +#### Task 2.1: Remove Submodules |
| 56 | +- [ ] Remove from `.gitmodules`: |
| 57 | + - `submodules/pyflakes` |
| 58 | + - `submodules/pycodestyle` |
| 59 | + - `submodules/mccabe` |
| 60 | + - `submodules/pylint` |
| 61 | + - `submodules/pydocstyle` |
| 62 | + - `submodules/pylama` |
| 63 | + - `submodules/autopep8` |
| 64 | +- [ ] Clean up submodule references in git |
| 65 | +- [ ] Update repository size documentation |
| 66 | + |
| 67 | +#### Task 2.2: Update Installation Requirements |
| 68 | +- [ ] Add ruff as external dependency requirement |
| 69 | +- [ ] Update installation documentation in README.md |
| 70 | +- [ ] Modify `Dockerfile` and `Dockerfile.base` to include ruff |
| 71 | +- [ ] Update `docker-compose.yml` if needed |
| 72 | +- [ ] Create installation verification script |
| 73 | + |
| 74 | +#### Task 2.3: Update Path Management |
| 75 | +- [ ] Modify `pymode/utils.py` `patch_paths()` function |
| 76 | +- [ ] Remove submodule path additions for replaced tools |
| 77 | +- [ ] Keep paths for remaining tools (rope, toml, etc.) |
| 78 | +- [ ] Test path resolution on different platforms |
| 79 | + |
| 80 | +### Phase 3: Configuration Migration |
| 81 | +**Timeline: 1 week** |
| 82 | + |
| 83 | +#### Task 3.1: Create Ruff Configuration Mapping |
| 84 | +- [ ] Map current settings to ruff equivalents: |
| 85 | + ``` |
| 86 | + g:pymode_lint_checkers -> ruff select rules |
| 87 | + g:pymode_lint_ignore -> ruff ignore patterns |
| 88 | + g:pymode_lint_select -> ruff select patterns |
| 89 | + g:pymode_lint_options_* -> ruff tool-specific config |
| 90 | + ``` |
| 91 | +- [ ] Create configuration converter utility |
| 92 | +- [ ] Document configuration changes |
| 93 | + |
| 94 | +#### Task 3.2: Add New Configuration Options |
| 95 | +- [ ] Add ruff-specific VimScript options: |
| 96 | + ```vim |
| 97 | + g:pymode_ruff_enabled |
| 98 | + g:pymode_ruff_select |
| 99 | + g:pymode_ruff_ignore |
| 100 | + g:pymode_ruff_format_enabled |
| 101 | + g:pymode_ruff_config_file |
| 102 | + ``` |
| 103 | +- [ ] Update default configurations |
| 104 | +- [ ] Add configuration validation |
| 105 | + |
| 106 | +### Phase 4: Preserve Advanced Features |
| 107 | +**Timeline: 1 week** |
| 108 | + |
| 109 | +#### Task 4.1: Keep Rope Integration |
| 110 | +- [ ] Maintain rope submodule |
| 111 | +- [ ] Keep astroid dependency if required by rope |
| 112 | +- [ ] Preserve all rope functionality: |
| 113 | + - Code completion |
| 114 | + - Go to definition |
| 115 | + - Refactoring operations |
| 116 | + - Auto-imports |
| 117 | +- [ ] Test rope integration with new ruff setup |
| 118 | + |
| 119 | +#### Task 4.2: Handle Configuration Dependencies |
| 120 | +- [ ] Evaluate toml/tomli necessity for ruff config |
| 121 | +- [ ] Assess pytoolconfig requirement |
| 122 | +- [ ] Determine if appdirs is still needed |
| 123 | +- [ ] Remove snowballstemmer if pydocstyle is replaced |
| 124 | +- [ ] Update dependency documentation |
| 125 | + |
| 126 | +### Phase 5: Testing and Validation |
| 127 | +**Timeline: 2-3 weeks** |
| 128 | + |
| 129 | +#### Task 5.1: Update Test Suite |
| 130 | +- [ ] Modify `tests/test_bash/test_autopep8.sh` for ruff formatting |
| 131 | +- [ ] Update `tests/test_procedures_vimscript/autopep8.vim` |
| 132 | +- [ ] Create comprehensive ruff integration tests |
| 133 | +- [ ] Test error handling and edge cases |
| 134 | +- [ ] Ensure all existing functionality works |
| 135 | + |
| 136 | +#### Task 5.2: Performance Validation |
| 137 | +- [ ] Benchmark ruff vs. current tools |
| 138 | +- [ ] Measure linting speed improvements |
| 139 | +- [ ] Verify memory usage reduction |
| 140 | +- [ ] Ensure async linting performance |
| 141 | +- [ ] Test with large codebases |
| 142 | + |
| 143 | +#### Task 5.3: Compatibility Testing |
| 144 | +- [ ] Test with Python versions 3.10-3.13 |
| 145 | +- [ ] Verify Docker environment compatibility |
| 146 | +- [ ] Test on Linux, macOS, Windows |
| 147 | +- [ ] Test with different Vim/Neovim versions |
| 148 | +- [ ] Validate plugin manager compatibility |
| 149 | + |
| 150 | +### Phase 6: Documentation and Migration |
| 151 | +**Timeline: 1-2 weeks** |
| 152 | + |
| 153 | +#### Task 6.1: Update Documentation |
| 154 | +- [ ] Update `doc/pymode.txt` with ruff information |
| 155 | +- [ ] Create migration guide from old configuration |
| 156 | +- [ ] Document new ruff-specific features |
| 157 | +- [ ] Update README.md with new requirements |
| 158 | +- [ ] Add troubleshooting section |
| 159 | + |
| 160 | +#### Task 6.2: Provide Migration Tools |
| 161 | +- [ ] Create configuration converter script |
| 162 | +- [ ] Implement backward compatibility warnings |
| 163 | +- [ ] Document breaking changes clearly |
| 164 | +- [ ] Provide rollback instructions |
| 165 | +- [ ] Create migration validation script |
| 166 | + |
| 167 | +#### Task 6.3: Release Strategy |
| 168 | +- [ ] Plan release as major version (0.15.0) |
| 169 | +- [ ] Prepare changelog with breaking changes |
| 170 | +- [ ] Create upgrade documentation |
| 171 | +- [ ] Consider maintaining compatibility branch |
| 172 | +- [ ] Plan communication strategy |
| 173 | + |
| 174 | +## Expected Benefits |
| 175 | + |
| 176 | +### Performance Improvements |
| 177 | +- **10-100x faster linting** compared to current tool combination |
| 178 | +- **Reduced memory usage** by eliminating multiple tool processes |
| 179 | +- **Single tool coordination** instead of managing multiple linters |
| 180 | +- **Near-instantaneous feedback** for developers |
| 181 | + |
| 182 | +### Maintenance Benefits |
| 183 | +- **7 fewer submodules** to maintain and update |
| 184 | +- **Unified configuration** instead of multiple tool configs |
| 185 | +- **Simplified dependency management** |
| 186 | +- **Easier troubleshooting** with single tool |
| 187 | + |
| 188 | +### User Experience |
| 189 | +- **Faster development workflow** |
| 190 | +- **Consistent linting behavior** |
| 191 | +- **Modern linting rules and features** |
| 192 | +- **Better error messages and suggestions** |
| 193 | + |
| 194 | +## Risk Assessment |
| 195 | + |
| 196 | +### High Priority Risks |
| 197 | +| Risk | Impact | Probability | Mitigation | |
| 198 | +|------|--------|-------------|------------| |
| 199 | +| Configuration breaking changes | High | High | Provide migration tools and compatibility warnings | |
| 200 | +| Performance regression in edge cases | Medium | Low | Comprehensive benchmarking and testing | |
| 201 | +| Feature gaps vs. current tools | Medium | Medium | Document differences and provide alternatives | |
| 202 | + |
| 203 | +### Medium Priority Risks |
| 204 | +| Risk | Impact | Probability | Mitigation | |
| 205 | +|------|--------|-------------|------------| |
| 206 | +| User adoption resistance | Medium | Medium | Clear communication of benefits and smooth migration | |
| 207 | +| Integration issues with existing workflows | Medium | Low | Extensive compatibility testing | |
| 208 | +| Ruff dependency management | Low | Low | Document installation requirements clearly | |
| 209 | + |
| 210 | +## Success Metrics |
| 211 | + |
| 212 | +### Performance Metrics |
| 213 | +- [ ] Linting speed improvement: Target 10x faster minimum |
| 214 | +- [ ] Memory usage reduction: Target 50% reduction |
| 215 | +- [ ] Plugin load time: No regression |
| 216 | + |
| 217 | +### Quality Metrics |
| 218 | +- [ ] All existing tests pass |
| 219 | +- [ ] No regression in error detection capability |
| 220 | +- [ ] User configuration migration success rate >95% |
| 221 | + |
| 222 | +### Adoption Metrics |
| 223 | +- [ ] Documentation completeness score >90% |
| 224 | +- [ ] User migration guide effectiveness |
| 225 | +- [ ] Issue resolution time improvement |
| 226 | + |
| 227 | +## Timeline Summary |
| 228 | + |
| 229 | +| Phase | Duration | Key Deliverables | |
| 230 | +|-------|----------|------------------| |
| 231 | +| Phase 1 | 2-3 weeks | Ruff integration module, core file updates | |
| 232 | +| Phase 2 | 1 week | Submodule removal, build system updates | |
| 233 | +| Phase 3 | 1 week | Configuration migration system | |
| 234 | +| Phase 4 | 1 week | Advanced feature preservation | |
| 235 | +| Phase 5 | 2-3 weeks | Comprehensive testing and validation | |
| 236 | +| Phase 6 | 1-2 weeks | Documentation and release preparation | |
| 237 | +| **Total** | **7-10 weeks** | **Full ruff migration complete** | |
| 238 | + |
| 239 | +## Conclusion |
| 240 | + |
| 241 | +This migration plan will significantly modernize python-mode by replacing 7 legacy submodules with a single, fast, modern tool while preserving essential features like rope integration. The result will be a faster, more maintainable, and more user-friendly Python development environment in Vim. |
| 242 | + |
| 243 | +The structured approach ensures minimal disruption to existing users while providing substantial performance and maintenance benefits. The comprehensive testing and documentation phases will ensure a smooth transition for the entire python-mode community. |
0 commit comments