def ensure_user_environment(user_requirements_txt_file):
    """
    Set up user conda environment with required packages
    """
    print("Setting up user environment...")
    conda.ensure_conda_env(USER_ENV_PREFIX)
    conda.ensure_conda_packages(
        USER_ENV_PREFIX,
        [
            # Conda's latest version is on conda much more so than on PyPI.
            'conda==4.5.8'
        ])

    conda.ensure_pip_packages(
        USER_ENV_PREFIX,
        [
            # JupyterHub + notebook package are base requirements for user environment
            'jupyterhub==0.9.1',
            'notebook==5.6.0',
            # Install additional notebook frontends!
            'jupyterlab==0.32.1',
            'nteract-on-jupyter==1.8.1',
            # nbgitpuller for easily pulling in Git repositories
            'nbgitpuller==0.6.1'
        ])

    if user_requirements_txt_file:
        # FIXME: This currently fails hard, should fail soft and not abort installer
        conda.ensure_pip_requirements(USER_ENV_PREFIX,
                                      user_requirements_txt_file)
def test_ensure_packages(prefix):
    """
    Test installing packages in conda environment
    """
    conda.ensure_conda_env(prefix)
    conda.ensure_conda_packages(prefix, ['numpy'])
    # Throws an error if this fails
    subprocess.check_call(
        [os.path.join(prefix, 'bin', 'python'), '-c', 'import numpy'])
def test_ensure_environment(prefix):
    """
    Test second call to ensure_conda_env works as expected

    A conda environment already exists, so we it should just do nothing
    """
    conda.ensure_conda_env(prefix)
    assert os.path.exists(prefix)
    conda.ensure_conda_env(prefix)
def test_create_environment(prefix):
    """
    Test conda environment creation

    An empty conda environment doesn't seem to have anything in it,
    so we just check for directory existence.
    """
    conda.ensure_conda_env(prefix)
    assert os.path.exists(prefix)
def test_ensure_pip_requirements(prefix):
    """
    Test installing pip packages with requirements.txt in conda environment
    """
    conda.ensure_conda_env(prefix)
    conda.ensure_conda_packages(prefix, ['pip'])
    with tempfile.NamedTemporaryFile() as f:
        # Sample small package to test
        f.write('there'.encode())
        f.flush()
        conda.ensure_pip_requirements(prefix, f.name)
    subprocess.check_call(
        [os.path.join(prefix, 'bin', 'python'), '-c', 'import there'])
Example #6
0
def ensure_user_environment():
    """
    Set up user conda environment with required packages
    """
    print("Setting up user environment...")
    conda.ensure_conda_env(USER_ENV_PREFIX)
    conda.ensure_conda_packages(
        USER_ENV_PREFIX,
        [
            # Conda's latest version is on conda much more so than on PyPI.
            'conda==4.5.8'
        ])

    conda.ensure_pip_packages(
        USER_ENV_PREFIX,
        [
            # JupyterHub + notebook package are base requirements for user environment
            'jupyterhub==0.9.0',
            'notebook==5.5.0',
            # Install additional notebook frontends!
            'jupyterlab==0.32.1',
            'nteract-on-jupyter==1.8.1'
        ])
Example #7
0

ensure_jupyterhub_package(HUB_ENV_PREFIX)
ensure_jupyterhub_service(HUB_ENV_PREFIX)

user.ensure_group('jupyterhub-admins')
user.ensure_group('jupyterhub-users')

with open('/etc/sudoers.d/jupyterhub-admins', 'w') as f:
    # JupyterHub admins should have full passwordless sudo access
    f.write('%jupyterhub-admins ALL = (ALL) NOPASSWD: ALL\n')
    # `sudo -E` should preserve the $PATH we set. This allows
    # admins in jupyter terminals to do `sudo -E pip install <package>`,
    # `pip` is in the $PATH we set in jupyterhub_config.py to include the user conda env.
    f.write('Defaults exempt_group = jupyterhub-admins\n')

conda.ensure_conda_env(USER_ENV_PREFIX)
conda.ensure_conda_packages(USER_ENV_PREFIX, [
    # Conda's latest version is on conda much more so than on PyPI.
    'conda==4.5.4'
])

conda.ensure_pip_packages(USER_ENV_PREFIX, [
    # JupyterHub + notebook package are base requirements for user environment
    'jupyterhub==0.9.0',
    'notebook==5.5.0',
    # Install additional notebook frontends!
    'jupyterlab==0.32.1',
    'nteract-on-jupyter==1.8.1'
])