mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
Let pip upgrade packages
Since we now longer pin versions to the patch version, we should make an install cause the packages upgrade within the version constraints rathern than just settle for the current version if it is already installed.
This commit is contained in:
@@ -96,6 +96,9 @@ def install_miniconda(installer_path, prefix):
|
|||||||
def ensure_conda_packages(prefix, packages):
|
def ensure_conda_packages(prefix, packages):
|
||||||
"""
|
"""
|
||||||
Ensure packages (from conda-forge) are installed in the conda prefix.
|
Ensure packages (from conda-forge) are installed in the conda prefix.
|
||||||
|
|
||||||
|
Note that conda seem to update dependencies by default, so there is probably
|
||||||
|
no need to have a update parameter exposed for this function.
|
||||||
"""
|
"""
|
||||||
conda_executable = [os.path.join(prefix, 'bin', 'mamba')]
|
conda_executable = [os.path.join(prefix, 'bin', 'mamba')]
|
||||||
abspath = os.path.abspath(prefix)
|
abspath = os.path.abspath(prefix)
|
||||||
@@ -124,21 +127,20 @@ def ensure_conda_packages(prefix, packages):
|
|||||||
fix_permissions(prefix)
|
fix_permissions(prefix)
|
||||||
|
|
||||||
|
|
||||||
def ensure_pip_packages(prefix, packages):
|
def ensure_pip_packages(prefix, packages, upgrade=False):
|
||||||
"""
|
"""
|
||||||
Ensure pip packages are installed in the given conda prefix.
|
Ensure pip packages are installed in the given conda prefix.
|
||||||
"""
|
"""
|
||||||
abspath = os.path.abspath(prefix)
|
abspath = os.path.abspath(prefix)
|
||||||
pip_executable = [os.path.join(abspath, 'bin', 'python'), '-m', 'pip']
|
pip_executable = [os.path.join(abspath, 'bin', 'python'), '-m', 'pip']
|
||||||
|
pip_cmd = pip_executable + ['install', '--no-cache-dir']
|
||||||
utils.run_subprocess(pip_executable + [
|
if upgrade:
|
||||||
'install',
|
pip_cmd.append('--upgrade')
|
||||||
'--no-cache-dir',
|
utils.run_subprocess(pip_cmd + packages)
|
||||||
] + packages)
|
|
||||||
fix_permissions(prefix)
|
fix_permissions(prefix)
|
||||||
|
|
||||||
|
|
||||||
def ensure_pip_requirements(prefix, requirements_path):
|
def ensure_pip_requirements(prefix, requirements_path, upgrade=False):
|
||||||
"""
|
"""
|
||||||
Ensure pip packages from given requirements_path are installed in given conda prefix.
|
Ensure pip packages from given requirements_path are installed in given conda prefix.
|
||||||
|
|
||||||
@@ -146,10 +148,8 @@ def ensure_pip_requirements(prefix, requirements_path):
|
|||||||
"""
|
"""
|
||||||
abspath = os.path.abspath(prefix)
|
abspath = os.path.abspath(prefix)
|
||||||
pip_executable = [os.path.join(abspath, 'bin', 'python'), '-m', 'pip']
|
pip_executable = [os.path.join(abspath, 'bin', 'python'), '-m', 'pip']
|
||||||
|
pip_cmd = pip_executable + ['install', '--no-cache-dir']
|
||||||
utils.run_subprocess(pip_executable + [
|
if upgrade:
|
||||||
'install',
|
pip_cmd.append('--upgrade')
|
||||||
'-r',
|
utils.run_subprocess(pip_cmd + ['--requirement', requirements_path])
|
||||||
requirements_path
|
|
||||||
])
|
|
||||||
fix_permissions(prefix)
|
fix_permissions(prefix)
|
||||||
|
|||||||
@@ -124,9 +124,7 @@ def ensure_jupyterhub_package(prefix):
|
|||||||
'libcurl4-openssl-dev',
|
'libcurl4-openssl-dev',
|
||||||
'build-essential'
|
'build-essential'
|
||||||
])
|
])
|
||||||
conda.ensure_pip_packages(prefix, [
|
conda.ensure_pip_packages(prefix, ['pycurl==7.*'], upgrade=True)
|
||||||
'pycurl==7.*'
|
|
||||||
])
|
|
||||||
|
|
||||||
conda.ensure_pip_packages(
|
conda.ensure_pip_packages(
|
||||||
prefix,
|
prefix,
|
||||||
@@ -141,6 +139,7 @@ def ensure_jupyterhub_package(prefix):
|
|||||||
"jupyterhub-idle-culler==1.*",
|
"jupyterhub-idle-culler==1.*",
|
||||||
"git+https://github.com/yuvipanda/jupyterhub-configurator@317759e17c8e48de1b1352b836dac2a230536dba"
|
"git+https://github.com/yuvipanda/jupyterhub-configurator@317759e17c8e48de1b1352b836dac2a230536dba"
|
||||||
],
|
],
|
||||||
|
upgrade=True,
|
||||||
)
|
)
|
||||||
traefik.ensure_traefik_binary(prefix)
|
traefik.ensure_traefik_binary(prefix)
|
||||||
|
|
||||||
@@ -193,20 +192,28 @@ def ensure_user_environment(user_requirements_txt_file):
|
|||||||
conda.install_miniconda(installer_path, USER_ENV_PREFIX)
|
conda.install_miniconda(installer_path, USER_ENV_PREFIX)
|
||||||
conda_version = '4.10.3'
|
conda_version = '4.10.3'
|
||||||
|
|
||||||
conda.ensure_conda_packages(USER_ENV_PREFIX, [
|
conda.ensure_conda_packages(
|
||||||
# Conda's latest version is on conda much more so than on PyPI.
|
USER_ENV_PREFIX,
|
||||||
'conda==' + conda_version,
|
[
|
||||||
'mamba==' + mambaforge_mamba_version,
|
# Conda's latest version is on conda much more so than on PyPI.
|
||||||
])
|
'conda==' + conda_version,
|
||||||
|
'mamba==' + mambaforge_mamba_version,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
conda.ensure_pip_requirements(
|
conda.ensure_pip_requirements(
|
||||||
USER_ENV_PREFIX,
|
USER_ENV_PREFIX,
|
||||||
os.path.join(HERE, 'requirements-base.txt'),
|
os.path.join(HERE, 'requirements-base.txt'),
|
||||||
|
upgrade=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
if user_requirements_txt_file:
|
if user_requirements_txt_file:
|
||||||
# FIXME: This currently fails hard, should fail soft and not abort installer
|
# FIXME: This currently fails hard, should fail soft and not abort installer
|
||||||
conda.ensure_pip_requirements(USER_ENV_PREFIX, user_requirements_txt_file)
|
conda.ensure_pip_requirements(
|
||||||
|
USER_ENV_PREFIX,
|
||||||
|
user_requirements_txt_file,
|
||||||
|
upgrade=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def ensure_admins(admin_password_list):
|
def ensure_admins(admin_password_list):
|
||||||
@@ -313,7 +320,7 @@ def setup_plugins(plugins=None):
|
|||||||
"""
|
"""
|
||||||
# Install plugins
|
# Install plugins
|
||||||
if plugins:
|
if plugins:
|
||||||
conda.ensure_pip_packages(HUB_ENV_PREFIX, plugins)
|
conda.ensure_pip_packages(HUB_ENV_PREFIX, plugins, upgrade=True)
|
||||||
|
|
||||||
# Set up plugin infrastructure
|
# Set up plugin infrastructure
|
||||||
pm = pluggy.PluginManager('tljh')
|
pm = pluggy.PluginManager('tljh')
|
||||||
@@ -342,7 +349,11 @@ def run_plugin_actions(plugin_manager):
|
|||||||
logger.info('Installing {} hub pip packages collected from plugins: {}'.format(
|
logger.info('Installing {} hub pip packages collected from plugins: {}'.format(
|
||||||
len(hub_pip_packages), ' '.join(hub_pip_packages)
|
len(hub_pip_packages), ' '.join(hub_pip_packages)
|
||||||
))
|
))
|
||||||
conda.ensure_pip_packages(HUB_ENV_PREFIX, hub_pip_packages)
|
conda.ensure_pip_packages(
|
||||||
|
HUB_ENV_PREFIX,
|
||||||
|
hub_pip_packages,
|
||||||
|
upgrade=True,
|
||||||
|
)
|
||||||
|
|
||||||
# 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())))
|
||||||
@@ -358,7 +369,11 @@ def run_plugin_actions(plugin_manager):
|
|||||||
logger.info('Installing {} user pip packages collected from plugins: {}'.format(
|
logger.info('Installing {} user pip packages collected from plugins: {}'.format(
|
||||||
len(user_pip_packages), ' '.join(user_pip_packages)
|
len(user_pip_packages), ' '.join(user_pip_packages)
|
||||||
))
|
))
|
||||||
conda.ensure_pip_packages(USER_ENV_PREFIX, user_pip_packages)
|
conda.ensure_pip_packages(
|
||||||
|
USER_ENV_PREFIX,
|
||||||
|
user_pip_packages,
|
||||||
|
upgrade=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Custom post install actions
|
# Custom post install actions
|
||||||
hook.tljh_post_install()
|
hook.tljh_post_install()
|
||||||
|
|||||||
Reference in New Issue
Block a user