|
| 1 | +# Contributing to TrueEntropy |
| 2 | + |
| 3 | +First off, thank you for considering contributing to TrueEntropy! 🎉 |
| 4 | + |
| 5 | +## Code of Conduct |
| 6 | + |
| 7 | +This project and everyone participating in it is governed by our [Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. |
| 8 | + |
| 9 | +## How Can I Contribute? |
| 10 | + |
| 11 | +### Reporting Bugs |
| 12 | + |
| 13 | +Before creating bug reports, please check the [existing issues](https://github.com/medeirosdev/TrueEntropy-PyLib/issues) as you might find that the bug has already been reported. |
| 14 | + |
| 15 | +When creating a bug report, please include: |
| 16 | + |
| 17 | +- **A clear and descriptive title** |
| 18 | +- **Steps to reproduce the behavior** |
| 19 | +- **Expected behavior** |
| 20 | +- **Actual behavior** |
| 21 | +- **Python version** (`python --version`) |
| 22 | +- **TrueEntropy version** (`pip show trueentropy`) |
| 23 | +- **Operating system** |
| 24 | + |
| 25 | +### Suggesting Enhancements |
| 26 | + |
| 27 | +Enhancement suggestions are tracked as GitHub issues. When creating an enhancement suggestion, please include: |
| 28 | + |
| 29 | +- **A clear and descriptive title** |
| 30 | +- **A detailed description of the proposed feature** |
| 31 | +- **Why this feature would be useful** |
| 32 | +- **Possible implementation approach** (optional) |
| 33 | + |
| 34 | +### Pull Requests |
| 35 | + |
| 36 | +1. **Fork the repository** and create your branch from `main` |
| 37 | +2. **Install development dependencies**: |
| 38 | + ```bash |
| 39 | + pip install -e ".[dev]" |
| 40 | + ``` |
| 41 | +3. **Make your changes** |
| 42 | +4. **Run the tests**: |
| 43 | + ```bash |
| 44 | + pytest |
| 45 | + ``` |
| 46 | +5. **Run the linters**: |
| 47 | + ```bash |
| 48 | + ruff check src/ |
| 49 | + black --check src/ |
| 50 | + ``` |
| 51 | +6. **Commit your changes** using conventional commits: |
| 52 | + ``` |
| 53 | + feat: add new feature |
| 54 | + fix: resolve bug |
| 55 | + docs: update documentation |
| 56 | + test: add tests |
| 57 | + refactor: code improvements |
| 58 | + ``` |
| 59 | +7. **Push to your fork** and submit a pull request |
| 60 | + |
| 61 | +## Development Setup |
| 62 | + |
| 63 | +```bash |
| 64 | +# Clone your fork |
| 65 | +git clone https://github.com/YOUR_USERNAME/TrueEntropy-PyLib.git |
| 66 | +cd TrueEntropy-PyLib |
| 67 | + |
| 68 | +# Create virtual environment |
| 69 | +python -m venv venv |
| 70 | +source venv/bin/activate # On Windows: venv\Scripts\activate |
| 71 | + |
| 72 | +# Install in development mode |
| 73 | +pip install -e ".[dev]" |
| 74 | + |
| 75 | +# Run tests |
| 76 | +pytest |
| 77 | + |
| 78 | +# Run linters |
| 79 | +ruff check src/ |
| 80 | +black src/ |
| 81 | +``` |
| 82 | + |
| 83 | +## Project Structure |
| 84 | + |
| 85 | +``` |
| 86 | +TrueEntropy/ |
| 87 | +├── src/trueentropy/ |
| 88 | +│ ├── __init__.py # Public API |
| 89 | +│ ├── pool.py # Entropy pool |
| 90 | +│ ├── tap.py # Value extraction |
| 91 | +│ ├── collector.py # Background collection |
| 92 | +│ ├── health.py # Health monitoring |
| 93 | +│ └── harvesters/ # Entropy sources |
| 94 | +│ ├── timing.py |
| 95 | +│ ├── network.py |
| 96 | +│ ├── system.py |
| 97 | +│ ├── external.py |
| 98 | +│ ├── weather.py |
| 99 | +│ └── radioactive.py |
| 100 | +├── tests/ # Test suite |
| 101 | +├── README.md |
| 102 | +├── ARCHITECTURE.md # Technical documentation |
| 103 | +├── CHANGELOG.md # Version history |
| 104 | +└── pyproject.toml # Project configuration |
| 105 | +``` |
| 106 | + |
| 107 | +## Testing Guidelines |
| 108 | + |
| 109 | +- Write tests for all new features |
| 110 | +- Maintain test coverage for existing functionality |
| 111 | +- Use descriptive test names that explain the behavior being tested |
| 112 | +- Group related tests in classes |
| 113 | + |
| 114 | +```python |
| 115 | +class TestFeatureName: |
| 116 | + def test_feature_does_something(self) -> None: |
| 117 | + """Feature should do something specific.""" |
| 118 | + result = feature() |
| 119 | + assert result == expected |
| 120 | +``` |
| 121 | + |
| 122 | +## Style Guide |
| 123 | + |
| 124 | +- Follow [PEP 8](https://pep8.org/) |
| 125 | +- Use [Black](https://github.com/psf/black) for formatting |
| 126 | +- Use [Ruff](https://github.com/astral-sh/ruff) for linting |
| 127 | +- Add type hints to all functions |
| 128 | +- Write docstrings for public APIs |
| 129 | + |
| 130 | +## Adding a New Harvester |
| 131 | + |
| 132 | +1. Create a new file in `src/trueentropy/harvesters/` |
| 133 | +2. Inherit from `BaseHarvester` |
| 134 | +3. Implement `name` property and `collect()` method |
| 135 | +4. Add tests in `tests/test_harvesters.py` |
| 136 | +5. Register in `lazy.py` for lazy loading |
| 137 | + |
| 138 | +```python |
| 139 | +from trueentropy.harvesters.base import BaseHarvester, HarvestResult |
| 140 | + |
| 141 | +class MyHarvester(BaseHarvester): |
| 142 | + @property |
| 143 | + def name(self) -> str: |
| 144 | + return "my_harvester" |
| 145 | + |
| 146 | + def collect(self) -> HarvestResult: |
| 147 | + # Collect entropy from your source |
| 148 | + data = self._collect_data() |
| 149 | + return HarvestResult( |
| 150 | + data=data, |
| 151 | + entropy_bits=len(data) * 2, # Conservative estimate |
| 152 | + source=self.name, |
| 153 | + success=True |
| 154 | + ) |
| 155 | +``` |
| 156 | + |
| 157 | +## Questions? |
| 158 | + |
| 159 | +Feel free to open an issue with the "question" label or reach out to the maintainers. |
| 160 | + |
| 161 | +Thank you for contributing! 🙏 |
0 commit comments