Coding Standards¶
This document outlines the coding standards and best practices for contributing to the YAML Workflow Engine project.
Python Code Style¶
Code Formatting¶
We use Black for code formatting and isort for import sorting:
# Format Python files
black src/ tests/
# Sort imports
isort --profile black src/ tests/
# Run both
black src/ tests/ && isort --profile black src/ tests/
Type Hints¶
Use type hints for all function parameters and return values:
from typing import Dict, List, Optional
def process_data(
input_data: List[Dict[str, str]],
batch_size: Optional[int] = None
) -> Dict[str, int]:
"""Process input data and return statistics."""
results = {}
# Implementation
return results
Docstrings¶
Use Google-style docstrings for all modules, classes, and functions:
def validate_workflow(
workflow_file: str,
strict: bool = False
) -> Dict[str, Any]:
"""Validate a workflow file without executing it.
Args:
workflow_file: Path to the workflow file to validate.
strict: Whether to perform strict validation.
Returns:
Dict containing validation results.
Raises:
ValidationError: If the workflow is invalid.
FileNotFoundError: If the workflow file doesn't exist.
"""
# Implementation
Error Handling¶
-
Use custom exceptions for domain-specific errors:
-
Provide helpful error messages:
Testing¶
Test Organization¶
Organize tests to mirror the source code structure:
tests/
├── __init__.py
├── test_cli.py
├── test_engine.py
└── tasks/
├── __init__.py
├── test_base.py
└── test_file_tasks.py
Test Cases¶
Use descriptive test names and arrange tests using the AAA pattern:
def test_workflow_validation_catches_missing_required_params():
# Arrange
workflow_data = {
"name": "test",
"steps": [
{
"name": "step1",
"task": "shell",
# Missing required 'command' parameter
}
]
}
# Act & Assert
with pytest.raises(ValidationError) as exc:
validate_workflow_data(workflow_data)
assert "Missing required parameter: command" in str(exc.value)
Test Coverage¶
Maintain high test coverage:
# Run tests with coverage
pytest tests/ --cov=yaml_workflow
# Generate coverage report
pytest tests/ --cov=yaml_workflow --cov-report=html
YAML Files¶
Workflow Files¶
Follow these guidelines for workflow files:
-
Use descriptive names:
-
Group related parameters:
-
Use consistent indentation (2 spaces):
Configuration Files¶
For configuration files:
-
Use clear sections:
-
Include comments for non-obvious settings:
Git Workflow¶
Commits¶
-
Use descriptive commit messages:
-
Keep commits focused and atomic
Branches¶
- Feature branches:
feature/add-http-retry
-
feature/improve-error-handling
-
Fix branches:
fix/validation-error
fix/cli-parameters
Pull Requests¶
- Include clear descriptions
- Reference related issues
- Update documentation
- Add/update tests
- Ensure CI passes
Code Review¶
Checklist¶
- [ ] Code follows style guide
- [ ] Tests added/updated
- [ ] Documentation updated
- [ ] Error handling implemented
- [ ] Performance considerations addressed
- [ ] Security implications considered
Review Comments¶
- Be constructive and specific
- Explain the reasoning
- Provide examples when helpful
- Consider alternative approaches