This is a template project for Python, designed to streamline the creation of Python projects using (What I think are) best practices.
- Code formatting and linting using Ruff.
- Type checking with Mypy.
- Pre-commit hooks to maintain code quality.
Follow these steps to get started with this template:
-
Clone the repository or use the template directly via GitHub.
-
Install Poetry:
Ensure you have Poetry installed. If not, you can install it using:
pip install poetry
Note: This template is set up using Poetry version 1.8.5.
-
Install dependencies:
poetry install
-
Ready to Implement:
You are now ready to implement your project. Keep in mind that this is a base template and not a fully functioning application.
This project includes a continuous integration (CI) workflow that is triggered on every push and pull request, using GitHub Actions to run the following jobs:
- Setup: Checks out the code, sets up Python, and installs dependencies using Poetry.
- Format: Formats the code with Ruff.
- Lint: Runs linting on the codebase with Ruff.
- Type Check: Checks for type consistency using Mypy.
- Create Release: Automatically creates a GitHub release when code is pushed to the main branch.
The main CI workflow is defined in .github/workflows/main.yml
.
Note: This workflow will only create a release tag based on your
pyproject.toml
version number. If the version has not been bumped, it will not create a new release.
This project includes the following dependencies:
-
Core Dependencies:
python
: ^3.13 (switch the.python-version
file to your liking)loguru
: ^0.7.3 (useful logging package)
-
Development Dependencies:
ruff
: ^0.8.x (for code linting and formatting)mypy
: ^1.x.y (for type checking)pre-commit
: ^4.x.y (for managing Git hooks)pytest
: ^8.x.y (for unit testing)
Useful pyenv commands
Updating pyenv will refresh the Python mirrors to find the latest Python versions available:
pyenv update
List all available Python versions:
pyenv install --list
Download & install a specific Python version:
pyenv install 3.13.3
List the global Python version set by your system:
pyenv global
List the Python version set for your project/folder:
pyenv local
Set the global Python version for your system:
pyenv global 3.13.3
Set the local Python version for your project:
pyenv local 3.13.3
Feel free to utilize Pyenv and modify the .python-version
file to your preference.
This repository employs several tools to ensure code quality:
- Ruff: A fast Python linter and formatter that enforces a consistent style and detects potential errors.
- Mypy: A static type checker for Python that ensures type safety.
To set up pre-commit hooks for automatic formatting and linting on commit, ensure pre-commit
is installed:
poetry install
Then, install the hooks:
poetry run pre-commit install
Once installed, the hooks will run automatically before each commit.
This repository uses pre-commit hooks to enforce code quality and standards before committing changes. Here’s an overview of the configured hooks:
- Purpose: Ensures commit messages adhere to defined conventions for consistency and clarity.
- Ruff Format: Automatically formats Python code according to specified rules.
- Ruff Lint: Performs linting to catch potential errors and maintain coding standards.
- Mypy Type Check: Checks type annotations for consistency and correctness in Python code.
- Pytest: Runs the tests found in the
/tests
folder.
You can run specific hooks manually using:
poetry run pre-commit run <HOOK-ID>
For example, to run the Ruff formatter:
poetry run pre-commit run ruff-format
For more information on pre-commit, visit pre-commit.com.
This project is licensed under the MIT License. See the LICENSE file for details.