Skip to content

Commit b3a4b97

Browse files
authored
Replace cpplint with clang-format (#55150)
* replace cpplint with clang-format * fixups * use conda for clang-format * language: conda * add additional_dependencies * try new source
1 parent fdcdd4c commit b3a4b97

28 files changed

+8307
-8354
lines changed

.pre-commit-config.yaml

+7-13
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,6 @@ repos:
7070
- id: fix-encoding-pragma
7171
args: [--remove]
7272
- id: trailing-whitespace
73-
- repo: https://github.com/cpplint/cpplint
74-
rev: 1.6.1
75-
hooks:
76-
- id: cpplint
77-
exclude: ^pandas/_libs/include/pandas/vendored/klib
78-
args: [
79-
--quiet,
80-
'--extensions=c,h',
81-
'--headers=h',
82-
--recursive,
83-
--linelength=88,
84-
'--filter=-readability/casting,-runtime/int,-build/include_subdir,-readability/fn_size'
85-
]
8673
- repo: https://github.com/pylint-dev/pylint
8774
rev: v3.0.0b0
8875
hooks:
@@ -127,6 +114,13 @@ repos:
127114
rev: v0.6.8
128115
hooks:
129116
- id: sphinx-lint
117+
- repo: https://github.com/pre-commit/mirrors-clang-format
118+
rev: ea59a72
119+
hooks:
120+
- id: clang-format
121+
files: ^pandas/_libs/src|^pandas/_libs/include
122+
args: [-i]
123+
types_or: [c, c++]
130124
- repo: local
131125
hooks:
132126
- id: pyright

doc/source/development/contributing_codebase.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Pre-commit
3939

4040
Additionally, :ref:`Continuous Integration <contributing.ci>` will run code formatting checks
4141
like ``black``, ``ruff``,
42-
``isort``, and ``cpplint`` and more using `pre-commit hooks <https://pre-commit.com/>`_.
42+
``isort``, and ``clang-format`` and more using `pre-commit hooks <https://pre-commit.com/>`_.
4343
Any warnings from these checks will cause the :ref:`Continuous Integration <contributing.ci>` to fail; therefore,
4444
it is helpful to run the check yourself before submitting code. This
4545
can be done by installing ``pre-commit`` (which should already have happened if you followed the instructions

pandas/_libs/include/pandas/datetime/date_conversions.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ int scaleNanosecToUnit(npy_int64 *value, NPY_DATETIMEUNIT unit);
1818
// up to precision `base` e.g. base="s" yields 2020-01-03T00:00:00Z
1919
// while base="ns" yields "2020-01-01T00:00:00.000000000Z"
2020
// len is mutated to save the length of the returned string
21-
char *int64ToIso(int64_t value,
22-
NPY_DATETIMEUNIT valueUnit,
23-
NPY_DATETIMEUNIT base,
24-
size_t *len);
21+
char *int64ToIso(int64_t value, NPY_DATETIMEUNIT valueUnit,
22+
NPY_DATETIMEUNIT base, size_t *len);
2523

2624
// TODO(username): this function doesn't do a lot; should augment or
2725
// replace with scaleNanosecToUnit

pandas/_libs/include/pandas/datetime/pd_datetime.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ See NUMPY_LICENSE.txt for the license.
1919

2020
#ifndef NPY_NO_DEPRECATED_API
2121
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
22-
#endif // NPY_NO_DEPRECATED_API
22+
#endif // NPY_NO_DEPRECATED_API
2323

24-
#include <numpy/ndarraytypes.h>
24+
#include "pandas/datetime/date_conversions.h"
2525
#include "pandas/vendored/numpy/datetime/np_datetime.h"
2626
#include "pandas/vendored/numpy/datetime/np_datetime_strings.h"
27-
#include "pandas/datetime/date_conversions.h"
27+
#include <numpy/ndarraytypes.h>
2828

2929
#ifdef __cplusplus
3030
extern "C" {

pandas/_libs/include/pandas/inline_helper.h

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ The full license is in the LICENSE file, distributed with this software.
1010
#pragma once
1111

1212
#ifndef PANDAS_INLINE
13-
#if defined(__clang__)
14-
#define PANDAS_INLINE static __inline__ __attribute__ ((__unused__))
15-
#elif defined(__GNUC__)
16-
#define PANDAS_INLINE static __inline__
17-
#elif defined(_MSC_VER)
18-
#define PANDAS_INLINE static __inline
19-
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
20-
#define PANDAS_INLINE static inline
21-
#else
22-
#define PANDAS_INLINE
23-
#endif // __GNUC__
24-
#endif // PANDAS_INLINE
13+
#if defined(__clang__)
14+
#define PANDAS_INLINE static __inline__ __attribute__((__unused__))
15+
#elif defined(__GNUC__)
16+
#define PANDAS_INLINE static __inline__
17+
#elif defined(_MSC_VER)
18+
#define PANDAS_INLINE static __inline
19+
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
20+
#define PANDAS_INLINE static inline
21+
#else
22+
#define PANDAS_INLINE
23+
#endif // __GNUC__
24+
#endif // PANDAS_INLINE

pandas/_libs/include/pandas/parser/io.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ The full license is in the LICENSE file, distributed with this software.
1010
#pragma once
1111

1212
#define PY_SSIZE_T_CLEAN
13-
#include <Python.h>
1413
#include "tokenizer.h"
14+
#include <Python.h>
1515

1616
#define FS(source) ((file_source *)source)
1717

1818
typedef struct _rd_source {
19-
PyObject *obj;
20-
PyObject *buffer;
21-
size_t position;
19+
PyObject *obj;
20+
PyObject *buffer;
21+
size_t position;
2222
} rd_source;
2323

2424
#define RDS(source) ((rd_source *)source)

pandas/_libs/include/pandas/parser/pd_parser.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ extern "C" {
1313
#endif
1414

1515
#define PY_SSIZE_T_CLEAN
16-
#include <Python.h>
1716
#include "pandas/parser/tokenizer.h"
17+
#include <Python.h>
1818

1919
typedef struct {
2020
int (*to_double)(char *, double *, char, char, int *);
@@ -81,11 +81,10 @@ static PandasParser_CAPI *PandasParserAPI = NULL;
8181
PandasParserAPI->parser_set_default_options((self))
8282
#define parser_consume_rows(self, nrows) \
8383
PandasParserAPI->parser_consume_rows((self), (nrows))
84-
#define parser_trim_buffers(self) \
85-
PandasParserAPI->parser_trim_buffers((self))
86-
#define tokenize_all_rows(self, encoding_errors) \
84+
#define parser_trim_buffers(self) PandasParserAPI->parser_trim_buffers((self))
85+
#define tokenize_all_rows(self, encoding_errors) \
8786
PandasParserAPI->tokenize_all_rows((self), (encoding_errors))
88-
#define tokenize_nrows(self, nrows, encoding_errors) \
87+
#define tokenize_nrows(self, nrows, encoding_errors) \
8988
PandasParserAPI->tokenize_nrows((self), (nrows), (encoding_errors))
9089
#define str_to_int64(p_item, int_min, int_max, error, t_sep) \
9190
PandasParserAPI->str_to_int64((p_item), (int_min), (int_max), (error), \
@@ -104,7 +103,7 @@ static PandasParser_CAPI *PandasParserAPI = NULL;
104103
PandasParserAPI->round_trip((p), (q), (decimal), (sci), (tsep), \
105104
(skip_trailing), (error), (maybe_int))
106105
#define to_boolean(item, val) PandasParserAPI->to_boolean((item), (val))
107-
#endif /* !defined(_PANDAS_PARSER_IMPL) */
106+
#endif /* !defined(_PANDAS_PARSER_IMPL) */
108107

109108
#ifdef __cplusplus
110109
}

0 commit comments

Comments
 (0)