Skip to content

Commit 3aba767

Browse files
authored
Add meson-format to pre-commit (#60682)
* Add pre-commit rule for meson * Format meson configuration files * Use github library
1 parent 8e49cbe commit 3aba767

File tree

6 files changed

+129
-114
lines changed

6 files changed

+129
-114
lines changed

.pre-commit-config.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ repos:
101101
files: ^pandas/_libs/src|^pandas/_libs/include
102102
args: [-i]
103103
types_or: [c, c++]
104+
- repo: https://github.com/trim21/pre-commit-mirror-meson
105+
rev: v1.6.1
106+
hooks:
107+
- id: meson-fmt
108+
args: ['--inplace']
104109
- repo: local
105110
hooks:
106111
- id: pyright

meson.build

+17-20
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
# This file is adapted from https://github.com/scipy/scipy/blob/main/meson.build
22
project(
33
'pandas',
4-
'c', 'cpp', 'cython',
4+
'c',
5+
'cpp',
6+
'cython',
57
version: run_command(['generate_version.py', '--print'], check: true).stdout().strip(),
68
license: 'BSD-3',
79
meson_version: '>=1.2.1',
8-
default_options: [
9-
'buildtype=release',
10-
'c_std=c11',
11-
'warning_level=2',
12-
]
10+
default_options: ['buildtype=release', 'c_std=c11', 'warning_level=2'],
1311
)
1412

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

2018

21-
add_project_arguments('-DNPY_NO_DEPRECATED_API=0', language : 'c')
22-
add_project_arguments('-DNPY_NO_DEPRECATED_API=0', language : 'cpp')
19+
add_project_arguments('-DNPY_NO_DEPRECATED_API=0', language: 'c')
20+
add_project_arguments('-DNPY_NO_DEPRECATED_API=0', language: 'cpp')
2321

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

3031

3132
if fs.exists('_version_meson.py')
3233
py.install_sources('_version_meson.py', subdir: 'pandas')
3334
else
34-
custom_target('write_version_file',
35+
custom_target(
36+
'write_version_file',
3537
output: '_version_meson.py',
36-
command: [
37-
py, versioneer, '-o', '@OUTPUT@'
38-
],
38+
command: [py, versioneer, '-o', '@OUTPUT@'],
3939
build_by_default: true,
4040
build_always_stale: true,
4141
install: true,
42-
install_dir: py.get_install_dir() / 'pandas'
42+
install_dir: py.get_install_dir() / 'pandas',
4343
)
4444
meson.add_dist_script(py, versioneer, '-o', '_version_meson.py')
4545
endif
4646

4747
cy = meson.get_compiler('cython')
4848
if cy.version().version_compare('>=3.1.0')
49-
add_project_arguments('-Xfreethreading_compatible=true', language : 'cython')
49+
add_project_arguments('-Xfreethreading_compatible=true', language: 'cython')
5050
endif
5151

5252
# Needed by pandas.test() when it looks for the pytest ini options
53-
py.install_sources(
54-
'pyproject.toml',
55-
subdir: 'pandas'
56-
)
53+
py.install_sources('pyproject.toml', subdir: 'pandas')
5754

5855
subdir('pandas')

pandas/_libs/meson.build

+85-63
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,119 @@
1-
_algos_take_helper = custom_target('algos_take_helper_pxi',
1+
_algos_take_helper = custom_target(
2+
'algos_take_helper_pxi',
23
output: 'algos_take_helper.pxi',
34
input: 'algos_take_helper.pxi.in',
4-
command: [
5-
py, tempita, '@INPUT@', '-o', '@OUTDIR@'
6-
]
5+
command: [py, tempita, '@INPUT@', '-o', '@OUTDIR@'],
76
)
8-
_algos_common_helper = custom_target('algos_common_helper_pxi',
7+
_algos_common_helper = custom_target(
8+
'algos_common_helper_pxi',
99
output: 'algos_common_helper.pxi',
1010
input: 'algos_common_helper.pxi.in',
11-
command: [
12-
py, tempita, '@INPUT@', '-o', '@OUTDIR@'
13-
]
11+
command: [py, tempita, '@INPUT@', '-o', '@OUTDIR@'],
1412
)
15-
_khash_primitive_helper = custom_target('khash_primitive_helper_pxi',
13+
_khash_primitive_helper = custom_target(
14+
'khash_primitive_helper_pxi',
1615
output: 'khash_for_primitive_helper.pxi',
1716
input: 'khash_for_primitive_helper.pxi.in',
18-
command: [
19-
py, tempita, '@INPUT@', '-o', '@OUTDIR@'
20-
]
17+
command: [py, tempita, '@INPUT@', '-o', '@OUTDIR@'],
2118
)
22-
_hashtable_class_helper = custom_target('hashtable_class_helper_pxi',
19+
_hashtable_class_helper = custom_target(
20+
'hashtable_class_helper_pxi',
2321
output: 'hashtable_class_helper.pxi',
2422
input: 'hashtable_class_helper.pxi.in',
25-
command: [
26-
py, tempita, '@INPUT@', '-o', '@OUTDIR@'
27-
]
23+
command: [py, tempita, '@INPUT@', '-o', '@OUTDIR@'],
2824
)
29-
_hashtable_func_helper = custom_target('hashtable_func_helper_pxi',
25+
_hashtable_func_helper = custom_target(
26+
'hashtable_func_helper_pxi',
3027
output: 'hashtable_func_helper.pxi',
3128
input: 'hashtable_func_helper.pxi.in',
32-
command: [
33-
py, tempita, '@INPUT@', '-o', '@OUTDIR@'
34-
]
29+
command: [py, tempita, '@INPUT@', '-o', '@OUTDIR@'],
3530
)
36-
_index_class_helper = custom_target('index_class_helper_pxi',
31+
_index_class_helper = custom_target(
32+
'index_class_helper_pxi',
3733
output: 'index_class_helper.pxi',
3834
input: 'index_class_helper.pxi.in',
39-
command: [
40-
py, tempita, '@INPUT@', '-o', '@OUTDIR@'
41-
]
35+
command: [py, tempita, '@INPUT@', '-o', '@OUTDIR@'],
4236
)
43-
_sparse_op_helper = custom_target('sparse_op_helper_pxi',
37+
_sparse_op_helper = custom_target(
38+
'sparse_op_helper_pxi',
4439
output: 'sparse_op_helper.pxi',
4540
input: 'sparse_op_helper.pxi.in',
46-
command: [
47-
py, tempita, '@INPUT@', '-o', '@OUTDIR@'
48-
]
41+
command: [py, tempita, '@INPUT@', '-o', '@OUTDIR@'],
4942
)
50-
_intervaltree_helper = custom_target('intervaltree_helper_pxi',
43+
_intervaltree_helper = custom_target(
44+
'intervaltree_helper_pxi',
5145
output: 'intervaltree.pxi',
5246
input: 'intervaltree.pxi.in',
53-
command: [
54-
py, tempita, '@INPUT@', '-o', '@OUTDIR@'
55-
]
47+
command: [py, tempita, '@INPUT@', '-o', '@OUTDIR@'],
48+
)
49+
_khash_primitive_helper_dep = declare_dependency(
50+
sources: _khash_primitive_helper,
5651
)
57-
_khash_primitive_helper_dep = declare_dependency(sources: _khash_primitive_helper)
5852

5953
subdir('tslibs')
6054

6155
libs_sources = {
6256
# Dict of extension name -> dict of {sources, include_dirs, and deps}
6357
# numpy include dir is implicitly included
64-
'algos': {'sources': ['algos.pyx', _algos_common_helper, _algos_take_helper], 'deps': _khash_primitive_helper_dep},
58+
'algos': {
59+
'sources': ['algos.pyx', _algos_common_helper, _algos_take_helper],
60+
'deps': _khash_primitive_helper_dep,
61+
},
6562
'arrays': {'sources': ['arrays.pyx']},
6663
'groupby': {'sources': ['groupby.pyx']},
6764
'hashing': {'sources': ['hashing.pyx']},
68-
'hashtable': {'sources': ['hashtable.pyx', _hashtable_class_helper, _hashtable_func_helper], 'deps': _khash_primitive_helper_dep},
69-
'index': {'sources': ['index.pyx', _index_class_helper], 'deps': _khash_primitive_helper_dep},
65+
'hashtable': {
66+
'sources': [
67+
'hashtable.pyx',
68+
_hashtable_class_helper,
69+
_hashtable_func_helper,
70+
],
71+
'deps': _khash_primitive_helper_dep,
72+
},
73+
'index': {
74+
'sources': ['index.pyx', _index_class_helper],
75+
'deps': _khash_primitive_helper_dep,
76+
},
7077
'indexing': {'sources': ['indexing.pyx']},
7178
'internals': {'sources': ['internals.pyx']},
72-
'interval': {'sources': ['interval.pyx', _intervaltree_helper],
73-
'deps': _khash_primitive_helper_dep},
74-
'join': {'sources': ['join.pyx', _khash_primitive_helper],
75-
'deps': _khash_primitive_helper_dep},
79+
'interval': {
80+
'sources': ['interval.pyx', _intervaltree_helper],
81+
'deps': _khash_primitive_helper_dep,
82+
},
83+
'join': {
84+
'sources': ['join.pyx', _khash_primitive_helper],
85+
'deps': _khash_primitive_helper_dep,
86+
},
7687
'lib': {'sources': ['lib.pyx', 'src/parser/tokenizer.c']},
7788
'missing': {'sources': ['missing.pyx']},
78-
'pandas_datetime': {'sources': ['src/vendored/numpy/datetime/np_datetime.c',
79-
'src/vendored/numpy/datetime/np_datetime_strings.c',
80-
'src/datetime/date_conversions.c',
81-
'src/datetime/pd_datetime.c']},
82-
'pandas_parser': {'sources': ['src/parser/tokenizer.c',
83-
'src/parser/io.c',
84-
'src/parser/pd_parser.c']},
85-
'parsers': {'sources': ['parsers.pyx', 'src/parser/tokenizer.c', 'src/parser/io.c'],
86-
'deps': _khash_primitive_helper_dep},
87-
'json': {'sources': ['src/vendored/ujson/python/ujson.c',
88-
'src/vendored/ujson/python/objToJSON.c',
89-
'src/vendored/ujson/python/JSONtoObj.c',
90-
'src/vendored/ujson/lib/ultrajsonenc.c',
91-
'src/vendored/ujson/lib/ultrajsondec.c']},
89+
'pandas_datetime': {
90+
'sources': [
91+
'src/vendored/numpy/datetime/np_datetime.c',
92+
'src/vendored/numpy/datetime/np_datetime_strings.c',
93+
'src/datetime/date_conversions.c',
94+
'src/datetime/pd_datetime.c',
95+
],
96+
},
97+
'pandas_parser': {
98+
'sources': [
99+
'src/parser/tokenizer.c',
100+
'src/parser/io.c',
101+
'src/parser/pd_parser.c',
102+
],
103+
},
104+
'parsers': {
105+
'sources': ['parsers.pyx', 'src/parser/tokenizer.c', 'src/parser/io.c'],
106+
'deps': _khash_primitive_helper_dep,
107+
},
108+
'json': {
109+
'sources': [
110+
'src/vendored/ujson/python/ujson.c',
111+
'src/vendored/ujson/python/objToJSON.c',
112+
'src/vendored/ujson/python/JSONtoObj.c',
113+
'src/vendored/ujson/lib/ultrajsonenc.c',
114+
'src/vendored/ujson/lib/ultrajsondec.c',
115+
],
116+
},
92117
'ops': {'sources': ['ops.pyx']},
93118
'ops_dispatch': {'sources': ['ops_dispatch.pyx']},
94119
'properties': {'sources': ['properties.pyx']},
@@ -98,13 +123,13 @@ libs_sources = {
98123
'sparse': {'sources': ['sparse.pyx', _sparse_op_helper]},
99124
'tslib': {'sources': ['tslib.pyx']},
100125
'testing': {'sources': ['testing.pyx']},
101-
'writers': {'sources': ['writers.pyx']}
126+
'writers': {'sources': ['writers.pyx']},
102127
}
103128

104129
cython_args = [
105130
'--include-dir',
106131
meson.current_build_dir(),
107-
'-X always_allow_keywords=true'
132+
'-X always_allow_keywords=true',
108133
]
109134
if get_option('buildtype') == 'debug'
110135
cython_args += ['--gdb']
@@ -118,7 +143,7 @@ foreach ext_name, ext_dict : libs_sources
118143
include_directories: [inc_np, inc_pd],
119144
dependencies: ext_dict.get('deps', ''),
120145
subdir: 'pandas/_libs',
121-
install: true
146+
install: true,
122147
)
123148
endforeach
124149

@@ -148,14 +173,11 @@ sources_to_install = [
148173
'sparse.pyi',
149174
'testing.pyi',
150175
'tslib.pyi',
151-
'writers.pyi'
176+
'writers.pyi',
152177
]
153178

154-
foreach source: sources_to_install
155-
py.install_sources(
156-
source,
157-
subdir: 'pandas/_libs'
158-
)
179+
foreach source : sources_to_install
180+
py.install_sources(source, subdir: 'pandas/_libs')
159181
endforeach
160182

161183
subdir('window')

pandas/_libs/tslibs/meson.build

+5-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ tslibs_sources = {
2222
cython_args = [
2323
'--include-dir',
2424
meson.current_build_dir(),
25-
'-X always_allow_keywords=true'
25+
'-X always_allow_keywords=true',
2626
]
2727
if get_option('buildtype') == 'debug'
2828
cython_args += ['--gdb']
@@ -36,7 +36,7 @@ foreach ext_name, ext_dict : tslibs_sources
3636
include_directories: [inc_np, inc_pd],
3737
dependencies: ext_dict.get('deps', ''),
3838
subdir: 'pandas/_libs/tslibs',
39-
install: true
39+
install: true,
4040
)
4141
endforeach
4242

@@ -56,12 +56,9 @@ sources_to_install = [
5656
'timestamps.pyi',
5757
'timezones.pyi',
5858
'tzconversion.pyi',
59-
'vectorized.pyi'
59+
'vectorized.pyi',
6060
]
6161

62-
foreach source: sources_to_install
63-
py.install_sources(
64-
source,
65-
subdir: 'pandas/_libs/tslibs'
66-
)
62+
foreach source : sources_to_install
63+
py.install_sources(source, subdir: 'pandas/_libs/tslibs')
6764
endforeach

pandas/_libs/window/meson.build

+6-13
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ py.extension_module(
44
cython_args: ['-X always_allow_keywords=true'],
55
include_directories: [inc_np, inc_pd],
66
subdir: 'pandas/_libs/window',
7-
override_options : ['cython_language=cpp'],
8-
install: true
7+
override_options: ['cython_language=cpp'],
8+
install: true,
99
)
1010

1111
py.extension_module(
@@ -14,18 +14,11 @@ py.extension_module(
1414
cython_args: ['-X always_allow_keywords=true'],
1515
include_directories: [inc_np, inc_pd],
1616
subdir: 'pandas/_libs/window',
17-
install: true
17+
install: true,
1818
)
1919

20-
sources_to_install = [
21-
'__init__.py',
22-
'aggregations.pyi',
23-
'indexers.pyi'
24-
]
20+
sources_to_install = ['__init__.py', 'aggregations.pyi', 'indexers.pyi']
2521

26-
foreach source: sources_to_install
27-
py.install_sources(
28-
source,
29-
subdir: 'pandas/_libs/window'
30-
)
22+
foreach source : sources_to_install
23+
py.install_sources(source, subdir: 'pandas/_libs/window')
3124
endforeach

0 commit comments

Comments
 (0)