Comprehensive guide for contributing to PyTorch Teaching.
# Clone the repository
git clone https://github.com/umitkacar/Pytorch-Teaching.git
cd Pytorch-Teaching
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install with development dependencies
make install-dev
# OR
pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit installpytorch-teaching/
├── src/pytorch_teaching/ # Source code
│ ├── __init__.py
│ ├── cli.py # CLI entry point
│ ├── lessons/ # Lesson modules
│ │ ├── lesson_01_tensors.py
│ │ ├── lesson_02_math_ops.py
│ │ ├── lesson_03_device_management.py
│ │ ├── lesson_21_executorch.py
│ │ └── ...
│ └── utils/ # Utility modules
│ ├── helpers.py
│ └── visualization.py
├── tests/ # Test suite
│ ├── __init__.py
│ └── test_lessons.py
├── docs/ # Documentation
├── pyproject.toml # Project configuration
├── .pre-commit-config.yaml # Pre-commit hooks
├── Makefile # Development commands
├── tox.ini # Tox configuration
└── .editorconfig # Editor configuration
make help # Show all available commands
make install-dev # Install with dev dependencies
make test # Run tests
make test-cov # Run tests with coverage
make test-parallel # Run tests in parallel
make lint # Run linters
make lint-fix # Auto-fix linting issues
make format # Format code
make format-check # Check formatting
make type-check # Run type checking
make security # Run security checks
make check # Run all checks
make clean # Clean build artifactshatch run test # Run tests
hatch run test-cov # Run tests with coverage
hatch run lint # Run linting
hatch run format # Format code
hatch run type-check # Type checking
hatch run security # Security checks
hatch run check # All checks
hatch run all # Format + lint + type + testtox -e py311 # Test on Python 3.11
tox -e lint # Linting
tox -e type # Type checking
tox -e security # Security checks
tox # Run all environments# All tests
pytest
# With coverage
pytest --cov=pytorch_teaching --cov-report=html
# Parallel execution
pytest -n auto
# Specific test file
pytest tests/test_lessons.py
# Specific test
pytest tests/test_lessons.py::TestLesson01::test_scalar_creation
# Verbose output
pytest -vv
# Stop on first failure
pytest -x
# Show locals on failure
pytest -l# Skip slow tests
pytest -m "not slow"
# Run only GPU tests
pytest -m gpu
# Run only integration tests
pytest -m integration# HTML report
pytest --cov=pytorch_teaching --cov-report=html
open htmlcov/index.html
# Terminal report
pytest --cov=pytorch_teaching --cov-report=term-missing
# XML report (for CI)
pytest --cov=pytorch_teaching --cov-report=xml# Format code
black src tests
# Check formatting
black --check src tests
# Format specific file
black src/pytorch_teaching/cli.py# Lint all code
ruff check src tests
# Auto-fix issues
ruff check --fix src tests
# Specific file
ruff check src/pytorch_teaching/cli.py
# Show rule descriptions
ruff check --show-source src tests# Check all code
mypy src
# Specific file
mypy src/pytorch_teaching/cli.py
# With coverage report
mypy --html-report mypy-report src# Scan for security issues
bandit -r src
# With configuration
bandit -r src -ll
# Generate baseline
bandit -r src -f json -o .bandit.jsonPre-commit hooks run automatically on git commit:
# Install hooks
pre-commit install
# Run manually on all files
pre-commit run --all-files
# Run specific hook
pre-commit run black --all-files
# Update hooks
pre-commit autoupdate
# Bypass hooks (not recommended)
git commit --no-verify-
Create lesson file:
touch src/pytorch_teaching/lessons/lesson_XX_name.py
-
Implement lesson structure:
""" Lesson XX: Title. Description of what this lesson covers. Learning Objectives: - Objective 1 - Objective 2 """ from rich.console import Console console = Console() def run(interactive: bool = True, verbose: bool = False): """Run Lesson XX.""" console.print("[bold cyan]Lesson XX: Title[/bold cyan]") # Implementation
-
Update CLI:
- Add import in
src/pytorch_teaching/lessons/__init__.py - Add case in
src/pytorch_teaching/cli.py
- Add import in
-
Add tests:
class TestLessonXX: def test_lesson_runs(self): lesson_XX.run(interactive=False, verbose=False)
-
Update documentation:
- Update README.md
- Update CHANGELOG.md
# Clean previous builds
make clean
# Build distribution
python -m build
# Check dist files
ls -lh dist/# Install twine
pip install twine
# Check package
twine check dist/*
# Test install locally
pip install dist/*.whl# Test PyPI
make publish-test
# Production PyPI
make publish# Run with verbose output
pytorch-teach run 1 --verbose
# Python debugger
python -m pdb -m pytorch_teaching.cli run 1
# IPython debugger
ipython --pdb -m pytorch_teaching.cli run 1# Run tests with pdb on failure
pytest --pdb
# Drop into pdb on first failure
pytest -x --pdb
# Verbose test output
pytest -vv --tb=long# Run benchmarks
pytest tests/ --benchmark-only
# Compare benchmarks
pytest tests/ --benchmark-compare# Using memory_profiler
from memory_profiler import profile
@profile
def my_function():
# Code to profile
pass-
Never commit secrets:
- Use
.envfiles (gitignored) - Use environment variables
- Use secret management tools
- Use
-
Dependency security:
# Check for vulnerabilities pip-audit # Update dependencies pip list --outdated
-
Code scanning:
# Bandit bandit -r src # Safety safety check
# Build documentation
cd docs
mkdocs build
# Serve locally
mkdocs serve
# Deploy to GitHub Pages
mkdocs gh-deployFollow Google-style docstrings:
def function(arg1: str, arg2: int) -> bool:
"""
Short description.
Longer description with more details.
Args:
arg1: Description of arg1
arg2: Description of arg2
Returns:
Description of return value
Raises:
ValueError: When something is wrong
Example:
>>> function("test", 42)
True
"""
pass-
Create feature branch:
git checkout -b feature/amazing-feature
-
Make changes:
- Write code
- Add tests
- Update documentation
-
Run checks:
make check make test-cov
-
Commit:
git add . git commit -m "feat: add amazing feature"
-
Push and create PR:
git push origin feature/amazing-feature
- Tests pass locally
- Code coverage maintained/improved
- Documentation updated
- Type hints added
- No linting errors
- Security checks pass
- Commit messages follow convention
- PR description is clear
Our CI pipeline runs:
- Linting: Black, Ruff, MyPy
- Security: Bandit
- Testing: Pytest on Python 3.9-3.12
- Coverage: Codecov upload
- Build: Package build test
- 💬 GitHub Discussions
- 🐛 Issue Tracker
- 📧 Contact maintainers
Happy Developing! 🚀