|
| 1 | +# Development Guide |
| 2 | + |
| 3 | +Welcome to geek-computers Python repository! This guide will help you set up your development environment and contribute to the project. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Python 3.10+ (we test against 3.10, 3.11, and 3.12) |
| 8 | +- pip (Python package manager) |
| 9 | +- git |
| 10 | + |
| 11 | +## Setup |
| 12 | + |
| 13 | +### 1. Clone the Repository |
| 14 | +```bash |
| 15 | +git clone https://github.com/geekcomputers/Python.git |
| 16 | +cd Python |
| 17 | +``` |
| 18 | + |
| 19 | +### 2. Create Virtual Environment |
| 20 | +```bash |
| 21 | +# On Linux/Mac |
| 22 | +python3 -m venv venv |
| 23 | +source venv/bin/activate |
| 24 | + |
| 25 | +# On Windows |
| 26 | +python -m venv venv |
| 27 | +venv\Scripts\activate |
| 28 | +``` |
| 29 | + |
| 30 | +### 3. Install Dependencies |
| 31 | +```bash |
| 32 | +pip install --upgrade pip |
| 33 | +pip install -r requirements.txt |
| 34 | +``` |
| 35 | + |
| 36 | +### 4. Install Development Tools |
| 37 | +```bash |
| 38 | +pip install ruff bandit mypy pytest codespell |
| 39 | +``` |
| 40 | + |
| 41 | +## Code Quality Checks |
| 42 | + |
| 43 | +Before submitting a PR, run these checks locally: |
| 44 | + |
| 45 | +### Run Codespell (spell checking) |
| 46 | +```bash |
| 47 | +codespell --skip "*.json,*.txt,*.pdf,*.md" |
| 48 | +``` |
| 49 | + |
| 50 | +### Run Bandit (security analysis) |
| 51 | +```bash |
| 52 | +bandit -r . --skip B101,B105 |
| 53 | +``` |
| 54 | + |
| 55 | +### Run Ruff (linting) |
| 56 | +```bash |
| 57 | +ruff check . |
| 58 | +``` |
| 59 | + |
| 60 | +### Run Pytest (unit tests) |
| 61 | +```bash |
| 62 | +pytest |
| 63 | +``` |
| 64 | + |
| 65 | +### Run MyPy (type checking) |
| 66 | +```bash |
| 67 | +mypy . --ignore-missing-imports |
| 68 | +``` |
| 69 | + |
| 70 | +## Writing Scripts |
| 71 | + |
| 72 | +When adding new scripts: |
| 73 | + |
| 74 | +1. **Use clear, descriptive names** - `calculate_fibonacci.py` instead of `test.py` |
| 75 | +2. **Add docstrings** - Describe what your script does |
| 76 | +3. **Include comments** - Explain complex logic |
| 77 | +4. **Use type hints** (where applicable) - Helps with code clarity |
| 78 | +5. **Test your code** - Run it locally before submitting |
| 79 | + |
| 80 | +### Example Script Template |
| 81 | +```python |
| 82 | +""" |
| 83 | +Module Name: Calculate Fibonacci Sequence |
| 84 | +Description: Generate Fibonacci numbers up to N |
| 85 | +Author: Your Name |
| 86 | +Date: YYYY-MM-DD |
| 87 | +""" |
| 88 | + |
| 89 | +def fibonacci(n: int) -> list[int]: |
| 90 | + """ |
| 91 | + Generate Fibonacci sequence up to nth number. |
| 92 | + |
| 93 | + Args: |
| 94 | + n: Number of Fibonacci numbers to generate |
| 95 | + |
| 96 | + Returns: |
| 97 | + List of Fibonacci numbers |
| 98 | + """ |
| 99 | + if n <= 0: |
| 100 | + return [] |
| 101 | + elif n == 1: |
| 102 | + return [0] |
| 103 | + |
| 104 | + fib = [0, 1] |
| 105 | + for i in range(2, n): |
| 106 | + fib.append(fib[i-1] + fib[i-2]) |
| 107 | + return fib |
| 108 | + |
| 109 | + |
| 110 | +if __name__ == "__main__": |
| 111 | + result = fibonacci(10) |
| 112 | + print(result) |
| 113 | +``` |
| 114 | + |
| 115 | +## Submission Process |
| 116 | + |
| 117 | +1. **Create a feature branch** - `git checkout -b feature/your-feature-name` |
| 118 | +2. **Make your changes** - Add or modify scripts |
| 119 | +3. **Run quality checks** - Use the commands above |
| 120 | +4. **Commit your changes** - Use clear commit messages |
| 121 | +5. **Push to your fork** - `git push origin feature/your-feature-name` |
| 122 | +6. **Create a Pull Request** - Include description and testing info |
| 123 | + |
| 124 | +## Pull Request Guidelines |
| 125 | + |
| 126 | +- Keep PRs focused on a single feature or fix |
| 127 | +- Update README.md if adding new scripts |
| 128 | +- Reference any related issues with "Closes #123" |
| 129 | +- Follow the pull request template |
| 130 | + |
| 131 | +## Common Issues |
| 132 | + |
| 133 | +### ImportError for dependencies |
| 134 | +Make sure you've activated the virtual environment and installed all requirements: |
| 135 | +```bash |
| 136 | +source venv/bin/activate # Linux/Mac |
| 137 | +pip install -r requirements.txt |
| 138 | +``` |
| 139 | + |
| 140 | +### Tests fail locally but not in CI |
| 141 | +Check your Python version - we test on 3.10, 3.11, and 3.12: |
| 142 | +```bash |
| 143 | +python --version |
| 144 | +``` |
| 145 | + |
| 146 | +### Code style issues |
| 147 | +Run ruff with auto-fix: |
| 148 | +```bash |
| 149 | +ruff check . --fix |
| 150 | +``` |
| 151 | + |
| 152 | +## Need Help? |
| 153 | + |
| 154 | +- Check existing [issues](https://github.com/geekcomputers/Python/issues) |
| 155 | +- Review the [README.md](README.md) for script documentation |
| 156 | +- Email: craig@geekcomputers.co.uk |
| 157 | + |
| 158 | +Happy coding! 🐍 |
0 commit comments