Contributing¶
We welcome contributions to R2X Core! This guide will help you get started with contributing to the project.
Development Setup¶
How to set up a development environment¶
Set up a development environment for contributing to R2X Core:
# Clone the repository
git clone https://github.com/NREL/r2x-core.git
cd r2x-core
# Install with development dependencies
uv sync --dev
# Install pre-commit hooks
uv run pre-commit install
How to run tests¶
Execute the test suite:
# Run all tests
uv run pytest
# Run tests with coverage
uv run pytest --cov --cov-report=xml
# Run tests with verbose output
uv run pytest -vvl
How to run code quality checks¶
Ensure code quality and consistency:
# Run pre-commit checks on all files
uv run pre-commit run --all-files
# Run type checking
uv run mypy --config-file=pyproject.toml src/
# Run linting and formatting
uv run ruff check src/
uv run ruff format src/
Documentation¶
How to build documentation locally¶
Build and preview the documentation:
# Navigate to docs directory
cd docs
# Build HTML documentation
make html
# Serve documentation locally for live editing
make livehtml
How to add new documentation¶
Add new content to the documentation:
Create or edit markdown files in
docs/source/
Update
docs/source/index.md
if adding new sectionsBuild and preview locally:
make html
Check that links and references work correctly
Contributing Guidelines¶
How to contribute to R2X Core¶
Follow these steps to contribute:
Fork the repository on GitHub
Create a feature branch:
git switch -c feature/my-new-feature
Make your changes following the coding standards
Run tests and checks:
uv run pytest uv run pre-commit run --all-files
Commit your changes using conventional commit format:
git commit -m "feat: add new file reader for XYZ format"
Push to your fork and create a pull request
How to report issues¶
Report bugs or request features:
Check existing issues on GitHub
Create a new issue with:
Clear description of the problem/feature
Steps to reproduce (for bugs)
Expected vs actual behavior
Environment details (Python version, OS, etc.)
How to write documentation¶
Follow documentation standards:
Use MyST Markdown format
Follow Diataxis principles:
How-tos: Goal-oriented guides
Tutorials: Learning-oriented lessons
Reference: Information-oriented details
Explanation: Understanding-oriented discussion
Include code examples where appropriate
Test documentation builds locally before submitting
Git Conventions¶
Branch Naming¶
Use descriptive branch names following this pattern:
<type>/<scope>
Types:
feature/
- New featuresfix/
- Bug fixesdocs/
- Documentation changeschore/
- Maintenance tasksrefactor/
- Code improvements
Examples:
feature/plexos-parser
fix/data-validation
docs/api-reference
Commit Message Format¶
Follow the Angular/Karma convention:
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
Types:
feat
: New featuresfix
: Bug fixesdocs
: Documentation changesstyle
: Code style changes (formatting, missing semicolons, etc.)refactor
: Code changes that neither fix bugs nor add featurestest
: Adding or modifying testschore
: Changes to build process or auxiliary tools
Examples:
feat(parser): add support for PLEXOS XML files
fix(validation): handle missing data columns
docs: update API reference for DataStore
Pull Request Guidelines¶
Create from feature branch: Always branch from
main
Keep changes focused: One feature or fix per PR
Include tests: All new code must have corresponding tests
Update documentation: Include relevant documentation updates
Clean commit history: Squash commits if necessary
Git Workflow¶
We use a trunk-based development approach:
Create feature branch from
main
:git switch -c feature/your-feature-name
Make changes and commit regularly with clear messages
Keep branch updated with main:
git fetch origin git rebase origin/main
Push and create PR when ready:
git push origin feature/your-feature-name
Delete branch after merge:
git branch -d feature/your-feature-name
Development Practices¶
Code Quality Tools¶
We use Ruff for linting and formatting:
# Check for issues
uv run ruff check
# Auto-fix issues
uv run ruff check --fix
# Format code
uv run ruff format
Pre-commit Hooks¶
Install pre-commit hooks to automatically run checks:
uv run pre-commit install
This will run linting and formatting before each commit.
Type Checking¶
Use mypy for static type checking:
uv run mypy src/
Testing Standards¶
Unit tests: Test individual functions and classes
Integration tests: Test component interactions
Coverage: Maintain minimum 80% code coverage
Clear test names: Use descriptive test function names
Isolated tests: Each test should be independent
Documentation Standards¶
We follow the Diataxis framework:
How-to guides: Problem-oriented practical steps
Tutorials: Learning-oriented lessons
Reference: Information-oriented technical descriptions
Explanation: Understanding-oriented discussions
Useful Python References¶
Code Standards¶
Coding Conventions¶
We follow Python best practices:
PEP 8 style guide (enforced by Ruff)
Type hints for all function signatures
Docstrings for all public functions and classes
Clear, descriptive variable and function names
Testing Requirements¶
All new features must include tests
Maintain minimum 80% code coverage
Tests should be clear and maintainable
Use pytest for all testing