Repository navigation
Conversation
β¦ix env activation on non-Python-3.10 jobs
| - conda config --add channels nodefaults | ||
| - conda config --add channels conda-forge | ||
| - conda config --set channel_priority strict | ||
| - conda init powershell |
There was a problem hiding this comment.
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.
| ) | ||
| IncludeDefaultRules = $true | ||
| # Additional rules that are disabled by default | ||
| ExcludeRules = @( |
There was a problem hiding this comment.
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 $?| 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. |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
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.
| 'h5py>=3.10' \ | ||
| 'ipywidgets>=8.1.2' \ | ||
| 'notebook>=7.1.2' | ||
| fi |
There was a problem hiding this comment.
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.
|
|
||
| [dependencies] | ||
| python = "3.10.*" | ||
| numpy = "*" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
ahhhhh ok yes I think you're right:
|
(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
left a comment
There was a problem hiding this comment.
Thank you for setting this up @jameslamb! I left a couple comments on best practices :)
| ) | ||
| if [[ "${PYTHON_ENV_MANAGER}" == "pixi" ]]; then | ||
| pixi remove -e "${CI_PIXI_ENV}" \ | ||
| "${PACKAGES_TO_REMOVE[@]}" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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-oldestCI 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.
There was a problem hiding this comment.
I did this in recent commits.
|
|
||
| [dependencies] | ||
| python = "3.10.*" | ||
| numpy = "*" |
There was a problem hiding this comment.
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.
| python = "3.10.*" | ||
| numpy = "*" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
| [environments] | ||
| py310 = ["py310"] |
There was a problem hiding this comment.
I would recommend to definitely have some default environment. We could just have the default (non-optional) dependencies in there now:
| [environments] | |
| py310 = ["py310"] | |
| [environments] | |
| default = [] | |
| py310 = ["py310"] |
There was a problem hiding this comment.
Ok makes sense, thanks for explaining that.
There was a problem hiding this comment.
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.
Co-authored-by: Oliver Borchert <me@borchero.com>
| pytest = "7.4.*" | ||
|
|
||
| # dask dependencies are not needed on Windows, so split out separately here | ||
| [feature.py310-dask.dependencies] |
There was a problem hiding this comment.
@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.
LightGBM/tests/python_package_test/test_dask.py
Lines 22 to 23 in 796f175
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Oh this seems much nicer, let me try that.
|
Thanks for all the comments and advice @borchero , I learned a lot! Think this is ready for another review whenever you have time. |
borchero
left a comment
There was a problem hiding this comment.
Thanks for the updates! :) I just have a few small comments left
| pytest = "7.4.*" | ||
|
|
||
| # dask dependencies are not needed on Windows, so split out separately here | ||
| [feature.py310-dask.dependencies] |
There was a problem hiding this comment.
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
Co-authored-by: Oliver Borchert <oliver.borchert@quantco.com>
Co-authored-by: Oliver Borchert <me@borchero.com>
borchero
left a comment
There was a problem hiding this comment.
Looks great, thank you! π
|
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:
I'm really happy with where this ended up, and now very motivated to see I think it could be interesting to eliminate
|
Agreed, that would be nice :) |
|
I just wrote up an RFC about dropping most (all) uses of 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 Lines 90 to 91 in cf16013 |
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.
condaenvironment solves dominate that time, and #7288 was one attempt to alleviate that by using a newerconda(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)
masterlinks to runs (click me)
this PR:
latest
masterbuild:So it helped a little in the GitHub Actions Python 3.10 job (which had an up-to-date
condausinglibmamba) 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.