Skip to content

Commit

Permalink
ci: Ensure pyenv works when generating lockfiles (#1296)
Browse files Browse the repository at this point in the history
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)
```
  • Loading branch information
thomass-dev authored Feb 10, 2025
1 parent e2cc5e6 commit e274264
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions skore/ci/pip-compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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
Expand All @@ -67,5 +80,7 @@ set -eu
--output-file="${filepath}" \
"${@:2}" \
skore/pyproject.toml

let counter++
done
)

0 comments on commit e274264

Please sign in to comment.