This repository serves as a template for starting new Python projects with Poetry, pre-configured with code quality tools and pre-commit hooks.
Follow these steps to set up your project:
-
Fork the Repository:
- Go to the repository page.
- Click the "Fork" button on the top right to create a copy of the repository under your GitHub account.
-
Use as a Template:
- Go to the repository page.
- Click the "Use this template" button.
- Follow the prompts to create a new repository based on this template.
- Open
pyproject.toml
in the root directory. - Update the
[tool.poetry]
section with your project's details:[tool.poetry] name = "your_project_name" version = "0.1.0" description = "A short description of your project" authors = ["Your Name <[email protected]>"]
If you haven't installed Poetry yet, follow the instructions here.
Navigate to the project directory and install the dependencies:
poetry install
This will create a virtual environment and install the necessary packages.
To ensure code quality and consistency, follow these steps to install and configure pre-commit hooks:
poetry run pre-commit install
To update the packages to their latest versions:
poetry update
This will update all dependencies in your pyproject.toml file to their latest compatible versions.
The default Python version is set to 3.11 in the pre-commit configuration. If you need to change this, update the default_language_version
in the .pre-commit-config.yaml
file.
The pre-commit hooks configured in this template include:
- Black for code formatting.
- Pydocstyle for enforcing docstring conventions.
- Pycln for removing unused imports.
- Trailing Whitespace to check for and remove trailing whitespace.
- Check JSON to validate JSON files.
- Check YAML to validate YAML files.
- Check Added Large Files to ensure large files are not committed.
- Mypy for type checking.
- Gitleaks for detecting secrets.
- Unit Tests to run tests using pytest.
You can customize these hooks by editing the .pre-commit-config.yaml
file.
To manually run all the pre-commit hooks on your codebase, use:
poetry run pre-commit run
This command runs the pre-commit hooks on the files that have been changed since the last commit.
To run the pre-commit hooks on all files in the repository, use:
poetry run pre-commit run --all-files
This command is useful when you want to apply the hooks to the entire codebase, ensuring all files meet the defined code quality and formatting standards.
To run unit tests:
poetry run pytest
Feel free to open issues or submit pull requests if you have suggestions for improvements or if you encounter any bugs.
This project is licensed under the Apache License 2.0. See the LICENSE file for details.