The Cookiecutter Python Template is designed to streamline the creation of new Python projects. With a single command, you can generate a fully-fledged project structure complete with a pyproject.toml
configuration file, ready to build and test your application.
Before you begin, make sure you have the following tools installed:
pip install cookiecutter ruff pytest pytest-cov pytest-xdist
To generate a new project, run the following command:
python -m cookiecutter gh:armantechhub/python-template
After running the command, a new directory will be created with the name of your project. Inside this directory, you will find a pyproject.toml
file which is pre-configured with the following features:
- Building System: Ready to use with
hatchling
andhatch-requirements-txt
for packaging your project. - Project Metadata: Including name, description, license, authors, and URLs.
- Dependency Management: Automatically reads dependencies from
requirements.txt
. - Versioning: Dynamically fetches the version number from the source code.
- Testing: Set up with
pytest
andcoverage
for running tests and generating coverage reports. - Linting: Configured with
black
,mypy
, andruff
for code style checking and formatting.
Run the linter to check and fix code style issues:
python -m ruff check . --fix
Run basic tests without coverage:
python -m pytest
Run tests with coverage and parallel execution:
python -m pytest --cov -n 4
During the generation process, you will be prompted to enter various details about your project, such as the project name, description, and author information. These details are used to populate the pyproject.toml
file and other relevant project files.
Here's an overview of the settings you will be asked to provide:
project_name
: The name of your project.description
: A brief description of your project.root_name
: The root name of your project, derived from the project name.module_name
: The module name of your project, derived from the root name.git_hosting
: The hosting service for your Git repository.author_name
: Your name or the name of the project author.author_email
: Your email address or the email address of the project author.git_username
: Your username for the Git hosting service.git_repo
: The URL of the Git repository, automatically generated from the other settings.
Using this template ensures that your Python project starts off on the right foot with a well-structured setup. It saves you time by automating the initial project configuration, allowing you to focus on developing your application instead of setting up the development environment.