distributable:
  url: https://github.com/pypa/pipenv/archive/refs/tags/v{{ version }}.tar.gz
  strip-components: 1

versions:
  github: pypa/pipenv/releases/tags
  strip: /^v/

companions:
  pip.pypa.io: '*'

dependencies:
  pkgx.sh: ^1

build:
  dependencies:
    python.org: ~3.11 # approx. 3 older versions won’t work with python 3.12
    crates.io/semverator: '*'
  script:
    - bkpyvenv stage {{prefix}} {{version}}
    - ${{prefix}}/venv/bin/pip install .
    - bkpyvenv seal {{prefix}} pipenv

    # create exec scripts for pipenv so it can auto install and use the pythons it wants
    - working-directory: ${{prefix}}/bin
      run: |
        v=3.6
        vMax=3.12  #FIXME determine dynamically or even script this in the shim
        while semverator lt $v $vMax; do
          v=$(semverator bump $v minor | cut -d. -f1,2)
          echo '#!/bin/sh' > python$v
          echo "exec pkgx python~$v \"\$@\"" >> python$v
          chmod +x python$v
        done

    # needs libpython
    - run: cp -a {{deps.python.org.prefix}}/lib/libpython* .
      working-directory: ${{prefix}}/lib/

runtime:
  env:
    PIPENV_IGNORE_VIRTUALENVS: 1

test:
  - pipenv --version
  - pipenv --version 2>&1 | grep {{version}}

  # changed to python3.8; 3.7 generates a lockfile resolver error
  - run: |
      source <(pkgx +python@3.8)
      pipenv --python 3.8
      pipenv --verbose install pycowsay
      pipenv run pycowsay "Hello World"
    working-directory: a

  - run: |
      source <(pkgx +python@3.10)
      pipenv --python 3.10
      pipenv install pycowsay
      pipenv run pycowsay "Hello World"
    working-directory: b

provides:
  - bin/pipenv

marker-files:
  - Pipfile
  - Pipfile.lock
  # TODO python version can be obtained from the Pipfile
