diff --git a/sklearn/__check_build/meson.build b/sklearn/__check_build/meson.build index 8295e6b573639..5f6115d976549 100644 --- a/sklearn/__check_build/meson.build +++ b/sklearn/__check_build/meson.build @@ -1,7 +1,6 @@ py.extension_module( '_check_build', - '_check_build.pyx', - cython_args: cython_args, + cython_gen.process('_check_build.pyx'), install: true, subdir: 'sklearn/__check_build', ) diff --git a/sklearn/_loss/meson.build b/sklearn/_loss/meson.build index ead867dcfa746..a4b3425a21cd2 100644 --- a/sklearn/_loss/meson.build +++ b/sklearn/_loss/meson.build @@ -16,9 +16,8 @@ _loss_pyx = custom_target( py.extension_module( '_loss', - _loss_pyx, + cython_gen.process(_loss_pyx), dependencies: [openmp_dep], - cython_args: cython_args, install: true, subdir: 'sklearn/_loss', ) diff --git a/sklearn/cluster/_hdbscan/meson.build b/sklearn/cluster/_hdbscan/meson.build index b6a11eda8bb71..f2e3ac91b1eb2 100644 --- a/sklearn/cluster/_hdbscan/meson.build +++ b/sklearn/cluster/_hdbscan/meson.build @@ -1,6 +1,6 @@ cluster_hdbscan_extension_metadata = { - '_linkage': {'sources': ['_linkage.pyx', metrics_cython_tree]}, - '_reachability': {'sources': ['_reachability.pyx']}, + '_linkage': {'sources': [cython_gen.process('_linkage.pyx'), metrics_cython_tree]}, + '_reachability': {'sources': [cython_gen.process('_reachability.pyx')]}, '_tree': {'sources': ['_tree.pyx']} } @@ -9,7 +9,6 @@ foreach ext_name, ext_dict : cluster_hdbscan_extension_metadata ext_name, ext_dict.get('sources'), dependencies: [np_dep], - cython_args: cython_args, subdir: 'sklearn/cluster/_hdbscan', install: true ) diff --git a/sklearn/cluster/meson.build b/sklearn/cluster/meson.build index 9031d11d56319..6c11619f3ca55 100644 --- a/sklearn/cluster/meson.build +++ b/sklearn/cluster/meson.build @@ -1,17 +1,16 @@ cluster_extension_metadata = { '_dbscan_inner': - {'sources': ['_dbscan_inner.pyx'], 'override_options': ['cython_language=cpp']}, + {'sources': [cython_gen_cpp.process('_dbscan_inner.pyx')]}, '_hierarchical_fast': - {'sources': ['_hierarchical_fast.pyx', metrics_cython_tree], - 'override_options': ['cython_language=cpp']}, + {'sources': [cython_gen_cpp.process('_hierarchical_fast.pyx'), metrics_cython_tree]}, '_k_means_common': - {'sources': ['_k_means_common.pyx'], 'dependencies': [openmp_dep]}, + {'sources': [cython_gen.process('_k_means_common.pyx')], 'dependencies': [openmp_dep]}, '_k_means_lloyd': - {'sources': ['_k_means_lloyd.pyx'], 'dependencies': [openmp_dep]}, + {'sources': [cython_gen.process('_k_means_lloyd.pyx')], 'dependencies': [openmp_dep]}, '_k_means_elkan': - {'sources': ['_k_means_elkan.pyx'], 'dependencies': [openmp_dep]}, + {'sources': [cython_gen.process('_k_means_elkan.pyx')], 'dependencies': [openmp_dep]}, '_k_means_minibatch': - {'sources': ['_k_means_minibatch.pyx'], 'dependencies': [openmp_dep]}, + {'sources': [cython_gen.process('_k_means_minibatch.pyx')], 'dependencies': [openmp_dep]}, } foreach ext_name, ext_dict : cluster_extension_metadata @@ -19,8 +18,6 @@ foreach ext_name, ext_dict : cluster_extension_metadata ext_name, [ext_dict.get('sources'), utils_cython_tree], dependencies: [np_dep] + ext_dict.get('dependencies', []), - override_options : ext_dict.get('override_options', []), - cython_args: cython_args, subdir: 'sklearn/cluster', install: true ) diff --git a/sklearn/datasets/meson.build b/sklearn/datasets/meson.build index 77f784d610b30..4efcd279315de 100644 --- a/sklearn/datasets/meson.build +++ b/sklearn/datasets/meson.build @@ -1,8 +1,7 @@ py.extension_module( '_svmlight_format_fast', - '_svmlight_format_fast.pyx', + cython_gen.process('_svmlight_format_fast.pyx'), dependencies: [np_dep], - cython_args: cython_args, subdir: 'sklearn/datasets', install: true ) diff --git a/sklearn/decomposition/meson.build b/sklearn/decomposition/meson.build index 93dc6dff06e90..75b67a46981f4 100644 --- a/sklearn/decomposition/meson.build +++ b/sklearn/decomposition/meson.build @@ -1,16 +1,14 @@ py.extension_module( '_online_lda_fast', - ['_online_lda_fast.pyx', utils_cython_tree], - cython_args: cython_args, + [cython_gen.process('_online_lda_fast.pyx'), utils_cython_tree], subdir: 'sklearn/decomposition', install: true ) py.extension_module( '_cdnmf_fast', - '_cdnmf_fast.pyx', + cython_gen.process('_cdnmf_fast.pyx'), dependencies: [np_dep], - cython_args: cython_args, subdir: 'sklearn/decomposition', install: true ) diff --git a/sklearn/ensemble/_hist_gradient_boosting/meson.build b/sklearn/ensemble/_hist_gradient_boosting/meson.build index 362bd5efb82d5..122a2102800f3 100644 --- a/sklearn/ensemble/_hist_gradient_boosting/meson.build +++ b/sklearn/ensemble/_hist_gradient_boosting/meson.build @@ -1,11 +1,12 @@ hist_gradient_boosting_extension_metadata = { - '_gradient_boosting': {'sources': ['_gradient_boosting.pyx'], 'dependencies': [openmp_dep]}, - 'histogram': {'sources': ['histogram.pyx'], 'dependencies': [openmp_dep]}, - 'splitting': {'sources': ['splitting.pyx'], 'dependencies': [openmp_dep]}, - '_binning': {'sources': ['_binning.pyx'], 'dependencies': [openmp_dep]}, - '_predictor': {'sources': ['_predictor.pyx'], 'dependencies': [openmp_dep]}, - '_bitset': {'sources': ['_bitset.pyx']}, - 'common': {'sources': ['common.pyx']}, + '_gradient_boosting': {'sources': [cython_gen.process('_gradient_boosting.pyx')], + 'dependencies': [openmp_dep]}, + 'histogram': {'sources': [cython_gen.process('histogram.pyx')], 'dependencies': [openmp_dep]}, + 'splitting': {'sources': [cython_gen.process('splitting.pyx')], 'dependencies': [openmp_dep]}, + '_binning': {'sources': [cython_gen.process('_binning.pyx')], 'dependencies': [openmp_dep]}, + '_predictor': {'sources': [cython_gen.process('_predictor.pyx')], 'dependencies': [openmp_dep]}, + '_bitset': {'sources': [cython_gen.process('_bitset.pyx')]}, + 'common': {'sources': [cython_gen.process('common.pyx')]}, } foreach ext_name, ext_dict : hist_gradient_boosting_extension_metadata @@ -13,7 +14,6 @@ foreach ext_name, ext_dict : hist_gradient_boosting_extension_metadata ext_name, ext_dict.get('sources'), dependencies: ext_dict.get('dependencies', []), - cython_args: cython_args, subdir: 'sklearn/ensemble/_hist_gradient_boosting', install: true ) diff --git a/sklearn/ensemble/meson.build b/sklearn/ensemble/meson.build index bc5868b3a0104..893a4eb1a510a 100644 --- a/sklearn/ensemble/meson.build +++ b/sklearn/ensemble/meson.build @@ -1,8 +1,7 @@ py.extension_module( '_gradient_boosting', - ['_gradient_boosting.pyx'] + utils_cython_tree, + [cython_gen.process('_gradient_boosting.pyx')] + utils_cython_tree, dependencies: [np_dep], - cython_args: cython_args, subdir: 'sklearn/ensemble', install: true ) diff --git a/sklearn/feature_extraction/meson.build b/sklearn/feature_extraction/meson.build index 81732474de3b2..f810d7b28576c 100644 --- a/sklearn/feature_extraction/meson.build +++ b/sklearn/feature_extraction/meson.build @@ -1,9 +1,7 @@ py.extension_module( '_hashing_fast', - ['_hashing_fast.pyx', utils_cython_tree], + [cython_gen_cpp.process('_hashing_fast.pyx'), utils_cython_tree], dependencies: [np_dep], - override_options: ['cython_language=cpp'], - cython_args: cython_args, subdir: 'sklearn/feature_extraction', install: true ) diff --git a/sklearn/linear_model/meson.build b/sklearn/linear_model/meson.build index 04fde5a16dde8..6d8405c793389 100644 --- a/sklearn/linear_model/meson.build +++ b/sklearn/linear_model/meson.build @@ -5,8 +5,7 @@ linear_model_cython_tree = [ py.extension_module( '_cd_fast', - ['_cd_fast.pyx', utils_cython_tree], - cython_args: cython_args, + [cython_gen.process('_cd_fast.pyx'), utils_cython_tree], subdir: 'sklearn/linear_model', install: true ) @@ -26,8 +25,7 @@ foreach name: name_list ) py.extension_module( name, - pyx, - cython_args: cython_args, + cython_gen.process(pyx), subdir: 'sklearn/linear_model', install: true ) diff --git a/sklearn/manifold/meson.build b/sklearn/manifold/meson.build index ee83e8afc5019..c060590410d63 100644 --- a/sklearn/manifold/meson.build +++ b/sklearn/manifold/meson.build @@ -1,16 +1,14 @@ py.extension_module( '_utils', - ['_utils.pyx', utils_cython_tree], - cython_args: cython_args, + [cython_gen.process('_utils.pyx'), utils_cython_tree], subdir: 'sklearn/manifold', install: true ) py.extension_module( '_barnes_hut_tsne', - '_barnes_hut_tsne.pyx', + cython_gen.process('_barnes_hut_tsne.pyx'), dependencies: [np_dep, openmp_dep], - cython_args: cython_args, subdir: 'sklearn/manifold', install: true ) diff --git a/sklearn/meson.build b/sklearn/meson.build index a8c97121ba806..93de0c18d99f9 100644 --- a/sklearn/meson.build +++ b/sklearn/meson.build @@ -190,6 +190,19 @@ scikit_learn_cython_args = [ ] cython_args += scikit_learn_cython_args +cython_program = find_program(cython.cmd_array()[0]) + +cython_gen = generator(cython_program, + arguments : cython_args + ['@INPUT@', '--output-file', '@OUTPUT@'], + output : '@BASENAME@.c', +) + +cython_gen_cpp = generator(cython_program, + arguments : cython_args + ['--cplus', '@INPUT@', '--output-file', '@OUTPUT@'], + output : '@BASENAME@.cpp', +) + + # Write file in Meson build dir to be able to figure out from Python code # whether scikit-learn was built with Meson. Adapted from pandas # _version_meson.py. diff --git a/sklearn/metrics/_pairwise_distances_reduction/meson.build b/sklearn/metrics/_pairwise_distances_reduction/meson.build index 4803305e85ec4..0f7eaa286399c 100644 --- a/sklearn/metrics/_pairwise_distances_reduction/meson.build +++ b/sklearn/metrics/_pairwise_distances_reduction/meson.build @@ -38,10 +38,8 @@ _datasets_pair_pyx = custom_target( ) _datasets_pair = py.extension_module( '_datasets_pair', - _datasets_pair_pyx, + cython_gen_cpp.process(_datasets_pair_pyx), dependencies: [np_dep], - override_options: ['cython_language=cpp'], - cython_args: cython_args, subdir: 'sklearn/metrics/_pairwise_distances_reduction', install: true ) @@ -65,10 +63,8 @@ _base_pyx = custom_target( ) _base = py.extension_module( '_base', - _base_pyx, + cython_gen_cpp.process(_base_pyx), dependencies: [np_dep, openmp_dep], - override_options: ['cython_language=cpp'], - cython_args: cython_args, subdir: 'sklearn/metrics/_pairwise_distances_reduction', install: true ) @@ -93,10 +89,8 @@ _middle_term_computer_pyx = custom_target( ) _middle_term_computer = py.extension_module( '_middle_term_computer', - _middle_term_computer_pyx, + cython_gen_cpp.process(_middle_term_computer_pyx), dependencies: [np_dep], - override_options: ['cython_language=cpp'], - cython_args: cython_args, subdir: 'sklearn/metrics/_pairwise_distances_reduction', install: true ) @@ -121,10 +115,8 @@ _argkmin_pyx = custom_target( ) _argkmin = py.extension_module( '_argkmin', - _argkmin_pyx, + cython_gen_cpp.process(_argkmin_pyx), dependencies: [np_dep, openmp_dep], - override_options: ['cython_language=cpp'], - cython_args: cython_args, subdir: 'sklearn/metrics/_pairwise_distances_reduction', install: true ) @@ -149,10 +141,8 @@ _radius_neighbors_pyx = custom_target( ) _radius_neighbors = py.extension_module( '_radius_neighbors', - _radius_neighbors_pyx, + cython_gen_cpp.process(_radius_neighbors_pyx), dependencies: [np_dep, openmp_dep], - override_options: ['cython_language=cpp'], - cython_args: cython_args, subdir: 'sklearn/metrics/_pairwise_distances_reduction', install: true ) @@ -171,10 +161,8 @@ _argkmin_classmode_pyx = custom_target( ) _argkmin_classmode = py.extension_module( '_argkmin_classmode', - _argkmin_classmode_pyx, + cython_gen_cpp.process(_argkmin_classmode_pyx), dependencies: [np_dep, openmp_dep], - override_options: ['cython_language=cpp'], - cython_args: cython_args, # XXX: for some reason -fno-sized-deallocation is needed otherwise there is # an error with undefined symbol _ZdlPv at import time in manylinux wheels. # See https://github.com/scikit-learn/scikit-learn/issues/28596 for more details. @@ -198,10 +186,8 @@ _radius_neighbors_classmode_pyx = custom_target( ) _radius_neighbors_classmode = py.extension_module( '_radius_neighbors_classmode', - _radius_neighbors_classmode_pyx, + cython_gen_cpp.process(_radius_neighbors_classmode_pyx), dependencies: [np_dep, openmp_dep], - override_options: ['cython_language=cpp'], - cython_args: cython_args, subdir: 'sklearn/metrics/_pairwise_distances_reduction', install: true ) diff --git a/sklearn/metrics/cluster/meson.build b/sklearn/metrics/cluster/meson.build index 80740fde22c69..5f25296c7540f 100644 --- a/sklearn/metrics/cluster/meson.build +++ b/sklearn/metrics/cluster/meson.build @@ -1,7 +1,6 @@ py.extension_module( '_expected_mutual_info_fast', - '_expected_mutual_info_fast.pyx', - cython_args: cython_args, + cython_gen.process('_expected_mutual_info_fast.pyx'), subdir: 'sklearn/metrics/cluster', install: true ) diff --git a/sklearn/metrics/meson.build b/sklearn/metrics/meson.build index d788cf08f3add..f0f9894cc6f59 100644 --- a/sklearn/metrics/meson.build +++ b/sklearn/metrics/meson.build @@ -31,18 +31,16 @@ _dist_metrics_pyx = custom_target( _dist_metrics = py.extension_module( '_dist_metrics', - _dist_metrics_pyx, + cython_gen.process(_dist_metrics_pyx), dependencies: [np_dep], - cython_args: cython_args, subdir: 'sklearn/metrics', install: true ) py.extension_module( '_pairwise_fast', - ['_pairwise_fast.pyx', metrics_cython_tree], + [cython_gen.process('_pairwise_fast.pyx'), metrics_cython_tree], dependencies: [openmp_dep], - cython_args: cython_args, subdir: 'sklearn/metrics', install: true ) diff --git a/sklearn/neighbors/meson.build b/sklearn/neighbors/meson.build index e7ce9a2972cd3..df2aab466500c 100644 --- a/sklearn/neighbors/meson.build +++ b/sklearn/neighbors/meson.build @@ -28,9 +28,8 @@ foreach name: name_list ) py.extension_module( name, - pyx, + cython_gen.process(pyx), dependencies: [np_dep], - cython_args: cython_args, subdir: 'sklearn/neighbors', install: true ) @@ -38,8 +37,8 @@ endforeach neighbors_extension_metadata = { '_partition_nodes': - {'sources': ['_partition_nodes.pyx'], - 'override_options': ['cython_language=cpp'], 'dependencies': [np_dep]}, + {'sources': [cython_gen_cpp.process('_partition_nodes.pyx')], + 'dependencies': [np_dep]}, '_quad_tree': {'sources': ['_quad_tree.pyx'], 'dependencies': [np_dep]}, } @@ -48,8 +47,6 @@ foreach ext_name, ext_dict : neighbors_extension_metadata ext_name, [ext_dict.get('sources'), utils_cython_tree], dependencies: ext_dict.get('dependencies'), - override_options : ext_dict.get('override_options', []), - cython_args: cython_args, subdir: 'sklearn/neighbors', install: true ) diff --git a/sklearn/preprocessing/meson.build b/sklearn/preprocessing/meson.build index a8f741ee352b1..052c4a6766ad4 100644 --- a/sklearn/preprocessing/meson.build +++ b/sklearn/preprocessing/meson.build @@ -1,16 +1,13 @@ py.extension_module( '_csr_polynomial_expansion', - ['_csr_polynomial_expansion.pyx', utils_cython_tree], - cython_args: cython_args, + [cython_gen.process('_csr_polynomial_expansion.pyx'), utils_cython_tree], subdir: 'sklearn/preprocessing', install: true ) py.extension_module( '_target_encoder_fast', - ['_target_encoder_fast.pyx', utils_cython_tree], - override_options: ['cython_language=cpp'], - cython_args: cython_args, + [cython_gen_cpp.process('_target_encoder_fast.pyx'), utils_cython_tree], subdir: 'sklearn/preprocessing', install: true ) diff --git a/sklearn/svm/meson.build b/sklearn/svm/meson.build index 8372364c429cd..6232d747d1feb 100644 --- a/sklearn/svm/meson.build +++ b/sklearn/svm/meson.build @@ -4,10 +4,8 @@ liblinear_include = include_directories('src/liblinear') _newrand = py.extension_module( '_newrand', - '_newrand.pyx', - override_options: ['cython_language=cpp'], + cython_gen_cpp.process('_newrand.pyx'), include_directories: [newrand_include], - cython_args: cython_args, subdir: 'sklearn/svm', install: true ) @@ -19,20 +17,18 @@ libsvm_skl = static_library( py.extension_module( '_libsvm', - ['_libsvm.pyx', utils_cython_tree], + [cython_gen.process('_libsvm.pyx'), utils_cython_tree], include_directories: [newrand_include, libsvm_include], link_with: libsvm_skl, - cython_args: cython_args, subdir: 'sklearn/svm', install: true ) py.extension_module( '_libsvm_sparse', - ['_libsvm_sparse.pyx', utils_cython_tree], + [cython_gen.process('_libsvm_sparse.pyx'), utils_cython_tree], include_directories: [newrand_include, libsvm_include], link_with: libsvm_skl, - cython_args: cython_args, subdir: 'sklearn/svm', install: true ) @@ -44,10 +40,9 @@ liblinear_skl = static_library( py.extension_module( '_liblinear', - ['_liblinear.pyx', utils_cython_tree], + [cython_gen.process('_liblinear.pyx'), utils_cython_tree], include_directories: [newrand_include, liblinear_include], link_with: [liblinear_skl], - cython_args: cython_args, subdir: 'sklearn/svm', install: true ) diff --git a/sklearn/tree/meson.build b/sklearn/tree/meson.build index 3e16af150b7ae..87345a1e344bf 100644 --- a/sklearn/tree/meson.build +++ b/sklearn/tree/meson.build @@ -1,18 +1,18 @@ tree_extension_metadata = { '_tree': - {'sources': ['_tree.pyx'], - 'override_options': ['cython_language=cpp', 'optimization=3']}, + {'sources': [cython_gen_cpp.process('_tree.pyx')], + 'override_options': ['optimization=3']}, '_splitter': - {'sources': ['_splitter.pyx'], + {'sources': [cython_gen.process('_splitter.pyx')], 'override_options': ['optimization=3']}, '_partitioner': - {'sources': ['_partitioner.pyx'], + {'sources': [cython_gen.process('_partitioner.pyx')], 'override_options': ['optimization=3']}, '_criterion': - {'sources': ['_criterion.pyx'], + {'sources': [cython_gen.process('_criterion.pyx')], 'override_options': ['optimization=3']}, '_utils': - {'sources': ['_utils.pyx'], + {'sources': [cython_gen.process('_utils.pyx')], 'override_options': ['optimization=3']}, } @@ -22,7 +22,6 @@ foreach ext_name, ext_dict : tree_extension_metadata [ext_dict.get('sources'), utils_cython_tree], dependencies: [np_dep], override_options : ext_dict.get('override_options', []), - cython_args: cython_args, subdir: 'sklearn/tree', install: true ) diff --git a/sklearn/utils/meson.build b/sklearn/utils/meson.build index 76b5f0141393d..9ac2454172c9a 100644 --- a/sklearn/utils/meson.build +++ b/sklearn/utils/meson.build @@ -16,23 +16,23 @@ utils_cython_tree = [ utils_extension_metadata = { 'sparsefuncs_fast': - {'sources': ['sparsefuncs_fast.pyx']}, - '_cython_blas': {'sources': ['_cython_blas.pyx']}, - 'arrayfuncs': {'sources': ['arrayfuncs.pyx']}, + {'sources': [cython_gen.process('sparsefuncs_fast.pyx')]}, + '_cython_blas': {'sources': [cython_gen.process('_cython_blas.pyx')]}, + 'arrayfuncs': {'sources': [cython_gen.process('arrayfuncs.pyx')]}, 'murmurhash': { 'sources': ['murmurhash.pyx', 'src' / 'MurmurHash3.cpp'], }, '_fast_dict': - {'sources': ['_fast_dict.pyx'], 'override_options': ['cython_language=cpp']}, - '_openmp_helpers': {'sources': ['_openmp_helpers.pyx'], 'dependencies': [openmp_dep]}, - '_random': {'sources': ['_random.pyx']}, - '_typedefs': {'sources': ['_typedefs.pyx']}, - '_heap': {'sources': ['_heap.pyx']}, - '_sorting': {'sources': ['_sorting.pyx']}, + {'sources': [cython_gen_cpp.process('_fast_dict.pyx')]}, + '_openmp_helpers': {'sources': [cython_gen.process('_openmp_helpers.pyx')], 'dependencies': [openmp_dep]}, + '_random': {'sources': [cython_gen.process('_random.pyx')]}, + '_typedefs': {'sources': [cython_gen.process('_typedefs.pyx')]}, + '_heap': {'sources': [cython_gen.process('_heap.pyx')]}, + '_sorting': {'sources': [cython_gen.process('_sorting.pyx')]}, '_vector_sentinel': - {'sources': ['_vector_sentinel.pyx'], 'override_options': ['cython_language=cpp'], + {'sources': [cython_gen_cpp.process('_vector_sentinel.pyx')], 'dependencies': [np_dep]}, - '_isfinite': {'sources': ['_isfinite.pyx']}, + '_isfinite': {'sources': [cython_gen.process('_isfinite.pyx')]}, } foreach ext_name, ext_dict : utils_extension_metadata @@ -40,8 +40,6 @@ foreach ext_name, ext_dict : utils_extension_metadata ext_name, [ext_dict.get('sources'), utils_cython_tree], dependencies: ext_dict.get('dependencies', []), - override_options : ext_dict.get('override_options', []), - cython_args: cython_args, subdir: 'sklearn/utils', install: true ) @@ -70,8 +68,7 @@ foreach name: util_extension_names ) py.extension_module( name, - pyx, - cython_args: cython_args, + cython_gen.process(pyx), subdir: 'sklearn/utils', install: true )