Skip to content
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

BLD: Setup meson builds #49115

Merged
merged 129 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
a5b2572
BLD: Add meson.build files
lithomas1 Oct 15, 2022
7191763
BLD: Python changes to make meson build work
lithomas1 Oct 15, 2022
65be7cc
Merge branch 'main' of https://github.com/pandas-dev/pandas into add-…
lithomas1 Oct 17, 2022
e5805fc
Revert moving generate_version.py to scripts
lithomas1 Oct 17, 2022
2e89b1f
Update for sas byteswap module
lithomas1 Oct 18, 2022
66346a4
Update
lithomas1 Oct 22, 2022
e267f87
Add pyproject.toml changes
lithomas1 Oct 23, 2022
545a91a
Merge branch 'meson-py-file-changes' into add-meson-build-files
lithomas1 Oct 23, 2022
f85bd93
Revert "Add pyproject.toml changes"
lithomas1 Oct 23, 2022
8896002
Merge branch 'main' into add-meson-build-files
lithomas1 Oct 25, 2022
399a93f
fix style?
lithomas1 Oct 29, 2022
d01fe1a
fix?
lithomas1 Oct 29, 2022
9b64577
Squashed commit of the following:
lithomas1 Nov 9, 2022
0de3320
Merge branch 'main' of https://github.com/pandas-dev/pandas into add-…
lithomas1 Nov 9, 2022
a26c9dd
catchsegv and prepare to disable asserts
lithomas1 Nov 9, 2022
cf24f5d
Go for green
lithomas1 Nov 10, 2022
c5cbcab
green take 2
lithomas1 Nov 11, 2022
f56d1d4
Go for green take 3
lithomas1 Nov 11, 2022
24d07c2
forgot something
lithomas1 Nov 12, 2022
8ceb278
get the code-checks passing too
lithomas1 Nov 12, 2022
7d26fca
Merge branch 'main' of https://github.com/pandas-dev/pandas into add-…
lithomas1 Nov 12, 2022
796d4c4
Fix the darn code checks
lithomas1 Nov 12, 2022
d2764ef
pls work
lithomas1 Nov 12, 2022
ec386f7
maybe get the last failure
lithomas1 Nov 12, 2022
069e76e
pls work
lithomas1 Nov 12, 2022
9068490
maybe maybe maybe???
lithomas1 Nov 12, 2022
6d18625
pls work
lithomas1 Nov 13, 2022
496294c
Respect pyproject.toml
lithomas1 Nov 13, 2022
2e642e8
Maybe bring back cython doctests
lithomas1 Nov 13, 2022
2157f06
Cleanup
lithomas1 Nov 13, 2022
f1555ee
Cleanup
lithomas1 Nov 15, 2022
057ea20
Merge branch 'main' into add-meson-build-files
lithomas1 Nov 15, 2022
beeab2a
Revert changes to 32 bit
lithomas1 Nov 18, 2022
4ecbb41
Fix tests and benchmarks
lithomas1 Nov 18, 2022
e4c5933
Merge branch 'main' of https://github.com/pandas-dev/pandas into add-…
lithomas1 Nov 18, 2022
d00d35a
Fix bad merge
lithomas1 Nov 18, 2022
a823304
Try to fix tests after sync
lithomas1 Nov 19, 2022
073e371
Fix package checks
lithomas1 Nov 19, 2022
55f7ec8
Update
lithomas1 Nov 23, 2022
5c5a0ac
Merge branch 'main' of https://github.com/pandas-dev/pandas into add-…
lithomas1 Nov 23, 2022
5570d9b
update deps
lithomas1 Nov 23, 2022
2b5505e
Update all deps
lithomas1 Nov 23, 2022
a7a2e6f
update the rest
lithomas1 Nov 23, 2022
6ef5a18
Go for green
lithomas1 Nov 23, 2022
9fd9d2b
Merge branch 'main' of https://github.com/pandas-dev/pandas into add-…
lithomas1 Nov 23, 2022
782a8c7
Disable arm64 wheels for now
lithomas1 Nov 23, 2022
3dae633
Merge branch 'main' into add-meson-build-files
lithomas1 Nov 25, 2022
f86b11a
Merge branch 'add-meson-build-files' of github.com:lithomas1/pandas i…
lithomas1 Nov 25, 2022
d7a7bf1
Add docs
lithomas1 Nov 26, 2022
597dd67
update test docs
lithomas1 Nov 26, 2022
aa94fc7
Merge branch 'main' into add-meson-build-files
lithomas1 Nov 29, 2022
77ed403
Update wheels.yml
lithomas1 Nov 29, 2022
a2a8361
Merge branch 'main' into add-meson-build-files
lithomas1 Nov 29, 2022
a01aee8
Bad merge
lithomas1 Nov 29, 2022
b0a2093
Merge branch 'main' into add-meson-build-files
lithomas1 Dec 3, 2022
c2291dc
Fix benchmarks
lithomas1 Dec 3, 2022
6663d31
Update test_rolling.py
lithomas1 Dec 3, 2022
094957d
Update test_rolling.py
lithomas1 Dec 4, 2022
4fe3ec0
Merge branch 'pandas-dev:main' into add-meson-build-files
lithomas1 Dec 7, 2022
0ee732d
Merge branch 'main' into add-meson-build-files
lithomas1 Dec 23, 2022
6291b9b
Adjust for editable support in meson-python
lithomas1 Dec 30, 2022
f6422e5
Merge branch 'main' into add-meson-build-files
lithomas1 Dec 30, 2022
e1f750e
fixes
lithomas1 Dec 30, 2022
f36e014
Merge branch 'add-meson-build-files' of github.com:lithomas1/pandas i…
lithomas1 Dec 30, 2022
6ed4572
Try again
lithomas1 Dec 30, 2022
792c9eb
bring back cov-config
lithomas1 Dec 30, 2022
d64acbf
syntax
lithomas1 Dec 30, 2022
de5c42f
fix arraymanager
lithomas1 Dec 30, 2022
a862508
go for green
lithomas1 Dec 30, 2022
320a64b
Merge branch 'add-meson-build-files' of github.com:lithomas1/pandas i…
lithomas1 Dec 30, 2022
a7f973a
Update docs
lithomas1 Dec 31, 2022
fe904c5
Merge branch 'main' of https://github.com/pandas-dev/pandas into add-…
lithomas1 Jan 3, 2023
1bdedc6
Update contributing_environment.rst
lithomas1 Jan 3, 2023
9e1ccc2
Merge branch 'add-meson-build-files' of github.com:lithomas1/pandas i…
lithomas1 Jan 7, 2023
09c573d
Merge branch 'main' of https://github.com/pandas-dev/pandas into add-…
lithomas1 Jan 7, 2023
9c63bb1
Re-enable more tests
lithomas1 Jan 7, 2023
a3e7ba2
fix code checks
lithomas1 Jan 8, 2023
7a5e1d8
Also install _util.py
lithomas1 Jan 8, 2023
7f6afda
Install in editable mode on Windows as well
lithomas1 Jan 8, 2023
b9e9087
Merge branch 'pandas-dev:main' into add-meson-build-files
lithomas1 Jan 10, 2023
9592429
Merge branch 'main' into add-meson-build-files
lithomas1 Jan 21, 2023
cc89d18
Merge branch 'main' of https://github.com/pandas-dev/pandas into add-…
lithomas1 Feb 11, 2023
c228822
Add back the conda-forge compilers
lithomas1 Feb 13, 2023
cd38f4c
Merge branch 'main' into add-meson-build-files
lithomas1 Feb 16, 2023
3136cc5
debug
lithomas1 Mar 2, 2023
93f6e86
Merge branch 'main' into add-meson-build-files
lithomas1 Mar 2, 2023
b8be6a4
try something
lithomas1 Mar 2, 2023
12617c0
Merge branch 'main' into add-meson-build-files
lithomas1 Mar 2, 2023
6d088dd
missing deps for 3.11
lithomas1 Mar 2, 2023
23c2aaa
Merge branch 'main' into add-meson-build-files
lithomas1 Mar 3, 2023
3d92e2b
Bump meson, simplify
lithomas1 Mar 4, 2023
3b6bc5c
Merge branch 'main' into add-meson-build-files
lithomas1 Mar 14, 2023
61e4172
update for capsules?
lithomas1 Mar 14, 2023
cd5137c
more fixes
lithomas1 Mar 14, 2023
65bba29
Merge branch 'main' into add-meson-build-files
lithomas1 Mar 18, 2023
7225844
debug
lithomas1 Mar 18, 2023
e6133df
pin meson-python
lithomas1 Mar 18, 2023
dd46921
add back coverage stuff
lithomas1 Mar 24, 2023
9142148
Merge branch 'main' into add-meson-build-files
lithomas1 Mar 24, 2023
cf67679
yay, a 32 bit test passed
lithomas1 Mar 24, 2023
5213192
Merge branch 'main' into add-meson-build-files
lithomas1 Mar 26, 2023
3881827
fully fix 32-bit
lithomas1 Mar 28, 2023
2306dd5
pin more
lithomas1 Mar 28, 2023
e8389ca
remove unnecessary import
lithomas1 Mar 28, 2023
dc9d5f1
Merge branch 'main' of https://github.com/pandas-dev/pandas into add-…
lithomas1 Apr 10, 2023
1ff6c41
Squashed commit of the following:
lithomas1 Apr 11, 2023
41ef248
fixes
lithomas1 Apr 12, 2023
98600cc
Merge branch 'main' into add-meson-build-files
lithomas1 Apr 18, 2023
e34480a
remove libreduction
lithomas1 Apr 18, 2023
fe03652
go for green
lithomas1 Apr 22, 2023
b513ee8
go for green
lithomas1 Apr 23, 2023
00fd024
Update code-checks.yml
lithomas1 Apr 23, 2023
f854c02
Merge branch 'main' into add-meson-build-files
lithomas1 Apr 23, 2023
6270a2a
fix id
lithomas1 Apr 23, 2023
035df6b
fix code checks
lithomas1 Apr 23, 2023
a3e59fa
Merge branch 'main' of https://github.com/pandas-dev/pandas into add-…
lithomas1 May 3, 2023
1bfd61e
Go for green
lithomas1 May 3, 2023
ae67059
use python instead of python3
lithomas1 May 3, 2023
70a43bb
fix 32bit/musl compile command
lithomas1 May 3, 2023
996b93c
updates
lithomas1 May 4, 2023
432cd42
go for green
lithomas1 May 4, 2023
cda4d05
Fix code checks again? and musllinux
lithomas1 May 4, 2023
62fa12c
fix doctests
lithomas1 May 4, 2023
4df819c
fix docstrings
lithomas1 May 4, 2023
46845d5
remove extra meson-python install
lithomas1 May 4, 2023
58895b2
Merge branch 'main' of https://github.com/pandas-dev/pandas into add-…
lithomas1 May 4, 2023
d9d1658
remove some TODOs
lithomas1 May 4, 2023
28237d9
Merge branch 'main' of https://github.com/pandas-dev/pandas into add-…
lithomas1 May 9, 2023
7774dea
update debug instructions
lithomas1 May 9, 2023
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 scripts/generate_version.py → generate_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Note: This file has to live next to setup.py or versioneer will not work
import argparse
import os

Expand All @@ -6,7 +7,6 @@

def write_version_info(path):
if os.environ.get("MESON_DIST_ROOT"):
# raise ValueError("dist root is", os.environ.get("MESON_DIST_ROOT"))
path = os.path.join(os.environ.get("MESON_DIST_ROOT"), path)
with open(path, "w") as file:
file.write(f'__version__="{versioneer.get_version()}"\n')
Expand Down
39 changes: 39 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This file is adapted from https://github.com/scipy/scipy/blob/main/meson.build
project(
'pandas',
'c', 'cpp', 'cython',
version: '1.6.0.dev0',
Copy link
Member

Choose a reason for hiding this comment

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

How does this version interact with some of the other work you've done to get versioneer to work?

Copy link
Member Author

@lithomas1 lithomas1 Oct 16, 2022

Choose a reason for hiding this comment

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

versioneer determines the __version__ attribute. The version here is currently only used be meson-python(incorrectly) to determine the wheel filename(we are working on getting meson-python to use the __version__ tag as well).

In the future, this'll probably only be a fallback version, if everything fails to detect the pandas version properly.

Copy link
Member

Choose a reason for hiding this comment

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

I am still a bit wary of using meson-python coming from the angle that it is relatively immature. Sorry if I lost the answer to this question but what is the advantage of using meson-python versus just creating a simple setuptools hook to invoke meson as needed? The latter wouldn't require any changes to versioneer or other setuptools-based tooling @rgommers

Copy link
Contributor

Choose a reason for hiding this comment

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

From lithomas1#19 (comment):

@WillAyd it is possible, but I think that opens a whole new can of worms for no real reason. For example, you build the sdist with setuptools while you're building the wheel with a mix Meson and setuptools, leading to possible inconsistencies. And you'll be making cross-compiling worse rather than better.

If you want a gradual transition, it'd be better to merge this PR first, but still default to setuptools in pyproject.toml. That allows devs to start using Meson, without all contributors and users who are pip-installing from GitHub getting it straight away. And then it's a patch of a few lines to switch that default later.

In addition, I think it's optimistic to think that you can write a hook like that which won't have bugs or surprising behavior.

I am still a bit wary of using meson-python coming from the angle that it is relatively immature.

That's understandable. I'm sure there's a couple of bugs left to discover. That said, it's now been in SciPy main since last December, and in the SciPy 1.9.x release series. So hopefully the most glaring defects have been found by now. And meson and meson-python are quite actively maintained, so any painful bugs can hopefully be remedied quickly.

You also have a number of months till the next release, right? Can always just try it, and in case you're not happy right before the next release, it's literally a one-line patch to revert back to setuptools for one more release cycle.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm fine with sticking to meson-python right now.

IMO, meson-python is pretty close to being feature-complete for our use case. We're just missing FFY00/meson-python#177 and the versioning issue(we can always rename the wheel by hand in the meantime).

license: 'BSD-3',
# TODO: bump when meson 0.64.0 comes out,
# we are relying on 0.64.0 features
meson_version: '>=0.63',
default_options: [
'buildtype=release',
'c_std=c99'
]
)

py_mod = import('python')
fs = import('fs')
py = py_mod.find_installation('python')
py_dep = py.dependency()
tempita = files('generate_pxi.py')
versioneer = files('generate_version.py')

if fs.exists('_version_meson.py')
py.install_sources('_version_meson.py', subdir: 'pandas')
else
custom_target('write_version_file',
output: '_version_meson.py',
command: [
py, versioneer, '-o', '@OUTPUT@'
],
build_by_default: true,
build_always_stale: true,
install: true,
install_dir: py.get_install_dir(pure: false) / 'pandas'
)
meson.add_dist_script(py, versioneer, '-o', '_version_meson.py')
endif

subdir('pandas')
16 changes: 11 additions & 5 deletions pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,18 @@
from pandas.util._tester import test

# use the closest tagged version if possible
from pandas._version import get_versions
_built_with_meson = False
try:
from pandas._version_meson import __version__, __git_version__

_built_with_meson = True
except ImportError:
from pandas._version import get_versions

v = get_versions()
__version__ = v.get("closest-tag", v["version"])
__git_version__ = v.get("full-revisionid")
del get_versions, v
v = get_versions()
__version__ = v.get("closest-tag", v["version"])
__git_version__ = v.get("full-revisionid")
del get_versions, v

# GH 27101
__deprecated_num_index_names = ["Float64Index", "Int64Index", "UInt64Index"]
Expand Down
165 changes: 165 additions & 0 deletions pandas/_libs/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
_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@'
],
# TODO: remove these two below lines
# Weird bug in meson that only repros on my potato computer
# (possibly b/c of low number of threads)?
# The first custom_target is never built for some reason
# so algos.pyx will error out later in the build.
build_by_default: true,
build_always_stale: true
)
_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@'
]
)
_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@'
]
)
_khash_primitive_helper_dep = declare_dependency(sources: _khash_primitive_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',
'dtypes.pxd',
'hashtable.pxd',
'hashtable.pyx',
'index.pyx',
'indexing.pyx',
'internals.pyx',
'interval.pyx',
'join.pyx',
'khash.pxd',
'lib.pxd',
'missing.pxd',
'parsers.pyx',
'sparse.pyx',
'testing.pyx',
'tslib.pyx',
'util.pxd',
]
cython_sources = {}

foreach source: cython_sources_list
source_pyx = fs.copyfile(source)
cython_sources += {source: source_pyx}
endforeach

subdir('tslibs')

libs_sources = {
# Dict of extension name -> dict of {sources, include_dirs, and deps}
# numpy include dir is implicitly included
'algos': {'sources': [cython_sources['algos.pyx'], _algos_common_helper, _algos_take_helper, _khash_primitive_helper],
'include_dirs': klib_include},
WillAyd marked this conversation as resolved.
Show resolved Hide resolved
'arrays': {'sources': ['arrays.pyx']},
'groupby': {'sources': ['groupby.pyx']},
'hashing': {'sources': ['hashing.pyx']},
'hashtable': {'sources': [cython_sources['hashtable.pyx'], _khash_primitive_helper, _hashtable_class_helper, _hashtable_func_helper],
'include_dirs': klib_include},
'index': {'sources': [cython_sources['index.pyx'], _index_class_helper],
'include_dirs': [klib_include, 'tslibs']},
'indexing': {'sources': ['indexing.pyx']},
'internals': {'sources': ['internals.pyx']},
'interval': {'sources': [cython_sources['interval.pyx'], _intervaltree_helper],
'include_dirs': [klib_include, 'tslibs']},
'join': {'sources': [cython_sources['join.pyx'], _khash_primitive_helper],
'include_dirs': klib_include,
'deps': _khash_primitive_helper_dep},
'lib': {'sources': ['lib.pyx', 'src/parser/tokenizer.c'],
'include_dirs': [klib_include, inc_datetime]},
'missing': {'sources': ['missing.pyx'],
'include_dirs': [inc_datetime]},
'parsers': {'sources': [cython_sources['parsers.pyx'], 'src/parser/tokenizer.c', 'src/parser/io.c'],
'include_dirs': [klib_include, 'src'],
'deps': _khash_primitive_helper_dep},
'json': {'sources': ['src/ujson/python/ujson.c',
'src/ujson/python/objToJSON.c',
'src/ujson/python/date_conversions.c',
'src/ujson/python/JSONtoObj.c',
'src/ujson/lib/ultrajsonenc.c',
'src/ujson/lib/ultrajsondec.c',
'tslibs/src/datetime/np_datetime.c',
'tslibs/src/datetime/np_datetime_strings.c'],
'include_dirs': [inc_datetime, 'src/ujson/lib', 'src/ujson/python']},
'reduction': {'sources': ['reduction.pyx']},
'ops': {'sources': ['ops.pyx']},
'ops_dispatch': {'sources': ['ops_dispatch.pyx']},
'properties': {'sources': ['properties.pyx']},
'reshape': {'sources': ['reshape.pyx']},
'sparse': {'sources': [cython_sources['sparse.pyx'], _sparse_op_helper]},
'tslib': {'sources': ['tslib.pyx', 'tslibs/src/datetime/np_datetime.c'],
'include_dirs': inc_datetime},
'testing': {'sources': ['testing.pyx']},
'writers': {'sources': ['writers.pyx']}
}


foreach ext_name, ext_dict : libs_sources
py.extension_module(
ext_name,
ext_dict.get('sources'),
include_directories: [inc_np] + ext_dict.get('include_dirs', ''),
dependencies: ext_dict.get('deps', ''),
subdir: 'pandas/_libs',
install: true
)
endforeach

py.install_sources('__init__.py',
pure: false,
subdir: 'pandas/_libs')

subdir('window')
75 changes: 75 additions & 0 deletions pandas/_libs/tslibs/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# TODO: can this be removed, I wish meson copied .pyx source to the build dir automatically
Copy link
Member

Choose a reason for hiding this comment

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

Is this copy actually required? Seems to somewhat blur the lines of the purpose of an in source vs out of source build if we have to copy the source over

Copy link
Contributor

Choose a reason for hiding this comment

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

AFAICT the ones that are passed to the extension_module() definitions below are the original sources, so it's not clear to me either, what this is doing.

In general I would not expect this to be needed unless somehow cython is attempting to automatically figure out information traversing multiple files. For example includes. But there do not seem to be any generated sources in this directory anyway?

Copy link
Member Author

Choose a reason for hiding this comment

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

The .pxi files are generated in the build directory, but the other sources are in the source directory. I don't think cython has an option to pass an include directory for .pxi files, so we have to copy the source files that depend on the .pxi files over.

If a source doesn't have a dependency on a .pxi file, we don't copy it.

Copy link
Contributor

@eli-schwartz eli-schwartz Oct 16, 2022

Choose a reason for hiding this comment

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

What confused me mostly is that you don't seem to be using the copied .pxd anyway? Meson is getting told to run the cython tool on a .pyx in the source directory, not the build directory, as far as I can tell.

Copy link
Contributor

@eli-schwartz eli-schwartz Oct 16, 2022

Choose a reason for hiding this comment

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

I don't think cython has an option to pass an include directory for .pxi files

Right, and this is another thing that may make sense to add to cython upstream, there's a couple other options that already got added while SciPy was porting over.

EDIT: Hold on, this should already exist...

Copy link
Member Author

Choose a reason for hiding this comment

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

What confused me mostly is that you don't seem to be using the copied .pxd anyway? Meson is getting told to run the cython tool on a .pyx in the source directory, not the build directory, as far as I can tell.

cython_sources is a dict mapping source file -> configure_file output(build directory location).

The copied pxd would be used if we did something like cython_sources['algos.pyx'].

Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this is too crazy but would it make sense to just have any imports of the generated templates assume those templates come from the build folder rather than the source?

Copy link
Member Author

Choose a reason for hiding this comment

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

This would mean patching Cython unfortunately. I don't think the include dir command line option works, for pxi files.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I was afraid of that... I wonder why not though. Is this a cython bug? If not, it's definitely a cython feature request.

tslibs_pxd_sources_list = [
# List of cython sources e.g. .pyx, .pxd & __init__.py
# Does NOT include .pxi.in
'__init__.py',
'base.pxd',
'ccalendar.pxd',
'conversion.pxd',
'dtypes.pxd',
'nattype.pxd',
'np_datetime.pxd',
'offsets.pxd',
'parsing.pxd',
'period.pxd',
'timedeltas.pxd',
'timestamps.pxd',
'timezones.pxd',
'tzconversion.pxd',
'util.pxd',
]

foreach source: tslibs_pxd_sources_list
source_pxd = configure_file(
input: source,
output: source,
copy: true
)
endforeach

tslibs_sources = {
# Dict of extension name -> dict of {sources, include_dirs, and deps}
# numpy include dir is implicitly included
'base': {'sources': ['base.pyx']},
'ccalendar': {'sources': ['ccalendar.pyx']},
'dtypes': {'sources': ['dtypes.pyx']},
'conversion': {'sources': ['conversion.pyx', 'src/datetime/np_datetime.c'],
'include_dirs': inc_datetime},
'fields': {'sources': ['fields.pyx', 'src/datetime/np_datetime.c']},
'nattype': {'sources': ['nattype.pyx']},
'np_datetime': {'sources': ['np_datetime.pyx', 'src/datetime/np_datetime.c', 'src/datetime/np_datetime_strings.c'],
'include_dirs': inc_datetime},
'offsets': {'sources': ['offsets.pyx', 'src/datetime/np_datetime.c'],
'include_dirs': inc_datetime},
'parsing': {'sources': ['parsing.pyx', '../src/parser/tokenizer.c'],
'include_dirs': klib_include},
'period': {'sources': ['period.pyx', 'src/datetime/np_datetime.c'],
'include_dirs': inc_datetime},
'strptime': {'sources': ['strptime.pyx', 'src/datetime/np_datetime.c'],
'include_dirs': inc_datetime},
'timedeltas': {'sources': ['timedeltas.pyx', 'src/datetime/np_datetime.c'],
'include_dirs': inc_datetime},
'timestamps': {'sources': ['timestamps.pyx', 'src/datetime/np_datetime.c'],
'include_dirs': inc_datetime},
'timezones': {'sources': ['timezones.pyx', 'src/datetime/np_datetime.c'],
'include_dirs': inc_datetime},
'tzconversion': {'sources': ['tzconversion.pyx', 'src/datetime/np_datetime.c'],
'include_dirs': inc_datetime},
'vectorized': {'sources': ['vectorized.pyx', 'src/datetime/np_datetime.c'],
'include_dirs': inc_datetime}
}

foreach ext_name, ext_dict : tslibs_sources
py.extension_module(
ext_name,
ext_dict.get('sources'),
include_directories: [inc_np] + ext_dict.get('include_dirs', ''),
dependencies: ext_dict.get('deps', ''),
subdir: 'pandas/_libs/tslibs',
install: true
)
endforeach

py.install_sources('__init__.py',
pure: false,
subdir: 'pandas/_libs/tslibs')
18 changes: 18 additions & 0 deletions pandas/_libs/window/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
py.extension_module(
'aggregations',
['aggregations.pyx'],
include_directories: [inc_np, '../src'],
WillAyd marked this conversation as resolved.
Show resolved Hide resolved
dependencies: [py_dep],
subdir: 'pandas/_libs/window',
override_options : ['cython_language=cpp'],
install: true
)

py.extension_module(
'indexers',
['indexers.pyx'],
include_directories: [inc_np],
dependencies: [py_dep],
subdir: 'pandas/_libs/window',
install: true
)
36 changes: 36 additions & 0 deletions pandas/io/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
subdirs_list = [
# exclude sas, since it contains extension modules
# and has its own meson.build
'clipboard',
'excel',
'formats',
'json',
'parsers'
]
foreach subdir: subdirs_list
install_subdir(subdir, install_dir: py.get_install_dir(pure: false) / 'pandas/io')
endforeach
top_level_py_list = [
'__init__.py',
'api.py',
'clipboards.py',
'common.py',
'date_converters.py',
'feather_format.py',
'gbq.py',
'html.py',
'orc.py',
'parquet.py',
'pickle.py',
'pytables.py',
'spss.py',
'sql.py',
'stata.py',
'xml.py'
]
foreach file: top_level_py_list
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to do this for python modules?

Copy link
Member Author

Choose a reason for hiding this comment

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

The io directory can't be installed with install_subdir unfortunately since the sas extension modules live there (and we need to have custom logic for that).

So we have to install each of the top-level files under io separately (since we are not using install_subdir). The rest of the files in folders are fine, since they can be installed with install_subdir.

Ideally, this file disappears when the sas Cython files are moved to _libs. I can do that in a follow-up if you'd like?

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of a for loop you could probably just pass the entire array as a variadic argument to py.install_sources

py.install_sources(file,
pure: false,
subdir: 'pandas/io')
endforeach
subdir('sas')
Loading