Thank you for your interest in contributing to ReHLine! This guide will help you get started.
-
Fork and clone the repository:
git clone https://github.com/your-username/ReHLine-python.git cd ReHLine-python -
Create a virtual environment (recommended):
python -m venv venv source venv/bin/activate # Linux/macOS # or: venv\Scripts\activate # Windows
-
Install in development mode:
pip install -e ".[test]"
ReHLine uses a hybrid Python/C++ architecture. The build process automatically downloads Eigen 3.0.1 during installation.
Standard build:
pip install -e .Using a custom Eigen installation:
export EIGEN3_INCLUDE_DIR=/path/to/eigen
pip install -e . --no-build-isolationManual build (for debugging):
# On Linux/macOS
c++ -O3 -Wall -shared -std=c++17 -fPIC $(python3 -m pybind11 --includes) ./src/rehline.cpp -o rehline/_internal$(python3-config --extension-suffix)
# On Windows
cl /LD /EHsc /I%PYTHON_INCLUDE% /I%PYTHON_HOME% /I<path-to-pybind11-include> /I<path-to-eigen> .\src\rehline.cpp /link /OUT:rehline\_internal.pydRun the test suite to verify the build:
pytest tests/ -vReHLine follows a layered architecture:
┌─────────────────────────────────────────────────────┐
│ sklearn Mixin Layer │ ← rehline/_sklearn_mixin.py
│ (Provides fit/predict compatible with sklearn) │
├─────────────────────────────────────────────────────┤
│ Python Wrapper Layer │ ← rehline/_base.py, _class.py
│ (High-level API, parameter validation) │
├─────────────────────────────────────────────────────┤
│ pybind11 Binding Layer │ ← src/rehline.cpp → _internal*.so
│ (C++ ↔ Python bridge) │
├─────────────────────────────────────────────────────┤
│ C++ Core Computation Layer │ ← src/rehline.cpp, src/rehline.h
│ (Numerical algorithms, linear algebra) │
└─────────────────────────────────────────────────────┘
| Layer | Files | Description |
|---|---|---|
| C++ Core | src/rehline.cpp, src/rehline.h |
Core optimization algorithms |
| pybind11 | src/rehline.cpp |
C++ to Python bindings |
| Python Base | rehline/_base.py |
Base classes, solver interface |
| Python Classes | rehline/_class.py |
ReHLine, plqERM_Ridge, etc. |
| sklearn Mixin | rehline/_sklearn_mixin.py |
sklearn-compatible estimators |
We follow PEP 8 with the following conventions:
- Line length: Maximum 100 characters
- Indentation: 4 spaces (no tabs)
- Quotes: Double quotes for strings, single quotes only when containing double quotes
- Imports: Use
isortfor sorting imports
Install pre-commit hooks (optional but recommended):
pip install pre-commit
pre-commit installOrganize imports in the following order (use isort to enforce):
- Standard library imports
- Third-party imports (numpy, scipy, sklearn)
- Local/rehline imports
Example:
import re
from functools import lru_cache
import numpy as np
from scipy.sparse import issparse
from sklearn.base import BaseEstimator, RegressorMixin
from rehline._base import _BaseReHLine
from rehline._internal import rehline_internal- Use type hints for function signatures and return types
- Prefer
from __future__ import annotationsfor forward references
All new features should include tests. We use pytest as the test framework.
# Run all tests
pytest tests/ -v
# Run specific test file
pytest tests/test_rehline.py -v
# Run with coverage
pytest --cov=rehline --cov-report=term-missing tests/- Place tests in the
tests/directory - Name test files as
test_<module>.py - Test classes should be named
Test<Feature> - Test functions should be named
test_<description>
- New code should maintain or improve test coverage
- Aim for >90% coverage on new modules
- Run
pytest --cov=rehlinebefore submitting PR
-
Create a feature branch:
git checkout -b feature/your-feature-name
-
Make your changes and add tests
-
Run the test suite:
pytest tests/ -v
-
Commit your changes with a clear commit message:
git add . git commit -m "Add feature: description of changes"
-
Push to your fork and submit a pull request
- PRs should target the
mainbranch - Include a clear description of changes
- Reference any related issues
- Ensure all tests pass
- Update documentation if needed
Include:
- Steps to reproduce
- Expected vs actual behavior
- Minimal code example
- Environment details (OS, Python version, package version)
Include:
- Use case description
- Proposed API design
- Any alternative solutions considered
We use GitHub Actions for continuous integration:
- CI Tests: Runs on Ubuntu, macOS, Windows with Python 3.10-3.13
- Build Wheels: Builds binary wheels for distribution
All PRs must pass CI checks before merging.
By contributing, you agree that your contributions will be licensed under the MIT License.