mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
Add hook to install packages in hub environment
Required when installing additional authenticators or spawners
This commit is contained in:
@@ -17,6 +17,11 @@ def tljh_extra_user_pip_packages():
|
|||||||
'django',
|
'django',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@hookimpl
|
||||||
|
def tljh_extra_hub_pip_packages():
|
||||||
|
return [
|
||||||
|
'there',
|
||||||
|
]
|
||||||
|
|
||||||
@hookimpl
|
@hookimpl
|
||||||
def tljh_extra_apt_packages():
|
def tljh_extra_apt_packages():
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ Test simplest plugin
|
|||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
from tljh.config import CONFIG_FILE, USER_ENV_PREFIX
|
from tljh.config import CONFIG_FILE, USER_ENV_PREFIX, HUB_ENV_PREFIX
|
||||||
|
|
||||||
yaml = YAML(typ='rt')
|
yaml = YAML(typ='rt')
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ def test_apt_packages():
|
|||||||
|
|
||||||
def test_pip_packages():
|
def test_pip_packages():
|
||||||
"""
|
"""
|
||||||
Test extra user pip packages are installed
|
Test extra user & hub pip packages are installed
|
||||||
"""
|
"""
|
||||||
subprocess.check_call([
|
subprocess.check_call([
|
||||||
f'{USER_ENV_PREFIX}/bin/python3',
|
f'{USER_ENV_PREFIX}/bin/python3',
|
||||||
@@ -26,6 +26,12 @@ def test_pip_packages():
|
|||||||
'import django'
|
'import django'
|
||||||
])
|
])
|
||||||
|
|
||||||
|
subprocess.check_call([
|
||||||
|
f'{HUB_ENV_PREFIX}/bin/python3',
|
||||||
|
'-c',
|
||||||
|
'import there'
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
def test_conda_packages():
|
def test_conda_packages():
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -22,6 +22,12 @@ def tljh_extra_user_pip_packages():
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@hookspec
|
||||||
|
def tljh_extra_hub_pip_packages():
|
||||||
|
"""
|
||||||
|
Return list of extra pip packages to install in the hub environment.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
@hookspec
|
@hookspec
|
||||||
def tljh_extra_apt_packages():
|
def tljh_extra_apt_packages():
|
||||||
|
|||||||
@@ -381,21 +381,29 @@ def run_plugin_actions(plugin_manager, plugins):
|
|||||||
))
|
))
|
||||||
apt.install_packages(apt_packages)
|
apt.install_packages(apt_packages)
|
||||||
|
|
||||||
|
# Install hub pip packages
|
||||||
|
hub_pip_packages = list(set(itertools.chain(*hook.tljh_extra_hub_pip_packages())))
|
||||||
|
if hub_pip_packages:
|
||||||
|
logger.info('Installing {} hub pip packages collected from plugins: {}'.format(
|
||||||
|
len(hub_pip_packages), ' '.join(hub_pip_packages)
|
||||||
|
))
|
||||||
|
conda.ensure_pip_packages(HUB_ENV_PREFIX, hub_pip_packages)
|
||||||
|
|
||||||
# Install conda packages
|
# Install conda packages
|
||||||
conda_packages = list(set(itertools.chain(*hook.tljh_extra_user_conda_packages())))
|
conda_packages = list(set(itertools.chain(*hook.tljh_extra_user_conda_packages())))
|
||||||
if conda_packages:
|
if conda_packages:
|
||||||
logger.info('Installing {} conda packages collected from plugins: {}'.format(
|
logger.info('Installing {} user conda packages collected from plugins: {}'.format(
|
||||||
len(conda_packages), ' '.join(conda_packages)
|
len(conda_packages), ' '.join(conda_packages)
|
||||||
))
|
))
|
||||||
conda.ensure_conda_packages(USER_ENV_PREFIX, conda_packages)
|
conda.ensure_conda_packages(USER_ENV_PREFIX, conda_packages)
|
||||||
|
|
||||||
# Install pip packages
|
# Install pip packages
|
||||||
pip_packages = list(set(itertools.chain(*hook.tljh_extra_user_pip_packages())))
|
user_pip_packages = list(set(itertools.chain(*hook.tljh_extra_user_pip_packages())))
|
||||||
if pip_packages:
|
if user_pip_packages:
|
||||||
logger.info('Installing {} pip packages collected from plugins: {}'.format(
|
logger.info('Installing {} user pip packages collected from plugins: {}'.format(
|
||||||
len(pip_packages), ' '.join(pip_packages)
|
len(user_pip_packages), ' '.join(user_pip_packages)
|
||||||
))
|
))
|
||||||
conda.ensure_pip_packages(USER_ENV_PREFIX, pip_packages)
|
conda.ensure_pip_packages(USER_ENV_PREFIX, user_pip_packages)
|
||||||
|
|
||||||
|
|
||||||
def ensure_config_yaml(plugin_manager):
|
def ensure_config_yaml(plugin_manager):
|
||||||
|
|||||||
Reference in New Issue
Block a user