Thank you for your interest in contributing to Machine Rules! This document provides guidelines and instructions for contributing to the project.
- Code of Conduct
- Getting Started
- Development Setup
- Development Workflow
- Testing
- Code Quality
- Security
- Pull Request Process
- Release Process
This project follows standard open source community guidelines:
- Be respectful and inclusive
- Focus on constructive feedback
- Help others learn and grow
- Prioritize project goals over personal preferences
- Python 3.8 or higher
- UV package manager (recommended)
- Git
- Basic understanding of rule engines and JSR-94 specification
- Fork the repository on GitHub
- Clone your fork locally:
git clone https://github.com/YOUR-USERNAME/machine_rules.git
cd machine_rules- Add the upstream repository:
git remote add upstream https://github.com/ORIGINAL-OWNER/machine_rules.gitUV is 10-100x faster than pip and is the recommended tool for development:
# Install UV
curl -LsSf https://astral.sh/uv/install.sh | sh
# Create a virtual environment
uv venv
# Activate the virtual environment
source .venv/bin/activate # On macOS/Linux
# or
.venv\Scripts\activate # On Windows
# Install the package in editable mode with dev dependencies
uv pip install -e ".[dev]"# Create a virtual environment
python -m venv .venv
# Activate the virtual environment
source .venv/bin/activate # On macOS/Linux
# or
.venv\Scripts\activate # On Windows
# Install the package in editable mode with dev dependencies
pip install -e ".[dev]"# Run tests to verify setup
pytest
# Check code quality
ruff check .
# Run type checking
mypy machine_rulesgit checkout -b feature/your-feature-name
# or
git checkout -b fix/your-bug-fixFollow these guidelines:
-
Write Tests First (TDD): Follow the Test-Driven Development approach
- Write failing tests first (RED)
- Implement minimum code to pass (GREEN)
- Refactor while keeping tests green (REFACTOR)
-
Code Style: Follow PEP 8 and use type hints
-
Documentation: Update docstrings and README as needed
-
Security: Never introduce unsafe expression evaluation
-
Commits: Make small, focused commits with clear messages
Use conventional commit messages:
git commit -m "feat: add new rule execution strategy"
git commit -m "fix: resolve thread safety issue in registry"
git commit -m "docs: update API documentation"
git commit -m "test: add tests for YAML loader validation"Commit types:
feat: New featurefix: Bug fixdocs: Documentation changestest: Adding or updating testsrefactor: Code refactoringperf: Performance improvementschore: Maintenance tasks
# Run all tests
pytest
# Run with coverage
pytest --cov=machine_rules --cov-report=term-missing
# Run specific test file
pytest machine_rules/tests/test_core.py
# Run specific test
pytest machine_rules/tests/test_core.py::TestRuleExecution::test_basic_execution
# Run tests in parallel (faster)
pytest -n auto- Location: Place tests in
machine_rules/tests/ - Naming: Use
test_*.pyfor test files andtest_*for test functions - Structure: Group related tests in classes
- Coverage: Aim for >95% code coverage
- Fixtures: Use pytest fixtures for common setup
Example test structure:
"""
Tests for new feature.
These tests verify that the new feature works correctly.
"""
import pytest
from machine_rules.api.runtime import RuleRuntime
class TestNewFeature:
"""Test suite for new feature."""
def test_basic_functionality(self):
"""Test that basic functionality works."""
# Arrange
runtime = RuleRuntime()
# Act
result = runtime.some_method()
# Assert
assert result is not None
def test_error_handling(self):
"""Test that errors are handled properly."""
runtime = RuleRuntime()
with pytest.raises(ValueError, match="expected error"):
runtime.invalid_operation()# Run ruff linter
ruff check .
# Auto-fix issues
ruff check --fix .
# Format code
ruff format .# Run mypy
mypy machine_rules
# Check specific file
mypy machine_rules/api/runtime.pyBefore committing, ensure:
- All tests pass:
pytest - No linting errors:
ruff check . - Type checking passes:
mypy machine_rules - Coverage is maintained:
pytest --cov=machine_rules
You can run all checks at once:
# Run all quality checks
pytest && ruff check . && mypy machine_rules- Never use
eval()orexec(): Usesafe_eval()frommachine_rules.security - Validate all inputs: Use Pydantic schemas for validation
- Block dangerous patterns: Check expressions for
__import__,__builtins__, etc. - Test security: Add tests to
test_security.pyfor any security-related code - Read SECURITY.md: Understand the security model before making changes
If you discover a security vulnerability, please email the maintainers directly instead of opening a public issue.
- Ensure all tests pass
- Add tests for new functionality
- Update documentation
- Run code quality checks
- Rebase on latest main branch
- Write a clear PR description
- Tests added/updated and passing
- Documentation updated
- Code follows style guidelines
- Type hints added
- Security implications considered
- Breaking changes documented
- Commit messages follow convention
## Description
Brief description of changes
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
## Testing
Describe the tests you ran
## Checklist
- [ ] Tests pass locally
- [ ] Code follows style guide
- [ ] Documentation updated
- [ ] Security reviewed- Maintainers will review your PR
- Address any feedback
- Once approved, maintainers will merge
- Your contribution will be included in the next release
Releases are managed by maintainers:
- Version bump in
pyproject.toml - Update CHANGELOG.md
- Create release tag
- Build and publish to PyPI
- Create GitHub release
- README.md - Project overview and usage
- SECURITY.md - Security guidelines
- examples.py - Code examples
- JSR-94 Specification - Java Rule Engine API specification
- UV - Fast Python package manager
- pytest - Testing framework
- ruff - Fast Python linter
- mypy - Static type checker
- Pydantic - Data validation
machine_rules/
├── machine_rules/ # Main package
│ ├── api/ # JSR-94 API implementation
│ ├── adapters/ # Rule engine adapters
│ ├── loader/ # Rule loaders (YAML)
│ ├── schemas/ # Pydantic schemas
│ ├── security/ # Safe expression evaluation
│ └── tests/ # Test suite
├── examples.py # Usage examples
├── pyproject.toml # Package configuration
├── README.md # Documentation
├── SECURITY.md # Security guidelines
└── CONTRIBUTING.md # This file
- Issues: Search existing issues or create a new one
- Discussions: Use GitHub Discussions for questions
- Documentation: Check README.md and code comments
Your contributions make this project better for everyone. We appreciate your time and effort!