-
Notifications
You must be signed in to change notification settings - Fork 1
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
Meson poc #19
Meson poc #19
Changes from 4 commits
36112ef
6219ad0
33a0a7c
43ba995
15e0385
0eeaa7d
7c2c132
3df0963
e70bfc6
950f0a6
7e401dc
95e49e7
781a671
d074fc1
e0214a5
2751aee
5e04d4e
6edad44
8f0adf2
47f21d7
30e11c6
132a689
89c4b6b
5f0a175
48b02d4
9b83eff
039123f
deb9305
eb41668
94ccae2
4c0d93c
6efabb1
883fca7
b49f4c5
da09ba0
5b4dddc
25178d5
a15586a
3c5ae94
c01409c
a286e66
e61ef35
588527f
9a94331
d4da54b
15e2cd0
3983e1c
f3a9419
bfcb9d0
524e493
a62ee23
0397b46
29184cb
cdf5605
4ce0be4
1766cf9
7ca8ef9
3ae8954
d7ddd87
19157f0
6f97335
a3a4eb5
9277582
b7e6624
dd65aaf
6cbdfb8
dd0f03c
a4c3389
05d2f53
26435dd
7a2bb0c
a16e989
71bcd58
a948860
dec5317
aa57379
ecb6f6e
4d0a15b
c4c3f9b
335ccf8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
*.py[ocd] | ||
*.so | ||
.build_cache_dir | ||
.mesonpy-native-file.ini | ||
MANIFEST | ||
|
||
# Python files # | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import argparse | ||
import os | ||
|
||
from Cython import Tempita | ||
|
||
|
||
def process_tempita(pxifile, outfile): | ||
if ( | ||
os.path.exists(outfile) | ||
and os.stat(pxifile).st_mtime < os.stat(outfile).st_mtime | ||
): | ||
# if .pxi.in is not updated, no need to output .pxi | ||
return | ||
|
||
with open(pxifile) as f: | ||
tmpl = f.read() | ||
pyxcontent = Tempita.sub(tmpl) | ||
|
||
with open(outfile, "w") as f: | ||
f.write(pyxcontent) | ||
|
||
|
||
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") | ||
args = parser.parse_args() | ||
|
||
if not args.infile.endswith(".in"): | ||
raise ValueError(f"Unexpected extension: {args.infile}") | ||
|
||
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) | ||
|
||
|
||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# This file is adapted from https://github.com/scipy/scipy/blob/main/meson.build | ||
project( | ||
'pandas', | ||
'c', 'cpp', 'cython', | ||
version: '1.5.0.dev0', | ||
license: 'BSD-3', | ||
meson_version: '>=0.60', | ||
default_options: [ | ||
'buildtype=debugoptimized', | ||
'c_std=c99' | ||
] | ||
) | ||
|
||
py_mod = import('python') | ||
py = py_mod.find_installation('python3') | ||
py_dep = py.dependency() | ||
tempita = files('generate_pxi.py') | ||
|
||
subdir('pandas') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,295 @@ | ||
_algos_common_helper = custom_target('algos_common_helper_pxi', | ||
output: 'algos_common_helper.pxi', | ||
input: 'algos_common_helper.pxi.in', | ||
command: [ | ||
py, tempita, '@INPUT@', '-o', '@OUTDIR@' | ||
] | ||
) | ||
_algos_take_helper = custom_target('algos_take_helper_pxi', | ||
output: 'algos_take_helper.pxi', | ||
input: 'algos_take_helper.pxi.in', | ||
command: [ | ||
py, tempita, '@INPUT@', '-o', '@OUTDIR@' | ||
] | ||
) | ||
_khash_primitive_helper = custom_target('khash_primitive_helper_pxi', | ||
output: 'khash_for_primitive_helper.pxi', | ||
input: 'khash_for_primitive_helper.pxi.in', | ||
command: [ | ||
py, tempita, '@INPUT@', '-o', '@OUTDIR@' | ||
] | ||
) | ||
_hashtable_class_helper = custom_target('hashtable_class_helper_pxi', | ||
output: 'hashtable_class_helper.pxi', | ||
input: 'hashtable_class_helper.pxi.in', | ||
command: [ | ||
py, tempita, '@INPUT@', '-o', '@OUTDIR@' | ||
] | ||
) | ||
_hashtable_func_helper = custom_target('hashtable_func_helper_pxi', | ||
output: 'hashtable_func_helper.pxi', | ||
input: 'hashtable_func_helper.pxi.in', | ||
command: [ | ||
py, tempita, '@INPUT@', '-o', '@OUTDIR@' | ||
] | ||
) | ||
_index_class_helper = custom_target('index_class_helper_pxi', | ||
output: 'index_class_helper.pxi', | ||
input: 'index_class_helper.pxi.in', | ||
command: [ | ||
py, tempita, '@INPUT@', '-o', '@OUTDIR@' | ||
] | ||
) | ||
_sparse_op_helper = custom_target('sparse_op_helper_pxi', | ||
output: 'sparse_op_helper.pxi', | ||
input: 'sparse_op_helper.pxi.in', | ||
command: [ | ||
py, tempita, '@INPUT@', '-o', '@OUTDIR@' | ||
] | ||
) | ||
_intervaltree_helper = custom_target('intervaltree_helper_pxi', | ||
output: 'intervaltree.pxi', | ||
input: 'intervaltree.pxi.in', | ||
command: [ | ||
py, tempita, '@INPUT@', '-o', '@OUTDIR@' | ||
] | ||
) | ||
_algos_common_helper_dep = declare_dependency(sources: _algos_common_helper) | ||
_algos_take_helper_dep = declare_dependency(sources: _algos_take_helper) | ||
_khash_primitive_helper_dep = declare_dependency(sources: _khash_primitive_helper) | ||
_hashtable_class_helper_dep = declare_dependency(sources: _hashtable_class_helper) | ||
_hashtable_func_helper_dep = declare_dependency(sources: _hashtable_func_helper) | ||
_index_class_helper_dep = declare_dependency(sources: _index_class_helper) | ||
_sparse_op_helper_dep = declare_dependency(sources: _sparse_op_helper) | ||
_intervaltree_helper_dep = declare_dependency(sources: _intervaltree_helper) | ||
# TODO: can this be removed, I wish meson copied .pyx source to the build dir automatically | ||
# The reason we can't build the pyx files inplace and copy to build dir is because | ||
# the generated pxi files cannot be written to the source directory. | ||
# (Meson only supports out of tree builds) | ||
cython_sources_list = [ | ||
# List of cython sources e.g. .pyx, .pxd & __init__.py | ||
# Does NOT include .pxi.in | ||
'__init__.py', | ||
'algos.pxd', | ||
'algos.pyx', | ||
'arrays.pxd', | ||
'arrays.pyx', | ||
'dtypes.pxd', | ||
'groupby.pyx', | ||
'hashing.pyx', | ||
'hashtable.pxd', | ||
'hashtable.pyx', | ||
'index.pyx', | ||
'indexing.pyx', | ||
'internals.pyx', | ||
'interval.pyx', | ||
'join.pyx', | ||
'khash.pxd', | ||
'lib.pyx', | ||
'lib.pxd', | ||
'missing.pxd', | ||
'missing.pyx', | ||
'ops.pyx', | ||
'ops_dispatch.pyx', | ||
'parsers.pyx', | ||
'properties.pyx', | ||
'reduction.pyx', | ||
'reshape.pyx', | ||
'sparse.pyx', | ||
'testing.pyx', | ||
'tslib.pyx', | ||
'util.pxd', | ||
'writers.pyx' | ||
] | ||
cython_sources = {} | ||
|
||
foreach source: cython_sources_list | ||
source_pyx = configure_file( | ||
input: source, | ||
output: source, | ||
copy: true | ||
) | ||
cython_sources += {source: source_pyx} | ||
endforeach | ||
|
||
#py.extension_module( | ||
# 'parsing', | ||
# ['tslibs/parsing.pyx'], | ||
# include_directories: [inc_np, klib_include, 'src/parser', 'src', 'tslibs/src/datetime'], | ||
# dependencies: [py_dep], | ||
# subdir: 'pandas/_libs/tslibs', | ||
# install: true | ||
#) | ||
|
||
subdir('tslibs') | ||
|
||
py.extension_module( | ||
'algos', | ||
[_algos_common_helper, _algos_take_helper, _khash_primitive_helper, cython_sources['algos.pyx']], | ||
include_directories: [inc_np, klib_include], | ||
dependencies: [py_dep, _algos_common_helper_dep, _algos_take_helper_dep, _khash_primitive_helper_dep], | ||
subdir: 'pandas/_libs', | ||
install: true | ||
) | ||
|
||
py.extension_module( | ||
'arrays', | ||
cython_sources['arrays.pyx'], | ||
include_directories: [inc_np], | ||
dependencies: py_dep, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on an SciPy discussion with @rgommers, Meson 0.63.0 now implicitly adds that py_dep for you. This reduces boilerplate in build definitions, as long as you bump your minimum requirement to the latest Meson release. Of course, the SciPy example you based this on, predates this change, so SciPy has not adapted to this yet or raised the minimum build requirements. As a brand-new Meson port, you'd be ideally placed to take advantage of this and in doing so avoid adding that boilerplate to any version of meson.build. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the heads-up, will include it in my next clean-up commit. |
||
subdir: 'pandas/_libs', | ||
install: true | ||
) | ||
|
||
py.extension_module( | ||
'groupby', | ||
cython_sources['groupby.pyx'], | ||
include_directories: [inc_np], | ||
dependencies: py_dep, | ||
subdir: 'pandas/_libs', | ||
install: true | ||
) | ||
|
||
py.extension_module( | ||
'hashing', | ||
cython_sources['hashing.pyx'], | ||
include_directories: [inc_np], | ||
dependencies: py_dep, | ||
subdir: 'pandas/_libs', | ||
install: true | ||
) | ||
|
||
py.extension_module( | ||
'hashtable', | ||
[cython_sources['hashtable.pyx'], _khash_primitive_helper, _hashtable_class_helper, _hashtable_func_helper], | ||
include_directories: [inc_np, klib_include], | ||
dependencies: [py_dep, _khash_primitive_helper_dep, _hashtable_class_helper_dep, _hashtable_func_helper_dep], | ||
subdir: 'pandas/_libs', | ||
install: true | ||
) | ||
|
||
#py.extension_module( | ||
# 'index', | ||
# [cython_sources['index.pyx'], _index_class_helper], | ||
# include_directories: [inc_np, klib_include], | ||
# dependencies: [py_dep, _index_class_helper_dep], | ||
# subdir: 'pandas/_libs', | ||
# install: true | ||
#) | ||
|
||
py.extension_module( | ||
'indexing', | ||
['indexing.pyx'], | ||
include_directories: [inc_np], | ||
dependencies: py_dep, | ||
subdir: 'pandas/_libs', | ||
install: true | ||
) | ||
|
||
py.extension_module( | ||
'internals', | ||
['internals.pyx'], | ||
include_directories: [inc_np], | ||
dependencies: py_dep, | ||
subdir: 'pandas/_libs', | ||
install: true | ||
) | ||
|
||
#py.extension_module( | ||
# 'interval', | ||
# [cython_sources['interval.pyx'], _intervaltree_helper], | ||
# include_directories: [inc_np, klib_include], | ||
# dependencies: [py_dep, _intervaltree_helper_dep], | ||
# subdir: 'pandas/_libs', | ||
# install: true | ||
#) | ||
|
||
py.extension_module( | ||
'join', | ||
[cython_sources['join.pyx'], _khash_primitive_helper], | ||
include_directories: [inc_np, klib_include], | ||
dependencies: [py_dep, _khash_primitive_helper_dep], | ||
subdir: 'pandas/_libs', | ||
install: true | ||
) | ||
|
||
py.extension_module( | ||
'lib', | ||
['lib.pyx', 'src/parser/tokenizer.c'], | ||
include_directories: [inc_np, klib_include, inc_datetime], | ||
dependencies: [py_dep], | ||
subdir: 'pandas/_libs', | ||
install: true | ||
) | ||
|
||
#py.extension_module( | ||
# 'parsers', | ||
# [cython_sources['parsers.pyx'], _khash_primitive_helper, 'src/parser/tokenizer.c', 'src/parser/io.c'], | ||
# include_directories: [inc_np, klib_include, 'src/parser', 'src'], | ||
# dependencies: [py_dep, _khash_primitive_helper_dep], | ||
# subdir: 'pandas/_libs', | ||
# install: true | ||
#) | ||
|
||
py.extension_module( | ||
'reduction', | ||
['reduction.pyx'], | ||
include_directories: [inc_np], | ||
dependencies: [py_dep], | ||
subdir: 'pandas/_libs', | ||
install: true | ||
) | ||
|
||
py.extension_module( | ||
'ops', | ||
['ops.pyx'], | ||
include_directories: [inc_np], | ||
dependencies: [py_dep], | ||
subdir: 'pandas/_libs', | ||
install: true | ||
) | ||
|
||
py.extension_module( | ||
'ops_dispatch', | ||
['ops_dispatch.pyx'], | ||
include_directories: [inc_np], | ||
dependencies: [py_dep], | ||
subdir: 'pandas/_libs', | ||
install: true | ||
) | ||
|
||
py.extension_module( | ||
'properties', | ||
['properties.pyx'], | ||
include_directories: [inc_np], | ||
dependencies: [py_dep], | ||
subdir: 'pandas/_libs', | ||
install: true | ||
) | ||
|
||
py.extension_module( | ||
'reshape', | ||
['reshape.pyx'], | ||
include_directories: [inc_np], | ||
dependencies: [py_dep], | ||
subdir: 'pandas/_libs', | ||
install: true | ||
) | ||
|
||
py.extension_module( | ||
'sparse', | ||
[cython_sources['sparse.pyx'], _sparse_op_helper], | ||
include_directories: [inc_np], | ||
dependencies: [py_dep, _sparse_op_helper_dep], | ||
subdir: 'pandas/_libs', | ||
install: true | ||
) | ||
|
||
py.extension_module( | ||
'tslib', | ||
['tslib.pyx', 'tslibs/src/datetime/np_datetime.c'], | ||
include_directories: [inc_np, inc_datetime], | ||
dependencies: [py_dep], | ||
subdir: 'pandas/_libs', | ||
install: true | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this normal to do this with meson? With setuptools you build release by default and have to opt in to debug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meson's default buildtype is "debug" (especially useful for getting started on a wide variety of generic C/C++ projects), but e.g. the PEP 517 builder will then set a release buildtype. So this poc, when built with
pip install
, will still build release by default. But runningmeson setup && ninja
will use this setting to build with debug.People running meson setup instead of pip install are probably hacking on pandas anyway, so that might not be a bad distinction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll note that
numpy.distutils
does build in debug mode by default (it has hardcoded-g
flags), and it indeed seems like a sensible default for development.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense in theory, but in practice to limit the scope of changes I would suggest we still now build release by default and come back to a later change to make a clear delineation between when we want a debug versus release build.