Skip to content

markgreene74/python-template

Repository files navigation

markgreene74/python-template Run tests and lint (Python 3.12)

Simple template for Python 3.12 with pyenv/pyenv-virtualenv and poetry.

quickstart

clone the repo

git clone git@github.com:markgreene74/python-template.git

pyenv/pyenv-virtualenv

  • make sure pyenv and pyenv-virtualenv are installed
  • install python 3.12, for example 3.12.3
    pyenv install 3.12.3
  • create a virtual environment
    pyenv virtualenv 3.12.3 python-template-3-12
  • activate the virtual environment
    pyenv activate python-template-3-12
  • make sure pip and setuptools are up-to-date
    pip install --upgrade pip setuptools

poetry

  • install poetry
    pip install --upgrade poetry==1.8.3
  • to install
    • the application runtime dependencies
      poetry install --only main
    • the application test dependencies
      poetry install --with test
    • the application dev and test dependencies
      poetry install --with test,dev
    • the dependencies but not the current project
      poetry install --no-root --with test,dev

pre-commit

This project uses pre-commit.

  • install the hooks from the .pre-commit-config.yaml file
    pre-commit install

docker

  • build the image
    docker build -t python-template .
  • run the container
    docker run -it --rm python-template

Intermediate stages (test, dev) are available in the Dockerfile. Build them with:

docker build -t python-template . --target <stage>

For example, build and tun the tests with:

docker build -t python-template . --target test && \
  docker run -it --rm python-template

vagrant

  • create the file .with_pyenv if you want to install Python using pyenv
    touch .with_pyenv
  • start the vagrant box
    vagrant up
    NOTE: when the VM is started for the first time vagrant will run the provisioning script. It's a good idea to redirect the output to a log file for troubleshooting.
    vagrant up 2>&1 | tee -a $(date +%F)-vagrant-up.log
  • login to the box
    vagrant ssh

reference