user env: ensure pip>=23.1.2 on install

This commit is contained in:
Erik Sundell
2023-05-18 23:45:27 +02:00
parent eaa16babb5
commit 9c83e9000e

View File

@@ -146,9 +146,10 @@ MAMBAFORGE_CHECKSUMS = {
# minimum versions of packages # minimum versions of packages
MINIMUM_VERSIONS = { MINIMUM_VERSIONS = {
# if conda/mamba 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": "0.16.0", "mamba": "0.16.0",
"conda": "4.10", "conda": "4.10",
"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",
} }
@@ -224,10 +225,14 @@ def ensure_user_environment(user_requirements_txt_file):
logger.error(msg) logger.error(msg)
raise ValueError(msg) raise ValueError(msg)
# at this point, we know we have an env ready with conda and are going to start installing # Ensure minimum versions of the following packages by upgrading to the
# first, check if we should upgrade/install conda and/or mamba # latest if below that version.
#
# - conda/mamba, via conda-forge
# - pip, via PyPI
#
to_upgrade = [] to_upgrade = []
for pkg in ("conda", "mamba"): for pkg in ("conda", "mamba", "pip"):
version = package_versions.get(pkg) version = package_versions.get(pkg)
min_version = MINIMUM_VERSIONS[pkg] min_version = MINIMUM_VERSIONS[pkg]
if not version: if not version:
@@ -241,17 +246,19 @@ def ensure_user_environment(user_requirements_txt_file):
) )
to_upgrade.append(pkg) to_upgrade.append(pkg)
if to_upgrade: cf_pkgs_to_upgrade = list(set(to_upgrade) & {"conda", "mamba"})
if cf_pkgs_to_upgrade:
conda.ensure_conda_packages( conda.ensure_conda_packages(
USER_ENV_PREFIX, USER_ENV_PREFIX,
# we _could_ explicitly pin Python here, # we _could_ explicitly pin Python here,
# but conda already does this by default # but conda already does this by default
to_upgrade, cf_pkgs_to_upgrade,
) )
pypi_pkgs_to_upgrade = list(set(to_upgrade) & {"pip"})
conda.ensure_pip_requirements( if pypi_pkgs_to_upgrade:
conda.ensure_pip_packages(
USER_ENV_PREFIX, USER_ENV_PREFIX,
os.path.join(HERE, "requirements-user-env.txt"), pypi_pkgs_to_upgrade,
upgrade=True, upgrade=True,
) )
if is_fresh_install: if is_fresh_install: