Thank you for your interest in contributing! This document provides guidelines for contributing to the project.
- Python 3.9+
- Docker & Docker Compose V2
- Git
# Clone the repository
git clone https://github.com/Nikhil172913832/Federated_Learning.git
cd Federated_Learning
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install development dependencies
cd complete/fl
pip install -e ".[dev]"We use the following tools to maintain code quality:
# Format code with black
black fl/ tests/
# Lint with flake8
flake8 fl/ tests/
# Type check with mypy
mypy fl/ --ignore-missing-imports
# Sort imports with isort
isort fl/ tests/Install pre-commit hooks to automatically check code quality:
pip install pre-commit
pre-commit installAll contributions must include tests:
# Run all tests
pytest tests/ -v
# Run with coverage
pytest tests/ -v --cov=fl --cov-report=term-missing
# Run specific test file
pytest tests/test_data_validation.py -v
# Run property-based tests
pytest tests/test_data_validation.py -v --hypothesis-show-statistics- Minimum coverage: 80%
- All new functions must have tests
- Include edge cases and error conditions
git checkout -b feature/your-feature-nameBranch naming conventions:
feature/- New featuresfix/- Bug fixesdocs/- Documentation updatesrefactor/- Code refactoringtest/- Test additions/improvements
- Write clean, readable code
- Follow existing code style
- Add docstrings to all public functions
- Update documentation as needed
# Run tests
pytest tests/ -v --cov=fl
# Check code quality
black --check fl/ tests/
flake8 fl/ tests/
mypy fl/Follow conventional commits format:
git commit -m "feat: add new feature"
git commit -m "fix: resolve bug in data loading"
git commit -m "docs: update README"
git commit -m "test: add tests for evaluation module"Commit types:
feat: New featurefix: Bug fixdocs: Documentation changestest: Test additions/changesrefactor: Code refactoringperf: Performance improvementschore: Maintenance tasks
git push origin feature/your-feature-nameThen create a Pull Request on GitHub with:
- Clear description of changes
- Link to related issues
- Screenshots/examples if applicable
Before submitting, ensure:
- Code follows project style guidelines
- All tests pass
- Coverage >= 80%
- Documentation updated
- Commit messages follow conventions
- No merge conflicts
- PR description is clear and complete
- Be constructive and respectful
- Focus on code quality, not personal preferences
- Suggest improvements with examples
- Approve when standards are met
- Respond to feedback promptly
- Ask questions if unclear
- Make requested changes
- Mark conversations as resolved
Use Google-style docstrings:
def example_function(param1: int, param2: str) -> bool:
"""Brief description of function.
More detailed description if needed.
Args:
param1: Description of param1
param2: Description of param2
Returns:
Description of return value
Raises:
ValueError: When param1 is negative
"""
passAlways include type hints:
from typing import List, Dict, Optional
def process_data(
data: List[int],
config: Dict[str, Any],
threshold: Optional[float] = None,
) -> Dict[str, float]:
passTest individual functions in isolation:
def test_load_data_validates_inputs():
"""Test that load_data validates partition bounds."""
with pytest.raises(ValueError):
load_data(partition_id=10, num_partitions=5)Test component interactions:
def test_federated_round():
"""Test complete FL round with real components."""
# Setup
server = FederatedServer(...)
clients = [FederatedClient(...) for _ in range(3)]
# Execute
results = run_fl_round(server, clients)
# Verify
assert results["accuracy"] > 0.5Use Hypothesis for edge cases:
from hypothesis import given, strategies as st
@given(partition_id=st.integers(), num_partitions=st.integers())
def test_partition_bounds(partition_id, num_partitions):
"""Property: partition_id must be in [0, num_partitions)."""
if not (0 <= partition_id < num_partitions and num_partitions > 0):
with pytest.raises(ValueError):
load_data(partition_id, num_partitions)Include:
- Clear description of the bug
- Steps to reproduce
- Expected vs actual behavior
- Environment details (OS, Python version, etc.)
- Error messages and stack traces
Include:
- Clear description of the feature
- Use case and motivation
- Proposed implementation (if any)
- Alternatives considered
- Be respectful and inclusive
- Help others learn and grow
- Give credit where due
- Follow the Code of Conduct
- Open a GitHub Discussion
- Check existing issues and PRs
- Read the documentation
Thank you for contributing! 🎉