This repository serves as inspiration/template for setting up your own modern python project.
It uses hatch as a project manager.
hatch
sets up a virtual environment, installs the correct Python version, downloads and installs the dependencies, and runs the program.
For a more comprehensive description, see below.
- Install
python3
- Install
hatch
using one of the methods described here - Download or clone this repository
- Run
hatch -v env create
- Install
python3
- Install
hatch
using one of the methods described here - Download or clone this repository
- Run
hatch -v env create dev
. This will download and install the appropriate Python version and any required packages - Run
hatch run dev:pre-commit install
. This will set uppre-commit
hatch run modern_python
hatch run dev:modern_python
hatch env remove
hatch env remove dev
Python3 is one of most popular languages in scientific programming. While its flexible syntax is great for beginners, this can become a issue for larger projects. Therefore, the community has started to adopt a number of best practices to make working on larger, multi-person projects more convenient. Some of these best practices have been incorporated in auxiliary programs (from here: 'plugins') that provide capabilities linting, formatting, type hinting, and testing.
- A basic project directory structure with some placeholder Python files (
modern_python
,tests
) - A set of standard files (in capital letters, e.g. LICENSE, CHANGELOG) for metadata about the repository
- A
pyproject.toml
file that manages metadata, versioning, dependencies, environments, and plugins. This file is also used byhatch
for setting up environments (default
,dev
), download and installation of dependencies. - A
.pre-commit-config.yaml
file that manages the plugins for linting (ruff-check
), formatting (ruff-format
), type hinting (mypy
), and testing (pytest
). Ifpre-commit
is activated, this suite of programs is performed with eachgit commmit
.
For Python projects not in version control (e.g. single-use scripts), such an advanced setup is likely not necessary. However, once a project becomes more elaborate, it is often useful to give it at least a minimum of formalism. This repo can help to reduce the time to do so, since it only requires a minimum of adaption.