Code Formatting Guide
This document explains how to format code in the GambitPairing project.
Quick Start
Using the Python Script (#1)
Run the formatting script directly with:
python3 {{git root}}/format_project.py
Or make it executable and run directly:
chmod +x format_project.py ./format_project.py
Manual Execution
If you prefer to run the formatting script manually:
python3 format_project.py --target src/gambitpairing
What Gets Formatted
The formatting script processes all Python files in the src/gambitpairing directory and applies:
- Code style formatting
- Import sorting
Requirements
- everything + dev dependencies in pyproject.toml
Troubleshooting
Permission Denied (Unix/Linux/macOS)
chmod +x format.py
Python Not Found
Make sure Python 3 is installed and available in your PATH:
python3 --version
IDE Integration
VS Code
Add this to your VS Code settings to run formatting automatically:
{ "python.formatting.provider": "black", "editor.formatOnSave": true, "python.sortImports.args": ["--profile", "black"] }
PyCharm
- Go to Settings → Tools → External Tools
- Add a new tool with:
- Program:
python3 - Arguments:
$ProjectFileDir$/format.py - Working directory:
$ProjectFileDir$
- Program:
Pre-commit Hook (Optional)
Best Practices
- Format before committing - Always run the formatter before pushing code
- Team consistency - All team members should use the same formatting configuration
- Editor configuration - Set up your editor to format on save for immediate feedback
Getting Help
If you encounter issues with formatting:
- Check that all dependencies are installed
- Verify you're in the correct directory
- Examine the output of the formatting script for error messages
- Consult the documentation for the specific formatting tools being used