forked from scikit-learn/scikit-learn
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BLD Add Meson support (scikit-learn#28040)
Co-authored-by: Adrin Jalali <adrin.jalali@gmail.com> Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org> Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com> Co-authored-by: Julien Jerphanion <git@jjerphan.xyz>
- Loading branch information
1 parent
07007b3
commit 56625c9
Showing
34 changed files
with
1,100 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import re | ||
import shlex | ||
import subprocess | ||
from pathlib import Path | ||
|
||
|
||
def main(): | ||
pyproject_path = Path("pyproject.toml") | ||
|
||
if not pyproject_path.exists(): | ||
raise SystemExit( | ||
"Can not find pyproject.toml. You should run this script from the" | ||
" scikit-learn root folder." | ||
) | ||
|
||
old_pyproject_content = pyproject_path.read_text(encoding="utf-8") | ||
if 'build-backend = "mesonpy"' not in old_pyproject_content: | ||
new_pyproject_content = re.sub( | ||
r"\[build-system\]", | ||
r'[build-system]\nbuild-backend = "mesonpy"', | ||
old_pyproject_content, | ||
) | ||
pyproject_path.write_text(new_pyproject_content, encoding="utf-8") | ||
|
||
command = shlex.split( | ||
"pip install --editable . --verbose --no-build-isolation " | ||
"--config-settings editable-verbose=true" | ||
) | ||
|
||
exception = None | ||
try: | ||
subprocess.check_call(command) | ||
except Exception as e: | ||
exception = e | ||
finally: | ||
pyproject_path.write_text(old_pyproject_content, encoding="utf-8") | ||
|
||
if exception is not None: | ||
raise RuntimeError( | ||
"There was some error when running the script" | ||
) from exception | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
project( | ||
'scikit-learn', | ||
'c', 'cpp', 'cython', | ||
version: run_command('sklearn/_build_utils/version.py', check: true).stdout().strip(), | ||
license: 'BSD-3', | ||
meson_version: '>= 1.1.0', | ||
default_options: [ | ||
'buildtype=debugoptimized', | ||
'c_std=c99', | ||
'cpp_std=c++14', | ||
], | ||
) | ||
|
||
cc = meson.get_compiler('c') | ||
cpp = meson.get_compiler('cpp') | ||
|
||
# Check compiler is recent enough (see "Toolchain Roadmap" for details) | ||
if cc.get_id() == 'gcc' | ||
if not cc.version().version_compare('>=8.0') | ||
error('scikit-learn requires GCC >= 8.0') | ||
endif | ||
elif cc.get_id() == 'msvc' | ||
if not cc.version().version_compare('>=19.20') | ||
error('scikit-learn requires at least vc142 (default with Visual Studio 2019) ' + \ | ||
'when building with MSVC') | ||
endif | ||
endif | ||
|
||
_global_c_args = cc.get_supported_arguments( | ||
'-Wno-unused-but-set-variable', | ||
'-Wno-unused-function', | ||
'-Wno-conversion', | ||
'-Wno-misleading-indentation', | ||
) | ||
add_project_arguments(_global_c_args, language : 'c') | ||
|
||
# We need -lm for all C code (assuming it uses math functions, which is safe to | ||
# assume for scikit-learn). For C++ it isn't needed, because libstdc++/libc++ is | ||
# guaranteed to depend on it. | ||
m_dep = cc.find_library('m', required : false) | ||
if m_dep.found() | ||
add_project_link_arguments('-lm', language : 'c') | ||
endif | ||
|
||
tempita = files('sklearn/_build_utils/tempita.py') | ||
|
||
py = import('python').find_installation(pure: false) | ||
|
||
# Copy all the .py files to the install dir, rather than using | ||
# py.install_sources and needing to list them explicitely one by one | ||
install_subdir('sklearn', install_dir: py.get_install_dir()) | ||
|
||
subdir('sklearn') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
py.extension_module( | ||
'_check_build', | ||
'_check_build.pyx', | ||
cython_args: cython_args, | ||
install: true, | ||
subdir: 'sklearn/__check_build', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import argparse | ||
import os | ||
|
||
from Cython import Tempita as tempita | ||
|
||
# XXX: If this import ever fails (does it really?), vendor either | ||
# cython.tempita or numpy/npy_tempita. | ||
|
||
|
||
def process_tempita(fromfile, outfile=None): | ||
"""Process tempita templated file and write out the result. | ||
The template file is expected to end in `.c.tp` or `.pyx.tp`: | ||
E.g. processing `template.c.in` generates `template.c`. | ||
""" | ||
with open(fromfile, "r", encoding="utf-8") as f: | ||
template_content = f.read() | ||
|
||
template = tempita.Template(template_content) | ||
content = template.substitute() | ||
|
||
with open(outfile, "w", encoding="utf-8") as f: | ||
f.write(content) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("infile", type=str, help="Path to the input file") | ||
parser.add_argument("-o", "--outdir", type=str, help="Path to the output directory") | ||
parser.add_argument( | ||
"-i", | ||
"--ignore", | ||
type=str, | ||
help=( | ||
"An ignored input - may be useful to add a " | ||
"dependency between custom targets" | ||
), | ||
) | ||
args = parser.parse_args() | ||
|
||
if not args.infile.endswith(".tp"): | ||
raise ValueError(f"Unexpected extension: {args.infile}") | ||
|
||
if not args.outdir: | ||
raise ValueError("Missing `--outdir` argument to tempita.py") | ||
|
||
outdir_abs = os.path.join(os.getcwd(), args.outdir) | ||
outfile = os.path.join( | ||
outdir_abs, os.path.splitext(os.path.split(args.infile)[1])[0] | ||
) | ||
|
||
process_tempita(args.infile, outfile) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.