Skip to content

BLD Check build dependencies in meson.build #28721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ all:
dev: dev-meson

dev-meson:
pip install --verbose --no-build-isolation --editable . --check-build-dependencies --config-settings editable-verbose=true
pip install --verbose --no-build-isolation --editable . --config-settings editable-verbose=true

clean: clean-meson

Expand Down
6 changes: 0 additions & 6 deletions build_tools/azure/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ scikit_learn_install() {
# toolchain
ADDITIONAL_PIP_OPTIONS='-Csetup-args=--vsenv'
fi
# TODO Always add --check-build-dependencies when all CI builds have
# pip >= 22.1.1. At the time of writing, two CI builds (debian32_atlas and
# ubuntu_atlas) have an older pip
if pip install --help | grep check-build-dependencies; then
ADDITIONAL_PIP_OPTIONS="$ADDITIONAL_PIP_OPTIONS --check-build-dependencies"
fi
# Use the pre-installed build dependencies and build directly in the
# current environment.
pip install --verbose --no-build-isolation --editable . $ADDITIONAL_PIP_OPTIONS
Expand Down
1 change: 0 additions & 1 deletion doc/developers/advanced_installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ feature, code or documentation improvement).

pip install --editable . \
--verbose --no-build-isolation \
--check-build-dependencies \
--config-settings editable-verbose=true

#. Check that the installed scikit-learn has a version number ending with
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ project(

cc = meson.get_compiler('c')
cpp = meson.get_compiler('cpp')
cython = meson.get_compiler('cython')

# Check compiler is recent enough (see "Toolchain Roadmap" for details)
if cc.get_id() == 'gcc'
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ build-backend = "mesonpy"
requires = [
"meson-python>=0.16.0",
"Cython>=3.0.10",
"numpy>=1.25",
"numpy>=2",
"scipy>=1.6.0",
]

Expand Down
35 changes: 35 additions & 0 deletions sklearn/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,41 @@ if is_mingw
add_project_arguments('-mlong-double-64', language: 'c')
endif

# Only check build dependencies version when not cross-compiling, as running
# Python interpreter can be tricky in cross-compilation settings. For more
# details, see https://docs.scipy.org/doc/scipy/building/cross_compilation.html
if not meson.is_cross_build()
Copy link
Member Author

Choose a reason for hiding this comment

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

Note to myself: I think this one should be removed, there are other places in the code where we execute Python script without protection.

I have to say I don't remember all the details about this and need to have a closer look.

Copy link
Member Author

@lesteve lesteve Jul 8, 2024

Choose a reason for hiding this comment

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

So I looked a little bit more at this and I moved all the build dependency version checks inside the if not meson.is_cross_build() clause, because I think this is safer. If I am wrong, I guess we may hear from some of this people relying on cross-compilation or they will do patches without telling us ...

It looks like conda-forge does not care about whether there is the protection if not meson.is_cross_build(), I tested this in conda-forge/scikit-learn-feedstock#268.

On the other hand, other cross-compilation settings may care more, so I would still leave this.

For example the scipy Nix package is using numpy-include-dir which is also meant to be used for tricky cross-compilation settings (basically you can not run the Python interpreter or the wrong numpy include dir gets picked): https://github.com/NixOS/nixpkgs/blob/81c768e223876ce8ff5120934c5d8f485731c6ed/pkgs/development/python-modules/scipy/default.nix#L61

The scikit-learn Nix package has a patch to get the version directly rather than running a Python script:
https://github.com/NixOS/nixpkgs/blob/fcf65eb2954fc78232b038ceef5d6a5390a734ec/pkgs/development/python-modules/scikit-learn/default.nix#L42-L44

if not py.version().version_compare('>=3.9')
error('scikit-learn requires Python>=3.9, got ' + py.version() + ' instead')
endif

cython_min_version = run_command(py, ['_min_dependencies.py', 'cython'], check: true).stdout().strip()
if not cython.version().version_compare('>=' + cython_min_version)
error('scikit-learn requires Cython>=' + cython_min_version + ', got ' + cython.version() + ' instead')
endif

meson_python_version = run_command(py,
['-c', 'import mesonpy; print(mesonpy.__version__)'], check: true).stdout().strip()
meson_python_min_version = run_command(py, ['_min_dependencies.py', 'meson-python'], check: true).stdout().strip()
if not meson_python_version.version_compare('>=' + meson_python_min_version)
error('scikit-learn requires meson-python>=' + meson_python_min_version + ', got ' + meson_python_version + ' instead')
endif

numpy_version = run_command(py,
['-c', 'import numpy; print(numpy.__version__)'], check: true).stdout().strip()
numpy_min_version = run_command(py, ['_min_dependencies.py', 'numpy'], check: true).stdout().strip()
if not numpy_version.version_compare('>=' + numpy_min_version)
error('scikit-learn requires numpy>=' + numpy_min_version + ', got ' + numpy_version + ' instead')
endif

scipy_version = run_command(py,
['-c', 'import scipy; print(scipy.__version__)'], check: true).stdout().strip()
scipy_min_version = run_command(py, ['_min_dependencies.py', 'scipy'], check: true).stdout().strip()
if not scipy_version.version_compare('>=' + scipy_min_version)
error('scikit-learn requires scipy>=' + scipy_min_version + ', got ' + scipy_version + ' instead')
endif
endif

# Adapted from scipy, each project seems to have its own tweaks for this. One
# day using dependency('numpy') will be a thing, see
# https://github.com/mesonbuild/meson/issues/9598.
Expand Down