Skip to content

Commit 9057962

Browse files
committed
fix: add explicit ordering to includes
1 parent d3746a9 commit 9057962

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+105
-53
lines changed

.clang-format

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,27 @@ BinPackParameters: false
99
BreakBeforeBinaryOperators: All
1010
BreakConstructorInitializers: BeforeColon
1111
ColumnLimit: 99
12+
IncludeBlocks: Regroup
1213
IndentCaseLabels: true
1314
IndentPPDirectives: AfterHash
1415
IndentWidth: 4
1516
Language: Cpp
1617
SpaceAfterCStyleCast: true
1718
Standard: Cpp11
1819
TabWidth: 4
20+
IncludeCategories:
21+
- Regex: '<pybind11/.*'
22+
Priority: -1
23+
- Regex: 'pybind11.h"$'
24+
Priority: 1
25+
- Regex: '^".*/?detail/'
26+
Priority: 1
27+
SortPriority: 2
28+
- Regex: '^"'
29+
Priority: 1
30+
SortPriority: 3
31+
- Regex: '<[[:alnum:]._]+>'
32+
Priority: 4
33+
- Regex: '.*'
34+
Priority: 5
1935
...

include/pybind11/cast.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "detail/type_caster_base.h"
1616
#include "detail/typeid.h"
1717
#include "pytypes.h"
18+
1819
#include <array>
1920
#include <cstring>
2021
#include <functional>

include/pybind11/chrono.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
#include <chrono>
1616
#include <cmath>
1717
#include <ctime>
18-
#include <mutex>
19-
2018
#include <datetime.h>
19+
#include <mutex>
2120

2221
// Backport the PyDateTime_DELTA functions from Python3.3 if required
2322
#ifndef PyDateTime_DELTA_GET_DAYS

include/pybind11/complex.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#pragma once
1111

1212
#include "pybind11.h"
13+
1314
#include <complex>
1415

1516
/// glibc defines I as a macro which breaks things, e.g., boost template names

include/pybind11/detail/internals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#pragma once
1111

1212
#include "../pytypes.h"
13+
1314
#include <exception>
1415

1516
/// Tracks the `internals` and `type_info` ABI version independent of the main library version.

include/pybind11/detail/type_caster_base.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "descr.h"
1515
#include "internals.h"
1616
#include "typeid.h"
17+
1718
#include <cstdint>
1819
#include <iterator>
1920
#include <new>

include/pybind11/embed.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
#pragma once
1111

12-
#include "eval.h"
1312
#include "pybind11.h"
13+
#include "eval.h"
1414

1515
#include <memory>
1616
#include <vector>

include/pybind11/eval.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
#pragma once
1313

14-
#include <utility>
15-
1614
#include "pybind11.h"
1715

16+
#include <utility>
17+
1818
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
1919
PYBIND11_NAMESPACE_BEGIN(detail)
2020

include/pybind11/functional.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#pragma once
1111

1212
#include "pybind11.h"
13+
1314
#include <functional>
1415

1516
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)

include/pybind11/numpy.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
#pragma once
1111

12-
#include "complex.h"
1312
#include "pybind11.h"
13+
#include "complex.h"
14+
1415
#include <algorithm>
1516
#include <array>
1617
#include <cstdint>

include/pybind11/pybind11.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@
1010

1111
#pragma once
1212

13-
#include "attr.h"
1413
#include "detail/class.h"
1514
#include "detail/init.h"
15+
#include "attr.h"
1616
#include "gil.h"
1717
#include "options.h"
1818

1919
#include <cstdlib>
20+
#include <cstring>
2021
#include <memory>
2122
#include <new>
2223
#include <string>
2324
#include <utility>
2425
#include <vector>
2526

26-
#include <cstring>
27-
2827
#if defined(__cpp_lib_launder) && !(defined(_MSC_VER) && (_MSC_VER < 1914))
2928
# define PYBIND11_STD_LAUNDER std::launder
3029
# define PYBIND11_HAS_STD_LAUNDER 1

include/pybind11/pytypes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
#pragma once
1111

12-
#include "buffer_info.h"
1312
#include "detail/common.h"
13+
#include "buffer_info.h"
14+
1415
#include <type_traits>
1516
#include <utility>
1617

include/pybind11/stl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
#pragma once
1111

12-
#include "detail/common.h"
1312
#include "pybind11.h"
13+
#include "detail/common.h"
14+
1415
#include <deque>
1516
#include <iostream>
1617
#include <list>

include/pybind11/stl/filesystem.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
#pragma once
66

7-
#include "../cast.h"
87
#include "../pybind11.h"
9-
#include "../pytypes.h"
10-
118
#include "../detail/common.h"
129
#include "../detail/descr.h"
10+
#include "../cast.h"
11+
#include "../pytypes.h"
1312

1413
#include <string>
1514

tests/constructor_stats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ inspection/testing in python) by using the functions with `print_` replaced with
6666
*/
6767

6868
#include "pybind11_tests.h"
69+
6970
#include <list>
7071
#include <sstream>
7172
#include <typeindex>

tests/cross_module_gil_utils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
All rights reserved. Use of this source code is governed by a
77
BSD-style license that can be found in the LICENSE file.
88
*/
9-
#include <cstdint>
109
#include <pybind11/pybind11.h>
1110

11+
#include <cstdint>
12+
1213
// This file mimics a DSO that makes pybind11 calls but does not define a
1314
// PYBIND11_MODULE. The purpose is to test that such a DSO can create a
1415
// py::gil_scoped_acquire when the running thread is in a GIL-released state.

tests/local_bindings.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
2-
#include <utility>
3-
42
#include "pybind11_tests.h"
53

4+
#include <utility>
5+
66
/// Simple class used to test py::local:
77
template <int>
88
class LocalBase {

tests/object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# define __OBJECT_H
33

44
# include "constructor_stats.h"
5+
56
# include <atomic>
67

78
/// Reference counted object base class

tests/pybind11_cross_module_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
BSD-style license that can be found in the LICENSE file.
88
*/
99

10+
#include <pybind11/stl_bind.h>
11+
1012
#include "local_bindings.h"
1113
#include "pybind11_tests.h"
1214
#include "test_exceptions.h"
1315

14-
#include <pybind11/stl_bind.h>
15-
1616
#include <numeric>
1717
#include <utility>
1818

tests/pybind11_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
#include "pybind11_tests.h"
11+
1112
#include "constructor_stats.h"
1213

1314
#include <functional>

tests/test_buffers.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
BSD-style license that can be found in the LICENSE file.
88
*/
99

10+
#include <pybind11/stl.h>
11+
1012
#include "constructor_stats.h"
1113
#include "pybind11_tests.h"
12-
#include <pybind11/stl.h>
1314

1415
TEST_SUBMODULE(buffers, m) {
1516
// test_from_python / test_to_python:

tests/test_builtin_casters.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
BSD-style license that can be found in the LICENSE file.
88
*/
99

10-
#include "pybind11_tests.h"
1110
#include <pybind11/complex.h>
1211

12+
#include "pybind11_tests.h"
13+
1314
struct ConstRefCasted {
1415
int tag;
1516
};

tests/test_callbacks.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
BSD-style license that can be found in the LICENSE file.
88
*/
99

10+
#include <pybind11/functional.h>
11+
1012
#include "constructor_stats.h"
1113
#include "pybind11_tests.h"
12-
#include <pybind11/functional.h>
14+
1315
#include <thread>
1416

1517
int dummy_function(int i) { return i + 1; }

tests/test_chrono.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
BSD-style license that can be found in the LICENSE file.
99
*/
1010

11+
#include <pybind11/chrono.h>
12+
1113
#include "pybind11_tests.h"
14+
1215
#include <chrono>
13-
#include <pybind11/chrono.h>
1416

1517
struct different_resolutions {
1618
using time_point_h = std::chrono::time_point<std::chrono::system_clock, std::chrono::hours>;

tests/test_class.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
# include <aligned_new>
1515
#endif
1616

17+
#include <pybind11/stl.h>
18+
1719
#include "constructor_stats.h"
1820
#include "local_bindings.h"
1921
#include "pybind11_tests.h"
20-
#include <pybind11/stl.h>
2122

2223
#include <utility>
2324

tests/test_copy_move.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
BSD-style license that can be found in the LICENSE file.
99
*/
1010

11+
#include <pybind11/stl.h>
12+
1113
#include "constructor_stats.h"
1214
#include "pybind11_tests.h"
13-
#include <pybind11/stl.h>
1415

1516
template <typename derived>
1617
struct empty {

tests/test_eigen.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
BSD-style license that can be found in the LICENSE file.
88
*/
99

10-
#include "constructor_stats.h"
11-
#include "pybind11_tests.h"
1210
#include <pybind11/eigen.h>
1311
#include <pybind11/stl.h>
1412

13+
#include "constructor_stats.h"
14+
#include "pybind11_tests.h"
15+
1516
#if defined(_MSC_VER)
1617
# if _MSC_VER < 1910 // VS 2015's MSVC
1718
# pragma warning(disable : 4127) // C4127: conditional expression is constant

tests/test_embed/test_interpreter.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#endif
88

99
#include <catch.hpp>
10-
1110
#include <cstdlib>
1211
#include <fstream>
1312
#include <functional>

tests/test_eval.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <pybind11/eval.h>
1111

1212
#include "pybind11_tests.h"
13+
1314
#include <utility>
1415

1516
TEST_SUBMODULE(eval_, m) {

tests/test_exceptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include "test_exceptions.h"
1010

1111
#include "local_bindings.h"
12-
1312
#include "pybind11_tests.h"
13+
1414
#include <exception>
1515
#include <stdexcept>
1616
#include <utility>

tests/test_exceptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include "pybind11_tests.h"
3+
34
#include <stdexcept>
45

56
// shared exceptions for cross_module_tests

tests/test_factory_constructors.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "constructor_stats.h"
1212
#include "pybind11_tests.h"
13+
1314
#include <cmath>
1415
#include <new>
1516
#include <utility>

tests/test_gil_scoped.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
BSD-style license that can be found in the LICENSE file.
88
*/
99

10-
#include "pybind11_tests.h"
1110
#include <pybind11/functional.h>
1211

12+
#include "pybind11_tests.h"
13+
1314
class VirtClass {
1415
public:
1516
virtual ~VirtClass() = default;

tests/test_iostream.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
# pragma warning(disable : 4702) // unreachable code in system header (xatomic.h(382))
1212
#endif
1313

14+
#include <pybind11/iostream.h>
15+
1416
#include "pybind11_tests.h"
17+
1518
#include <atomic>
1619
#include <iostream>
1720
#include <mutex>
18-
#include <pybind11/iostream.h>
1921
#include <string>
2022
#include <thread>
2123

0 commit comments

Comments
 (0)