Skip to content

Commit

Permalink
Add meson-format to pre-commit (pandas-dev#60682)
Browse files Browse the repository at this point in the history
* Add pre-commit rule for meson

* Format meson configuration files

* Use github library
  • Loading branch information
WillAyd authored Jan 8, 2025
1 parent 8e49cbe commit 3aba767
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 114 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ repos:
files: ^pandas/_libs/src|^pandas/_libs/include
args: [-i]
types_or: [c, c++]
- repo: https://github.com/trim21/pre-commit-mirror-meson
rev: v1.6.1
hooks:
- id: meson-fmt
args: ['--inplace']
- repo: local
hooks:
- id: pyright
Expand Down
37 changes: 17 additions & 20 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# This file is adapted from https://github.com/scipy/scipy/blob/main/meson.build
project(
'pandas',
'c', 'cpp', 'cython',
'c',
'cpp',
'cython',
version: run_command(['generate_version.py', '--print'], check: true).stdout().strip(),
license: 'BSD-3',
meson_version: '>=1.2.1',
default_options: [
'buildtype=release',
'c_std=c11',
'warning_level=2',
]
default_options: ['buildtype=release', 'c_std=c11', 'warning_level=2'],
)

fs = import('fs')
Expand All @@ -18,41 +16,40 @@ tempita = files('generate_pxi.py')
versioneer = files('generate_version.py')


add_project_arguments('-DNPY_NO_DEPRECATED_API=0', language : 'c')
add_project_arguments('-DNPY_NO_DEPRECATED_API=0', language : 'cpp')
add_project_arguments('-DNPY_NO_DEPRECATED_API=0', language: 'c')
add_project_arguments('-DNPY_NO_DEPRECATED_API=0', language: 'cpp')

# Allow supporting older numpys than the version compiled against
# Set the define to the min supported version of numpy for pandas
# e.g. right now this is targeting numpy 1.21+
add_project_arguments('-DNPY_TARGET_VERSION=NPY_1_21_API_VERSION', language : 'c')
add_project_arguments('-DNPY_TARGET_VERSION=NPY_1_21_API_VERSION', language : 'cpp')
add_project_arguments('-DNPY_TARGET_VERSION=NPY_1_21_API_VERSION', language: 'c')
add_project_arguments(
'-DNPY_TARGET_VERSION=NPY_1_21_API_VERSION',
language: 'cpp',
)


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

cy = meson.get_compiler('cython')
if cy.version().version_compare('>=3.1.0')
add_project_arguments('-Xfreethreading_compatible=true', language : 'cython')
add_project_arguments('-Xfreethreading_compatible=true', language: 'cython')
endif

# Needed by pandas.test() when it looks for the pytest ini options
py.install_sources(
'pyproject.toml',
subdir: 'pandas'
)
py.install_sources('pyproject.toml', subdir: 'pandas')

subdir('pandas')
148 changes: 85 additions & 63 deletions pandas/_libs/meson.build
Original file line number Diff line number Diff line change
@@ -1,94 +1,119 @@
_algos_take_helper = custom_target('algos_take_helper_pxi',
_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@'
]
command: [py, tempita, '@INPUT@', '-o', '@OUTDIR@'],
)
_algos_common_helper = custom_target('algos_common_helper_pxi',
_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@'
]
command: [py, tempita, '@INPUT@', '-o', '@OUTDIR@'],
)
_khash_primitive_helper = custom_target('khash_primitive_helper_pxi',
_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@'
]
command: [py, tempita, '@INPUT@', '-o', '@OUTDIR@'],
)
_hashtable_class_helper = custom_target('hashtable_class_helper_pxi',
_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@'
]
command: [py, tempita, '@INPUT@', '-o', '@OUTDIR@'],
)
_hashtable_func_helper = custom_target('hashtable_func_helper_pxi',
_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@'
]
command: [py, tempita, '@INPUT@', '-o', '@OUTDIR@'],
)
_index_class_helper = custom_target('index_class_helper_pxi',
_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@'
]
command: [py, tempita, '@INPUT@', '-o', '@OUTDIR@'],
)
_sparse_op_helper = custom_target('sparse_op_helper_pxi',
_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@'
]
command: [py, tempita, '@INPUT@', '-o', '@OUTDIR@'],
)
_intervaltree_helper = custom_target('intervaltree_helper_pxi',
_intervaltree_helper = custom_target(
'intervaltree_helper_pxi',
output: 'intervaltree.pxi',
input: 'intervaltree.pxi.in',
command: [
py, tempita, '@INPUT@', '-o', '@OUTDIR@'
]
command: [py, tempita, '@INPUT@', '-o', '@OUTDIR@'],
)
_khash_primitive_helper_dep = declare_dependency(
sources: _khash_primitive_helper,
)
_khash_primitive_helper_dep = declare_dependency(sources: _khash_primitive_helper)

subdir('tslibs')

libs_sources = {
# Dict of extension name -> dict of {sources, include_dirs, and deps}
# numpy include dir is implicitly included
'algos': {'sources': ['algos.pyx', _algos_common_helper, _algos_take_helper], 'deps': _khash_primitive_helper_dep},
'algos': {
'sources': ['algos.pyx', _algos_common_helper, _algos_take_helper],
'deps': _khash_primitive_helper_dep,
},
'arrays': {'sources': ['arrays.pyx']},
'groupby': {'sources': ['groupby.pyx']},
'hashing': {'sources': ['hashing.pyx']},
'hashtable': {'sources': ['hashtable.pyx', _hashtable_class_helper, _hashtable_func_helper], 'deps': _khash_primitive_helper_dep},
'index': {'sources': ['index.pyx', _index_class_helper], 'deps': _khash_primitive_helper_dep},
'hashtable': {
'sources': [
'hashtable.pyx',
_hashtable_class_helper,
_hashtable_func_helper,
],
'deps': _khash_primitive_helper_dep,
},
'index': {
'sources': ['index.pyx', _index_class_helper],
'deps': _khash_primitive_helper_dep,
},
'indexing': {'sources': ['indexing.pyx']},
'internals': {'sources': ['internals.pyx']},
'interval': {'sources': ['interval.pyx', _intervaltree_helper],
'deps': _khash_primitive_helper_dep},
'join': {'sources': ['join.pyx', _khash_primitive_helper],
'deps': _khash_primitive_helper_dep},
'interval': {
'sources': ['interval.pyx', _intervaltree_helper],
'deps': _khash_primitive_helper_dep,
},
'join': {
'sources': ['join.pyx', _khash_primitive_helper],
'deps': _khash_primitive_helper_dep,
},
'lib': {'sources': ['lib.pyx', 'src/parser/tokenizer.c']},
'missing': {'sources': ['missing.pyx']},
'pandas_datetime': {'sources': ['src/vendored/numpy/datetime/np_datetime.c',
'src/vendored/numpy/datetime/np_datetime_strings.c',
'src/datetime/date_conversions.c',
'src/datetime/pd_datetime.c']},
'pandas_parser': {'sources': ['src/parser/tokenizer.c',
'src/parser/io.c',
'src/parser/pd_parser.c']},
'parsers': {'sources': ['parsers.pyx', 'src/parser/tokenizer.c', 'src/parser/io.c'],
'deps': _khash_primitive_helper_dep},
'json': {'sources': ['src/vendored/ujson/python/ujson.c',
'src/vendored/ujson/python/objToJSON.c',
'src/vendored/ujson/python/JSONtoObj.c',
'src/vendored/ujson/lib/ultrajsonenc.c',
'src/vendored/ujson/lib/ultrajsondec.c']},
'pandas_datetime': {
'sources': [
'src/vendored/numpy/datetime/np_datetime.c',
'src/vendored/numpy/datetime/np_datetime_strings.c',
'src/datetime/date_conversions.c',
'src/datetime/pd_datetime.c',
],
},
'pandas_parser': {
'sources': [
'src/parser/tokenizer.c',
'src/parser/io.c',
'src/parser/pd_parser.c',
],
},
'parsers': {
'sources': ['parsers.pyx', 'src/parser/tokenizer.c', 'src/parser/io.c'],
'deps': _khash_primitive_helper_dep,
},
'json': {
'sources': [
'src/vendored/ujson/python/ujson.c',
'src/vendored/ujson/python/objToJSON.c',
'src/vendored/ujson/python/JSONtoObj.c',
'src/vendored/ujson/lib/ultrajsonenc.c',
'src/vendored/ujson/lib/ultrajsondec.c',
],
},
'ops': {'sources': ['ops.pyx']},
'ops_dispatch': {'sources': ['ops_dispatch.pyx']},
'properties': {'sources': ['properties.pyx']},
Expand All @@ -98,13 +123,13 @@ libs_sources = {
'sparse': {'sources': ['sparse.pyx', _sparse_op_helper]},
'tslib': {'sources': ['tslib.pyx']},
'testing': {'sources': ['testing.pyx']},
'writers': {'sources': ['writers.pyx']}
'writers': {'sources': ['writers.pyx']},
}

cython_args = [
'--include-dir',
meson.current_build_dir(),
'-X always_allow_keywords=true'
'-X always_allow_keywords=true',
]
if get_option('buildtype') == 'debug'
cython_args += ['--gdb']
Expand All @@ -118,7 +143,7 @@ foreach ext_name, ext_dict : libs_sources
include_directories: [inc_np, inc_pd],
dependencies: ext_dict.get('deps', ''),
subdir: 'pandas/_libs',
install: true
install: true,
)
endforeach

Expand Down Expand Up @@ -148,14 +173,11 @@ sources_to_install = [
'sparse.pyi',
'testing.pyi',
'tslib.pyi',
'writers.pyi'
'writers.pyi',
]

foreach source: sources_to_install
py.install_sources(
source,
subdir: 'pandas/_libs'
)
foreach source : sources_to_install
py.install_sources(source, subdir: 'pandas/_libs')
endforeach

subdir('window')
13 changes: 5 additions & 8 deletions pandas/_libs/tslibs/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tslibs_sources = {
cython_args = [
'--include-dir',
meson.current_build_dir(),
'-X always_allow_keywords=true'
'-X always_allow_keywords=true',
]
if get_option('buildtype') == 'debug'
cython_args += ['--gdb']
Expand All @@ -36,7 +36,7 @@ foreach ext_name, ext_dict : tslibs_sources
include_directories: [inc_np, inc_pd],
dependencies: ext_dict.get('deps', ''),
subdir: 'pandas/_libs/tslibs',
install: true
install: true,
)
endforeach

Expand All @@ -56,12 +56,9 @@ sources_to_install = [
'timestamps.pyi',
'timezones.pyi',
'tzconversion.pyi',
'vectorized.pyi'
'vectorized.pyi',
]

foreach source: sources_to_install
py.install_sources(
source,
subdir: 'pandas/_libs/tslibs'
)
foreach source : sources_to_install
py.install_sources(source, subdir: 'pandas/_libs/tslibs')
endforeach
19 changes: 6 additions & 13 deletions pandas/_libs/window/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ py.extension_module(
cython_args: ['-X always_allow_keywords=true'],
include_directories: [inc_np, inc_pd],
subdir: 'pandas/_libs/window',
override_options : ['cython_language=cpp'],
install: true
override_options: ['cython_language=cpp'],
install: true,
)

py.extension_module(
Expand All @@ -14,18 +14,11 @@ py.extension_module(
cython_args: ['-X always_allow_keywords=true'],
include_directories: [inc_np, inc_pd],
subdir: 'pandas/_libs/window',
install: true
install: true,
)

sources_to_install = [
'__init__.py',
'aggregations.pyi',
'indexers.pyi'
]
sources_to_install = ['__init__.py', 'aggregations.pyi', 'indexers.pyi']

foreach source: sources_to_install
py.install_sources(
source,
subdir: 'pandas/_libs/window'
)
foreach source : sources_to_install
py.install_sources(source, subdir: 'pandas/_libs/window')
endforeach
Loading

0 comments on commit 3aba767

Please sign in to comment.