mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
reinstall conda/mamba in a separate, unconditional step
makes it more likely that subsequent conda installs will succeed - fix indentation on the upgrade steps so they aren't run every iteration - no longer need to bump required versions
This commit is contained in:
@@ -98,7 +98,7 @@ def install_miniconda(installer_path, prefix):
|
|||||||
fix_permissions(prefix)
|
fix_permissions(prefix)
|
||||||
|
|
||||||
|
|
||||||
def ensure_conda_packages(prefix, packages, force=False):
|
def ensure_conda_packages(prefix, packages, force_reinstall=False):
|
||||||
"""
|
"""
|
||||||
Ensure packages (from conda-forge) are installed in the conda prefix.
|
Ensure packages (from conda-forge) are installed in the conda prefix.
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ def ensure_conda_packages(prefix, packages, force=False):
|
|||||||
|
|
||||||
cmd = [conda_executable, "install", "--yes"]
|
cmd = [conda_executable, "install", "--yes"]
|
||||||
|
|
||||||
if force:
|
if force_reinstall:
|
||||||
# use force-reinstall, e.g. for conda/mamba to ensure everything is okay
|
# use force-reinstall, e.g. for conda/mamba to ensure everything is okay
|
||||||
# avoids problems with RemoveError upgrading conda from old versions
|
# avoids problems with RemoveError upgrading conda from old versions
|
||||||
cmd += ["--force-reinstall"]
|
cmd += ["--force-reinstall"]
|
||||||
|
|||||||
@@ -148,8 +148,8 @@ MAMBAFORGE_CHECKSUMS = {
|
|||||||
# minimum versions of packages
|
# minimum versions of packages
|
||||||
MINIMUM_VERSIONS = {
|
MINIMUM_VERSIONS = {
|
||||||
# if conda/mamba/pip are lower than this, upgrade them before installing the user packages
|
# if conda/mamba/pip are lower than this, upgrade them before installing the user packages
|
||||||
"mamba": "1.4.2",
|
"mamba": "0.16.0",
|
||||||
"conda": "23.3.1",
|
"conda": "4.10",
|
||||||
"pip": "23.1.2",
|
"pip": "23.1.2",
|
||||||
# minimum Python version (if not matched, abort to avoid big disruptive updates)
|
# minimum Python version (if not matched, abort to avoid big disruptive updates)
|
||||||
"python": "3.9",
|
"python": "3.9",
|
||||||
@@ -242,23 +242,36 @@ def ensure_user_environment(user_requirements_txt_file):
|
|||||||
)
|
)
|
||||||
to_upgrade.append(pkg)
|
to_upgrade.append(pkg)
|
||||||
|
|
||||||
cf_pkgs_to_upgrade = list(set(to_upgrade) & {"conda", "mamba"})
|
# force reinstall conda/mamba to ensure a basically consistent env
|
||||||
if cf_pkgs_to_upgrade:
|
# avoids issues with RemoveError: 'requests' is a dependency of conda
|
||||||
conda.ensure_conda_packages(
|
if not is_fresh_install:
|
||||||
USER_ENV_PREFIX,
|
# force-reinstall doesn't upgrade packages
|
||||||
# we _could_ explicitly pin Python here,
|
# it reinstalls them in-place
|
||||||
# but conda already does this by default
|
# only include packages already installed here
|
||||||
cf_pkgs_to_upgrade,
|
to_reinstall = {"conda", "mamba"} & set(package_versions)
|
||||||
# use force to avoid RemoveError: 'requests' is a dependency of conda
|
logger.info(
|
||||||
force=True,
|
f"Reinstalling {', '.join(to_reinstall)} to ensure a consistent environment"
|
||||||
)
|
)
|
||||||
pypi_pkgs_to_upgrade = list(set(to_upgrade) & {"pip"})
|
conda.ensure_conda_packages(
|
||||||
if pypi_pkgs_to_upgrade:
|
USER_ENV_PREFIX, list(to_reinstall), force_reinstall=True
|
||||||
conda.ensure_pip_packages(
|
)
|
||||||
USER_ENV_PREFIX,
|
|
||||||
pypi_pkgs_to_upgrade,
|
cf_pkgs_to_upgrade = list(set(to_upgrade) & {"conda", "mamba"})
|
||||||
upgrade=True,
|
if cf_pkgs_to_upgrade:
|
||||||
)
|
conda.ensure_conda_packages(
|
||||||
|
USER_ENV_PREFIX,
|
||||||
|
# we _could_ explicitly pin Python here,
|
||||||
|
# but conda already does this by default
|
||||||
|
cf_pkgs_to_upgrade,
|
||||||
|
)
|
||||||
|
|
||||||
|
pypi_pkgs_to_upgrade = list(set(to_upgrade) & {"pip"})
|
||||||
|
if pypi_pkgs_to_upgrade:
|
||||||
|
conda.ensure_pip_packages(
|
||||||
|
USER_ENV_PREFIX,
|
||||||
|
pypi_pkgs_to_upgrade,
|
||||||
|
upgrade=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Install/upgrade the jupyterhub version in the user env based on the
|
# Install/upgrade the jupyterhub version in the user env based on the
|
||||||
# version specification used for the hub env.
|
# version specification used for the hub env.
|
||||||
|
|||||||
Reference in New Issue
Block a user