hammerkit

pip

Install the pinned requirements of a Python project with pip.

Install the pinned requirements of a Python project with pip. The task runs in a python container and installs into __pypackages__, so it is skipped when the requirements file is unchanged. Tasks that need the packages set PYTHONPATH=__pypackages__.

.hammerkit.yaml
includes:
  pip:
    git: https://github.com/no0dles/hammerkit.git
    ref: v1.19.0
    path: catalog/pip

tasks:
  test:
    image: python:3.13-slim
    deps: [pip:install]
    src: [app, tests]
    envs:
      PYTHONPATH: __pypackages__
    cmds:
      - python -m unittest

Tasks

TaskWhat it doesReadsProduces
installInstall the pinned requirements with pip.the requirements file (requirements.txt)__pypackages__

Inputs

InputDefaultMeaning
PYTHON_VERSION3.13Tag of the python image the install runs in. The image is python:<PYTHON_VERSION>-slim. Quote it in with ('3.10'), or YAML reads it as the number 3.1.
REQUIREMENTSrequirements.txtThe file to install from, with exact versions (pip freeze, pip-compile). Use it for a different name or folder, for example requirements/prod.txt.

The entry

catalog/pip/build.yaml
# Installs the pinned requirements of a Python project with pip.
envs:
  # tag of the python image the install runs in, quoted so 3.10 stays 3.10
  PYTHON_VERSION: '3.13'
  # the file to install from, with exact versions (pip freeze, pip-compile)
  REQUIREMENTS: requirements.txt

tasks:
  install:
    description: install the pinned requirements with pip
    image: python:${PYTHON_VERSION}-slim
    src:
      - '${REQUIREMENTS}'
    generates: [__pypackages__]
    cmds:
      - pip install --no-cache-dir --disable-pip-version-check --target __pypackages__ -r ${REQUIREMENTS}

On this page