From e27426431aeff73fb31ca4e6745ee674acc105c4 Mon Sep 17 00:00:00 2001 From: "Thomas S." Date: Mon, 10 Feb 2025 11:33:31 +0100 Subject: [PATCH] ci: Ensure pyenv works when generating lockfiles (#1296) Currently, if the developer has some `pyenv` global settings or use `direnv`, we can't set the python version in a subshell to generate lockfiles. Instead, the developer python version is used silently. --- We fix it by overloading `PYENV_VERSION`, which is the highest way to define the python version we want. https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-shell > Sets a shell-specific Python version by setting the PYENV_VERSION environment variable in your shell. This version overrides application-specific versions and the global version. --- ```diff $ bash pip-compile.sh Generating requirements: python==3.9 | scikit-learn==1.6 (1/6) - Something wrong setting 'python-3.9', get '3.12' ``` ```bash $ bash pip-compile.sh Generating requirements: python==3.9 | scikit-learn==1.6 (1/6) Generating requirements: python==3.10 | scikit-learn==1.6 (2/6) Generating requirements: python==3.11 | scikit-learn==1.6 (3/6) Generating requirements: python==3.12 | scikit-learn==1.4 (4/6) Generating requirements: python==3.12 | scikit-learn==1.5 (5/6) Generating requirements: python==3.12 | scikit-learn==1.6 (6/6) ``` --- skore/ci/pip-compile.sh | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/skore/ci/pip-compile.sh b/skore/ci/pip-compile.sh index b6d48e615..0ea315fe5 100644 --- a/skore/ci/pip-compile.sh +++ b/skore/ci/pip-compile.sh @@ -36,6 +36,7 @@ set -eu # Move to `TMPDIR` to avoid absolute paths in requirements file cd "${TMPDIR}" + counter=1 for combination in "${COMBINATIONS[@]}" do IFS=";" read -r -a combination <<< "${combination}" @@ -44,12 +45,24 @@ set -eu scikit_learn="${combination[1]}" filepath="${CWD}/requirements/python-${python}/scikit-learn-${scikit_learn}/test-requirements.txt" - echo "Generating requirements: python ==${python} | scikit-learn ==${scikit_learn}" + echo "Generating requirements: python==${python} | scikit-learn==${scikit_learn} (${counter}/${#COMBINATIONS[@]})" - # Force the `python` version by creating the appropriate virtual environment - pyenv local "${python}" - python -m venv "python-${python}" - source "python-${python}/bin/activate" + # Install the `python` version using pyenv + pyenv install --skip-existing "${python}" + + # Force the `python` version with pyenv, overriding application-specific/global versions + export PYENV_VERSION="${python}" + + # Ensure the pyenv `python` version is well set + pyenv_version=$(pyenv version-name) + + if [[ "${pyenv_version}" != "${python}."* ]]; then + echo -e "\033[0;31mSomething wrong setting 'python-${python}', get '${pyenv_version%.*}'\033[0m" + exit 1 + fi + + # Create the appropriate virtual environment + python -m venv "python-${python}"; source "python-${python}/bin/activate" # Force the `scikit-learn` version by overloading test requirements sed -i "s/scikit-learn.*/scikit-learn==${scikit_learn}.*/g" skore/test-requirements.in @@ -67,5 +80,7 @@ set -eu --output-file="${filepath}" \ "${@:2}" \ skore/pyproject.toml + + let counter++ done )