Skip to content

Contributing

Thank you for your interest in contributing to this modern Python package template! This guide will help you get started.

๐ŸŽฏ Overview

This cookiecutter template helps developers create modern Python packages with best practices built-in. We welcome contributions that:

  • Improve the template quality and usability
  • Add support for new tools and practices
  • Fix bugs and issues
  • Enhance documentation
  • Add comprehensive tests

๐Ÿš€ Quick Start

  1. Fork and Clone

    git clone https://github.com/s-celles/cookiecutter-python-package.git
    cd cookiecutter-python-package
    

  2. Set Up Development Environment

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    pip install -e ".[dev]"
    

  3. Install Pre-commit Hooks

    pre-commit install
    pre-commit install --hook-type commit-msg
    

  4. Run Tests

    make test
    # Or manually:
    pytest
    

๐Ÿ› ๏ธ Development Workflow

Making Changes

  1. Create a Feature Branch

    git checkout -b feature/your-feature-name
    

  2. Make Your Changes

  3. Template files are in {{cookiecutter.project_slug}}/
  4. Template configuration is in cookiecutter.json
  5. Hooks are in hooks/
  6. Tests are in tests/

  7. Test Your Changes

    # Run all tests
    make test
    
    # Test template generation
    make bake-test
    
    # Run quality checks
    make check
    

  8. Commit Your Changes

    git add .
    git commit -m "feat: add new feature"
    

Testing Template Changes

When modifying the template, always test:

  1. Template Generation

    cookiecutter . --no-input
    

  2. Different Configurations

    # Test minimal config
    cookiecutter . --no-input use_ruff=n use_mypy=n
    
    # Test full config
    cookiecutter . --no-input use_ruff=y use_mypy=y use_github_actions=y
    

  3. Generated Project Quality

    cd generated-project/
    pip install -e ".[dev]"
    pytest
    ruff check .
    mypy src/
    

๐Ÿ“‹ Types of Contributions

๐Ÿ”ง Template Improvements

  • Adding New Tools: Update cookiecutter.json, template files, and documentation
  • Improving Configurations: Enhance tool configurations for better defaults
  • File Structure: Improve the generated project structure

๐Ÿงช Testing

  • Template Tests: Add tests for template generation and validation
  • Generated Project Tests: Ensure generated projects work correctly
  • Edge Cases: Test unusual configurations and inputs

๐Ÿ“š Documentation

  • Usage Examples: Add more usage examples and configurations
  • Tool Explanations: Improve documentation with better explanations
  • README Updates: Keep documentation current and comprehensive

๐Ÿ› Bug Fixes

  • Template Issues: Fix problems with template generation
  • Configuration Bugs: Fix issues with tool configurations
  • Cross-platform Issues: Ensure template works on Windows, macOS, Linux

๐ŸŽจ Code Style

Template Files

  • Use 4 spaces for indentation in Python files
  • Use double quotes for strings (Ruff default)
  • Follow PEP 8 guidelines
  • Include type hints where appropriate

Jinja2 Templates

  • Use clear, readable Jinja2 syntax
  • Add comments for complex conditionals
  • Keep template logic simple and maintainable

Example:

{%- if cookiecutter.use_ruff == 'y' %}
# Ruff configuration
[tool.ruff]
line-length = 88
{%- endif %}

Test Code

  • Write clear, descriptive test names
  • Include docstrings explaining test purpose
  • Use fixtures for common setup
  • Add parametrized tests for multiple scenarios

๐Ÿ“ Commit Convention

We use Conventional Commits and enforce this format with a pre-commit hook:

  • feat: - New features
  • fix: - Bug fixes
  • docs: - Documentation changes
  • test: - Test additions/changes
  • refactor: - Code refactoring
  • style: - Code style changes
  • ci: - CI/CD changes
  • chore: - Build, dependencies, tools

Examples:

feat: add support for Poetry as build backend
fix: resolve Windows path issues in hooks
docs: update tools guide with MyPy explanation
test: add integration tests for CLI generation

Note: The commitizen pre-commit hook will automatically validate your commit messages. Non-conventional commits will be rejected.

๐Ÿ” Review Process

Before Submitting

  1. Run Full Test Suite

    make test-all
    make check
    make bake-test
    

  2. Update Documentation

  3. Update documentation for new tools
  4. Update README for new features
  5. Add docstrings and comments

  6. Test Multiple Configurations

  7. Test with different Python versions
  8. Test on different operating systems
  9. Test various tool combinations

Pull Request Guidelines

  1. Clear Description
  2. Explain what changes were made
  3. Include motivation and context
  4. Link to related issues

  5. Test Coverage

  6. Include tests for new features
  7. Ensure existing tests pass
  8. Add integration tests where needed

  9. Documentation

  10. Update relevant documentation
  11. Include examples for new features
  12. Update changelog if applicable

๐Ÿšฆ CI/CD Pipeline

Our CI pipeline runs:

  1. Linting and Formatting
  2. Ruff for code quality
  3. MyPy for type checking
  4. Bandit for security

  5. Testing

  6. Unit tests for template logic
  7. Integration tests for generation
  8. Cross-platform testing

  9. Template Validation

  10. Generate projects with different configs
  11. Test generated project quality
  12. Verify all features work

๐Ÿ—๏ธ Template Architecture

Directory Structure

cookiecutter-python-package/
โ”œโ”€โ”€ cookiecutter.json          # Template configuration
โ”œโ”€โ”€ hooks/                     # Post-generation hooks
โ”‚   โ””โ”€โ”€ post_gen_project.py   # Cleanup and setup script
โ”œโ”€โ”€ tests/                     # Template tests
โ”‚   โ”œโ”€โ”€ test_template.py      # Template generation tests
โ”‚   โ”œโ”€โ”€ test_validation.py    # Validation tests
โ”‚   โ””โ”€โ”€ test_hooks.py         # Hook tests
โ”œโ”€โ”€ {{cookiecutter.project_slug}}/  # Main template
โ”‚   โ”œโ”€โ”€ src/                   # Source code structure
โ”‚   โ”œโ”€โ”€ tests/                 # Test structure
โ”‚   โ”œโ”€โ”€ pyproject.toml        # Python project configuration
โ”‚   โ””โ”€โ”€ ...                   # Other project files
โ””โ”€โ”€ docs/                      # Template documentation

Key Files

  • cookiecutter.json: Defines all template variables and options
  • hooks/post_gen_project.py: Cleans up unused files based on configuration
  • {{cookiecutter.project_slug}}/pyproject.toml: Modern Python project configuration
  • Template tests: Ensure template works correctly

๐Ÿค Getting Help

Questions and Discussions

  • GitHub Discussions: For questions and ideas
  • Issues: For bug reports and feature requests
  • Email: Contact maintainers directly

Resources

๐ŸŽ‰ Recognition

Contributors are recognized:

  • In the project README
  • In release notes
  • In the contributor's guide

Thank you for contributing to making Python development better for everyone! ๐Ÿโœจ