#!/usr/bin/env python3
""" perform a development install of jupyter-videochat and jupyter_videochat

    On Binder, this will run _after_ the environment has been fully created from
    the environment.yml in this directory.

    This script should also run locally on Linux/MacOS/Windows:

        python3 binder/postBuild
"""
import subprocess
import sys
from pathlib import Path


ROOT = Path.cwd()
LAB_EXTENSIONS = ROOT / "binder" / "labextensions.txt"

if not LAB_EXTENSIONS.exists():
    LAB_EXTENSIONS = ROOT / "labextensions.txt"


def _(*args, **kwargs):
    """ Run a command, echoing the args

        fails hard if something goes wrong
    """
    print("\n\t", " ".join(args), "\n")
    return_code = subprocess.call(args, **kwargs)
    if return_code != 0:
        print("\nERROR", return_code, " ".join(args))
        sys.exit(return_code)

# install dependencies
_("jlpm")

_('jlpm', 'build')

# Link your development version of the extension with JupyterLab
_('jupyter', 'labextension', 'link', '.')

# verify the list of extensions one last time
_("jupyter", "labextension", "list")

print("JupyterLab with jupyter-videochat is ready to run with:\n")
print("\tjupyter lab\n")
