|
1 | | -# python-template |
| 1 | +# Python Template |
2 | 2 |
|
3 | | -Used to templatize python projects. |
| 3 | +This is a template project for Python, designed to streamline the creation of Python projects using (What I think are) |
| 4 | +best practices. |
| 5 | + |
| 6 | +## Table of Contents |
| 7 | + |
| 8 | +- [Features](#features) |
| 9 | +- [Getting Started](#getting-started) |
| 10 | +- [CI/CD Workflow](#cicd-workflow) |
| 11 | +- [Dependencies](#dependencies) |
| 12 | +- [Code Quality](#code-quality) |
| 13 | +- [Pre-commit Hooks](#pre-commit-hooks) |
| 14 | +- [License](#license) |
| 15 | + |
| 16 | +## Features |
| 17 | + |
| 18 | +- Code formatting and linting using [Ruff](https://ruff.rs). |
| 19 | +- Type checking with [Mypy](https://mypy.readthedocs.io). |
| 20 | +- Pre-commit hooks to maintain code quality. |
| 21 | + |
| 22 | +## Getting Started |
| 23 | + |
| 24 | +Follow these steps to get started with this template: |
| 25 | + |
| 26 | +1. **Clone the repository or use the template directly via GitHub.** |
| 27 | + |
| 28 | +2. **Install Poetry:** |
| 29 | + |
| 30 | + Ensure you have [Poetry](https://python-poetry.org/) installed. If not, you can install it using: |
| 31 | + ```bash |
| 32 | + pip install poetry |
| 33 | + ``` |
| 34 | + > **Note:** This template is set up using Poetry version 1.8.3. |
| 35 | +
|
| 36 | +3. **Install dependencies:** |
| 37 | + |
| 38 | + ```bash |
| 39 | + poetry install |
| 40 | + ``` |
| 41 | + |
| 42 | +4. **Ready to Implement:** |
| 43 | + |
| 44 | + You are now ready to implement your project. Keep in mind that this is a base template and not a fully functioning |
| 45 | + application. |
| 46 | + |
| 47 | +## CI/CD Workflow |
| 48 | + |
| 49 | +This project includes a continuous integration (CI) workflow that is triggered on every push and pull request, using |
| 50 | +GitHub Actions to run the following jobs: |
| 51 | + |
| 52 | +1. **Setup**: Checks out the code, sets up Python, and installs dependencies using Poetry. |
| 53 | +2. **Format**: Formats the code with Ruff. |
| 54 | +3. **Lint**: Runs linting on the codebase with Ruff. |
| 55 | +4. **Type Check**: Checks for type consistency using Mypy. |
| 56 | +5. **Create Release**: Automatically creates a GitHub release when code is pushed to the main branch. |
| 57 | + |
| 58 | +### Workflow File |
| 59 | + |
| 60 | +The CI workflow is defined in `.github/workflows/ci_check_release.yml`. |
| 61 | + |
| 62 | +## Dependencies |
| 63 | + |
| 64 | +This project includes the following dependencies: |
| 65 | + |
| 66 | +- **Core Dependencies**: |
| 67 | + - `python`: ^3.12 |
| 68 | + - `loguru`: ^0.7.2 |
| 69 | + |
| 70 | +- **Development Dependencies**: |
| 71 | + - `ruff`: ^0.6.7 (for code linting and formatting) |
| 72 | + - `mypy`: ^1.11.2 (for type checking) |
| 73 | + - `pre-commit`: ^3.8.0 (for managing Git hooks) |
| 74 | + - `pytest`: ^7.2.0 (for unit testing) |
| 75 | + |
| 76 | +## Code Quality |
| 77 | + |
| 78 | +This repository employs several tools to ensure code quality: |
| 79 | + |
| 80 | +- **Ruff**: A fast Python linter and formatter that enforces a consistent style and detects potential errors. |
| 81 | +- **Mypy**: A static type checker for Python that ensures type safety. |
| 82 | + |
| 83 | +## Pre-commit Hooks |
| 84 | + |
| 85 | +To set up pre-commit hooks for automatic formatting and linting on commit, ensure `pre-commit` is installed: |
| 86 | + |
| 87 | +```bash |
| 88 | +poetry install |
| 89 | +``` |
| 90 | + |
| 91 | +Then, install the hooks: |
| 92 | + |
| 93 | +```bash |
| 94 | +pre-commit install |
| 95 | +``` |
| 96 | + |
| 97 | +Once installed, the hooks will run automatically before each commit. |
| 98 | + |
| 99 | +### Pre-commit Hooks Configuration |
| 100 | + |
| 101 | +This repository uses pre-commit hooks to enforce code quality and standards before committing changes. Here’s an |
| 102 | +overview of the configured hooks: |
| 103 | + |
| 104 | +#### 1. Commitlint Hook |
| 105 | + |
| 106 | +- **Purpose**: Ensures commit messages adhere to defined conventions for consistency and clarity. |
| 107 | + |
| 108 | +#### 2. Local Hooks |
| 109 | + |
| 110 | +- **Ruff Format**: Automatically formats Python code according to specified rules. |
| 111 | +- **Ruff Lint**: Performs linting to catch potential errors and maintain coding standards. |
| 112 | +- **Mypy Type Check**: Checks type annotations for consistency and correctness in Python code. |
| 113 | +- **Pytest**: Runs the tests found in the /tests folder. |
| 114 | + |
| 115 | +For more information on pre-commit, visit [pre-commit.com](https://pre-commit.com). |
| 116 | + |
| 117 | +## License |
| 118 | + |
| 119 | +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
0 commit comments