Skip to content

sidisinsane/copier-python-hatch-template

Repository files navigation

Project Logo

Copier Python Hatch Template

A Copier template for Python projects managed by Hatch.

License CI Status CodeQL Status GH-Pages Deploy Status

Python Version Copier Hatch Material for MkDocs Pytest Markdownlint Commitlint Ruff Bandit Mypy

Prerequisites

Copier

Copier is a library and CLI app for rendering project templates.

Install Copier

Important

If you haven't already, install pipx first: pip install --user pipx.

pipx install copier

Inject Copier Templates Extensions

pipx inject copier copier-templates-extensions

Hatch

Hatch is a modern, PEP 621 compliant, extensible Python project manager.

Install Hatch

pipx install hatch

Configure Hatch

Store virtual environments in a directory named .hatch in each project directory.

hatch config set dirs.env.virtual .hatch

Note

This adds the following to the configuration:

[dirs.env]
virtual = ".hatch"

The Configuration for Hatch is stored in a config.toml file at i.e. ~/Library/Application Support/hatch on macOS.

Usage

Generate a Project

copier copy --trust https://github.com/sidisinsane/copier-python-hatch-template.git PATH/TO/DESTINATION

or

copier copy --trust gh:sidisinsane/copier-python-hatch-template PATH/TO/DESTINATION

This will generate a new project with the following structure:

YOUR-PROJECT-NAME
├── .github
│   └── workflows
│       ├── ci.yml
│       ├── codeql.yml
│       ├── gh-pages-deploy.yml
│       └── test.yml
├── .vscode
│   ├── extensions.json
│   └── settings.json
├── mkdocs
│   ├── images
│   │   ├── favicon.svg
│   │   └── logo.svg
│   ├── javascripts
│   │   └── mathjax.js
│   ├── index.md
│   └── license.md
├── src
│   └── YOUR_PROJECT_NAME
│       ├── __about__.py
│       ├── __init__.py
│       └── calc.py
├── tests
│   ├── __init__.py
│   └── test_calc.py
├── .coveragerc
├── .gitignore
├── .markdownlint.yml
├── .pre-commit-config.yaml
├── .pylintrc
├── bandit.yml
├── commitlint.config.js
├── LICENSE
├── mkdocs.yml
├── mypy.ini
├── pyproject.toml
├── pytest.ini
└── README.md

Note

You can also clone the project template using git clone https://github.com/sidisinsane/copier-python-hatch-template.git, modify it and generate a project the locally cloned repo.

copier copy --trust PATH/TO/CLONED/PROJECT/TEMPLATE PATH/TO/DESTINATION

Aftermath

Create Virtual Environment

cd PATH/TO/DESTINATION && hatch env create

Note

You can locate environments by running hatch env find.

Install Pre-Commit Hooks

git init && hatch run dev:pre-commit-install

Note

After you have created a new empty GitHub project, you are ready to make your initial commit.

git add .
git commit -m "initial commit"
git branch -M main
git remote add origin <https://github.com/REPO_NAMESPACE/REPO_NAME.git>
git push -u origin main

See the documentation for more details.