---
version: '3'

vars:
  REQUIREMENTS_FILE: requirements.txt
  VENV_DIR: .venv

tasks:

  dev-tools:bootstrap:
    cmds:
      - task: python:create-venv
      - npm install

  dev-tools:update:
    cmds:
      - task: python:update-venv
      - npm update --save

  python:create-venv:
    vars:
      PYTHON_VERSION: 3.12
    cmds:
      - python{{.PYTHON_VERSION}} -m 'venv' '{{.VENV_DIR}}'
      - "{{.VENV_DIR}}/bin/pip --require-virtualenv install -r '{{.REQUIREMENTS_FILE}}'"

  python:recreate-venv:
    cmds:
      - "rm -rf '{{.VENV_DIR}}'"
      - task: python:create-venv

  python:update-venv:
    cmd: >-
      {{.VENV_DIR}}/bin/pip freeze -l --require-virtualenv | sed 's/==/>=/'
      | xargs {{.VENV_DIR}}/bin/pip --require-virtualenv install -U
