Skip to content

[ci] use pixi to manage end-of-life Python environments - #7328

Merged
jameslamb merged 26 commits into
masterfrom
pixi
Jun 17, 2026
Merged

jameslamb merged 26 commits into
masterfrom
pixi

Conversation

@jameslamb

@jameslamb jameslamb commented Jun 3, 2026 •

Copy link
Copy Markdown
Member

Contributes to #7292

Closes #7288

AppVeyor CI is a serious bottleneck in this repo during periods of active development. On our plan, we only get 1 concurrent job and each job is taking 30-40 minutes.

conda environment solves dominate that time, and #7288 was one attempt to alleviate that by using a newer conda (via miniforge) + pinning more packages.

In response to #7288 (comment), this tries a different approach, using pixi (https://pixi.prefix.dev/latest/) to manage those environments.

Impact

Reusing the table from #5648 (comment)

job latest master this PR
(GHA) windows-2022 sdist (py3.10) 8m10s 7m38s
(GHA) windows-2022 bdist (py3.13) 8m24s 8m24s
(GHA) windows-2022 regular (py3.11) 9m39s 9m54s
(Appveyor) MSVC (py3.10) 34m37s 11m31s
(Appveyor) MINGW (py3.10) 35m35s 11m39s
links to runs (click me)

this PR:

latest master build:

So it helped a little in the GitHub Actions Python 3.10 job (which had an up-to-date conda using libmamba) and probably faster disk and CPUs but helped a LOT for AppVeyor 😁

Notes for Reviewers

I am totally new to pixi, please teach me through brutal criticism.

Comment thread .appveyor.yml
- conda config --add channels nodefaults
- conda config --add channels conda-forge
- conda config --set channel_priority strict
- conda init powershell

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor is specifically used here to test old, mostly-end-of-life stuff... I think we can assume that if this PR is merged, we'll use pixi there forever and don't need any conda stuff at all.

Comment thread .ci/lint-powershell.ps1
)
IncludeDefaultRules = $true
# Additional rules that are disabled by default
ExcludeRules = @(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pixi install creates a virtual environment that has an Activate.ps1 file in it (even on non-Windows platforms), which triggered warnings from this Powershell linter, which led me down this path of needing to reconfigure the Powershell linter to skip the .pixi/ directory (and some others, just to extra safety).

Also needed to add this exclusion to be able to activate a pixi shell non-interactively inside a Poweshell script, like this:

pixi install -e py310 ; Assert-Output $?
$activation = ((& pixi shell-hook -e py310 --shell powershell) -join "`n")
Invoke-Expression $activation ; Assert-Output $?

Comment thread .ci/test-windows.ps1
conda list -n $env:CONDA_ENV

# 'bdist' job invokes 'RefreshEnv' to update PATH from the registry (which may have been modified
# by building in OpenCL support), so defer activating the conda environment until later for those builds.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern of deferring conda activate until later for bdist jobs already exists on master, and has for 6 years: #3403

I stumbled over this because I tried to consolidate them to a single unconditional conda activate and hit errors like "pytest not found".

I've added these explanatory comments (1 here, 1 down in the bdist job) to provide some context for why this is necessary. To save the next person who touches this some pain.

Comment thread .ci/test.sh
sh ./build-python.sh sdist || exit 1
sh .ci/check-python-dists.sh ./dist || exit 1
pip install "./dist/lightgbm-${LGB_VER}.tar.gz" -v || exit 1
pip install -v --no-deps "./dist/lightgbm-${LGB_VER}.tar.gz" || exit 1

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we pip install a just-built lightgbm package in CI, it's generally been JUST lightgbm because all the runtime dependencies were already set up, like this:

Requirement already satisfied: numpy>=1.21.3 in c:\miniconda\envs\test-env\lib\site-packages (from lightgbm==4.6.0.99) (1.22.4)
Requirement already satisfied: scipy in c:\miniconda\envs\test-env\lib\site-packages (from lightgbm==4.6.0.99) (1.7.3)

(example Windows 'sdist' job from master)

But in some of the pixi-managed environments, I saw lines like this:

Processing .\lightgbm-4.6.0.99-py3-none-win_amd64.whl
Collecting numpy>=1.21.3 (from lightgbm==4.6.0.99)
  Downloading numpy-2.4.6-cp312-cp312-win_amd64.whl.metadata (6.6 kB)
Collecting scipy (from lightgbm==4.6.0.99)
  Downloading scipy-1.17.1-cp312-cp312-win_amd64.whl.metadata (60 kB)
Downloading numpy-2.4.6-cp312-cp312-win_amd64.whl (12.3 MB)
   ---------------------------------------- 12.3/12.3 MB 76.8 MB/s  0:00:00
Downloading scipy-1.17.1-cp312-cp312-win_amd64.whl (36.5 MB)
   ---------------------------------------- 36.5/36.5 MB 64.6 MB/s  0:00:00
Installing collected packages: numpy, scipy, lightgbm

Successfully installed lightgbm-4.6.0.99 numpy-2.4.6 scipy-1.17.1

Notice:  A new release of pip is available: 26.1.1 -> 26.1.2
Notice:  To update, run: python.exe -m pip install --upgrade pip
pytest: D:\a\LightGBM\LightGBM\.ci\test-windows.ps1:149
Line |
 149 |  pytest -ra $tests ; Assert-Output $?
     |  ~~~~~~
     | The term 'pytest' is not recognized as a name of a cmdlet, function, script file, or executable program. Check
     | the spelling of the name, or if a path was included, verify that the path is correct and try again.

(build log from this PR)

I've seen stuff like that when mixing pip and conda locally too before... pip install numpy inside a conda environment can just lead to weird stuff.

Since we're intended to use conda / pixi to provide all runtime dependency for test environments in this repo, proposing installing the lightgbm packages with pip install --no-deps to avoid having to worry about problems like this.

Comment thread .ci/test.sh
'h5py>=3.10' \
'ipywidgets>=8.1.2' \
'notebook>=7.1.2'
fi

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is separate down here so we don't pay the cost installing these for jobs that don't need them.

For pixi-managed jobs with the environment locked already, I'm just proposing including them in the environment. There's 0 conda solve (the biggest addition to the time), and the file downloads, writes, and disk space are negligible here in CI.

Comment thread pixi.toml Outdated

[dependencies]
python = "3.10.*"
numpy = "*"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setup-pixi whines if you don't have any default dependencies, so I added these. I don't understand the impact of what's added here in [dependencies], so open to suggestions on other values.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is the culprit. setup-pixi probably whines because there is no default environment (we only have py310 here) and by not specifying environments: ..., it tries to install the default environment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jameslamb jameslamb changed the title WIP: [ci] use pixi to manage end-of-life Python environments [ci] use pixi to manage end-of-life Python environments Jun 3, 2026
@jameslamb
jameslamb marked this pull request as ready for review June 3, 2026 19:31
@jameslamb

jameslamb commented Jun 3, 2026 •

Copy link
Copy Markdown
Member Author

(ignore the failing R jobs, I'll document and fix them separately... they're unrelated to this PR)

update: put up a fix in #7331

@borchero borchero left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for setting this up @jameslamb! I left a couple comments on best practices :)

Comment thread .ci/test.sh Resolved
Comment thread .ci/test.sh Outdated
)
if [[ "${PYTHON_ENV_MANAGER}" == "pixi" ]]; then
pixi remove -e "${CI_PIXI_ENV}" \
"${PACKAGES_TO_REMOVE[@]}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This not only uninstalls the packages but also modifies the pixi.toml (and pixi.lock). It also causes another solve.

The standard way to do this with pixi would actually be to have two separate environments (e.g. py310 and py310-no-optionals), see e.g. https://github.com/Quantco/dataframely/blob/50e18a8d403c46046ef8867da45af685fe10f316/pixi.toml#L135-L142.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh ok I see.

This is a bit awkward because at this point in the script we've already activated one environment in the shell with pixi shell-hook... activating another one might lead to weird behavior if the activation scripts in any of the packages conflict. Would also need to install lightgbm into the py310-no-optionals environment, and the method of that differs slightly based on how it was built above.

For now I think we can just do something like:

  • skip this codepath in pixi-managed environments
  • do the "import works without any optional dependencies" test in the test-python-oldest CI job

That'd mean we miss a bit of coverage if any dependencies have imports that are conditional on operating system or CPU architecture but only for oldest-supported-Python, so I think it's a very very acceptable risk.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this in recent commits.

Comment thread .github/workflows/python_package.yml Resolved
Comment thread .github/workflows/static_analysis.yml Resolved
Comment thread pixi.toml Outdated

[dependencies]
python = "3.10.*"
numpy = "*"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is the culprit. setup-pixi probably whines because there is no default environment (we only have py310 here) and by not specifying environments: ..., it tries to install the default environment.

Comment thread pixi.toml Outdated
Comment on lines +7 to +8
python = "3.10.*"
numpy = "*"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the current use, this is totally fine. In general, one would list all non-optional dependencies here with the same bounds as in pyproject.toml (e.g. python = ">=3.10). Then, you can override/concretize the bounds within the features. For example, within the [feature.py310.dependencies] block, we'd set python = "3.10.*". This way, we could easily introduce [feature.py311.dependencies] etc in the future.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhhh ok I see now how things compose together, got it.

I've updated this list to match LightGBM's non-optional dependencies, including with the same pins as pyproject.toml: #7328 (comment)

Comment thread pixi.toml Resolved
Comment thread pixi.toml
Comment on lines +32 to +33
[environments]
py310 = ["py310"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend to definitely have some default environment. We could just have the default (non-optional) dependencies in there now:

Suggested change
[environments]
py310 = ["py310"]
[environments]
default = []
py310 = ["py310"]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok makes sense, thanks for explaining that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In recent commits, I've set this up with the non-optional dependencies + pip.

[dependencies]
pip = "*"
python = "3.10.*"
numpy = ">=1.21.3"
scipy = "*"

[environments]
default = []

Thanks for explaining that.

Comment thread pixi.toml Outdated
pytest = "7.4.*"

# dask dependencies are not needed on Windows, so split out separately here
[feature.py310-dask.dependencies]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@borchero this is new since you last reviewed. I realize I'd accidentally dropped running the Dask tests in Python 3.10 jobs on Linux / macOS.

Splitting this out because I want to avoid dask being installed and imported on Windows, since we end up skipping those tests anyway.

if platform in {"cygwin", "win32"}:
pytest.skip("lightgbm.dask is not currently supported on Windows", allow_module_level=True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! Since it is rather uncommon to see operating systems in environment names, one thing that you could do would be to add dask to the py310 environment based on the OS. Specifically:

[feature.py310.target.unix.dependencies]
dask = "2022.12.*"
distributed = "2022.12.*"

This way, you could drop the py310-windows env below

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this seems much nicer, let me try that.

@jameslamb
jameslamb requested a review from borchero June 7, 2026 06:02
@jameslamb

Copy link
Copy Markdown
Member Author

Thanks for all the comments and advice @borchero , I learned a lot! Think this is ready for another review whenever you have time.

@borchero borchero left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates! :) I just have a few small comments left

Comment thread pixi.toml Outdated
pytest = "7.4.*"

# dask dependencies are not needed on Windows, so split out separately here
[feature.py310-dask.dependencies]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! Since it is rather uncommon to see operating systems in environment names, one thing that you could do would be to add dask to the py310 environment based on the OS. Specifically:

[feature.py310.target.unix.dependencies]
dask = "2022.12.*"
distributed = "2022.12.*"

This way, you could drop the py310-windows env below

Comment thread pixi.toml Resolved
Comment thread .ci/test-windows.ps1 Resolved
Comment thread .github/workflows/python_package.yml Resolved

@borchero borchero left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you! 😁

@jameslamb

Copy link
Copy Markdown
Member Author

Thanks so much for the guidance @borchero !

I just double-checked and everything in the recent commits I pushed (in response to your review) appears to be working:

  • Dask tests are running on macOS / Linux
  • setup-pixi is getting skipped on CI jobs that don't need it

I'm really happy with where this ended up, and now very motivated to see pixi adopted for more things where we want locked environments.

I think it could be interesting to eliminate conda completely in our Python CI, actually. Like:

  • linting, docs, etc. --> pixi
  • Python unit tests for end-of-life versions --> pixi
  • all other Python unit test jobs --> pip (to more thoroughly test the pip experience for users, and reduce the risk of accidentally linking to shared libraries from conda or using conda's compilers)

@jameslamb
jameslamb merged commit 431d988 into master Jun 17, 2026
60 checks passed
@jameslamb
jameslamb deleted the pixi branch June 17, 2026 01:40
@borchero

Copy link
Copy Markdown
Member

I think it could be interesting to eliminate conda completely in our Python CI, actually

Agreed, that would be nice :)

@jameslamb

Copy link
Copy Markdown
Member Author

I just wrote up an RFC about dropping most (all) uses of conda here: #7355

I'd like to do at least some of that after the v4.7.0 release is done, as part of a bunch of build and packaging related improvements I'd like to work on.

@borchero if you're interested in working on more pixi stuff here, I think the if-else jobs would be great candidate for locked environments with pixi... they use a Python interpreter + conda environment just for running pytest tests, but really are testing C++-only functionality so I'd be very happy to see this conda env replaced with pixi:

LightGBM/.ci/test.sh

Lines 90 to 91 in cf16013

if [[ $TASK == "if-else" ]]; then
conda create -q -y -n "${CONDA_ENV}" "${CONDA_PYTHON_REQUIREMENT}" numpy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants