#!/usr/bin/env python
import os
from subprocess import check_call
import sys

version = os.environ['JUPYTERHUB_VERSION']

pip_install = [
    sys.executable,
    '-m',
    'pip',
    'install',
    '--no-cache',
    '--upgrade',
    '--upgrade-strategy',
    'only-if-needed',
]
if version.startswith("git:"):
    ref = version.partition(":")[-1]
    req = f"https://github.com/jupyterhub/jupyterhub/archive/{ref}.tar.gz"
else:
    req = f"jupyterhub=={version}"

check_call(pip_install + [req])
