|
| 1 | +# Contributing to pycodify |
| 2 | + |
| 3 | +Thank you for your interest in contributing to pycodify! This document provides guidelines for development, testing, and submission. |
| 4 | + |
| 5 | +## Development Setup |
| 6 | + |
| 7 | +### Prerequisites |
| 8 | +- Python 3.10+ |
| 9 | +- Git |
| 10 | + |
| 11 | +### Installation |
| 12 | + |
| 13 | +```bash |
| 14 | +# Clone the repository |
| 15 | +git clone https://github.com/OpenHCSDev/pycodify.git |
| 16 | +cd pycodify |
| 17 | + |
| 18 | +# Create virtual environment |
| 19 | +python -m venv venv |
| 20 | +source venv/bin/activate # On Windows: venv\Scripts\activate |
| 21 | + |
| 22 | +# Install in development mode with all dependencies |
| 23 | +pip install -e ".[dev,docs]" |
| 24 | +``` |
| 25 | + |
| 26 | +## Code Style |
| 27 | + |
| 28 | +pycodify follows strict code quality standards: |
| 29 | + |
| 30 | +### Formatting |
| 31 | +- **Black**: Code formatting (line length: 100) |
| 32 | +- **Ruff**: Linting and import sorting |
| 33 | +- **MyPy**: Static type checking |
| 34 | + |
| 35 | +```bash |
| 36 | +# Format code |
| 37 | +black src/ tests/ |
| 38 | + |
| 39 | +# Lint |
| 40 | +ruff check src/ tests/ |
| 41 | + |
| 42 | +# Type check |
| 43 | +mypy src/ |
| 44 | +``` |
| 45 | + |
| 46 | +### Docstrings |
| 47 | +- Use Google-style docstrings |
| 48 | +- Include type hints in function signatures |
| 49 | +- Document all public APIs |
| 50 | + |
| 51 | +## Testing |
| 52 | + |
| 53 | +### Running Tests |
| 54 | + |
| 55 | +```bash |
| 56 | +# Run all tests |
| 57 | +pytest tests/ -v |
| 58 | + |
| 59 | +# Run with coverage |
| 60 | +pytest tests/ --cov=src/pycodify --cov-report=html |
| 61 | + |
| 62 | +# Run specific test file |
| 63 | +pytest tests/test_core.py -v |
| 64 | +``` |
| 65 | + |
| 66 | +### Test Requirements |
| 67 | +- Minimum 80% code coverage |
| 68 | +- All tests must pass before submission |
| 69 | +- Use pytest fixtures for setup/teardown |
| 70 | +- Test both collection and regeneration passes |
| 71 | + |
| 72 | +## Submitting Changes |
| 73 | + |
| 74 | +### Before Submitting |
| 75 | +1. Ensure all tests pass: `pytest tests/` |
| 76 | +2. Format code: `black src/ tests/` |
| 77 | +3. Run linter: `ruff check src/ tests/` |
| 78 | +4. Type check: `mypy src/` |
| 79 | +5. Update documentation if needed |
| 80 | + |
| 81 | +### Pull Request Process |
| 82 | +1. Create a feature branch: `git checkout -b feature/your-feature` |
| 83 | +2. Make your changes with clear commit messages |
| 84 | +3. Push to your fork and create a Pull Request |
| 85 | +4. Ensure CI/CD checks pass |
| 86 | +5. Request review from maintainers |
| 87 | + |
| 88 | +### Commit Message Format |
| 89 | +``` |
| 90 | +<type>: <subject> |
| 91 | +
|
| 92 | +<body> |
| 93 | +
|
| 94 | +<footer> |
| 95 | +``` |
| 96 | + |
| 97 | +Types: `feat`, `fix`, `docs`, `style`, `refactor`, `test`, `chore` |
| 98 | + |
| 99 | +## Documentation |
| 100 | + |
| 101 | +### Building Docs Locally |
| 102 | + |
| 103 | +```bash |
| 104 | +cd docs |
| 105 | +make html |
| 106 | +# Open build/html/index.html in browser |
| 107 | +``` |
| 108 | + |
| 109 | +### Documentation Standards |
| 110 | +- Update README.md for user-facing changes |
| 111 | +- Update docstrings for API changes |
| 112 | +- Add examples for new features |
| 113 | +- Document the two-pass algorithm for custom formatters |
| 114 | + |
| 115 | +## Architecture Notes |
| 116 | + |
| 117 | +pycodify uses a two-pass algorithm: |
| 118 | +1. **Collection Pass**: Traverse object, emit code fragments, collect imports |
| 119 | +2. **Resolution Pass**: Detect collisions, generate aliases, regenerate code |
| 120 | + |
| 121 | +Custom formatters should inherit from `SourceFormatter` and implement: |
| 122 | +- `can_format(value)`: Check if formatter handles this type |
| 123 | +- `format(value, context)`: Return SourceFragment with code and imports |
| 124 | + |
| 125 | +## Questions? |
| 126 | + |
| 127 | +- Open an issue for bugs or feature requests |
| 128 | +- Check existing issues before creating new ones |
| 129 | +- Use discussions for questions |
| 130 | + |
| 131 | +## License |
| 132 | + |
| 133 | +By contributing, you agree that your contributions will be licensed under the MIT License. |
| 134 | + |
0 commit comments