tokev commited on
Commit
4d03ebc
·
verified ·
1 Parent(s): 248a619

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. third_party/CityFlow/docs/source/introduction.rst +20 -20
  2. third_party/CityFlow/docs/source/replay.rst +69 -69
  3. third_party/CityFlow/docs/source/roadnet.rst +129 -129
  4. third_party/CityFlow/docs/source/start.rst +228 -228
  5. third_party/CityFlow/extern/milo/dtoa_milo.h +395 -395
  6. third_party/CityFlow/extern/pybind11/.appveyor.yml +35 -35
  7. third_party/CityFlow/extern/pybind11/.clang-format +38 -38
  8. third_party/CityFlow/extern/pybind11/.clang-tidy +77 -77
  9. third_party/CityFlow/extern/pybind11/.cmake-format.yaml +73 -73
  10. third_party/CityFlow/extern/pybind11/.codespell-ignore-lines +24 -24
  11. third_party/CityFlow/extern/pybind11/.git.bak/FETCH_HEAD +32 -32
  12. third_party/CityFlow/extern/pybind11/.git.bak/HEAD +1 -1
  13. third_party/CityFlow/extern/pybind11/.git.bak/config +13 -13
  14. third_party/CityFlow/extern/pybind11/.git.bak/description +1 -1
  15. third_party/CityFlow/extern/pybind11/.git.bak/packed-refs +143 -143
  16. third_party/CityFlow/extern/pybind11/.gitattributes +1 -1
  17. third_party/CityFlow/extern/pybind11/.github/CODEOWNERS +9 -9
  18. third_party/CityFlow/extern/pybind11/.github/CONTRIBUTING.md +388 -388
  19. third_party/CityFlow/extern/pybind11/.github/dependabot.yml +15 -15
  20. third_party/CityFlow/extern/pybind11/.github/labeler.yml +8 -8
  21. third_party/CityFlow/extern/pybind11/.github/labeler_merged.yml +3 -3
  22. third_party/CityFlow/extern/pybind11/.github/pull_request_template.md +19 -19
  23. third_party/CityFlow/extern/pybind11/.gitignore +46 -46
  24. third_party/CityFlow/extern/pybind11/.pre-commit-config.yaml +155 -155
  25. third_party/CityFlow/extern/pybind11/.readthedocs.yml +20 -20
  26. third_party/CityFlow/extern/pybind11/CMakeLists.txt +373 -373
  27. third_party/CityFlow/extern/pybind11/LICENSE +29 -29
  28. third_party/CityFlow/extern/pybind11/MANIFEST.in +6 -6
  29. third_party/CityFlow/extern/pybind11/README.rst +181 -181
  30. third_party/CityFlow/extern/pybind11/SECURITY.md +13 -13
  31. third_party/CityFlow/extern/pybind11/docs/Doxyfile +21 -21
  32. third_party/CityFlow/extern/pybind11/docs/basics.rst +307 -307
  33. third_party/CityFlow/extern/pybind11/docs/benchmark.py +87 -87
  34. third_party/CityFlow/extern/pybind11/docs/benchmark.rst +95 -95
  35. third_party/CityFlow/extern/pybind11/docs/changelog.rst +0 -0
  36. third_party/CityFlow/extern/pybind11/docs/classes.rst +555 -555
  37. third_party/CityFlow/extern/pybind11/docs/compiling.rst +649 -649
  38. third_party/CityFlow/extern/pybind11/docs/conf.py +368 -368
  39. third_party/CityFlow/extern/pybind11/docs/faq.rst +308 -308
  40. third_party/CityFlow/extern/pybind11/docs/index.rst +48 -48
  41. third_party/CityFlow/extern/pybind11/docs/installing.rst +105 -105
  42. third_party/CityFlow/extern/pybind11/docs/limitations.rst +72 -72
  43. third_party/CityFlow/extern/pybind11/docs/reference.rst +130 -130
  44. third_party/CityFlow/extern/pybind11/docs/release.rst +143 -143
  45. third_party/CityFlow/extern/pybind11/docs/requirements.txt +6 -6
  46. third_party/CityFlow/extern/pybind11/docs/upgrade.rst +594 -594
  47. third_party/CityFlow/extern/pybind11/noxfile.py +107 -107
  48. third_party/CityFlow/extern/pybind11/pybind11/__init__.py +17 -17
  49. third_party/CityFlow/extern/pybind11/pybind11/__main__.py +62 -62
  50. third_party/CityFlow/extern/pybind11/pybind11/_version.py +12 -12
third_party/CityFlow/docs/source/introduction.rst CHANGED
@@ -1,21 +1,21 @@
1
- Introduction
2
- ============
3
-
4
- CityFlow is a multi-agent reinforcement learning environment for large scale city traffic scenario.
5
-
6
- Checkout these features!
7
-
8
- - a microscopic traffic simulator which simulates the behavior of each vehicle, providing highest level detail of traffic evolution.
9
- - support flexible definitions for road network and traffic flow
10
- - provides friendly python interface for reinforcement learning
11
- - **Fast!** Elaborately designed data structure and simulation algorithm with multithreading. Capable of simulating city-wide traffic. See the performance comparison with SUMO [#sumo]_.
12
-
13
- .. figure:: https://github.com/cityflow-project/data/raw/master/docs/images/performance.png
14
- :align: center
15
-
16
- Performance comparison between CityFlow with different number of threads (1, 2, 4, 8) and SUMO. From small 1x1 grid roadnet to city-level 30x30 roadnet. Even faster when you need to interact with the simulator through python API.
17
-
18
- See :ref:`start` to get started.
19
-
20
- .. [#paper] `WWW 2019 Demo Paper <https://arxiv.org/abs/1905.05217>`_
21
  .. [#sumo] `SUMO home page <https://sumo.dlr.de/index.html>`_
 
1
+ Introduction
2
+ ============
3
+
4
+ CityFlow is a multi-agent reinforcement learning environment for large scale city traffic scenario.
5
+
6
+ Checkout these features!
7
+
8
+ - a microscopic traffic simulator which simulates the behavior of each vehicle, providing highest level detail of traffic evolution.
9
+ - support flexible definitions for road network and traffic flow
10
+ - provides friendly python interface for reinforcement learning
11
+ - **Fast!** Elaborately designed data structure and simulation algorithm with multithreading. Capable of simulating city-wide traffic. See the performance comparison with SUMO [#sumo]_.
12
+
13
+ .. figure:: https://github.com/cityflow-project/data/raw/master/docs/images/performance.png
14
+ :align: center
15
+
16
+ Performance comparison between CityFlow with different number of threads (1, 2, 4, 8) and SUMO. From small 1x1 grid roadnet to city-level 30x30 roadnet. Even faster when you need to interact with the simulator through python API.
17
+
18
+ See :ref:`start` to get started.
19
+
20
+ .. [#paper] `WWW 2019 Demo Paper <https://arxiv.org/abs/1905.05217>`_
21
  .. [#sumo] `SUMO home page <https://sumo.dlr.de/index.html>`_
third_party/CityFlow/docs/source/replay.rst CHANGED
@@ -1,69 +1,69 @@
1
- .. _replay:
2
-
3
- Replay
4
- ======
5
-
6
- Start
7
- ------
8
-
9
- 1. enter the ``frontend`` folder and open ``index.html`` in your browser.
10
-
11
- 2. choose the roadnet log file (as defined by ``roadnetLogFile`` field in the config file, **not 'roadnetFile'**) and wait for it to be loaded. When it has finished loading, there will be a message shown in the info box.
12
-
13
- 3. choose the replay file (as defined by ``replayLogFile`` field in the config file) .
14
-
15
- 4. choose the chart data file (optional, see section *Chart* below).
16
-
17
- 5. press ``Start`` button to start the replay.
18
-
19
- Control
20
- -------
21
-
22
- - Use the mouse to navigate. Dragging and mouse wheel zooming are supported.
23
-
24
- - Move the slider in Control Box to adjust the replay speed. You can also press ``1`` on keyboard to slow down or ``2`` to speed up.
25
-
26
- - Press ``Pause`` button in Control Box to pause/resume. You can also double-click on the map to pause and resume.
27
-
28
- - Press ``[`` or ``]`` on keyboard to take a step backward or forward.
29
-
30
- - To restart the replay, just press ``Start`` button again.
31
-
32
- - The ``debug`` option enables displaying the ID of vehicles, roads and intersections during a mouse hover. **This will cause a slower replaying**, so we suggest using it only for debugging purposes.
33
-
34
- Chart
35
- ------
36
-
37
- The player supports showing the change of different metrics in a chart simultaneously with the replay process.
38
-
39
- To provide required data, a log file in a format as shown below is needed:
40
-
41
- .. code-block::
42
-
43
- title
44
- 0.3 0.4 0.1 ...(step1)
45
- 0.5 0.2 0.2 ...(step2)
46
- ...(metric1) ...(metric2) ...(metric3)
47
-
48
- The first line is the title of the chart.
49
-
50
- Each row stands for a time step and each column stands for a specific metric.
51
- For example, to track vehicle numbers of three crossroads respectively, we need three columns and each column stands for the vehicle number of a certain crossroads.
52
-
53
- In one row, numbers are separated by one or more spaces or tabs.
54
-
55
- The numbers in one column will be shown as points connected by one line in the chart.
56
-
57
- .. note::
58
- Make sure that each row is corresponding with the right time step.
59
-
60
- Notes
61
- ------
62
-
63
- - To get the example replay files, run ``download_replay.py`` under ``frontend`` folder.
64
-
65
- - If you create a new Engine object with same ``replayLogFile``, it will clear the old replay file first
66
-
67
- - Using ``eng.reset()`` won't clear old replays, it will append newly generated replay to the end of ``replayLogFile``
68
-
69
- - You can change ``replayLogFile`` during runtime using ``set_replay_file``, see :ref:`set-replay-file`
 
1
+ .. _replay:
2
+
3
+ Replay
4
+ ======
5
+
6
+ Start
7
+ ------
8
+
9
+ 1. enter the ``frontend`` folder and open ``index.html`` in your browser.
10
+
11
+ 2. choose the roadnet log file (as defined by ``roadnetLogFile`` field in the config file, **not 'roadnetFile'**) and wait for it to be loaded. When it has finished loading, there will be a message shown in the info box.
12
+
13
+ 3. choose the replay file (as defined by ``replayLogFile`` field in the config file) .
14
+
15
+ 4. choose the chart data file (optional, see section *Chart* below).
16
+
17
+ 5. press ``Start`` button to start the replay.
18
+
19
+ Control
20
+ -------
21
+
22
+ - Use the mouse to navigate. Dragging and mouse wheel zooming are supported.
23
+
24
+ - Move the slider in Control Box to adjust the replay speed. You can also press ``1`` on keyboard to slow down or ``2`` to speed up.
25
+
26
+ - Press ``Pause`` button in Control Box to pause/resume. You can also double-click on the map to pause and resume.
27
+
28
+ - Press ``[`` or ``]`` on keyboard to take a step backward or forward.
29
+
30
+ - To restart the replay, just press ``Start`` button again.
31
+
32
+ - The ``debug`` option enables displaying the ID of vehicles, roads and intersections during a mouse hover. **This will cause a slower replaying**, so we suggest using it only for debugging purposes.
33
+
34
+ Chart
35
+ ------
36
+
37
+ The player supports showing the change of different metrics in a chart simultaneously with the replay process.
38
+
39
+ To provide required data, a log file in a format as shown below is needed:
40
+
41
+ .. code-block::
42
+
43
+ title
44
+ 0.3 0.4 0.1 ...(step1)
45
+ 0.5 0.2 0.2 ...(step2)
46
+ ...(metric1) ...(metric2) ...(metric3)
47
+
48
+ The first line is the title of the chart.
49
+
50
+ Each row stands for a time step and each column stands for a specific metric.
51
+ For example, to track vehicle numbers of three crossroads respectively, we need three columns and each column stands for the vehicle number of a certain crossroads.
52
+
53
+ In one row, numbers are separated by one or more spaces or tabs.
54
+
55
+ The numbers in one column will be shown as points connected by one line in the chart.
56
+
57
+ .. note::
58
+ Make sure that each row is corresponding with the right time step.
59
+
60
+ Notes
61
+ ------
62
+
63
+ - To get the example replay files, run ``download_replay.py`` under ``frontend`` folder.
64
+
65
+ - If you create a new Engine object with same ``replayLogFile``, it will clear the old replay file first
66
+
67
+ - Using ``eng.reset()`` won't clear old replays, it will append newly generated replay to the end of ``replayLogFile``
68
+
69
+ - You can change ``replayLogFile`` during runtime using ``set_replay_file``, see :ref:`set-replay-file`
third_party/CityFlow/docs/source/roadnet.rst CHANGED
@@ -1,129 +1,129 @@
1
- .. _roadnet:
2
-
3
- Roadnet File Format
4
- ===================
5
-
6
- Roadnet file defines the roadnet structure. CityFlow's roadnet mainly consists of intersections and roads (see them as nodes and edges of a graph).
7
-
8
- - *Road* represents a directional road from one *intersection* to another *intersection* with road-specific properties. A *road* may contain multiple *lanes*.
9
- - *Intersection* is where roads intersects. An *intersection* contains several *roadlinks*. Each *roadlink* connects two roads of the intersection and can be controlled by traffic signals.
10
- - A *roadlink* may contain several *lanelinks*. Each lanelink represents a specific path from one lane of incoming road to one lane of outgoing road.
11
-
12
- Now let's see a sample roadnet file and we'll explain the meaning of each components. Relax, the definition of field is quite straight forward, if you are familiar with modern road networks. For the following json file, ``[]`` means this field is an array, but we will only show one object for demonstration.
13
-
14
- .. note::
15
- Runnable sample roadnet files can be found in ``examples`` folder.
16
-
17
- Sample ``roadnet.json`` with explanation.
18
-
19
- .. code-block:: js
20
-
21
- {
22
- "intersections": [
23
- {
24
- // id of the intersection
25
- "id": "intersection_1_0",
26
- // coordinate of center of intersection
27
- "point": {
28
- "x": 0,
29
- "y": 0
30
- },
31
- // width of the intersection
32
- "width": 10,
33
- // roads connected to the intersection
34
- "roads": [
35
- "road_1",
36
- "road_2"
37
- ],
38
- // roadLinks of the intersection
39
- "roadLinks": [
40
- {
41
- // 'turn_left', 'turn_right', 'go_straight'
42
- "type": "go_straight",
43
- // id of starting road
44
- "startRoad": "road_1",
45
- // id of ending road
46
- "endRoad": "road_2",
47
- // lanelinks of roadlink
48
- "laneLinks": [
49
- {
50
- // from startRoad's startLaneIndex lane to endRoad's endLaneIndex lane
51
- "startLaneIndex": 0,
52
- "endLaneIndex": 1,
53
- // points along the laneLink which describe the shape of laneLink
54
- "points": [
55
- {
56
- "x": -10,
57
- "y": 2
58
- },
59
- {
60
- "x": 10,
61
- "y": -2
62
- }
63
- ]
64
- }
65
- ]
66
- }
67
- ],
68
- // traffic light plan of the intersection
69
- "trafficLight": {
70
- "lightphases": [
71
- {
72
- // default duration of the phase
73
- "time": 30,
74
- // available roadLinks of current phase, index is the no. of roadlinks defined above.
75
- "availableRoadLinks": [
76
- 0,
77
- 2
78
- ]
79
- }
80
- ]
81
- },
82
- // true if it's a peripheral intersection (if it only connects to one road)
83
- "virtual": false
84
- }
85
- ],
86
- "roads": [
87
- {
88
- // id of road
89
- "id": "road_1",
90
- // id of start intersection
91
- "startIntersection": "intersection_1",
92
- // id of end intersection
93
- "endIntersection": "intersection_2",
94
- // points along the road which describe the shape of the road
95
- "points": [
96
- {
97
- "x": -200,
98
- "y": 0
99
- },
100
- {
101
- "x": 0,
102
- "y": 0
103
- }
104
- ],
105
- // property of each lane
106
- "lanes": [
107
- {
108
- "width": 4,
109
- "maxSpeed": 16.67
110
- }
111
- ]
112
- }
113
- ]
114
- }
115
-
116
-
117
- .. figure:: https://github.com/cityflow-project/data/raw/master/docs/images/roadnet.jpg
118
- :align: center
119
-
120
- Illustration of a 1x2 grid roadnet.
121
-
122
-
123
- You can convert SUMO roadnet files into CityFlow format using tools/Converter/converter.py
124
-
125
- For example, the following code converts a sumo roadnet file, atlanta.net.xml, to CityFlow format.
126
-
127
- .. code-block:: shell
128
-
129
- python converter.py --sumonet atlanta_sumo.net.xml --cityflownet atlanta_cityflow.json
 
1
+ .. _roadnet:
2
+
3
+ Roadnet File Format
4
+ ===================
5
+
6
+ Roadnet file defines the roadnet structure. CityFlow's roadnet mainly consists of intersections and roads (see them as nodes and edges of a graph).
7
+
8
+ - *Road* represents a directional road from one *intersection* to another *intersection* with road-specific properties. A *road* may contain multiple *lanes*.
9
+ - *Intersection* is where roads intersects. An *intersection* contains several *roadlinks*. Each *roadlink* connects two roads of the intersection and can be controlled by traffic signals.
10
+ - A *roadlink* may contain several *lanelinks*. Each lanelink represents a specific path from one lane of incoming road to one lane of outgoing road.
11
+
12
+ Now let's see a sample roadnet file and we'll explain the meaning of each components. Relax, the definition of field is quite straight forward, if you are familiar with modern road networks. For the following json file, ``[]`` means this field is an array, but we will only show one object for demonstration.
13
+
14
+ .. note::
15
+ Runnable sample roadnet files can be found in ``examples`` folder.
16
+
17
+ Sample ``roadnet.json`` with explanation.
18
+
19
+ .. code-block:: js
20
+
21
+ {
22
+ "intersections": [
23
+ {
24
+ // id of the intersection
25
+ "id": "intersection_1_0",
26
+ // coordinate of center of intersection
27
+ "point": {
28
+ "x": 0,
29
+ "y": 0
30
+ },
31
+ // width of the intersection
32
+ "width": 10,
33
+ // roads connected to the intersection
34
+ "roads": [
35
+ "road_1",
36
+ "road_2"
37
+ ],
38
+ // roadLinks of the intersection
39
+ "roadLinks": [
40
+ {
41
+ // 'turn_left', 'turn_right', 'go_straight'
42
+ "type": "go_straight",
43
+ // id of starting road
44
+ "startRoad": "road_1",
45
+ // id of ending road
46
+ "endRoad": "road_2",
47
+ // lanelinks of roadlink
48
+ "laneLinks": [
49
+ {
50
+ // from startRoad's startLaneIndex lane to endRoad's endLaneIndex lane
51
+ "startLaneIndex": 0,
52
+ "endLaneIndex": 1,
53
+ // points along the laneLink which describe the shape of laneLink
54
+ "points": [
55
+ {
56
+ "x": -10,
57
+ "y": 2
58
+ },
59
+ {
60
+ "x": 10,
61
+ "y": -2
62
+ }
63
+ ]
64
+ }
65
+ ]
66
+ }
67
+ ],
68
+ // traffic light plan of the intersection
69
+ "trafficLight": {
70
+ "lightphases": [
71
+ {
72
+ // default duration of the phase
73
+ "time": 30,
74
+ // available roadLinks of current phase, index is the no. of roadlinks defined above.
75
+ "availableRoadLinks": [
76
+ 0,
77
+ 2
78
+ ]
79
+ }
80
+ ]
81
+ },
82
+ // true if it's a peripheral intersection (if it only connects to one road)
83
+ "virtual": false
84
+ }
85
+ ],
86
+ "roads": [
87
+ {
88
+ // id of road
89
+ "id": "road_1",
90
+ // id of start intersection
91
+ "startIntersection": "intersection_1",
92
+ // id of end intersection
93
+ "endIntersection": "intersection_2",
94
+ // points along the road which describe the shape of the road
95
+ "points": [
96
+ {
97
+ "x": -200,
98
+ "y": 0
99
+ },
100
+ {
101
+ "x": 0,
102
+ "y": 0
103
+ }
104
+ ],
105
+ // property of each lane
106
+ "lanes": [
107
+ {
108
+ "width": 4,
109
+ "maxSpeed": 16.67
110
+ }
111
+ ]
112
+ }
113
+ ]
114
+ }
115
+
116
+
117
+ .. figure:: https://github.com/cityflow-project/data/raw/master/docs/images/roadnet.jpg
118
+ :align: center
119
+
120
+ Illustration of a 1x2 grid roadnet.
121
+
122
+
123
+ You can convert SUMO roadnet files into CityFlow format using tools/Converter/converter.py
124
+
125
+ For example, the following code converts a sumo roadnet file, atlanta.net.xml, to CityFlow format.
126
+
127
+ .. code-block:: shell
128
+
129
+ python converter.py --sumonet atlanta_sumo.net.xml --cityflownet atlanta_cityflow.json
third_party/CityFlow/docs/source/start.rst CHANGED
@@ -1,229 +1,229 @@
1
- .. _start:
2
-
3
- Quick Start
4
- ===========
5
-
6
- Installation
7
- ------------
8
-
9
- If you have not installed CityFlow yet, :ref:`install` is a simple guide for installation.
10
-
11
-
12
- Create Engine
13
- -------------
14
-
15
- .. code-block:: python
16
-
17
- import cityflow
18
- eng = cityflow.Engine(config_path, thread_num=1)
19
-
20
-
21
- - ``config_path``: path for config file.
22
- - ``thread_num``: number of threads.
23
-
24
- Arguments In Config File
25
- ^^^^^^^^^^^^^^^^^^^^^^^^
26
- - ``interval``: time of each simulation step (in seconds). An ``interval`` of 0.5 means for each simulation step, the system will move 0.5 seconds forward. For example, if a car is at location 0 with speed 10m/s, after one simulation step, it will move to location 10*0.5=5.
27
- - ``seed``: random seed.
28
- - ``dir``: root directory, all file path will be relative to this directory.
29
- - ``roadnetFile``: path for roadnet file.
30
- - ``flowFile``: path for flow file.
31
- - ``rlTrafficLight``: whether to enable traffic light control through python API. If set to ``false``, default traffic light plan defined in ``roadnetFile`` will be used.
32
- - ``saveReplay``: whether to save simulation for replay. If set to ``true``, ``roadnetLogFile`` and ``replayLogFile`` are required.
33
- - ``roadnetLogFile``: path for roadnet replay file. This is a special roadnet file for replay, not the same as ``roadnetFile``.
34
- - ``replayLogFile``: path for replay. This file contains vehicle positions and traffic light situation of each simulation step.
35
- - ``laneChange``: whether to enable lane changing. The default value is 'false'.
36
-
37
- For format of ``roadnetFile`` and ``flowFile``, please see :ref:`roadnet`, :ref:`flow`
38
-
39
- .. note::
40
- Runnable sample roadnet and flow files can be found in ``examples`` folder.
41
-
42
- You can generate grid roadnet and flow files using `tools/generate_grid_scenario.py`
43
-
44
- For example, you can generate a 2x3 roadnet with predefined traffic light plan and a corresponding flow file with
45
-
46
- .. code-block:: shell
47
-
48
- python generate_grid_scenario.py 2 3 --roadnetFile roadnet.json --flowFile flow.json --dir . --tlPlan
49
-
50
- Sample Config File
51
- ^^^^^^^^^^^^^^^^^^^
52
-
53
- .. note::
54
- Runnable sample config files can be found in ``examples`` folder.
55
-
56
- .. code-block:: json
57
-
58
- {
59
- "interval": 1.0,
60
- "seed": 0,
61
- "dir": "data/",
62
- "roadnetFile": "roadnet/testcase_roadnet_3x3.json",
63
- "flowFile": "flow/testcase_flow_3x3.json",
64
- "rlTrafficLight": false,
65
- "saveReplay": true,
66
- "roadnetLogFile": "frontend/web/testcase_roadnet_3x3.json",
67
- "replayLogFile": "frontend/web/testcase_replay_3x3.txt"
68
- }
69
-
70
- Simulation
71
- ----------
72
-
73
- To simulate one step, simply call ``eng.next_step()``
74
-
75
- .. code-block:: python
76
-
77
- eng.next_step()
78
-
79
- Data Access API
80
- ---------------
81
-
82
- ``get_vehicle_count()``:
83
-
84
- - Get number of total running vehicles.
85
- - Return an ``int``
86
-
87
- ``get_vehicles(include_waiting=False)``:
88
-
89
- - Get all vehicle ids
90
- - Include vehicles in lane's waiting buffer if ``include_waiting=True``
91
- - Return an ``list`` of vehicle ids
92
-
93
- ``get_lane_vehicle_count()``:
94
-
95
- - Get number of running vehicles on each lane.
96
- - Return a ``dict`` with lane id as key and corresponding number as value.
97
-
98
- ``get_lane_waiting_vehicle_count()``:
99
-
100
- - Get number of waiting vehicles on each lane. Currently, vehicles with speed less than 0.1m/s is considered as waiting.
101
- - Return a ``dict`` with lane id as key and corresponding number as value.
102
-
103
- ``get_lane_vehicles()``:
104
-
105
- - Get vehicle ids on each lane.
106
- - Return a ``dict`` with lane id as key and list of vehicle id as value.
107
-
108
- ``get_vehicle_info(vehicle_id)``:
109
-
110
- - Return a ``dict`` which contains information of the given vehicle.
111
- - The items include:
112
-
113
- + ``running``: whether the vehicle is running.
114
- + If the vehicle is running:
115
-
116
- * ``speed``: The speed of the vehicle.
117
- * ``distance``: The distance the vehicle has travelled on the current lane or lanelink.
118
- * ``drivable``: The id of the current drivable(lane or lanelink)
119
- * ``road``: The id of the current road if the vehicle is running on a lane.
120
- * ``intersection``: The next intersection if the vehicle is running on a lane.
121
- * ``route``: A string contains ids of following roads in the vehicle's route which are separated by ``' '``.
122
-
123
- - Note that all items are stored as ``str``.
124
-
125
- ``get_vehicle_speed()``:
126
-
127
- - Get speed of each vehicle
128
- - Return a ``dict`` with vehicle id as key and corresponding speed as value.
129
-
130
- ``get_vehicle_distance()``:
131
-
132
- - Get distance travelled on current lane of each vehicle.
133
- - Return a ``dict`` with vehicle id as key and corresponding distance as value.
134
-
135
- ``get_leader(vehicle_id)``
136
-
137
- - Return the id of the vehicle in front of ``vehicle_id``.
138
- - Return an empty string ``""`` when ``vehicle_id`` does not have a leader
139
-
140
- ``get_current_time()``:
141
-
142
- - Get simulation time (in seconds)
143
- - Return a ``double``
144
-
145
- ``get_average_travel_time()``:
146
-
147
- - Get average travel time (in seconds)
148
- - Return a ``double``
149
-
150
- Control API
151
- -----------
152
-
153
- ``set_tl_phase(intersection_id, phase_id)``:
154
-
155
- - Set the phase of traffic light of ``intersection_id`` to ``phase_id``. Only works when ``rlTrafficLight`` is set to ``true``.
156
- - The ``intersection_id`` should be defined in ``roadnetFile``
157
- - ``phase_id`` is the index of phase in array ``"lightphases"``, defined in ``roadnetFile``.
158
-
159
- ``set_vehicle_speed(vehicle_id, speed)``:
160
-
161
- - Set the speed of ``vehicle_id`` to ``speed``.
162
- - The vehicles have to obey fundamental rules to avoid collisions so the real speed might be different from ``speed``.
163
-
164
- ``reset(seed=False)``:
165
-
166
- - Reset the simulation (clear all vehicles and set simulation time back to zero)
167
- - Reset random seed if ``seed`` is set to ``True``
168
- - This does not clear old replays, instead, it appends new replays to ``replayLogFile``.
169
-
170
- ``snapshot()``:
171
-
172
- - Take a snapshot of current simulation state
173
- - This will generate an ``Archive`` object which can be loaded later
174
- - You can save an ``Archive`` object to a file using its ``dump`` method.
175
-
176
- ``load(archive)``:
177
-
178
- - Load an ``Archive`` object and restore simulation state
179
-
180
- ``load_from_file(path)``
181
-
182
- - Load a snapshot file created by ``dump`` method and restore simulation state.
183
- - The whole process of saving and loading file is like:
184
-
185
- .. code-block:: python
186
-
187
- archive = eng.snapshot() # create an archive object
188
- archive.dump("save.json") # if you want to save the snapshot to a file
189
-
190
- # do something
191
-
192
- eng.load(archive)
193
- # load 'archive' and the simulation will start from the status when 'archive'is created
194
-
195
- # or if you want to load from 'save.json'
196
- eng.load_from_file("save.json")
197
-
198
-
199
- ``set_random_seed(seed)``:
200
-
201
- - Set seed of random generator to ``seed``
202
-
203
- .. _set-replay-file:
204
-
205
-
206
- ``set_vehicle_route(vehicle_id, route)``:
207
-
208
- - To change the route of a vehicle during its travelling.
209
- - `route` is a list of road ids (doesn't include the current road)
210
- - Return true if the route is available and can be connected.
211
-
212
-
213
-
214
- Other API
215
- ---------
216
-
217
- ``set_replay_file(replay_file)``:
218
-
219
- - ``replay_file`` should be a path related to ``dir`` in config file
220
- - Set ``replayLogFile`` to ``replay_file``, newly generated replays will be output into ``replay_file``
221
- - This is useful when you want to look at a specific episode for debugging purposes
222
- - This API works only when ``saveReplay`` is ``true`` in config json
223
-
224
- ``set_save_replay(open)``:
225
-
226
- - Open or close replay saving
227
- - Set ``open`` to False to stop replay saving
228
- - Set ``open`` to True to start replay saving
229
  - This API works only when ``saveReplay`` is ``true`` in config json
 
1
+ .. _start:
2
+
3
+ Quick Start
4
+ ===========
5
+
6
+ Installation
7
+ ------------
8
+
9
+ If you have not installed CityFlow yet, :ref:`install` is a simple guide for installation.
10
+
11
+
12
+ Create Engine
13
+ -------------
14
+
15
+ .. code-block:: python
16
+
17
+ import cityflow
18
+ eng = cityflow.Engine(config_path, thread_num=1)
19
+
20
+
21
+ - ``config_path``: path for config file.
22
+ - ``thread_num``: number of threads.
23
+
24
+ Arguments In Config File
25
+ ^^^^^^^^^^^^^^^^^^^^^^^^
26
+ - ``interval``: time of each simulation step (in seconds). An ``interval`` of 0.5 means for each simulation step, the system will move 0.5 seconds forward. For example, if a car is at location 0 with speed 10m/s, after one simulation step, it will move to location 10*0.5=5.
27
+ - ``seed``: random seed.
28
+ - ``dir``: root directory, all file path will be relative to this directory.
29
+ - ``roadnetFile``: path for roadnet file.
30
+ - ``flowFile``: path for flow file.
31
+ - ``rlTrafficLight``: whether to enable traffic light control through python API. If set to ``false``, default traffic light plan defined in ``roadnetFile`` will be used.
32
+ - ``saveReplay``: whether to save simulation for replay. If set to ``true``, ``roadnetLogFile`` and ``replayLogFile`` are required.
33
+ - ``roadnetLogFile``: path for roadnet replay file. This is a special roadnet file for replay, not the same as ``roadnetFile``.
34
+ - ``replayLogFile``: path for replay. This file contains vehicle positions and traffic light situation of each simulation step.
35
+ - ``laneChange``: whether to enable lane changing. The default value is 'false'.
36
+
37
+ For format of ``roadnetFile`` and ``flowFile``, please see :ref:`roadnet`, :ref:`flow`
38
+
39
+ .. note::
40
+ Runnable sample roadnet and flow files can be found in ``examples`` folder.
41
+
42
+ You can generate grid roadnet and flow files using `tools/generate_grid_scenario.py`
43
+
44
+ For example, you can generate a 2x3 roadnet with predefined traffic light plan and a corresponding flow file with
45
+
46
+ .. code-block:: shell
47
+
48
+ python generate_grid_scenario.py 2 3 --roadnetFile roadnet.json --flowFile flow.json --dir . --tlPlan
49
+
50
+ Sample Config File
51
+ ^^^^^^^^^^^^^^^^^^^
52
+
53
+ .. note::
54
+ Runnable sample config files can be found in ``examples`` folder.
55
+
56
+ .. code-block:: json
57
+
58
+ {
59
+ "interval": 1.0,
60
+ "seed": 0,
61
+ "dir": "data/",
62
+ "roadnetFile": "roadnet/testcase_roadnet_3x3.json",
63
+ "flowFile": "flow/testcase_flow_3x3.json",
64
+ "rlTrafficLight": false,
65
+ "saveReplay": true,
66
+ "roadnetLogFile": "frontend/web/testcase_roadnet_3x3.json",
67
+ "replayLogFile": "frontend/web/testcase_replay_3x3.txt"
68
+ }
69
+
70
+ Simulation
71
+ ----------
72
+
73
+ To simulate one step, simply call ``eng.next_step()``
74
+
75
+ .. code-block:: python
76
+
77
+ eng.next_step()
78
+
79
+ Data Access API
80
+ ---------------
81
+
82
+ ``get_vehicle_count()``:
83
+
84
+ - Get number of total running vehicles.
85
+ - Return an ``int``
86
+
87
+ ``get_vehicles(include_waiting=False)``:
88
+
89
+ - Get all vehicle ids
90
+ - Include vehicles in lane's waiting buffer if ``include_waiting=True``
91
+ - Return an ``list`` of vehicle ids
92
+
93
+ ``get_lane_vehicle_count()``:
94
+
95
+ - Get number of running vehicles on each lane.
96
+ - Return a ``dict`` with lane id as key and corresponding number as value.
97
+
98
+ ``get_lane_waiting_vehicle_count()``:
99
+
100
+ - Get number of waiting vehicles on each lane. Currently, vehicles with speed less than 0.1m/s is considered as waiting.
101
+ - Return a ``dict`` with lane id as key and corresponding number as value.
102
+
103
+ ``get_lane_vehicles()``:
104
+
105
+ - Get vehicle ids on each lane.
106
+ - Return a ``dict`` with lane id as key and list of vehicle id as value.
107
+
108
+ ``get_vehicle_info(vehicle_id)``:
109
+
110
+ - Return a ``dict`` which contains information of the given vehicle.
111
+ - The items include:
112
+
113
+ + ``running``: whether the vehicle is running.
114
+ + If the vehicle is running:
115
+
116
+ * ``speed``: The speed of the vehicle.
117
+ * ``distance``: The distance the vehicle has travelled on the current lane or lanelink.
118
+ * ``drivable``: The id of the current drivable(lane or lanelink)
119
+ * ``road``: The id of the current road if the vehicle is running on a lane.
120
+ * ``intersection``: The next intersection if the vehicle is running on a lane.
121
+ * ``route``: A string contains ids of following roads in the vehicle's route which are separated by ``' '``.
122
+
123
+ - Note that all items are stored as ``str``.
124
+
125
+ ``get_vehicle_speed()``:
126
+
127
+ - Get speed of each vehicle
128
+ - Return a ``dict`` with vehicle id as key and corresponding speed as value.
129
+
130
+ ``get_vehicle_distance()``:
131
+
132
+ - Get distance travelled on current lane of each vehicle.
133
+ - Return a ``dict`` with vehicle id as key and corresponding distance as value.
134
+
135
+ ``get_leader(vehicle_id)``
136
+
137
+ - Return the id of the vehicle in front of ``vehicle_id``.
138
+ - Return an empty string ``""`` when ``vehicle_id`` does not have a leader
139
+
140
+ ``get_current_time()``:
141
+
142
+ - Get simulation time (in seconds)
143
+ - Return a ``double``
144
+
145
+ ``get_average_travel_time()``:
146
+
147
+ - Get average travel time (in seconds)
148
+ - Return a ``double``
149
+
150
+ Control API
151
+ -----------
152
+
153
+ ``set_tl_phase(intersection_id, phase_id)``:
154
+
155
+ - Set the phase of traffic light of ``intersection_id`` to ``phase_id``. Only works when ``rlTrafficLight`` is set to ``true``.
156
+ - The ``intersection_id`` should be defined in ``roadnetFile``
157
+ - ``phase_id`` is the index of phase in array ``"lightphases"``, defined in ``roadnetFile``.
158
+
159
+ ``set_vehicle_speed(vehicle_id, speed)``:
160
+
161
+ - Set the speed of ``vehicle_id`` to ``speed``.
162
+ - The vehicles have to obey fundamental rules to avoid collisions so the real speed might be different from ``speed``.
163
+
164
+ ``reset(seed=False)``:
165
+
166
+ - Reset the simulation (clear all vehicles and set simulation time back to zero)
167
+ - Reset random seed if ``seed`` is set to ``True``
168
+ - This does not clear old replays, instead, it appends new replays to ``replayLogFile``.
169
+
170
+ ``snapshot()``:
171
+
172
+ - Take a snapshot of current simulation state
173
+ - This will generate an ``Archive`` object which can be loaded later
174
+ - You can save an ``Archive`` object to a file using its ``dump`` method.
175
+
176
+ ``load(archive)``:
177
+
178
+ - Load an ``Archive`` object and restore simulation state
179
+
180
+ ``load_from_file(path)``
181
+
182
+ - Load a snapshot file created by ``dump`` method and restore simulation state.
183
+ - The whole process of saving and loading file is like:
184
+
185
+ .. code-block:: python
186
+
187
+ archive = eng.snapshot() # create an archive object
188
+ archive.dump("save.json") # if you want to save the snapshot to a file
189
+
190
+ # do something
191
+
192
+ eng.load(archive)
193
+ # load 'archive' and the simulation will start from the status when 'archive'is created
194
+
195
+ # or if you want to load from 'save.json'
196
+ eng.load_from_file("save.json")
197
+
198
+
199
+ ``set_random_seed(seed)``:
200
+
201
+ - Set seed of random generator to ``seed``
202
+
203
+ .. _set-replay-file:
204
+
205
+
206
+ ``set_vehicle_route(vehicle_id, route)``:
207
+
208
+ - To change the route of a vehicle during its travelling.
209
+ - `route` is a list of road ids (doesn't include the current road)
210
+ - Return true if the route is available and can be connected.
211
+
212
+
213
+
214
+ Other API
215
+ ---------
216
+
217
+ ``set_replay_file(replay_file)``:
218
+
219
+ - ``replay_file`` should be a path related to ``dir`` in config file
220
+ - Set ``replayLogFile`` to ``replay_file``, newly generated replays will be output into ``replay_file``
221
+ - This is useful when you want to look at a specific episode for debugging purposes
222
+ - This API works only when ``saveReplay`` is ``true`` in config json
223
+
224
+ ``set_save_replay(open)``:
225
+
226
+ - Open or close replay saving
227
+ - Set ``open`` to False to stop replay saving
228
+ - Set ``open`` to True to start replay saving
229
  - This API works only when ``saveReplay`` is ``true`` in config json
third_party/CityFlow/extern/milo/dtoa_milo.h CHANGED
@@ -1,396 +1,396 @@
1
- #pragma once
2
- #include <assert.h>
3
- #include <cmath>
4
- #include <string.h>
5
- #include <stdint.h>
6
-
7
- #define UINT64_C2(h, l) ((static_cast<uint64_t>(h) << 32) | static_cast<uint64_t>(l))
8
-
9
- struct DiyFp {
10
- DiyFp() {}
11
-
12
- DiyFp(uint64_t f, int e) : f(f), e(e) {}
13
-
14
- DiyFp(double d) {
15
- union {
16
- double d;
17
- uint64_t u64;
18
- } u = { d };
19
-
20
- int biased_e = (u.u64 & kDpExponentMask) >> kDpSignificandSize;
21
- uint64_t significand = (u.u64 & kDpSignificandMask);
22
- if (biased_e != 0) {
23
- f = significand + kDpHiddenBit;
24
- e = biased_e - kDpExponentBias;
25
- }
26
- else {
27
- f = significand;
28
- e = kDpMinExponent + 1;
29
- }
30
- }
31
-
32
- DiyFp operator-(const DiyFp& rhs) const {
33
- assert(e == rhs.e);
34
- assert(f >= rhs.f);
35
- return DiyFp(f - rhs.f, e);
36
- }
37
-
38
- DiyFp operator*(const DiyFp& rhs) const {
39
- #if defined(_MSC_VER) && defined(_M_AMD64)
40
- uint64_t h;
41
- uint64_t l = _umul128(f, rhs.f, &h);
42
- if (l & (uint64_t(1) << 63)) // rounding
43
- h++;
44
- return DiyFp(h, e + rhs.e + 64);
45
- #elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__)
46
- unsigned __int128 p = static_cast<unsigned __int128>(f) * static_cast<unsigned __int128>(rhs.f);
47
- uint64_t h = p >> 64;
48
- uint64_t l = static_cast<uint64_t>(p);
49
- if (l & (uint64_t(1) << 63)) // rounding
50
- h++;
51
- return DiyFp(h, e + rhs.e + 64);
52
- #else
53
- const uint64_t M32 = 0xFFFFFFFF;
54
- const uint64_t a = f >> 32;
55
- const uint64_t b = f & M32;
56
- const uint64_t c = rhs.f >> 32;
57
- const uint64_t d = rhs.f & M32;
58
- const uint64_t ac = a * c;
59
- const uint64_t bc = b * c;
60
- const uint64_t ad = a * d;
61
- const uint64_t bd = b * d;
62
- uint64_t tmp = (bd >> 32) + (ad & M32) + (bc & M32);
63
- tmp += 1U << 31; /// mult_round
64
- return DiyFp(ac + (ad >> 32) + (bc >> 32) + (tmp >> 32), e + rhs.e + 64);
65
- #endif
66
- }
67
-
68
- DiyFp Normalize() const {
69
- #if defined(_MSC_VER) && defined(_M_AMD64)
70
- unsigned long index;
71
- _BitScanReverse64(&index, f);
72
- return DiyFp(f << (63 - index), e - (63 - index));
73
- #elif defined(__GNUC__)
74
- int s = __builtin_clzll(f);
75
- return DiyFp(f << s, e - s);
76
- #else
77
- DiyFp res = *this;
78
- while (!(res.f & kDpHiddenBit)) {
79
- res.f <<= 1;
80
- res.e--;
81
- }
82
- res.f <<= (kDiySignificandSize - kDpSignificandSize - 1);
83
- res.e = res.e - (kDiySignificandSize - kDpSignificandSize - 1);
84
- return res;
85
- #endif
86
- }
87
-
88
- DiyFp NormalizeBoundary() const {
89
- #if defined(_MSC_VER) && defined(_M_AMD64)
90
- unsigned long index;
91
- _BitScanReverse64(&index, f);
92
- return DiyFp (f << (63 - index), e - (63 - index));
93
- #else
94
- DiyFp res = *this;
95
- while (!(res.f & (kDpHiddenBit << 1))) {
96
- res.f <<= 1;
97
- res.e--;
98
- }
99
- res.f <<= (kDiySignificandSize - kDpSignificandSize - 2);
100
- res.e = res.e - (kDiySignificandSize - kDpSignificandSize - 2);
101
- return res;
102
- #endif
103
- }
104
-
105
- void NormalizedBoundaries(DiyFp* minus, DiyFp* plus) const {
106
- DiyFp pl = DiyFp((f << 1) + 1, e - 1).NormalizeBoundary();
107
- DiyFp mi = (f == kDpHiddenBit) ? DiyFp((f << 2) - 1, e - 2) : DiyFp((f << 1) - 1, e - 1);
108
- mi.f <<= mi.e - pl.e;
109
- mi.e = pl.e;
110
- *plus = pl;
111
- *minus = mi;
112
- }
113
-
114
- static const int kDiySignificandSize = 64;
115
- static const int kDpSignificandSize = 52;
116
- static const int kDpExponentBias = 0x3FF + kDpSignificandSize;
117
- static const int kDpMinExponent = -kDpExponentBias;
118
- static const uint64_t kDpExponentMask = UINT64_C2(0x7FF00000, 0x00000000);
119
- static const uint64_t kDpSignificandMask = UINT64_C2(0x000FFFFF, 0xFFFFFFFF);
120
- static const uint64_t kDpHiddenBit = UINT64_C2(0x00100000, 0x00000000);
121
-
122
- uint64_t f;
123
- int e;
124
- };
125
-
126
- inline DiyFp GetCachedPower(int e, int* K) {
127
- // 10^-348, 10^-340, ..., 10^340
128
- static const uint64_t kCachedPowers_F[] = {
129
- UINT64_C2(0xfa8fd5a0, 0x081c0288), UINT64_C2(0xbaaee17f, 0xa23ebf76),
130
- UINT64_C2(0x8b16fb20, 0x3055ac76), UINT64_C2(0xcf42894a, 0x5dce35ea),
131
- UINT64_C2(0x9a6bb0aa, 0x55653b2d), UINT64_C2(0xe61acf03, 0x3d1a45df),
132
- UINT64_C2(0xab70fe17, 0xc79ac6ca), UINT64_C2(0xff77b1fc, 0xbebcdc4f),
133
- UINT64_C2(0xbe5691ef, 0x416bd60c), UINT64_C2(0x8dd01fad, 0x907ffc3c),
134
- UINT64_C2(0xd3515c28, 0x31559a83), UINT64_C2(0x9d71ac8f, 0xada6c9b5),
135
- UINT64_C2(0xea9c2277, 0x23ee8bcb), UINT64_C2(0xaecc4991, 0x4078536d),
136
- UINT64_C2(0x823c1279, 0x5db6ce57), UINT64_C2(0xc2109436, 0x4dfb5637),
137
- UINT64_C2(0x9096ea6f, 0x3848984f), UINT64_C2(0xd77485cb, 0x25823ac7),
138
- UINT64_C2(0xa086cfcd, 0x97bf97f4), UINT64_C2(0xef340a98, 0x172aace5),
139
- UINT64_C2(0xb23867fb, 0x2a35b28e), UINT64_C2(0x84c8d4df, 0xd2c63f3b),
140
- UINT64_C2(0xc5dd4427, 0x1ad3cdba), UINT64_C2(0x936b9fce, 0xbb25c996),
141
- UINT64_C2(0xdbac6c24, 0x7d62a584), UINT64_C2(0xa3ab6658, 0x0d5fdaf6),
142
- UINT64_C2(0xf3e2f893, 0xdec3f126), UINT64_C2(0xb5b5ada8, 0xaaff80b8),
143
- UINT64_C2(0x87625f05, 0x6c7c4a8b), UINT64_C2(0xc9bcff60, 0x34c13053),
144
- UINT64_C2(0x964e858c, 0x91ba2655), UINT64_C2(0xdff97724, 0x70297ebd),
145
- UINT64_C2(0xa6dfbd9f, 0xb8e5b88f), UINT64_C2(0xf8a95fcf, 0x88747d94),
146
- UINT64_C2(0xb9447093, 0x8fa89bcf), UINT64_C2(0x8a08f0f8, 0xbf0f156b),
147
- UINT64_C2(0xcdb02555, 0x653131b6), UINT64_C2(0x993fe2c6, 0xd07b7fac),
148
- UINT64_C2(0xe45c10c4, 0x2a2b3b06), UINT64_C2(0xaa242499, 0x697392d3),
149
- UINT64_C2(0xfd87b5f2, 0x8300ca0e), UINT64_C2(0xbce50864, 0x92111aeb),
150
- UINT64_C2(0x8cbccc09, 0x6f5088cc), UINT64_C2(0xd1b71758, 0xe219652c),
151
- UINT64_C2(0x9c400000, 0x00000000), UINT64_C2(0xe8d4a510, 0x00000000),
152
- UINT64_C2(0xad78ebc5, 0xac620000), UINT64_C2(0x813f3978, 0xf8940984),
153
- UINT64_C2(0xc097ce7b, 0xc90715b3), UINT64_C2(0x8f7e32ce, 0x7bea5c70),
154
- UINT64_C2(0xd5d238a4, 0xabe98068), UINT64_C2(0x9f4f2726, 0x179a2245),
155
- UINT64_C2(0xed63a231, 0xd4c4fb27), UINT64_C2(0xb0de6538, 0x8cc8ada8),
156
- UINT64_C2(0x83c7088e, 0x1aab65db), UINT64_C2(0xc45d1df9, 0x42711d9a),
157
- UINT64_C2(0x924d692c, 0xa61be758), UINT64_C2(0xda01ee64, 0x1a708dea),
158
- UINT64_C2(0xa26da399, 0x9aef774a), UINT64_C2(0xf209787b, 0xb47d6b85),
159
- UINT64_C2(0xb454e4a1, 0x79dd1877), UINT64_C2(0x865b8692, 0x5b9bc5c2),
160
- UINT64_C2(0xc83553c5, 0xc8965d3d), UINT64_C2(0x952ab45c, 0xfa97a0b3),
161
- UINT64_C2(0xde469fbd, 0x99a05fe3), UINT64_C2(0xa59bc234, 0xdb398c25),
162
- UINT64_C2(0xf6c69a72, 0xa3989f5c), UINT64_C2(0xb7dcbf53, 0x54e9bece),
163
- UINT64_C2(0x88fcf317, 0xf22241e2), UINT64_C2(0xcc20ce9b, 0xd35c78a5),
164
- UINT64_C2(0x98165af3, 0x7b2153df), UINT64_C2(0xe2a0b5dc, 0x971f303a),
165
- UINT64_C2(0xa8d9d153, 0x5ce3b396), UINT64_C2(0xfb9b7cd9, 0xa4a7443c),
166
- UINT64_C2(0xbb764c4c, 0xa7a44410), UINT64_C2(0x8bab8eef, 0xb6409c1a),
167
- UINT64_C2(0xd01fef10, 0xa657842c), UINT64_C2(0x9b10a4e5, 0xe9913129),
168
- UINT64_C2(0xe7109bfb, 0xa19c0c9d), UINT64_C2(0xac2820d9, 0x623bf429),
169
- UINT64_C2(0x80444b5e, 0x7aa7cf85), UINT64_C2(0xbf21e440, 0x03acdd2d),
170
- UINT64_C2(0x8e679c2f, 0x5e44ff8f), UINT64_C2(0xd433179d, 0x9c8cb841),
171
- UINT64_C2(0x9e19db92, 0xb4e31ba9), UINT64_C2(0xeb96bf6e, 0xbadf77d9),
172
- UINT64_C2(0xaf87023b, 0x9bf0ee6b)
173
- };
174
- static const int16_t kCachedPowers_E[] = {
175
- -1220, -1193, -1166, -1140, -1113, -1087, -1060, -1034, -1007, -980,
176
- -954, -927, -901, -874, -847, -821, -794, -768, -741, -715,
177
- -688, -661, -635, -608, -582, -555, -529, -502, -475, -449,
178
- -422, -396, -369, -343, -316, -289, -263, -236, -210, -183,
179
- -157, -130, -103, -77, -50, -24, 3, 30, 56, 83,
180
- 109, 136, 162, 189, 216, 242, 269, 295, 322, 348,
181
- 375, 402, 428, 455, 481, 508, 534, 561, 588, 614,
182
- 641, 667, 694, 720, 747, 774, 800, 827, 853, 880,
183
- 907, 933, 960, 986, 1013, 1039, 1066
184
- };
185
-
186
- //int k = static_cast<int>(ceil((-61 - e) * 0.30102999566398114)) + 374;
187
- double dk = (-61 - e) * 0.30102999566398114 + 347; // dk must be positive, so can do ceiling in positive
188
- int k = static_cast<int>(dk);
189
- if (k != dk)
190
- k++;
191
-
192
- unsigned index = static_cast<unsigned>((k >> 3) + 1);
193
- *K = -(-348 + static_cast<int>(index << 3)); // decimal exponent no need lookup table
194
-
195
- assert(index < sizeof(kCachedPowers_F) / sizeof(kCachedPowers_F[0]));
196
- return DiyFp(kCachedPowers_F[index], kCachedPowers_E[index]);
197
- }
198
-
199
- inline void GrisuRound(char* buffer, int len, uint64_t delta, uint64_t rest, uint64_t ten_kappa, uint64_t wp_w) {
200
- while (rest < wp_w && delta - rest >= ten_kappa &&
201
- (rest + ten_kappa < wp_w || /// closer
202
- wp_w - rest > rest + ten_kappa - wp_w)) {
203
- buffer[len - 1]--;
204
- rest += ten_kappa;
205
- }
206
- }
207
-
208
- inline unsigned CountDecimalDigit32(uint32_t n) {
209
- // Simple pure C++ implementation was faster than __builtin_clz version in this situation.
210
- if (n < 10) return 1;
211
- if (n < 100) return 2;
212
- if (n < 1000) return 3;
213
- if (n < 10000) return 4;
214
- if (n < 100000) return 5;
215
- if (n < 1000000) return 6;
216
- if (n < 10000000) return 7;
217
- if (n < 100000000) return 8;
218
- if (n < 1000000000) return 9;
219
- return 10;
220
- }
221
-
222
- inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buffer, int* len, int* K) {
223
- static const uint32_t kPow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
224
- const DiyFp one(uint64_t(1) << -Mp.e, Mp.e);
225
- const DiyFp wp_w = Mp - W;
226
- uint32_t p1 = static_cast<uint32_t>(Mp.f >> -one.e);
227
- uint64_t p2 = Mp.f & (one.f - 1);
228
- int kappa = static_cast<int>(CountDecimalDigit32(p1));
229
- *len = 0;
230
-
231
- while (kappa > 0) {
232
- uint32_t d;
233
- switch (kappa) {
234
- case 10: d = p1 / 1000000000; p1 %= 1000000000; break;
235
- case 9: d = p1 / 100000000; p1 %= 100000000; break;
236
- case 8: d = p1 / 10000000; p1 %= 10000000; break;
237
- case 7: d = p1 / 1000000; p1 %= 1000000; break;
238
- case 6: d = p1 / 100000; p1 %= 100000; break;
239
- case 5: d = p1 / 10000; p1 %= 10000; break;
240
- case 4: d = p1 / 1000; p1 %= 1000; break;
241
- case 3: d = p1 / 100; p1 %= 100; break;
242
- case 2: d = p1 / 10; p1 %= 10; break;
243
- case 1: d = p1; p1 = 0; break;
244
- default:
245
- #if defined(_MSC_VER)
246
- __assume(0);
247
- #elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
248
- __builtin_unreachable();
249
- #else
250
- d = 0;
251
- #endif
252
- }
253
- if (d || *len)
254
- buffer[(*len)++] = '0' + static_cast<char>(d);
255
- kappa--;
256
- uint64_t tmp = (static_cast<uint64_t>(p1) << -one.e) + p2;
257
- if (tmp <= delta) {
258
- *K += kappa;
259
- GrisuRound(buffer, *len, delta, tmp, static_cast<uint64_t>(kPow10[kappa]) << -one.e, wp_w.f);
260
- return;
261
- }
262
- }
263
-
264
- // kappa = 0
265
- for (;;) {
266
- p2 *= 10;
267
- delta *= 10;
268
- char d = static_cast<char>(p2 >> -one.e);
269
- if (d || *len)
270
- buffer[(*len)++] = '0' + d;
271
- p2 &= one.f - 1;
272
- kappa--;
273
- if (p2 < delta) {
274
- *K += kappa;
275
- GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * kPow10[-kappa]);
276
- return;
277
- }
278
- }
279
- }
280
-
281
- inline void Grisu2(double value, char* buffer, int* length, int* K) {
282
- const DiyFp v(value);
283
- DiyFp w_m, w_p;
284
- v.NormalizedBoundaries(&w_m, &w_p);
285
-
286
- const DiyFp c_mk = GetCachedPower(w_p.e, K);
287
- const DiyFp W = v.Normalize() * c_mk;
288
- DiyFp Wp = w_p * c_mk;
289
- DiyFp Wm = w_m * c_mk;
290
- Wm.f++;
291
- Wp.f--;
292
- DigitGen(W, Wp, Wp.f - Wm.f, buffer, length, K);
293
- }
294
-
295
- inline const char* GetDigitsLut() {
296
- static const char cDigitsLut[200] = {
297
- '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9',
298
- '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9',
299
- '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9',
300
- '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '3', '8', '3', '9',
301
- '4', '0', '4', '1', '4', '2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '4', '8', '4', '9',
302
- '5', '0', '5', '1', '5', '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9',
303
- '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6', '7', '6', '8', '6', '9',
304
- '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', '7', '7', '7', '8', '7', '9',
305
- '8', '0', '8', '1', '8', '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9',
306
- '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9', '7', '9', '8', '9', '9'
307
- };
308
- return cDigitsLut;
309
- }
310
-
311
- inline void WriteExponent(int K, char* buffer) {
312
- if (K < 0) {
313
- *buffer++ = '-';
314
- K = -K;
315
- }
316
-
317
- if (K >= 100) {
318
- *buffer++ = '0' + static_cast<char>(K / 100);
319
- K %= 100;
320
- const char* d = GetDigitsLut() + K * 2;
321
- *buffer++ = d[0];
322
- *buffer++ = d[1];
323
- }
324
- else if (K >= 10) {
325
- const char* d = GetDigitsLut() + K * 2;
326
- *buffer++ = d[0];
327
- *buffer++ = d[1];
328
- }
329
- else
330
- *buffer++ = '0' + static_cast<char>(K);
331
-
332
- *buffer = '\0';
333
- }
334
-
335
- inline void Prettify(char* buffer, int length, int k) {
336
- const int kk = length + k; // 10^(kk-1) <= v < 10^kk
337
-
338
- if (length <= kk && kk <= 21) {
339
- // 1234e7 -> 12340000000
340
- for (int i = length; i < kk; i++)
341
- buffer[i] = '0';
342
- buffer[kk] = '.';
343
- buffer[kk + 1] = '0';
344
- buffer[kk + 2] = '\0';
345
- }
346
- else if (0 < kk && kk <= 21) {
347
- // 1234e-2 -> 12.34
348
- memmove(&buffer[kk + 1], &buffer[kk], length - kk);
349
- buffer[kk] = '.';
350
- buffer[length + 1] = '\0';
351
- }
352
- else if (-6 < kk && kk <= 0) {
353
- // 1234e-6 -> 0.001234
354
- const int offset = 2 - kk;
355
- memmove(&buffer[offset], &buffer[0], length);
356
- buffer[0] = '0';
357
- buffer[1] = '.';
358
- for (int i = 2; i < offset; i++)
359
- buffer[i] = '0';
360
- buffer[length + offset] = '\0';
361
- }
362
- else if (length == 1) {
363
- // 1e30
364
- buffer[1] = 'e';
365
- WriteExponent(kk - 1, &buffer[2]);
366
- }
367
- else {
368
- // 1234e30 -> 1.234e33
369
- memmove(&buffer[2], &buffer[1], length - 1);
370
- buffer[1] = '.';
371
- buffer[length + 1] = 'e';
372
- WriteExponent(kk - 1, &buffer[0 + length + 2]);
373
- }
374
- }
375
-
376
- inline void dtoa_milo(double value, char* buffer) {
377
- // Not handling NaN and inf
378
- assert(!std::isnan(value));
379
- assert(!std::isinf(value));
380
-
381
- if (value == 0) {
382
- buffer[0] = '0';
383
- buffer[1] = '.';
384
- buffer[2] = '0';
385
- buffer[3] = '\0';
386
- }
387
- else {
388
- if (value < 0) {
389
- *buffer++ = '-';
390
- value = -value;
391
- }
392
- int length, K;
393
- Grisu2(value, buffer, &length, &K);
394
- Prettify(buffer, length, K);
395
- }
396
  }
 
1
+ #pragma once
2
+ #include <assert.h>
3
+ #include <cmath>
4
+ #include <string.h>
5
+ #include <stdint.h>
6
+
7
+ #define UINT64_C2(h, l) ((static_cast<uint64_t>(h) << 32) | static_cast<uint64_t>(l))
8
+
9
+ struct DiyFp {
10
+ DiyFp() {}
11
+
12
+ DiyFp(uint64_t f, int e) : f(f), e(e) {}
13
+
14
+ DiyFp(double d) {
15
+ union {
16
+ double d;
17
+ uint64_t u64;
18
+ } u = { d };
19
+
20
+ int biased_e = (u.u64 & kDpExponentMask) >> kDpSignificandSize;
21
+ uint64_t significand = (u.u64 & kDpSignificandMask);
22
+ if (biased_e != 0) {
23
+ f = significand + kDpHiddenBit;
24
+ e = biased_e - kDpExponentBias;
25
+ }
26
+ else {
27
+ f = significand;
28
+ e = kDpMinExponent + 1;
29
+ }
30
+ }
31
+
32
+ DiyFp operator-(const DiyFp& rhs) const {
33
+ assert(e == rhs.e);
34
+ assert(f >= rhs.f);
35
+ return DiyFp(f - rhs.f, e);
36
+ }
37
+
38
+ DiyFp operator*(const DiyFp& rhs) const {
39
+ #if defined(_MSC_VER) && defined(_M_AMD64)
40
+ uint64_t h;
41
+ uint64_t l = _umul128(f, rhs.f, &h);
42
+ if (l & (uint64_t(1) << 63)) // rounding
43
+ h++;
44
+ return DiyFp(h, e + rhs.e + 64);
45
+ #elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__)
46
+ unsigned __int128 p = static_cast<unsigned __int128>(f) * static_cast<unsigned __int128>(rhs.f);
47
+ uint64_t h = p >> 64;
48
+ uint64_t l = static_cast<uint64_t>(p);
49
+ if (l & (uint64_t(1) << 63)) // rounding
50
+ h++;
51
+ return DiyFp(h, e + rhs.e + 64);
52
+ #else
53
+ const uint64_t M32 = 0xFFFFFFFF;
54
+ const uint64_t a = f >> 32;
55
+ const uint64_t b = f & M32;
56
+ const uint64_t c = rhs.f >> 32;
57
+ const uint64_t d = rhs.f & M32;
58
+ const uint64_t ac = a * c;
59
+ const uint64_t bc = b * c;
60
+ const uint64_t ad = a * d;
61
+ const uint64_t bd = b * d;
62
+ uint64_t tmp = (bd >> 32) + (ad & M32) + (bc & M32);
63
+ tmp += 1U << 31; /// mult_round
64
+ return DiyFp(ac + (ad >> 32) + (bc >> 32) + (tmp >> 32), e + rhs.e + 64);
65
+ #endif
66
+ }
67
+
68
+ DiyFp Normalize() const {
69
+ #if defined(_MSC_VER) && defined(_M_AMD64)
70
+ unsigned long index;
71
+ _BitScanReverse64(&index, f);
72
+ return DiyFp(f << (63 - index), e - (63 - index));
73
+ #elif defined(__GNUC__)
74
+ int s = __builtin_clzll(f);
75
+ return DiyFp(f << s, e - s);
76
+ #else
77
+ DiyFp res = *this;
78
+ while (!(res.f & kDpHiddenBit)) {
79
+ res.f <<= 1;
80
+ res.e--;
81
+ }
82
+ res.f <<= (kDiySignificandSize - kDpSignificandSize - 1);
83
+ res.e = res.e - (kDiySignificandSize - kDpSignificandSize - 1);
84
+ return res;
85
+ #endif
86
+ }
87
+
88
+ DiyFp NormalizeBoundary() const {
89
+ #if defined(_MSC_VER) && defined(_M_AMD64)
90
+ unsigned long index;
91
+ _BitScanReverse64(&index, f);
92
+ return DiyFp (f << (63 - index), e - (63 - index));
93
+ #else
94
+ DiyFp res = *this;
95
+ while (!(res.f & (kDpHiddenBit << 1))) {
96
+ res.f <<= 1;
97
+ res.e--;
98
+ }
99
+ res.f <<= (kDiySignificandSize - kDpSignificandSize - 2);
100
+ res.e = res.e - (kDiySignificandSize - kDpSignificandSize - 2);
101
+ return res;
102
+ #endif
103
+ }
104
+
105
+ void NormalizedBoundaries(DiyFp* minus, DiyFp* plus) const {
106
+ DiyFp pl = DiyFp((f << 1) + 1, e - 1).NormalizeBoundary();
107
+ DiyFp mi = (f == kDpHiddenBit) ? DiyFp((f << 2) - 1, e - 2) : DiyFp((f << 1) - 1, e - 1);
108
+ mi.f <<= mi.e - pl.e;
109
+ mi.e = pl.e;
110
+ *plus = pl;
111
+ *minus = mi;
112
+ }
113
+
114
+ static const int kDiySignificandSize = 64;
115
+ static const int kDpSignificandSize = 52;
116
+ static const int kDpExponentBias = 0x3FF + kDpSignificandSize;
117
+ static const int kDpMinExponent = -kDpExponentBias;
118
+ static const uint64_t kDpExponentMask = UINT64_C2(0x7FF00000, 0x00000000);
119
+ static const uint64_t kDpSignificandMask = UINT64_C2(0x000FFFFF, 0xFFFFFFFF);
120
+ static const uint64_t kDpHiddenBit = UINT64_C2(0x00100000, 0x00000000);
121
+
122
+ uint64_t f;
123
+ int e;
124
+ };
125
+
126
+ inline DiyFp GetCachedPower(int e, int* K) {
127
+ // 10^-348, 10^-340, ..., 10^340
128
+ static const uint64_t kCachedPowers_F[] = {
129
+ UINT64_C2(0xfa8fd5a0, 0x081c0288), UINT64_C2(0xbaaee17f, 0xa23ebf76),
130
+ UINT64_C2(0x8b16fb20, 0x3055ac76), UINT64_C2(0xcf42894a, 0x5dce35ea),
131
+ UINT64_C2(0x9a6bb0aa, 0x55653b2d), UINT64_C2(0xe61acf03, 0x3d1a45df),
132
+ UINT64_C2(0xab70fe17, 0xc79ac6ca), UINT64_C2(0xff77b1fc, 0xbebcdc4f),
133
+ UINT64_C2(0xbe5691ef, 0x416bd60c), UINT64_C2(0x8dd01fad, 0x907ffc3c),
134
+ UINT64_C2(0xd3515c28, 0x31559a83), UINT64_C2(0x9d71ac8f, 0xada6c9b5),
135
+ UINT64_C2(0xea9c2277, 0x23ee8bcb), UINT64_C2(0xaecc4991, 0x4078536d),
136
+ UINT64_C2(0x823c1279, 0x5db6ce57), UINT64_C2(0xc2109436, 0x4dfb5637),
137
+ UINT64_C2(0x9096ea6f, 0x3848984f), UINT64_C2(0xd77485cb, 0x25823ac7),
138
+ UINT64_C2(0xa086cfcd, 0x97bf97f4), UINT64_C2(0xef340a98, 0x172aace5),
139
+ UINT64_C2(0xb23867fb, 0x2a35b28e), UINT64_C2(0x84c8d4df, 0xd2c63f3b),
140
+ UINT64_C2(0xc5dd4427, 0x1ad3cdba), UINT64_C2(0x936b9fce, 0xbb25c996),
141
+ UINT64_C2(0xdbac6c24, 0x7d62a584), UINT64_C2(0xa3ab6658, 0x0d5fdaf6),
142
+ UINT64_C2(0xf3e2f893, 0xdec3f126), UINT64_C2(0xb5b5ada8, 0xaaff80b8),
143
+ UINT64_C2(0x87625f05, 0x6c7c4a8b), UINT64_C2(0xc9bcff60, 0x34c13053),
144
+ UINT64_C2(0x964e858c, 0x91ba2655), UINT64_C2(0xdff97724, 0x70297ebd),
145
+ UINT64_C2(0xa6dfbd9f, 0xb8e5b88f), UINT64_C2(0xf8a95fcf, 0x88747d94),
146
+ UINT64_C2(0xb9447093, 0x8fa89bcf), UINT64_C2(0x8a08f0f8, 0xbf0f156b),
147
+ UINT64_C2(0xcdb02555, 0x653131b6), UINT64_C2(0x993fe2c6, 0xd07b7fac),
148
+ UINT64_C2(0xe45c10c4, 0x2a2b3b06), UINT64_C2(0xaa242499, 0x697392d3),
149
+ UINT64_C2(0xfd87b5f2, 0x8300ca0e), UINT64_C2(0xbce50864, 0x92111aeb),
150
+ UINT64_C2(0x8cbccc09, 0x6f5088cc), UINT64_C2(0xd1b71758, 0xe219652c),
151
+ UINT64_C2(0x9c400000, 0x00000000), UINT64_C2(0xe8d4a510, 0x00000000),
152
+ UINT64_C2(0xad78ebc5, 0xac620000), UINT64_C2(0x813f3978, 0xf8940984),
153
+ UINT64_C2(0xc097ce7b, 0xc90715b3), UINT64_C2(0x8f7e32ce, 0x7bea5c70),
154
+ UINT64_C2(0xd5d238a4, 0xabe98068), UINT64_C2(0x9f4f2726, 0x179a2245),
155
+ UINT64_C2(0xed63a231, 0xd4c4fb27), UINT64_C2(0xb0de6538, 0x8cc8ada8),
156
+ UINT64_C2(0x83c7088e, 0x1aab65db), UINT64_C2(0xc45d1df9, 0x42711d9a),
157
+ UINT64_C2(0x924d692c, 0xa61be758), UINT64_C2(0xda01ee64, 0x1a708dea),
158
+ UINT64_C2(0xa26da399, 0x9aef774a), UINT64_C2(0xf209787b, 0xb47d6b85),
159
+ UINT64_C2(0xb454e4a1, 0x79dd1877), UINT64_C2(0x865b8692, 0x5b9bc5c2),
160
+ UINT64_C2(0xc83553c5, 0xc8965d3d), UINT64_C2(0x952ab45c, 0xfa97a0b3),
161
+ UINT64_C2(0xde469fbd, 0x99a05fe3), UINT64_C2(0xa59bc234, 0xdb398c25),
162
+ UINT64_C2(0xf6c69a72, 0xa3989f5c), UINT64_C2(0xb7dcbf53, 0x54e9bece),
163
+ UINT64_C2(0x88fcf317, 0xf22241e2), UINT64_C2(0xcc20ce9b, 0xd35c78a5),
164
+ UINT64_C2(0x98165af3, 0x7b2153df), UINT64_C2(0xe2a0b5dc, 0x971f303a),
165
+ UINT64_C2(0xa8d9d153, 0x5ce3b396), UINT64_C2(0xfb9b7cd9, 0xa4a7443c),
166
+ UINT64_C2(0xbb764c4c, 0xa7a44410), UINT64_C2(0x8bab8eef, 0xb6409c1a),
167
+ UINT64_C2(0xd01fef10, 0xa657842c), UINT64_C2(0x9b10a4e5, 0xe9913129),
168
+ UINT64_C2(0xe7109bfb, 0xa19c0c9d), UINT64_C2(0xac2820d9, 0x623bf429),
169
+ UINT64_C2(0x80444b5e, 0x7aa7cf85), UINT64_C2(0xbf21e440, 0x03acdd2d),
170
+ UINT64_C2(0x8e679c2f, 0x5e44ff8f), UINT64_C2(0xd433179d, 0x9c8cb841),
171
+ UINT64_C2(0x9e19db92, 0xb4e31ba9), UINT64_C2(0xeb96bf6e, 0xbadf77d9),
172
+ UINT64_C2(0xaf87023b, 0x9bf0ee6b)
173
+ };
174
+ static const int16_t kCachedPowers_E[] = {
175
+ -1220, -1193, -1166, -1140, -1113, -1087, -1060, -1034, -1007, -980,
176
+ -954, -927, -901, -874, -847, -821, -794, -768, -741, -715,
177
+ -688, -661, -635, -608, -582, -555, -529, -502, -475, -449,
178
+ -422, -396, -369, -343, -316, -289, -263, -236, -210, -183,
179
+ -157, -130, -103, -77, -50, -24, 3, 30, 56, 83,
180
+ 109, 136, 162, 189, 216, 242, 269, 295, 322, 348,
181
+ 375, 402, 428, 455, 481, 508, 534, 561, 588, 614,
182
+ 641, 667, 694, 720, 747, 774, 800, 827, 853, 880,
183
+ 907, 933, 960, 986, 1013, 1039, 1066
184
+ };
185
+
186
+ //int k = static_cast<int>(ceil((-61 - e) * 0.30102999566398114)) + 374;
187
+ double dk = (-61 - e) * 0.30102999566398114 + 347; // dk must be positive, so can do ceiling in positive
188
+ int k = static_cast<int>(dk);
189
+ if (k != dk)
190
+ k++;
191
+
192
+ unsigned index = static_cast<unsigned>((k >> 3) + 1);
193
+ *K = -(-348 + static_cast<int>(index << 3)); // decimal exponent no need lookup table
194
+
195
+ assert(index < sizeof(kCachedPowers_F) / sizeof(kCachedPowers_F[0]));
196
+ return DiyFp(kCachedPowers_F[index], kCachedPowers_E[index]);
197
+ }
198
+
199
+ inline void GrisuRound(char* buffer, int len, uint64_t delta, uint64_t rest, uint64_t ten_kappa, uint64_t wp_w) {
200
+ while (rest < wp_w && delta - rest >= ten_kappa &&
201
+ (rest + ten_kappa < wp_w || /// closer
202
+ wp_w - rest > rest + ten_kappa - wp_w)) {
203
+ buffer[len - 1]--;
204
+ rest += ten_kappa;
205
+ }
206
+ }
207
+
208
+ inline unsigned CountDecimalDigit32(uint32_t n) {
209
+ // Simple pure C++ implementation was faster than __builtin_clz version in this situation.
210
+ if (n < 10) return 1;
211
+ if (n < 100) return 2;
212
+ if (n < 1000) return 3;
213
+ if (n < 10000) return 4;
214
+ if (n < 100000) return 5;
215
+ if (n < 1000000) return 6;
216
+ if (n < 10000000) return 7;
217
+ if (n < 100000000) return 8;
218
+ if (n < 1000000000) return 9;
219
+ return 10;
220
+ }
221
+
222
+ inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buffer, int* len, int* K) {
223
+ static const uint32_t kPow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
224
+ const DiyFp one(uint64_t(1) << -Mp.e, Mp.e);
225
+ const DiyFp wp_w = Mp - W;
226
+ uint32_t p1 = static_cast<uint32_t>(Mp.f >> -one.e);
227
+ uint64_t p2 = Mp.f & (one.f - 1);
228
+ int kappa = static_cast<int>(CountDecimalDigit32(p1));
229
+ *len = 0;
230
+
231
+ while (kappa > 0) {
232
+ uint32_t d;
233
+ switch (kappa) {
234
+ case 10: d = p1 / 1000000000; p1 %= 1000000000; break;
235
+ case 9: d = p1 / 100000000; p1 %= 100000000; break;
236
+ case 8: d = p1 / 10000000; p1 %= 10000000; break;
237
+ case 7: d = p1 / 1000000; p1 %= 1000000; break;
238
+ case 6: d = p1 / 100000; p1 %= 100000; break;
239
+ case 5: d = p1 / 10000; p1 %= 10000; break;
240
+ case 4: d = p1 / 1000; p1 %= 1000; break;
241
+ case 3: d = p1 / 100; p1 %= 100; break;
242
+ case 2: d = p1 / 10; p1 %= 10; break;
243
+ case 1: d = p1; p1 = 0; break;
244
+ default:
245
+ #if defined(_MSC_VER)
246
+ __assume(0);
247
+ #elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
248
+ __builtin_unreachable();
249
+ #else
250
+ d = 0;
251
+ #endif
252
+ }
253
+ if (d || *len)
254
+ buffer[(*len)++] = '0' + static_cast<char>(d);
255
+ kappa--;
256
+ uint64_t tmp = (static_cast<uint64_t>(p1) << -one.e) + p2;
257
+ if (tmp <= delta) {
258
+ *K += kappa;
259
+ GrisuRound(buffer, *len, delta, tmp, static_cast<uint64_t>(kPow10[kappa]) << -one.e, wp_w.f);
260
+ return;
261
+ }
262
+ }
263
+
264
+ // kappa = 0
265
+ for (;;) {
266
+ p2 *= 10;
267
+ delta *= 10;
268
+ char d = static_cast<char>(p2 >> -one.e);
269
+ if (d || *len)
270
+ buffer[(*len)++] = '0' + d;
271
+ p2 &= one.f - 1;
272
+ kappa--;
273
+ if (p2 < delta) {
274
+ *K += kappa;
275
+ GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * kPow10[-kappa]);
276
+ return;
277
+ }
278
+ }
279
+ }
280
+
281
+ inline void Grisu2(double value, char* buffer, int* length, int* K) {
282
+ const DiyFp v(value);
283
+ DiyFp w_m, w_p;
284
+ v.NormalizedBoundaries(&w_m, &w_p);
285
+
286
+ const DiyFp c_mk = GetCachedPower(w_p.e, K);
287
+ const DiyFp W = v.Normalize() * c_mk;
288
+ DiyFp Wp = w_p * c_mk;
289
+ DiyFp Wm = w_m * c_mk;
290
+ Wm.f++;
291
+ Wp.f--;
292
+ DigitGen(W, Wp, Wp.f - Wm.f, buffer, length, K);
293
+ }
294
+
295
+ inline const char* GetDigitsLut() {
296
+ static const char cDigitsLut[200] = {
297
+ '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9',
298
+ '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9',
299
+ '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9',
300
+ '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '3', '8', '3', '9',
301
+ '4', '0', '4', '1', '4', '2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '4', '8', '4', '9',
302
+ '5', '0', '5', '1', '5', '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9',
303
+ '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6', '7', '6', '8', '6', '9',
304
+ '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', '7', '7', '7', '8', '7', '9',
305
+ '8', '0', '8', '1', '8', '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9',
306
+ '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9', '7', '9', '8', '9', '9'
307
+ };
308
+ return cDigitsLut;
309
+ }
310
+
311
+ inline void WriteExponent(int K, char* buffer) {
312
+ if (K < 0) {
313
+ *buffer++ = '-';
314
+ K = -K;
315
+ }
316
+
317
+ if (K >= 100) {
318
+ *buffer++ = '0' + static_cast<char>(K / 100);
319
+ K %= 100;
320
+ const char* d = GetDigitsLut() + K * 2;
321
+ *buffer++ = d[0];
322
+ *buffer++ = d[1];
323
+ }
324
+ else if (K >= 10) {
325
+ const char* d = GetDigitsLut() + K * 2;
326
+ *buffer++ = d[0];
327
+ *buffer++ = d[1];
328
+ }
329
+ else
330
+ *buffer++ = '0' + static_cast<char>(K);
331
+
332
+ *buffer = '\0';
333
+ }
334
+
335
+ inline void Prettify(char* buffer, int length, int k) {
336
+ const int kk = length + k; // 10^(kk-1) <= v < 10^kk
337
+
338
+ if (length <= kk && kk <= 21) {
339
+ // 1234e7 -> 12340000000
340
+ for (int i = length; i < kk; i++)
341
+ buffer[i] = '0';
342
+ buffer[kk] = '.';
343
+ buffer[kk + 1] = '0';
344
+ buffer[kk + 2] = '\0';
345
+ }
346
+ else if (0 < kk && kk <= 21) {
347
+ // 1234e-2 -> 12.34
348
+ memmove(&buffer[kk + 1], &buffer[kk], length - kk);
349
+ buffer[kk] = '.';
350
+ buffer[length + 1] = '\0';
351
+ }
352
+ else if (-6 < kk && kk <= 0) {
353
+ // 1234e-6 -> 0.001234
354
+ const int offset = 2 - kk;
355
+ memmove(&buffer[offset], &buffer[0], length);
356
+ buffer[0] = '0';
357
+ buffer[1] = '.';
358
+ for (int i = 2; i < offset; i++)
359
+ buffer[i] = '0';
360
+ buffer[length + offset] = '\0';
361
+ }
362
+ else if (length == 1) {
363
+ // 1e30
364
+ buffer[1] = 'e';
365
+ WriteExponent(kk - 1, &buffer[2]);
366
+ }
367
+ else {
368
+ // 1234e30 -> 1.234e33
369
+ memmove(&buffer[2], &buffer[1], length - 1);
370
+ buffer[1] = '.';
371
+ buffer[length + 1] = 'e';
372
+ WriteExponent(kk - 1, &buffer[0 + length + 2]);
373
+ }
374
+ }
375
+
376
+ inline void dtoa_milo(double value, char* buffer) {
377
+ // Not handling NaN and inf
378
+ assert(!std::isnan(value));
379
+ assert(!std::isinf(value));
380
+
381
+ if (value == 0) {
382
+ buffer[0] = '0';
383
+ buffer[1] = '.';
384
+ buffer[2] = '0';
385
+ buffer[3] = '\0';
386
+ }
387
+ else {
388
+ if (value < 0) {
389
+ *buffer++ = '-';
390
+ value = -value;
391
+ }
392
+ int length, K;
393
+ Grisu2(value, buffer, &length, &K);
394
+ Prettify(buffer, length, K);
395
+ }
396
  }
third_party/CityFlow/extern/pybind11/.appveyor.yml CHANGED
@@ -1,35 +1,35 @@
1
- version: 1.0.{build}
2
- image:
3
- - Visual Studio 2017
4
- test: off
5
- skip_branch_with_pr: true
6
- build:
7
- parallel: true
8
- platform:
9
- - x86
10
- environment:
11
- matrix:
12
- - PYTHON: 36
13
- CONFIG: Debug
14
- install:
15
- - ps: |
16
- $env:CMAKE_GENERATOR = "Visual Studio 15 2017"
17
- if ($env:PLATFORM -eq "x64") { $env:PYTHON = "$env:PYTHON-x64" }
18
- $env:PATH = "C:\Python$env:PYTHON\;C:\Python$env:PYTHON\Scripts\;$env:PATH"
19
- python -W ignore -m pip install --upgrade pip wheel
20
- python -W ignore -m pip install pytest numpy --no-warn-script-location pytest-timeout
21
- - ps: |
22
- Start-FileDownload 'https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.zip'
23
- 7z x eigen-3.3.7.zip -y > $null
24
- $env:CMAKE_INCLUDE_PATH = "eigen-3.3.7;$env:CMAKE_INCLUDE_PATH"
25
- build_script:
26
- - cmake -G "%CMAKE_GENERATOR%" -A "%CMAKE_ARCH%"
27
- -DCMAKE_CXX_STANDARD=14
28
- -DPYBIND11_WERROR=ON
29
- -DDOWNLOAD_CATCH=ON
30
- -DCMAKE_SUPPRESS_REGENERATION=1
31
- .
32
- - set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
33
- - cmake --build . --config %CONFIG% --target pytest -- /m /v:m /logger:%MSBuildLogger%
34
- - cmake --build . --config %CONFIG% --target cpptest -- /m /v:m /logger:%MSBuildLogger%
35
- on_failure: if exist "tests\test_cmake_build" type tests\test_cmake_build\*.log*
 
1
+ version: 1.0.{build}
2
+ image:
3
+ - Visual Studio 2017
4
+ test: off
5
+ skip_branch_with_pr: true
6
+ build:
7
+ parallel: true
8
+ platform:
9
+ - x86
10
+ environment:
11
+ matrix:
12
+ - PYTHON: 36
13
+ CONFIG: Debug
14
+ install:
15
+ - ps: |
16
+ $env:CMAKE_GENERATOR = "Visual Studio 15 2017"
17
+ if ($env:PLATFORM -eq "x64") { $env:PYTHON = "$env:PYTHON-x64" }
18
+ $env:PATH = "C:\Python$env:PYTHON\;C:\Python$env:PYTHON\Scripts\;$env:PATH"
19
+ python -W ignore -m pip install --upgrade pip wheel
20
+ python -W ignore -m pip install pytest numpy --no-warn-script-location pytest-timeout
21
+ - ps: |
22
+ Start-FileDownload 'https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.zip'
23
+ 7z x eigen-3.3.7.zip -y > $null
24
+ $env:CMAKE_INCLUDE_PATH = "eigen-3.3.7;$env:CMAKE_INCLUDE_PATH"
25
+ build_script:
26
+ - cmake -G "%CMAKE_GENERATOR%" -A "%CMAKE_ARCH%"
27
+ -DCMAKE_CXX_STANDARD=14
28
+ -DPYBIND11_WERROR=ON
29
+ -DDOWNLOAD_CATCH=ON
30
+ -DCMAKE_SUPPRESS_REGENERATION=1
31
+ .
32
+ - set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
33
+ - cmake --build . --config %CONFIG% --target pytest -- /m /v:m /logger:%MSBuildLogger%
34
+ - cmake --build . --config %CONFIG% --target cpptest -- /m /v:m /logger:%MSBuildLogger%
35
+ on_failure: if exist "tests\test_cmake_build" type tests\test_cmake_build\*.log*
third_party/CityFlow/extern/pybind11/.clang-format CHANGED
@@ -1,38 +1,38 @@
1
- ---
2
- # See all possible options and defaults with:
3
- # clang-format --style=llvm --dump-config
4
- BasedOnStyle: LLVM
5
- AccessModifierOffset: -4
6
- AllowShortLambdasOnASingleLine: true
7
- AlwaysBreakTemplateDeclarations: Yes
8
- BinPackArguments: false
9
- BinPackParameters: false
10
- BreakBeforeBinaryOperators: All
11
- BreakConstructorInitializers: BeforeColon
12
- ColumnLimit: 99
13
- CommentPragmas: 'NOLINT:.*|^ IWYU pragma:'
14
- IncludeBlocks: Regroup
15
- IndentCaseLabels: true
16
- IndentPPDirectives: AfterHash
17
- IndentWidth: 4
18
- Language: Cpp
19
- SpaceAfterCStyleCast: true
20
- Standard: Cpp11
21
- StatementMacros: ['PyObject_HEAD']
22
- TabWidth: 4
23
- IncludeCategories:
24
- - Regex: '<pybind11/.*'
25
- Priority: -1
26
- - Regex: 'pybind11.h"$'
27
- Priority: 1
28
- - Regex: '^".*/?detail/'
29
- Priority: 1
30
- SortPriority: 2
31
- - Regex: '^"'
32
- Priority: 1
33
- SortPriority: 3
34
- - Regex: '<[[:alnum:]._]+>'
35
- Priority: 4
36
- - Regex: '.*'
37
- Priority: 5
38
- ...
 
1
+ ---
2
+ # See all possible options and defaults with:
3
+ # clang-format --style=llvm --dump-config
4
+ BasedOnStyle: LLVM
5
+ AccessModifierOffset: -4
6
+ AllowShortLambdasOnASingleLine: true
7
+ AlwaysBreakTemplateDeclarations: Yes
8
+ BinPackArguments: false
9
+ BinPackParameters: false
10
+ BreakBeforeBinaryOperators: All
11
+ BreakConstructorInitializers: BeforeColon
12
+ ColumnLimit: 99
13
+ CommentPragmas: 'NOLINT:.*|^ IWYU pragma:'
14
+ IncludeBlocks: Regroup
15
+ IndentCaseLabels: true
16
+ IndentPPDirectives: AfterHash
17
+ IndentWidth: 4
18
+ Language: Cpp
19
+ SpaceAfterCStyleCast: true
20
+ Standard: Cpp11
21
+ StatementMacros: ['PyObject_HEAD']
22
+ TabWidth: 4
23
+ IncludeCategories:
24
+ - Regex: '<pybind11/.*'
25
+ Priority: -1
26
+ - Regex: 'pybind11.h"$'
27
+ Priority: 1
28
+ - Regex: '^".*/?detail/'
29
+ Priority: 1
30
+ SortPriority: 2
31
+ - Regex: '^"'
32
+ Priority: 1
33
+ SortPriority: 3
34
+ - Regex: '<[[:alnum:]._]+>'
35
+ Priority: 4
36
+ - Regex: '.*'
37
+ Priority: 5
38
+ ...
third_party/CityFlow/extern/pybind11/.clang-tidy CHANGED
@@ -1,77 +1,77 @@
1
- FormatStyle: file
2
-
3
- Checks: |
4
- *bugprone*,
5
- *performance*,
6
- clang-analyzer-optin.cplusplus.VirtualCall,
7
- clang-analyzer-optin.performance.Padding,
8
- cppcoreguidelines-init-variables,
9
- cppcoreguidelines-prefer-member-initializer,
10
- cppcoreguidelines-pro-type-static-cast-downcast,
11
- cppcoreguidelines-slicing,
12
- google-explicit-constructor,
13
- llvm-namespace-comment,
14
- misc-definitions-in-headers,
15
- misc-misplaced-const,
16
- misc-non-copyable-objects,
17
- misc-static-assert,
18
- misc-throw-by-value-catch-by-reference,
19
- misc-uniqueptr-reset-release,
20
- misc-unused-parameters,
21
- modernize-avoid-bind,
22
- modernize-loop-convert,
23
- modernize-make-shared,
24
- modernize-redundant-void-arg,
25
- modernize-replace-auto-ptr,
26
- modernize-replace-disallow-copy-and-assign-macro,
27
- modernize-replace-random-shuffle,
28
- modernize-shrink-to-fit,
29
- modernize-use-auto,
30
- modernize-use-bool-literals,
31
- modernize-use-default-member-init,
32
- modernize-use-emplace,
33
- modernize-use-equals-default,
34
- modernize-use-equals-delete,
35
- modernize-use-noexcept,
36
- modernize-use-nullptr,
37
- modernize-use-override,
38
- modernize-use-using,
39
- readability-avoid-const-params-in-decls,
40
- readability-braces-around-statements,
41
- readability-const-return-type,
42
- readability-container-size-empty,
43
- readability-delete-null-pointer,
44
- readability-else-after-return,
45
- readability-implicit-bool-conversion,
46
- readability-inconsistent-declaration-parameter-name,
47
- readability-make-member-function-const,
48
- readability-misplaced-array-index,
49
- readability-non-const-parameter,
50
- readability-qualified-auto,
51
- readability-redundant-function-ptr-dereference,
52
- readability-redundant-smartptr-get,
53
- readability-redundant-string-cstr,
54
- readability-simplify-subscript-expr,
55
- readability-static-accessed-through-instance,
56
- readability-static-definition-in-anonymous-namespace,
57
- readability-string-compare,
58
- readability-suspicious-call-argument,
59
- readability-uniqueptr-delete-release,
60
- -bugprone-easily-swappable-parameters,
61
- -bugprone-exception-escape,
62
- -bugprone-reserved-identifier,
63
- -bugprone-unused-raii,
64
-
65
- CheckOptions:
66
- - key: modernize-use-equals-default.IgnoreMacros
67
- value: false
68
- - key: performance-for-range-copy.WarnOnAllAutoCopies
69
- value: true
70
- - key: performance-inefficient-string-concatenation.StrictMode
71
- value: true
72
- - key: performance-unnecessary-value-param.AllowedTypes
73
- value: 'exception_ptr$;'
74
- - key: readability-implicit-bool-conversion.AllowPointerConditions
75
- value: true
76
-
77
- HeaderFilterRegex: 'pybind11/.*h'
 
1
+ FormatStyle: file
2
+
3
+ Checks: |
4
+ *bugprone*,
5
+ *performance*,
6
+ clang-analyzer-optin.cplusplus.VirtualCall,
7
+ clang-analyzer-optin.performance.Padding,
8
+ cppcoreguidelines-init-variables,
9
+ cppcoreguidelines-prefer-member-initializer,
10
+ cppcoreguidelines-pro-type-static-cast-downcast,
11
+ cppcoreguidelines-slicing,
12
+ google-explicit-constructor,
13
+ llvm-namespace-comment,
14
+ misc-definitions-in-headers,
15
+ misc-misplaced-const,
16
+ misc-non-copyable-objects,
17
+ misc-static-assert,
18
+ misc-throw-by-value-catch-by-reference,
19
+ misc-uniqueptr-reset-release,
20
+ misc-unused-parameters,
21
+ modernize-avoid-bind,
22
+ modernize-loop-convert,
23
+ modernize-make-shared,
24
+ modernize-redundant-void-arg,
25
+ modernize-replace-auto-ptr,
26
+ modernize-replace-disallow-copy-and-assign-macro,
27
+ modernize-replace-random-shuffle,
28
+ modernize-shrink-to-fit,
29
+ modernize-use-auto,
30
+ modernize-use-bool-literals,
31
+ modernize-use-default-member-init,
32
+ modernize-use-emplace,
33
+ modernize-use-equals-default,
34
+ modernize-use-equals-delete,
35
+ modernize-use-noexcept,
36
+ modernize-use-nullptr,
37
+ modernize-use-override,
38
+ modernize-use-using,
39
+ readability-avoid-const-params-in-decls,
40
+ readability-braces-around-statements,
41
+ readability-const-return-type,
42
+ readability-container-size-empty,
43
+ readability-delete-null-pointer,
44
+ readability-else-after-return,
45
+ readability-implicit-bool-conversion,
46
+ readability-inconsistent-declaration-parameter-name,
47
+ readability-make-member-function-const,
48
+ readability-misplaced-array-index,
49
+ readability-non-const-parameter,
50
+ readability-qualified-auto,
51
+ readability-redundant-function-ptr-dereference,
52
+ readability-redundant-smartptr-get,
53
+ readability-redundant-string-cstr,
54
+ readability-simplify-subscript-expr,
55
+ readability-static-accessed-through-instance,
56
+ readability-static-definition-in-anonymous-namespace,
57
+ readability-string-compare,
58
+ readability-suspicious-call-argument,
59
+ readability-uniqueptr-delete-release,
60
+ -bugprone-easily-swappable-parameters,
61
+ -bugprone-exception-escape,
62
+ -bugprone-reserved-identifier,
63
+ -bugprone-unused-raii,
64
+
65
+ CheckOptions:
66
+ - key: modernize-use-equals-default.IgnoreMacros
67
+ value: false
68
+ - key: performance-for-range-copy.WarnOnAllAutoCopies
69
+ value: true
70
+ - key: performance-inefficient-string-concatenation.StrictMode
71
+ value: true
72
+ - key: performance-unnecessary-value-param.AllowedTypes
73
+ value: 'exception_ptr$;'
74
+ - key: readability-implicit-bool-conversion.AllowPointerConditions
75
+ value: true
76
+
77
+ HeaderFilterRegex: 'pybind11/.*h'
third_party/CityFlow/extern/pybind11/.cmake-format.yaml CHANGED
@@ -1,73 +1,73 @@
1
- parse:
2
- additional_commands:
3
- pybind11_add_module:
4
- flags:
5
- - THIN_LTO
6
- - MODULE
7
- - SHARED
8
- - NO_EXTRAS
9
- - EXCLUDE_FROM_ALL
10
- - SYSTEM
11
-
12
- format:
13
- line_width: 99
14
- tab_size: 2
15
-
16
- # If an argument group contains more than this many sub-groups
17
- # (parg or kwarg groups) then force it to a vertical layout.
18
- max_subgroups_hwrap: 2
19
-
20
- # If a positional argument group contains more than this many
21
- # arguments, then force it to a vertical layout.
22
- max_pargs_hwrap: 6
23
-
24
- # If a cmdline positional group consumes more than this many
25
- # lines without nesting, then invalidate the layout (and nest)
26
- max_rows_cmdline: 2
27
- separate_ctrl_name_with_space: false
28
- separate_fn_name_with_space: false
29
- dangle_parens: false
30
-
31
- # If the trailing parenthesis must be 'dangled' on its on
32
- # 'line, then align it to this reference: `prefix`: the start'
33
- # 'of the statement, `prefix-indent`: the start of the'
34
- # 'statement, plus one indentation level, `child`: align to'
35
- # the column of the arguments
36
- dangle_align: prefix
37
- # If the statement spelling length (including space and
38
- # parenthesis) is smaller than this amount, then force reject
39
- # nested layouts.
40
- min_prefix_chars: 4
41
-
42
- # If the statement spelling length (including space and
43
- # parenthesis) is larger than the tab width by more than this
44
- # amount, then force reject un-nested layouts.
45
- max_prefix_chars: 10
46
-
47
- # If a candidate layout is wrapped horizontally but it exceeds
48
- # this many lines, then reject the layout.
49
- max_lines_hwrap: 2
50
-
51
- line_ending: unix
52
-
53
- # Format command names consistently as 'lower' or 'upper' case
54
- command_case: canonical
55
-
56
- # Format keywords consistently as 'lower' or 'upper' case
57
- # unchanged is valid too
58
- keyword_case: 'upper'
59
-
60
- # A list of command names which should always be wrapped
61
- always_wrap: []
62
-
63
- # If true, the argument lists which are known to be sortable
64
- # will be sorted lexicographically
65
- enable_sort: true
66
-
67
- # If true, the parsers may infer whether or not an argument
68
- # list is sortable (without annotation).
69
- autosort: false
70
-
71
- # Causes a few issues - can be solved later, possibly.
72
- markup:
73
- enable_markup: false
 
1
+ parse:
2
+ additional_commands:
3
+ pybind11_add_module:
4
+ flags:
5
+ - THIN_LTO
6
+ - MODULE
7
+ - SHARED
8
+ - NO_EXTRAS
9
+ - EXCLUDE_FROM_ALL
10
+ - SYSTEM
11
+
12
+ format:
13
+ line_width: 99
14
+ tab_size: 2
15
+
16
+ # If an argument group contains more than this many sub-groups
17
+ # (parg or kwarg groups) then force it to a vertical layout.
18
+ max_subgroups_hwrap: 2
19
+
20
+ # If a positional argument group contains more than this many
21
+ # arguments, then force it to a vertical layout.
22
+ max_pargs_hwrap: 6
23
+
24
+ # If a cmdline positional group consumes more than this many
25
+ # lines without nesting, then invalidate the layout (and nest)
26
+ max_rows_cmdline: 2
27
+ separate_ctrl_name_with_space: false
28
+ separate_fn_name_with_space: false
29
+ dangle_parens: false
30
+
31
+ # If the trailing parenthesis must be 'dangled' on its on
32
+ # 'line, then align it to this reference: `prefix`: the start'
33
+ # 'of the statement, `prefix-indent`: the start of the'
34
+ # 'statement, plus one indentation level, `child`: align to'
35
+ # the column of the arguments
36
+ dangle_align: prefix
37
+ # If the statement spelling length (including space and
38
+ # parenthesis) is smaller than this amount, then force reject
39
+ # nested layouts.
40
+ min_prefix_chars: 4
41
+
42
+ # If the statement spelling length (including space and
43
+ # parenthesis) is larger than the tab width by more than this
44
+ # amount, then force reject un-nested layouts.
45
+ max_prefix_chars: 10
46
+
47
+ # If a candidate layout is wrapped horizontally but it exceeds
48
+ # this many lines, then reject the layout.
49
+ max_lines_hwrap: 2
50
+
51
+ line_ending: unix
52
+
53
+ # Format command names consistently as 'lower' or 'upper' case
54
+ command_case: canonical
55
+
56
+ # Format keywords consistently as 'lower' or 'upper' case
57
+ # unchanged is valid too
58
+ keyword_case: 'upper'
59
+
60
+ # A list of command names which should always be wrapped
61
+ always_wrap: []
62
+
63
+ # If true, the argument lists which are known to be sortable
64
+ # will be sorted lexicographically
65
+ enable_sort: true
66
+
67
+ # If true, the parsers may infer whether or not an argument
68
+ # list is sortable (without annotation).
69
+ autosort: false
70
+
71
+ # Causes a few issues - can be solved later, possibly.
72
+ markup:
73
+ enable_markup: false
third_party/CityFlow/extern/pybind11/.codespell-ignore-lines CHANGED
@@ -1,24 +1,24 @@
1
- template <op_id id, op_type ot, typename L = undefined_t, typename R = undefined_t>
2
- template <typename ThisT>
3
- auto &this_ = static_cast<ThisT &>(*this);
4
- if (load_impl<ThisT>(temp, false)) {
5
- ssize_t nd = 0;
6
- auto trivial = broadcast(buffers, nd, shape);
7
- auto ndim = (size_t) nd;
8
- int nd;
9
- ssize_t ndim() const { return detail::array_proxy(m_ptr)->nd; }
10
- using op = op_impl<id, ot, Base, L_type, R_type>;
11
- template <op_id id, op_type ot, typename L, typename R>
12
- template <detail::op_id id, detail::op_type ot, typename L, typename R, typename... Extra>
13
- class_ &def(const detail::op_<id, ot, L, R> &op, const Extra &...extra) {
14
- class_ &def_cast(const detail::op_<id, ot, L, R> &op, const Extra &...extra) {
15
- @pytest.mark.parametrize("access", ["ro", "rw", "static_ro", "static_rw"])
16
- struct IntStruct {
17
- explicit IntStruct(int v) : value(v){};
18
- ~IntStruct() { value = -value; }
19
- IntStruct(const IntStruct &) = default;
20
- IntStruct &operator=(const IntStruct &) = default;
21
- py::class_<IntStruct>(m, "IntStruct").def(py::init([](const int i) { return IntStruct(i); }));
22
- py::implicitly_convertible<int, IntStruct>();
23
- m.def("test", [](int expected, const IntStruct &in) {
24
- [](int expected, const IntStruct &in) {
 
1
+ template <op_id id, op_type ot, typename L = undefined_t, typename R = undefined_t>
2
+ template <typename ThisT>
3
+ auto &this_ = static_cast<ThisT &>(*this);
4
+ if (load_impl<ThisT>(temp, false)) {
5
+ ssize_t nd = 0;
6
+ auto trivial = broadcast(buffers, nd, shape);
7
+ auto ndim = (size_t) nd;
8
+ int nd;
9
+ ssize_t ndim() const { return detail::array_proxy(m_ptr)->nd; }
10
+ using op = op_impl<id, ot, Base, L_type, R_type>;
11
+ template <op_id id, op_type ot, typename L, typename R>
12
+ template <detail::op_id id, detail::op_type ot, typename L, typename R, typename... Extra>
13
+ class_ &def(const detail::op_<id, ot, L, R> &op, const Extra &...extra) {
14
+ class_ &def_cast(const detail::op_<id, ot, L, R> &op, const Extra &...extra) {
15
+ @pytest.mark.parametrize("access", ["ro", "rw", "static_ro", "static_rw"])
16
+ struct IntStruct {
17
+ explicit IntStruct(int v) : value(v){};
18
+ ~IntStruct() { value = -value; }
19
+ IntStruct(const IntStruct &) = default;
20
+ IntStruct &operator=(const IntStruct &) = default;
21
+ py::class_<IntStruct>(m, "IntStruct").def(py::init([](const int i) { return IntStruct(i); }));
22
+ py::implicitly_convertible<int, IntStruct>();
23
+ m.def("test", [](int expected, const IntStruct &in) {
24
+ [](int expected, const IntStruct &in) {
third_party/CityFlow/extern/pybind11/.git.bak/FETCH_HEAD CHANGED
@@ -1,32 +1,32 @@
1
- 68a11bb65b774df161c898204d08e85ac2cbac5f not-for-merge branch 'archive/smart_holder' of https://github.com/pybind/pybind11
2
- 619fb2305697c1eb4a6e248af03eab2c8c57237d not-for-merge branch 'array-sequence-fix' of https://github.com/pybind/pybind11
3
- 1423623205a5d656ec2f068b948dcf5f02146f2f not-for-merge branch 'cpp17-aligned-new' of https://github.com/pybind/pybind11
4
- fd3a93c520a661b78e177280128a9c855d7f5be5 not-for-merge branch 'fold-expression-caster' of https://github.com/pybind/pybind11
5
- 9fa6acdf5bf53b6f26d6bf2f1bdab65da782ec08 not-for-merge branch 'henryiii-patch-1' of https://github.com/pybind/pybind11
6
- d8c30a8f2df87007ca2a5679119af50aff5c0695 not-for-merge branch 'henryiii-patch-2' of https://github.com/pybind/pybind11
7
- d7cc5b052d737de8478b536fee4a2075cedec866 not-for-merge branch 'henryiii-patch-3' of https://github.com/pybind/pybind11
8
- 19ddbe5bc3eb3064201a914626ac642e1884e654 not-for-merge branch 'henryiii/revert/pycapsule' of https://github.com/pybind/pybind11
9
- 78e074b8bbda1073e60273620e084aac28b0740c not-for-merge branch 'internals_ptr' of https://github.com/pybind/pybind11
10
- 8986743b6daebfcb07428e921192ff77308db055 not-for-merge branch 'issue1561_fix' of https://github.com/pybind/pybind11
11
- cd538ed1184d41cf685dd4da81c1eca80d24f353 not-for-merge branch 'master' of https://github.com/pybind/pybind11
12
- 45c45eefe9bb7ba37a7e71dcabff5e7b5ff4596c not-for-merge branch 'pre-commit-ci-update-config' of https://github.com/pybind/pybind11
13
- dba00d7369677617d00974f5a00ebcd5e6288cdc not-for-merge branch 'revert-4220-fix-nvcc-11.4-11.8' of https://github.com/pybind/pybind11
14
- 04cfb45b7998fe960a70743770b94bdb3a712f73 not-for-merge branch 'stable' of https://github.com/pybind/pybind11
15
- e076c4513dc2c89c1e9b7cb716fb8e4588e8e067 not-for-merge branch 'undefined-macos' of https://github.com/pybind/pybind11
16
- 121360c6ae0fff0c97c64470508c11a0cc27bf94 not-for-merge branch 'v1.8' of https://github.com/pybind/pybind11
17
- 07de0d8627101be53986e841cd4e21ee38c2498a not-for-merge branch 'v2.0' of https://github.com/pybind/pybind11
18
- 1df91d36cfa997c8987889234304ea5e37cc3e68 not-for-merge branch 'v2.1' of https://github.com/pybind/pybind11
19
- 5b0a6fc2017fcc176545afe3e09c9f9885283242 not-for-merge branch 'v2.10' of https://github.com/pybind/pybind11
20
- 95d943ae0ebdf609bbd650d119fda539509929b6 not-for-merge branch 'v2.11' of https://github.com/pybind/pybind11
21
- 2e0815278cb899b20870a67ca8205996ef47e70f not-for-merge branch 'v2.12' of https://github.com/pybind/pybind11
22
- a2e59f0e7065404b44dfe92a28aca47ba1378dc4 not-for-merge branch 'v2.13' of https://github.com/pybind/pybind11
23
- a23996fce38ff6ccfbcdc09f1e63f2c4be5ea2ef not-for-merge branch 'v2.2' of https://github.com/pybind/pybind11
24
- a1b71df137e015d44f7e31f7b6d4807253fb7871 not-for-merge branch 'v2.3' of https://github.com/pybind/pybind11
25
- 80d452484c5409444b0ec19383faa84bb7a4d351 not-for-merge branch 'v2.4' of https://github.com/pybind/pybind11
26
- 3b1dbebabc801c9cf6f0953a4c20b904d444f879 not-for-merge branch 'v2.5' of https://github.com/pybind/pybind11
27
- 8de7772cc72daca8e947b79b83fea46214931604 not-for-merge branch 'v2.6' of https://github.com/pybind/pybind11
28
- 5b4432439ed72417253f9eec99f2a014636c0362 not-for-merge branch 'v2.7' of https://github.com/pybind/pybind11
29
- f7b499615e14d70ab098a20deb0cdb3889998a1a not-for-merge branch 'v2.8' of https://github.com/pybind/pybind11
30
- 914c06fb252b6cc3727d0eedab6736e88a3fcb01 not-for-merge branch 'v2.9' of https://github.com/pybind/pybind11
31
- 45fab4087eaaff234227a10cf7845e8b07f28a98 not-for-merge branch 'v3.0' of https://github.com/pybind/pybind11
32
- 0991e90375606254087f7bffe0dd15dd910ec62b not-for-merge branch 'void-caster-fix' of https://github.com/pybind/pybind11
 
1
+ 68a11bb65b774df161c898204d08e85ac2cbac5f not-for-merge branch 'archive/smart_holder' of https://github.com/pybind/pybind11
2
+ 619fb2305697c1eb4a6e248af03eab2c8c57237d not-for-merge branch 'array-sequence-fix' of https://github.com/pybind/pybind11
3
+ 1423623205a5d656ec2f068b948dcf5f02146f2f not-for-merge branch 'cpp17-aligned-new' of https://github.com/pybind/pybind11
4
+ fd3a93c520a661b78e177280128a9c855d7f5be5 not-for-merge branch 'fold-expression-caster' of https://github.com/pybind/pybind11
5
+ 9fa6acdf5bf53b6f26d6bf2f1bdab65da782ec08 not-for-merge branch 'henryiii-patch-1' of https://github.com/pybind/pybind11
6
+ d8c30a8f2df87007ca2a5679119af50aff5c0695 not-for-merge branch 'henryiii-patch-2' of https://github.com/pybind/pybind11
7
+ d7cc5b052d737de8478b536fee4a2075cedec866 not-for-merge branch 'henryiii-patch-3' of https://github.com/pybind/pybind11
8
+ 19ddbe5bc3eb3064201a914626ac642e1884e654 not-for-merge branch 'henryiii/revert/pycapsule' of https://github.com/pybind/pybind11
9
+ 78e074b8bbda1073e60273620e084aac28b0740c not-for-merge branch 'internals_ptr' of https://github.com/pybind/pybind11
10
+ 8986743b6daebfcb07428e921192ff77308db055 not-for-merge branch 'issue1561_fix' of https://github.com/pybind/pybind11
11
+ cd538ed1184d41cf685dd4da81c1eca80d24f353 not-for-merge branch 'master' of https://github.com/pybind/pybind11
12
+ 45c45eefe9bb7ba37a7e71dcabff5e7b5ff4596c not-for-merge branch 'pre-commit-ci-update-config' of https://github.com/pybind/pybind11
13
+ dba00d7369677617d00974f5a00ebcd5e6288cdc not-for-merge branch 'revert-4220-fix-nvcc-11.4-11.8' of https://github.com/pybind/pybind11
14
+ 04cfb45b7998fe960a70743770b94bdb3a712f73 not-for-merge branch 'stable' of https://github.com/pybind/pybind11
15
+ e076c4513dc2c89c1e9b7cb716fb8e4588e8e067 not-for-merge branch 'undefined-macos' of https://github.com/pybind/pybind11
16
+ 121360c6ae0fff0c97c64470508c11a0cc27bf94 not-for-merge branch 'v1.8' of https://github.com/pybind/pybind11
17
+ 07de0d8627101be53986e841cd4e21ee38c2498a not-for-merge branch 'v2.0' of https://github.com/pybind/pybind11
18
+ 1df91d36cfa997c8987889234304ea5e37cc3e68 not-for-merge branch 'v2.1' of https://github.com/pybind/pybind11
19
+ 5b0a6fc2017fcc176545afe3e09c9f9885283242 not-for-merge branch 'v2.10' of https://github.com/pybind/pybind11
20
+ 95d943ae0ebdf609bbd650d119fda539509929b6 not-for-merge branch 'v2.11' of https://github.com/pybind/pybind11
21
+ 2e0815278cb899b20870a67ca8205996ef47e70f not-for-merge branch 'v2.12' of https://github.com/pybind/pybind11
22
+ a2e59f0e7065404b44dfe92a28aca47ba1378dc4 not-for-merge branch 'v2.13' of https://github.com/pybind/pybind11
23
+ a23996fce38ff6ccfbcdc09f1e63f2c4be5ea2ef not-for-merge branch 'v2.2' of https://github.com/pybind/pybind11
24
+ a1b71df137e015d44f7e31f7b6d4807253fb7871 not-for-merge branch 'v2.3' of https://github.com/pybind/pybind11
25
+ 80d452484c5409444b0ec19383faa84bb7a4d351 not-for-merge branch 'v2.4' of https://github.com/pybind/pybind11
26
+ 3b1dbebabc801c9cf6f0953a4c20b904d444f879 not-for-merge branch 'v2.5' of https://github.com/pybind/pybind11
27
+ 8de7772cc72daca8e947b79b83fea46214931604 not-for-merge branch 'v2.6' of https://github.com/pybind/pybind11
28
+ 5b4432439ed72417253f9eec99f2a014636c0362 not-for-merge branch 'v2.7' of https://github.com/pybind/pybind11
29
+ f7b499615e14d70ab098a20deb0cdb3889998a1a not-for-merge branch 'v2.8' of https://github.com/pybind/pybind11
30
+ 914c06fb252b6cc3727d0eedab6736e88a3fcb01 not-for-merge branch 'v2.9' of https://github.com/pybind/pybind11
31
+ 45fab4087eaaff234227a10cf7845e8b07f28a98 not-for-merge branch 'v3.0' of https://github.com/pybind/pybind11
32
+ 0991e90375606254087f7bffe0dd15dd910ec62b not-for-merge branch 'void-caster-fix' of https://github.com/pybind/pybind11
third_party/CityFlow/extern/pybind11/.git.bak/HEAD CHANGED
@@ -1 +1 @@
1
- 3e9dfa2866941655c56877882565e7577de6fc7b
 
1
+ 3e9dfa2866941655c56877882565e7577de6fc7b
third_party/CityFlow/extern/pybind11/.git.bak/config CHANGED
@@ -1,13 +1,13 @@
1
- [core]
2
- repositoryformatversion = 0
3
- filemode = true
4
- bare = false
5
- logallrefupdates = true
6
- ignorecase = true
7
- precomposeunicode = true
8
- [remote "origin"]
9
- url = https://github.com/pybind/pybind11.git
10
- fetch = +refs/heads/*:refs/remotes/origin/*
11
- [branch "master"]
12
- remote = origin
13
- merge = refs/heads/master
 
1
+ [core]
2
+ repositoryformatversion = 0
3
+ filemode = true
4
+ bare = false
5
+ logallrefupdates = true
6
+ ignorecase = true
7
+ precomposeunicode = true
8
+ [remote "origin"]
9
+ url = https://github.com/pybind/pybind11.git
10
+ fetch = +refs/heads/*:refs/remotes/origin/*
11
+ [branch "master"]
12
+ remote = origin
13
+ merge = refs/heads/master
third_party/CityFlow/extern/pybind11/.git.bak/description CHANGED
@@ -1 +1 @@
1
- Unnamed repository; edit this file 'description' to name the repository.
 
1
+ Unnamed repository; edit this file 'description' to name the repository.
third_party/CityFlow/extern/pybind11/.git.bak/packed-refs CHANGED
@@ -1,143 +1,143 @@
1
- # pack-refs with: peeled fully-peeled sorted
2
- 68a11bb65b774df161c898204d08e85ac2cbac5f refs/remotes/origin/archive/smart_holder
3
- 619fb2305697c1eb4a6e248af03eab2c8c57237d refs/remotes/origin/array-sequence-fix
4
- 1423623205a5d656ec2f068b948dcf5f02146f2f refs/remotes/origin/cpp17-aligned-new
5
- fd3a93c520a661b78e177280128a9c855d7f5be5 refs/remotes/origin/fold-expression-caster
6
- 9fa6acdf5bf53b6f26d6bf2f1bdab65da782ec08 refs/remotes/origin/henryiii-patch-1
7
- d8c30a8f2df87007ca2a5679119af50aff5c0695 refs/remotes/origin/henryiii-patch-2
8
- d7cc5b052d737de8478b536fee4a2075cedec866 refs/remotes/origin/henryiii-patch-3
9
- 19ddbe5bc3eb3064201a914626ac642e1884e654 refs/remotes/origin/henryiii/revert/pycapsule
10
- 78e074b8bbda1073e60273620e084aac28b0740c refs/remotes/origin/internals_ptr
11
- 8986743b6daebfcb07428e921192ff77308db055 refs/remotes/origin/issue1561_fix
12
- cd538ed1184d41cf685dd4da81c1eca80d24f353 refs/remotes/origin/master
13
- 45c45eefe9bb7ba37a7e71dcabff5e7b5ff4596c refs/remotes/origin/pre-commit-ci-update-config
14
- dba00d7369677617d00974f5a00ebcd5e6288cdc refs/remotes/origin/revert-4220-fix-nvcc-11.4-11.8
15
- 04cfb45b7998fe960a70743770b94bdb3a712f73 refs/remotes/origin/stable
16
- e076c4513dc2c89c1e9b7cb716fb8e4588e8e067 refs/remotes/origin/undefined-macos
17
- 121360c6ae0fff0c97c64470508c11a0cc27bf94 refs/remotes/origin/v1.8
18
- 07de0d8627101be53986e841cd4e21ee38c2498a refs/remotes/origin/v2.0
19
- 1df91d36cfa997c8987889234304ea5e37cc3e68 refs/remotes/origin/v2.1
20
- 5b0a6fc2017fcc176545afe3e09c9f9885283242 refs/remotes/origin/v2.10
21
- 95d943ae0ebdf609bbd650d119fda539509929b6 refs/remotes/origin/v2.11
22
- 2e0815278cb899b20870a67ca8205996ef47e70f refs/remotes/origin/v2.12
23
- a2e59f0e7065404b44dfe92a28aca47ba1378dc4 refs/remotes/origin/v2.13
24
- a23996fce38ff6ccfbcdc09f1e63f2c4be5ea2ef refs/remotes/origin/v2.2
25
- a1b71df137e015d44f7e31f7b6d4807253fb7871 refs/remotes/origin/v2.3
26
- 80d452484c5409444b0ec19383faa84bb7a4d351 refs/remotes/origin/v2.4
27
- 3b1dbebabc801c9cf6f0953a4c20b904d444f879 refs/remotes/origin/v2.5
28
- 8de7772cc72daca8e947b79b83fea46214931604 refs/remotes/origin/v2.6
29
- 5b4432439ed72417253f9eec99f2a014636c0362 refs/remotes/origin/v2.7
30
- f7b499615e14d70ab098a20deb0cdb3889998a1a refs/remotes/origin/v2.8
31
- 914c06fb252b6cc3727d0eedab6736e88a3fcb01 refs/remotes/origin/v2.9
32
- 45fab4087eaaff234227a10cf7845e8b07f28a98 refs/remotes/origin/v3.0
33
- 0991e90375606254087f7bffe0dd15dd910ec62b refs/remotes/origin/void-caster-fix
34
- 8ae716ab79e0141537eff420cb7e79b06d14c402 refs/tags/v1.0
35
- ^929fd7e6946255ed84c803d2993f48912de96e15
36
- 1a25b3f8f7455246adf2930e4c857c128c71a240 refs/tags/v1.1
37
- ^bda3b67dc5f9481857aa7a14478bab3293bb376f
38
- ef4345f46c672a74e161f5a8955784658fb10ae8 refs/tags/v1.2
39
- ^8ed2808239f3a6052e7789feeeab34eed39b5c62
40
- 1c32fcbfba8849abedf2a50e675e5f847c20a42d refs/tags/v1.3
41
- ^d2385e8fc6a3008cab96532c99db4c3d57541fc5
42
- 0b8a0c621a2872312b477bed4f8b72a1a3a34d61 refs/tags/v1.4
43
- ^0e6ca5916e2585ca9b778f8304c166b6a36b7e5a
44
- dce23aeae9dcae322670073e6b5a7a22fb740c14 refs/tags/v1.5
45
- ^bb79d7bdc0f48f1a9284af85bf36d392afc28307
46
- 549781cb1c71a91b8bab23e452c5bfed413dee40 refs/tags/v1.6
47
- ^e85e9d82824e88352c9389694ff2130e4a6c5d02
48
- f21d226f83c5c3db2f3f5c554c35fb8942fd6dcb refs/tags/v1.7
49
- ^e70b2abb6dee27a2889b01f245a2a28e6fcd4b01
50
- 8e8bd7090ba1197117560c7e7f46cd2e9d026424 refs/tags/v1.8
51
- ^c0759976177b92f386856a5d9f2e8d63ef89293a
52
- 4da184714d7a3ee298edcabb51497c629108205b refs/tags/v1.8.1
53
- ^121360c6ae0fff0c97c64470508c11a0cc27bf94
54
- 40585804f4e9dbf45b277dd55c19a8026b356eef refs/tags/v2.0.0
55
- ^e33ef9c20d36fe760792c61ccc95ecf1b42cf81d
56
- 12006926087bdd34dcbd4db40611be7d5b6ed830 refs/tags/v2.0.0-rc1
57
- ^3c7967111280b0a796986ac2025d0ca201623656
58
- f74dd5d5a4033e68d9000d3c288d0b57a3fc0105 refs/tags/v2.0.1
59
- ^07de0d8627101be53986e841cd4e21ee38c2498a
60
- a2207c044fdffac6023975df015e73f161082b57 refs/tags/v2.1.0
61
- ^ad9d574c85f1836c57f2f0727ffe997bb8cbfdd7
62
- cbf3c94e781074f2f094e9a39d7ea86304d69a1d refs/tags/v2.1.1
63
- ^1df91d36cfa997c8987889234304ea5e37cc3e68
64
- 8d298f32f3bf5c1854adeadf7f1ec1c236dd5221 refs/tags/v2.10.0
65
- ^aa304c9c7d725ffb9d10af08a3b34cb372307020
66
- bcee506ac0b09ea13000484c08ab3e5a41ee0fb2 refs/tags/v2.10.1
67
- ^80dc998efced8ceb2be59756668a7e90e8bef917
68
- 76b3533f96774e555a6e10d6deb9bbafe4970011 refs/tags/v2.10.2
69
- ^0694ec6a15863bff2e0ea5efe07c78de39b9a33c
70
- 70a09bf92bff267b3eceee51bee00741bc91367f refs/tags/v2.10.3
71
- ^0bd8896a4010f2d91b2340570c24fa08606ec406
72
- 95ddd6b61bbecd06d00eef8a0e72fa9ffd46631e refs/tags/v2.10.4
73
- ^5b0a6fc2017fcc176545afe3e09c9f9885283242
74
- 8d8aecf4a5579c0e51d07fb93411aa120ae0360c refs/tags/v2.11.0
75
- ^1a917f1852eb7819b671fc3fa862840f4c491a07
76
- 0630807c3070287c716f6be3eacb00b8816b4215 refs/tags/v2.11.1
77
- ^8a099e44b3d5f85b20f05828d919d2332a8de841
78
- 95d943ae0ebdf609bbd650d119fda539509929b6 refs/tags/v2.11.2
79
- 3e9dfa2866941655c56877882565e7577de6fc7b refs/tags/v2.12.0
80
- 2e0815278cb899b20870a67ca8205996ef47e70f refs/tags/v2.12.1
81
- 0c69e1eb2177fa8f8580632c7b1f97fdb606ce8f refs/tags/v2.13.0
82
- 941f45bcb51457884fa1afd6e24a67377d70f75c refs/tags/v2.13.1
83
- 07f30430d4186c2712761f1ffaea50ede63f2b2b refs/tags/v2.13.2
84
- bd67643652d3800837f1f41549a2a5adbaa3fafe refs/tags/v2.13.3
85
- c6239a8a1b6871cc0fb5f7af885a02ffd1349f9d refs/tags/v2.13.4
86
- 7c33cdc2d39c7b99a122579f53bc94c8eb3332ff refs/tags/v2.13.5
87
- a2e59f0e7065404b44dfe92a28aca47ba1378dc4 refs/tags/v2.13.6
88
- c36cf6254170aa8aef35b65854f518016551d5b8 refs/tags/v2.2.0
89
- ^2a5a5ec0a47c245fbf1bb1a8a90b4c3278e01693
90
- 9a9239eaa52e0e2a16c76894a7f30f19997f0167 refs/tags/v2.2.1
91
- ^86e2ad4f77442c3350f9a2476650da6bee253c52
92
- 8bd683141ccf900aafc3dc76e5efd86f1e8ac541 refs/tags/v2.2.2
93
- ^f117a48ea2fd446d2865826a58d08027d4579cb3
94
- 197ae8a04cec7bf9327d36c780d4fca2a6b51339 refs/tags/v2.2.3
95
- ^8edc147d67ca85a93ed1f53628004528dc36a04d
96
- e4637eb508aa3e41233875f6ce3891d96fbc5d33 refs/tags/v2.2.4
97
- ^9a19306fbf30642ca331d0ec88e7da54a96860f9
98
- 7107ada7cbbd01e76a2a9f3e2ec27b683dcec99b refs/tags/v2.3.0
99
- ^e43e1cc01ae6d4e4e5ba10557a057d7f3d5ece0d
100
- ca8264815ffcf8beda3b206405a92927c722027f refs/tags/v2.4.0
101
- ^00a0aa992953d6482114a0f539a21bb535a16383
102
- 8b7a01d0b8dddf9ff650a6511377cd32a4f1501a refs/tags/v2.4.1
103
- ^e44fcc3c15b41f0720c72832c0b9cd07de819781
104
- 6c383e01bbd4155a29ad280ad7ba7941e05675dd refs/tags/v2.4.2
105
- ^7ec2ddfc95f65d1e986d359466a6c254aa514ef3
106
- aa56a0e4a40af9ff27dd5b4d283d29bc64c19088 refs/tags/v2.4.3
107
- ^80d452484c5409444b0ec19383faa84bb7a4d351
108
- 014cd12ec1a3258f3bfc6597f371ed46c8e89ccd refs/tags/v2.5.0
109
- ^3b1dbebabc801c9cf6f0953a4c20b904d444f879
110
- 78b2d1991b9e81bbc1a6670ab4af189094e952eb refs/tags/v2.6.0
111
- ^59a2ac2745d8a57ac94c6accced73620d59fb844
112
- 319b99648b94c37e16cec64e0aec6d80557de64f refs/tags/v2.6.0b1
113
- d46f3322a45cb907777f568bb1377ab1b9457ad8 refs/tags/v2.6.0rc1
114
- c4a8b5bb9140cdc8c214044d41e2593986f875d0 refs/tags/v2.6.0rc2
115
- c16da993094988141101ac4d96a9b2c92f9ac714 refs/tags/v2.6.0rc3
116
- f4bc37b3de4857b9d80c1d85ff9f9e5dceef3dd4 refs/tags/v2.6.1
117
- ^f1abf5d9159b805674197f6bc443592e631c9130
118
- c7faa0f557df4ee266e6e6dca311cd1474ad2123 refs/tags/v2.6.2
119
- ^8de7772cc72daca8e947b79b83fea46214931604
120
- 40d14c37b4cb8488a241f837ea2e3eb60404f7b7 refs/tags/v2.7.0
121
- ^65e95ea8675ea34bdd566d6461330f25c651e5a8
122
- c0e8a831c6023be719144e7d10c8ea7c9fb81a58 refs/tags/v2.7.1
123
- ^787d2c88cafa4d07fb38c9519c485a86323cfcf4
124
- dc756043d5ed7654e48c41d97a64403a847214a7 refs/tags/v2.8.0
125
- ^97976c16fb7652f7faf02d76756666ef87adbe7d
126
- 79dfe03e432e2af41bba00add596e6df92099b49 refs/tags/v2.8.1
127
- ^f7b499615e14d70ab098a20deb0cdb3889998a1a
128
- 1dad2a58efb1eef1eb9f2e5532dedd3711924810 refs/tags/v2.9.0
129
- ^45f792efdd92da094548e2095d6efdbfa7e536ee
130
- 35b51445ba2bf5e67137c04bc26ceaab33e4285f refs/tags/v2.9.1
131
- ^ffa346860b306c9bbfb341aed9c14c067751feb8
132
- dd9ef9f901f3d49426f87a67666393970a6c9431 refs/tags/v2.9.2
133
- ^914c06fb252b6cc3727d0eedab6736e88a3fcb01
134
- f0ecf21301c0c24bc78b8b310347c7507d9f41d0 refs/tags/v3.0.0
135
- ^ed5057ded698e305210269dafa57574ecf964483
136
- fc888f758fde1c37d80f85666060d3f179f6c001 refs/tags/v3.0.0rc1
137
- df595b16579d847cd019072aa0daec1e566c7ba2 refs/tags/v3.0.0rc2
138
- 5d32ed76c0ea53d689f9cec3d4c152d1b0738e8e refs/tags/v3.0.0rc3
139
- ea3e33e40dd1cbfa9f885e991386337a0e5b4b66 refs/tags/v3.0.0rc4
140
- e86205cb2ba070755d582856430c0f83c0af6694 refs/tags/v3.0.1
141
- ^f5fbe867d2d26e4a0a9177a51f6e568868ad3dc8
142
- e6c503bb0b0c13f76ca0546eca7f8d986039517f refs/tags/v3.0.2
143
- ^45fab4087eaaff234227a10cf7845e8b07f28a98
 
1
+ # pack-refs with: peeled fully-peeled sorted
2
+ 68a11bb65b774df161c898204d08e85ac2cbac5f refs/remotes/origin/archive/smart_holder
3
+ 619fb2305697c1eb4a6e248af03eab2c8c57237d refs/remotes/origin/array-sequence-fix
4
+ 1423623205a5d656ec2f068b948dcf5f02146f2f refs/remotes/origin/cpp17-aligned-new
5
+ fd3a93c520a661b78e177280128a9c855d7f5be5 refs/remotes/origin/fold-expression-caster
6
+ 9fa6acdf5bf53b6f26d6bf2f1bdab65da782ec08 refs/remotes/origin/henryiii-patch-1
7
+ d8c30a8f2df87007ca2a5679119af50aff5c0695 refs/remotes/origin/henryiii-patch-2
8
+ d7cc5b052d737de8478b536fee4a2075cedec866 refs/remotes/origin/henryiii-patch-3
9
+ 19ddbe5bc3eb3064201a914626ac642e1884e654 refs/remotes/origin/henryiii/revert/pycapsule
10
+ 78e074b8bbda1073e60273620e084aac28b0740c refs/remotes/origin/internals_ptr
11
+ 8986743b6daebfcb07428e921192ff77308db055 refs/remotes/origin/issue1561_fix
12
+ cd538ed1184d41cf685dd4da81c1eca80d24f353 refs/remotes/origin/master
13
+ 45c45eefe9bb7ba37a7e71dcabff5e7b5ff4596c refs/remotes/origin/pre-commit-ci-update-config
14
+ dba00d7369677617d00974f5a00ebcd5e6288cdc refs/remotes/origin/revert-4220-fix-nvcc-11.4-11.8
15
+ 04cfb45b7998fe960a70743770b94bdb3a712f73 refs/remotes/origin/stable
16
+ e076c4513dc2c89c1e9b7cb716fb8e4588e8e067 refs/remotes/origin/undefined-macos
17
+ 121360c6ae0fff0c97c64470508c11a0cc27bf94 refs/remotes/origin/v1.8
18
+ 07de0d8627101be53986e841cd4e21ee38c2498a refs/remotes/origin/v2.0
19
+ 1df91d36cfa997c8987889234304ea5e37cc3e68 refs/remotes/origin/v2.1
20
+ 5b0a6fc2017fcc176545afe3e09c9f9885283242 refs/remotes/origin/v2.10
21
+ 95d943ae0ebdf609bbd650d119fda539509929b6 refs/remotes/origin/v2.11
22
+ 2e0815278cb899b20870a67ca8205996ef47e70f refs/remotes/origin/v2.12
23
+ a2e59f0e7065404b44dfe92a28aca47ba1378dc4 refs/remotes/origin/v2.13
24
+ a23996fce38ff6ccfbcdc09f1e63f2c4be5ea2ef refs/remotes/origin/v2.2
25
+ a1b71df137e015d44f7e31f7b6d4807253fb7871 refs/remotes/origin/v2.3
26
+ 80d452484c5409444b0ec19383faa84bb7a4d351 refs/remotes/origin/v2.4
27
+ 3b1dbebabc801c9cf6f0953a4c20b904d444f879 refs/remotes/origin/v2.5
28
+ 8de7772cc72daca8e947b79b83fea46214931604 refs/remotes/origin/v2.6
29
+ 5b4432439ed72417253f9eec99f2a014636c0362 refs/remotes/origin/v2.7
30
+ f7b499615e14d70ab098a20deb0cdb3889998a1a refs/remotes/origin/v2.8
31
+ 914c06fb252b6cc3727d0eedab6736e88a3fcb01 refs/remotes/origin/v2.9
32
+ 45fab4087eaaff234227a10cf7845e8b07f28a98 refs/remotes/origin/v3.0
33
+ 0991e90375606254087f7bffe0dd15dd910ec62b refs/remotes/origin/void-caster-fix
34
+ 8ae716ab79e0141537eff420cb7e79b06d14c402 refs/tags/v1.0
35
+ ^929fd7e6946255ed84c803d2993f48912de96e15
36
+ 1a25b3f8f7455246adf2930e4c857c128c71a240 refs/tags/v1.1
37
+ ^bda3b67dc5f9481857aa7a14478bab3293bb376f
38
+ ef4345f46c672a74e161f5a8955784658fb10ae8 refs/tags/v1.2
39
+ ^8ed2808239f3a6052e7789feeeab34eed39b5c62
40
+ 1c32fcbfba8849abedf2a50e675e5f847c20a42d refs/tags/v1.3
41
+ ^d2385e8fc6a3008cab96532c99db4c3d57541fc5
42
+ 0b8a0c621a2872312b477bed4f8b72a1a3a34d61 refs/tags/v1.4
43
+ ^0e6ca5916e2585ca9b778f8304c166b6a36b7e5a
44
+ dce23aeae9dcae322670073e6b5a7a22fb740c14 refs/tags/v1.5
45
+ ^bb79d7bdc0f48f1a9284af85bf36d392afc28307
46
+ 549781cb1c71a91b8bab23e452c5bfed413dee40 refs/tags/v1.6
47
+ ^e85e9d82824e88352c9389694ff2130e4a6c5d02
48
+ f21d226f83c5c3db2f3f5c554c35fb8942fd6dcb refs/tags/v1.7
49
+ ^e70b2abb6dee27a2889b01f245a2a28e6fcd4b01
50
+ 8e8bd7090ba1197117560c7e7f46cd2e9d026424 refs/tags/v1.8
51
+ ^c0759976177b92f386856a5d9f2e8d63ef89293a
52
+ 4da184714d7a3ee298edcabb51497c629108205b refs/tags/v1.8.1
53
+ ^121360c6ae0fff0c97c64470508c11a0cc27bf94
54
+ 40585804f4e9dbf45b277dd55c19a8026b356eef refs/tags/v2.0.0
55
+ ^e33ef9c20d36fe760792c61ccc95ecf1b42cf81d
56
+ 12006926087bdd34dcbd4db40611be7d5b6ed830 refs/tags/v2.0.0-rc1
57
+ ^3c7967111280b0a796986ac2025d0ca201623656
58
+ f74dd5d5a4033e68d9000d3c288d0b57a3fc0105 refs/tags/v2.0.1
59
+ ^07de0d8627101be53986e841cd4e21ee38c2498a
60
+ a2207c044fdffac6023975df015e73f161082b57 refs/tags/v2.1.0
61
+ ^ad9d574c85f1836c57f2f0727ffe997bb8cbfdd7
62
+ cbf3c94e781074f2f094e9a39d7ea86304d69a1d refs/tags/v2.1.1
63
+ ^1df91d36cfa997c8987889234304ea5e37cc3e68
64
+ 8d298f32f3bf5c1854adeadf7f1ec1c236dd5221 refs/tags/v2.10.0
65
+ ^aa304c9c7d725ffb9d10af08a3b34cb372307020
66
+ bcee506ac0b09ea13000484c08ab3e5a41ee0fb2 refs/tags/v2.10.1
67
+ ^80dc998efced8ceb2be59756668a7e90e8bef917
68
+ 76b3533f96774e555a6e10d6deb9bbafe4970011 refs/tags/v2.10.2
69
+ ^0694ec6a15863bff2e0ea5efe07c78de39b9a33c
70
+ 70a09bf92bff267b3eceee51bee00741bc91367f refs/tags/v2.10.3
71
+ ^0bd8896a4010f2d91b2340570c24fa08606ec406
72
+ 95ddd6b61bbecd06d00eef8a0e72fa9ffd46631e refs/tags/v2.10.4
73
+ ^5b0a6fc2017fcc176545afe3e09c9f9885283242
74
+ 8d8aecf4a5579c0e51d07fb93411aa120ae0360c refs/tags/v2.11.0
75
+ ^1a917f1852eb7819b671fc3fa862840f4c491a07
76
+ 0630807c3070287c716f6be3eacb00b8816b4215 refs/tags/v2.11.1
77
+ ^8a099e44b3d5f85b20f05828d919d2332a8de841
78
+ 95d943ae0ebdf609bbd650d119fda539509929b6 refs/tags/v2.11.2
79
+ 3e9dfa2866941655c56877882565e7577de6fc7b refs/tags/v2.12.0
80
+ 2e0815278cb899b20870a67ca8205996ef47e70f refs/tags/v2.12.1
81
+ 0c69e1eb2177fa8f8580632c7b1f97fdb606ce8f refs/tags/v2.13.0
82
+ 941f45bcb51457884fa1afd6e24a67377d70f75c refs/tags/v2.13.1
83
+ 07f30430d4186c2712761f1ffaea50ede63f2b2b refs/tags/v2.13.2
84
+ bd67643652d3800837f1f41549a2a5adbaa3fafe refs/tags/v2.13.3
85
+ c6239a8a1b6871cc0fb5f7af885a02ffd1349f9d refs/tags/v2.13.4
86
+ 7c33cdc2d39c7b99a122579f53bc94c8eb3332ff refs/tags/v2.13.5
87
+ a2e59f0e7065404b44dfe92a28aca47ba1378dc4 refs/tags/v2.13.6
88
+ c36cf6254170aa8aef35b65854f518016551d5b8 refs/tags/v2.2.0
89
+ ^2a5a5ec0a47c245fbf1bb1a8a90b4c3278e01693
90
+ 9a9239eaa52e0e2a16c76894a7f30f19997f0167 refs/tags/v2.2.1
91
+ ^86e2ad4f77442c3350f9a2476650da6bee253c52
92
+ 8bd683141ccf900aafc3dc76e5efd86f1e8ac541 refs/tags/v2.2.2
93
+ ^f117a48ea2fd446d2865826a58d08027d4579cb3
94
+ 197ae8a04cec7bf9327d36c780d4fca2a6b51339 refs/tags/v2.2.3
95
+ ^8edc147d67ca85a93ed1f53628004528dc36a04d
96
+ e4637eb508aa3e41233875f6ce3891d96fbc5d33 refs/tags/v2.2.4
97
+ ^9a19306fbf30642ca331d0ec88e7da54a96860f9
98
+ 7107ada7cbbd01e76a2a9f3e2ec27b683dcec99b refs/tags/v2.3.0
99
+ ^e43e1cc01ae6d4e4e5ba10557a057d7f3d5ece0d
100
+ ca8264815ffcf8beda3b206405a92927c722027f refs/tags/v2.4.0
101
+ ^00a0aa992953d6482114a0f539a21bb535a16383
102
+ 8b7a01d0b8dddf9ff650a6511377cd32a4f1501a refs/tags/v2.4.1
103
+ ^e44fcc3c15b41f0720c72832c0b9cd07de819781
104
+ 6c383e01bbd4155a29ad280ad7ba7941e05675dd refs/tags/v2.4.2
105
+ ^7ec2ddfc95f65d1e986d359466a6c254aa514ef3
106
+ aa56a0e4a40af9ff27dd5b4d283d29bc64c19088 refs/tags/v2.4.3
107
+ ^80d452484c5409444b0ec19383faa84bb7a4d351
108
+ 014cd12ec1a3258f3bfc6597f371ed46c8e89ccd refs/tags/v2.5.0
109
+ ^3b1dbebabc801c9cf6f0953a4c20b904d444f879
110
+ 78b2d1991b9e81bbc1a6670ab4af189094e952eb refs/tags/v2.6.0
111
+ ^59a2ac2745d8a57ac94c6accced73620d59fb844
112
+ 319b99648b94c37e16cec64e0aec6d80557de64f refs/tags/v2.6.0b1
113
+ d46f3322a45cb907777f568bb1377ab1b9457ad8 refs/tags/v2.6.0rc1
114
+ c4a8b5bb9140cdc8c214044d41e2593986f875d0 refs/tags/v2.6.0rc2
115
+ c16da993094988141101ac4d96a9b2c92f9ac714 refs/tags/v2.6.0rc3
116
+ f4bc37b3de4857b9d80c1d85ff9f9e5dceef3dd4 refs/tags/v2.6.1
117
+ ^f1abf5d9159b805674197f6bc443592e631c9130
118
+ c7faa0f557df4ee266e6e6dca311cd1474ad2123 refs/tags/v2.6.2
119
+ ^8de7772cc72daca8e947b79b83fea46214931604
120
+ 40d14c37b4cb8488a241f837ea2e3eb60404f7b7 refs/tags/v2.7.0
121
+ ^65e95ea8675ea34bdd566d6461330f25c651e5a8
122
+ c0e8a831c6023be719144e7d10c8ea7c9fb81a58 refs/tags/v2.7.1
123
+ ^787d2c88cafa4d07fb38c9519c485a86323cfcf4
124
+ dc756043d5ed7654e48c41d97a64403a847214a7 refs/tags/v2.8.0
125
+ ^97976c16fb7652f7faf02d76756666ef87adbe7d
126
+ 79dfe03e432e2af41bba00add596e6df92099b49 refs/tags/v2.8.1
127
+ ^f7b499615e14d70ab098a20deb0cdb3889998a1a
128
+ 1dad2a58efb1eef1eb9f2e5532dedd3711924810 refs/tags/v2.9.0
129
+ ^45f792efdd92da094548e2095d6efdbfa7e536ee
130
+ 35b51445ba2bf5e67137c04bc26ceaab33e4285f refs/tags/v2.9.1
131
+ ^ffa346860b306c9bbfb341aed9c14c067751feb8
132
+ dd9ef9f901f3d49426f87a67666393970a6c9431 refs/tags/v2.9.2
133
+ ^914c06fb252b6cc3727d0eedab6736e88a3fcb01
134
+ f0ecf21301c0c24bc78b8b310347c7507d9f41d0 refs/tags/v3.0.0
135
+ ^ed5057ded698e305210269dafa57574ecf964483
136
+ fc888f758fde1c37d80f85666060d3f179f6c001 refs/tags/v3.0.0rc1
137
+ df595b16579d847cd019072aa0daec1e566c7ba2 refs/tags/v3.0.0rc2
138
+ 5d32ed76c0ea53d689f9cec3d4c152d1b0738e8e refs/tags/v3.0.0rc3
139
+ ea3e33e40dd1cbfa9f885e991386337a0e5b4b66 refs/tags/v3.0.0rc4
140
+ e86205cb2ba070755d582856430c0f83c0af6694 refs/tags/v3.0.1
141
+ ^f5fbe867d2d26e4a0a9177a51f6e568868ad3dc8
142
+ e6c503bb0b0c13f76ca0546eca7f8d986039517f refs/tags/v3.0.2
143
+ ^45fab4087eaaff234227a10cf7845e8b07f28a98
third_party/CityFlow/extern/pybind11/.gitattributes CHANGED
@@ -1 +1 @@
1
- docs/*.svg binary
 
1
+ docs/*.svg binary
third_party/CityFlow/extern/pybind11/.github/CODEOWNERS CHANGED
@@ -1,9 +1,9 @@
1
- *.cmake @henryiii
2
- CMakeLists.txt @henryiii
3
- *.yml @henryiii
4
- *.yaml @henryiii
5
- /tools/ @henryiii
6
- /pybind11/ @henryiii
7
- noxfile.py @henryiii
8
- .clang-format @henryiii
9
- .clang-tidy @henryiii
 
1
+ *.cmake @henryiii
2
+ CMakeLists.txt @henryiii
3
+ *.yml @henryiii
4
+ *.yaml @henryiii
5
+ /tools/ @henryiii
6
+ /pybind11/ @henryiii
7
+ noxfile.py @henryiii
8
+ .clang-format @henryiii
9
+ .clang-tidy @henryiii
third_party/CityFlow/extern/pybind11/.github/CONTRIBUTING.md CHANGED
@@ -1,388 +1,388 @@
1
- Thank you for your interest in this project! Please refer to the following
2
- sections on how to contribute code and bug reports.
3
-
4
- ### Reporting bugs
5
-
6
- Before submitting a question or bug report, please take a moment of your time
7
- and ensure that your issue isn't already discussed in the project documentation
8
- provided at [pybind11.readthedocs.org][] or in the [issue tracker][]. You can
9
- also check [gitter][] to see if it came up before.
10
-
11
- Assuming that you have identified a previously unknown problem or an important
12
- question, it's essential that you submit a self-contained and minimal piece of
13
- code that reproduces the problem. In other words: no external dependencies,
14
- isolate the function(s) that cause breakage, submit matched and complete C++
15
- and Python snippets that can be easily compiled and run in isolation; or
16
- ideally make a small PR with a failing test case that can be used as a starting
17
- point.
18
-
19
- ## Pull requests
20
-
21
- Contributions are submitted, reviewed, and accepted using GitHub pull requests.
22
- Please refer to [this article][using pull requests] for details and adhere to
23
- the following rules to make the process as smooth as possible:
24
-
25
- * Make a new branch for every feature you're working on.
26
- * Make small and clean pull requests that are easy to review but make sure they
27
- do add value by themselves.
28
- * Add tests for any new functionality and run the test suite (`cmake --build
29
- build --target pytest`) to ensure that no existing features break.
30
- * Please run [`pre-commit`][pre-commit] to check your code matches the
31
- project style. (Note that `gawk` is required.) Use `pre-commit run
32
- --all-files` before committing (or use installed-mode, check pre-commit docs)
33
- to verify your code passes before pushing to save time.
34
- * This project has a strong focus on providing general solutions using a
35
- minimal amount of code, thus small pull requests are greatly preferred.
36
-
37
- ### Licensing of contributions
38
-
39
- pybind11 is provided under a BSD-style license that can be found in the
40
- ``LICENSE`` file. By using, distributing, or contributing to this project, you
41
- agree to the terms and conditions of this license.
42
-
43
- You are under no obligation whatsoever to provide any bug fixes, patches, or
44
- upgrades to the features, functionality or performance of the source code
45
- ("Enhancements") to anyone; however, if you choose to make your Enhancements
46
- available either publicly, or directly to the author of this software, without
47
- imposing a separate written license agreement for such Enhancements, then you
48
- hereby grant the following license: a non-exclusive, royalty-free perpetual
49
- license to install, use, modify, prepare derivative works, incorporate into
50
- other computer software, distribute, and sublicense such enhancements or
51
- derivative works thereof, in binary and source code form.
52
-
53
-
54
- ## Development of pybind11
55
-
56
- ### Quick setup
57
-
58
- To setup a quick development environment, use [`nox`](https://nox.thea.codes).
59
- This will allow you to do some common tasks with minimal setup effort, but will
60
- take more time to run and be less flexible than a full development environment.
61
- If you use [`pipx run nox`](https://pipx.pypa.io), you don't even need to
62
- install `nox`. Examples:
63
-
64
- ```bash
65
- # List all available sessions
66
- nox -l
67
-
68
- # Run linters
69
- nox -s lint
70
-
71
- # Run tests on Python 3.9
72
- nox -s tests-3.9
73
-
74
- # Build and preview docs
75
- nox -s docs -- serve
76
-
77
- # Build SDists and wheels
78
- nox -s build
79
- ```
80
-
81
- ### Full setup
82
-
83
- To setup an ideal development environment, run the following commands on a
84
- system with CMake 3.14+:
85
-
86
- ```bash
87
- python3 -m venv venv
88
- source venv/bin/activate
89
- pip install -r tests/requirements.txt
90
- cmake -S . -B build -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON
91
- cmake --build build -j4
92
- ```
93
-
94
- Tips:
95
-
96
- * You can use `virtualenv` (faster, from PyPI) instead of `venv`.
97
- * You can select any name for your environment folder; if it contains "env" it
98
- will be ignored by git.
99
- * If you don't have CMake 3.14+, just add "cmake" to the pip install command.
100
- * You can use `-DPYBIND11_FINDPYTHON=ON` to use FindPython on CMake 3.12+
101
- * In classic mode, you may need to set `-DPYTHON_EXECUTABLE=/path/to/python`.
102
- FindPython uses `-DPython_ROOT_DIR=/path/to` or
103
- `-DPython_EXECUTABLE=/path/to/python`.
104
-
105
- ### Configuration options
106
-
107
- In CMake, configuration options are given with "-D". Options are stored in the
108
- build directory, in the `CMakeCache.txt` file, so they are remembered for each
109
- build directory. Two selections are special - the generator, given with `-G`,
110
- and the compiler, which is selected based on environment variables `CXX` and
111
- similar, or `-DCMAKE_CXX_COMPILER=`. Unlike the others, these cannot be changed
112
- after the initial run.
113
-
114
- The valid options are:
115
-
116
- * `-DCMAKE_BUILD_TYPE`: Release, Debug, MinSizeRel, RelWithDebInfo
117
- * `-DPYBIND11_FINDPYTHON=ON`: Use CMake 3.12+'s FindPython instead of the
118
- classic, deprecated, custom FindPythonLibs
119
- * `-DPYBIND11_NOPYTHON=ON`: Disable all Python searching (disables tests)
120
- * `-DBUILD_TESTING=ON`: Enable the tests
121
- * `-DDOWNLOAD_CATCH=ON`: Download catch to build the C++ tests
122
- * `-DDOWNLOAD_EIGEN=ON`: Download Eigen for the NumPy tests
123
- * `-DPYBIND11_INSTALL=ON/OFF`: Enable the install target (on by default for the
124
- master project)
125
- * `-DUSE_PYTHON_INSTALL_DIR=ON`: Try to install into the python dir
126
-
127
-
128
- <details><summary>A few standard CMake tricks: (click to expand)</summary><p>
129
-
130
- * Use `cmake --build build -v` to see the commands used to build the files.
131
- * Use `cmake build -LH` to list the CMake options with help.
132
- * Use `ccmake` if available to see a curses (terminal) gui, or `cmake-gui` for
133
- a completely graphical interface (not present in the PyPI package).
134
- * Use `cmake --build build -j12` to build with 12 cores (for example).
135
- * Use `-G` and the name of a generator to use something different. `cmake
136
- --help` lists the generators available.
137
- - On Unix, setting `CMAKE_GENERATER=Ninja` in your environment will give
138
- you automatic multithreading on all your CMake projects!
139
- * Open the `CMakeLists.txt` with QtCreator to generate for that IDE.
140
- * You can use `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON` to generate the `.json` file
141
- that some tools expect.
142
-
143
- </p></details>
144
-
145
-
146
- To run the tests, you can "build" the check target:
147
-
148
- ```bash
149
- cmake --build build --target check
150
- ```
151
-
152
- `--target` can be spelled `-t` in CMake 3.15+. You can also run individual
153
- tests with these targets:
154
-
155
- * `pytest`: Python tests only, using the
156
- [pytest](https://docs.pytest.org/en/stable/) framework
157
- * `cpptest`: C++ tests only
158
- * `test_cmake_build`: Install / subdirectory tests
159
-
160
- If you want to build just a subset of tests, use
161
- `-DPYBIND11_TEST_OVERRIDE="test_callbacks;test_pickling"`. If this is
162
- empty, all tests will be built. Tests are specified without an extension if they need both a .py and
163
- .cpp file.
164
-
165
- You may also pass flags to the `pytest` target by editing `tests/pytest.ini` or
166
- by using the `PYTEST_ADDOPTS` environment variable
167
- (see [`pytest` docs](https://docs.pytest.org/en/2.7.3/customize.html#adding-default-options)). As an example:
168
-
169
- ```bash
170
- env PYTEST_ADDOPTS="--capture=no --exitfirst" \
171
- cmake --build build --target pytest
172
- # Or using abbreviated flags
173
- env PYTEST_ADDOPTS="-s -x" cmake --build build --target pytest
174
- ```
175
-
176
- ### Formatting
177
-
178
- All formatting is handled by pre-commit.
179
-
180
- Install with brew (macOS) or pip (any OS):
181
-
182
- ```bash
183
- # Any OS
184
- python3 -m pip install pre-commit
185
-
186
- # OR macOS with homebrew:
187
- brew install pre-commit
188
- ```
189
-
190
- Then, you can run it on the items you've added to your staging area, or all
191
- files:
192
-
193
- ```bash
194
- pre-commit run
195
- # OR
196
- pre-commit run --all-files
197
- ```
198
-
199
- And, if you want to always use it, you can install it as a git hook (hence the
200
- name, pre-commit):
201
-
202
- ```bash
203
- pre-commit install
204
- ```
205
-
206
- ### Clang-Format
207
-
208
- As of v2.6.2, pybind11 ships with a [`clang-format`][clang-format]
209
- configuration file at the top level of the repo (the filename is
210
- `.clang-format`). Currently, formatting is NOT applied automatically, but
211
- manually using `clang-format` for newly developed files is highly encouraged.
212
- To check if a file needs formatting:
213
-
214
- ```bash
215
- clang-format -style=file --dry-run some.cpp
216
- ```
217
-
218
- The output will show things to be fixed, if any. To actually format the file:
219
-
220
- ```bash
221
- clang-format -style=file -i some.cpp
222
- ```
223
-
224
- Note that the `-style-file` option searches the parent directories for the
225
- `.clang-format` file, i.e. the commands above can be run in any subdirectory
226
- of the pybind11 repo.
227
-
228
- ### Clang-Tidy
229
-
230
- [`clang-tidy`][clang-tidy] performs deeper static code analyses and is
231
- more complex to run, compared to `clang-format`, but support for `clang-tidy`
232
- is built into the pybind11 CMake configuration. To run `clang-tidy`, the
233
- following recipe should work. Run the `docker` command from the top-level
234
- directory inside your pybind11 git clone. Files will be modified in place,
235
- so you can use git to monitor the changes.
236
-
237
- ```bash
238
- docker run --rm -v $PWD:/mounted_pybind11 -it silkeh/clang:15-bullseye
239
- apt-get update && apt-get install -y git python3-dev python3-pytest
240
- cmake -S /mounted_pybind11/ -B build -DCMAKE_CXX_CLANG_TIDY="$(which clang-tidy);--use-color" -DDOWNLOAD_EIGEN=ON -DDOWNLOAD_CATCH=ON -DCMAKE_CXX_STANDARD=17
241
- cmake --build build -j 2
242
- ```
243
-
244
- You can add `--fix` to the options list if you want.
245
-
246
- ### Include what you use
247
-
248
- To run include what you use, install (`brew install include-what-you-use` on
249
- macOS), then run:
250
-
251
- ```bash
252
- cmake -S . -B build-iwyu -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=$(which include-what-you-use)
253
- cmake --build build
254
- ```
255
-
256
- The report is sent to stderr; you can pipe it into a file if you wish.
257
-
258
- ### Build recipes
259
-
260
- This builds with the Intel compiler (assuming it is in your path, along with a
261
- recent CMake and Python):
262
-
263
- ```bash
264
- python3 -m venv venv
265
- . venv/bin/activate
266
- pip install pytest
267
- cmake -S . -B build-intel -DCMAKE_CXX_COMPILER=$(which icpc) -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON -DPYBIND11_WERROR=ON
268
- ```
269
-
270
- This will test the PGI compilers:
271
-
272
- ```bash
273
- docker run --rm -it -v $PWD:/pybind11 nvcr.io/hpc/pgi-compilers:ce
274
- apt-get update && apt-get install -y python3-dev python3-pip python3-pytest
275
- wget -qO- "https://cmake.org/files/v3.18/cmake-3.18.2-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local
276
- cmake -S pybind11/ -B build
277
- cmake --build build
278
- ```
279
-
280
- ### Explanation of the SDist/wheel building design
281
-
282
- > These details below are _only_ for packaging the Python sources from git. The
283
- > SDists and wheels created do not have any extra requirements at all and are
284
- > completely normal.
285
-
286
- The main objective of the packaging system is to create SDists (Python's source
287
- distribution packages) and wheels (Python's binary distribution packages) that
288
- include everything that is needed to work with pybind11, and which can be
289
- installed without any additional dependencies. This is more complex than it
290
- appears: in order to support CMake as a first class language even when using
291
- the PyPI package, they must include the _generated_ CMake files (so as not to
292
- require CMake when installing the `pybind11` package itself). They should also
293
- provide the option to install to the "standard" location
294
- (`<ENVROOT>/include/pybind11` and `<ENVROOT>/share/cmake/pybind11`) so they are
295
- easy to find with CMake, but this can cause problems if you are not an
296
- environment or using ``pyproject.toml`` requirements. This was solved by having
297
- two packages; the "nice" pybind11 package that stores the includes and CMake
298
- files inside the package, that you get access to via functions in the package,
299
- and a `pybind11-global` package that can be included via `pybind11[global]` if
300
- you want the more invasive but discoverable file locations.
301
-
302
- If you want to install or package the GitHub source, it is best to have Pip 10
303
- or newer on Windows, macOS, or Linux (manylinux1 compatible, includes most
304
- distributions). You can then build the SDists, or run any procedure that makes
305
- SDists internally, like making wheels or installing.
306
-
307
-
308
- ```bash
309
- # Editable development install example
310
- python3 -m pip install -e .
311
- ```
312
-
313
- Since Pip itself does not have an `sdist` command (it does have `wheel` and
314
- `install`), you may want to use the upcoming `build` package:
315
-
316
- ```bash
317
- python3 -m pip install build
318
-
319
- # Normal package
320
- python3 -m build -s .
321
-
322
- # Global extra
323
- PYBIND11_GLOBAL_SDIST=1 python3 -m build -s .
324
- ```
325
-
326
- If you want to use the classic "direct" usage of `python setup.py`, you will
327
- need CMake 3.15+ and either `make` or `ninja` preinstalled (possibly via `pip
328
- install cmake ninja`), since directly running Python on `setup.py` cannot pick
329
- up and install `pyproject.toml` requirements. As long as you have those two
330
- things, though, everything works the way you would expect:
331
-
332
- ```bash
333
- # Normal package
334
- python3 setup.py sdist
335
-
336
- # Global extra
337
- PYBIND11_GLOBAL_SDIST=1 python3 setup.py sdist
338
- ```
339
-
340
- A detailed explanation of the build procedure design for developers wanting to
341
- work on or maintain the packaging system is as follows:
342
-
343
- #### 1. Building from the source directory
344
-
345
- When you invoke any `setup.py` command from the source directory, including
346
- `pip wheel .` and `pip install .`, you will activate a full source build. This
347
- is made of the following steps:
348
-
349
- 1. If the tool is PEP 518 compliant, like Pip 10+, it will create a temporary
350
- virtual environment and install the build requirements (mostly CMake) into
351
- it. (if you are not on Windows, macOS, or a manylinux compliant system, you
352
- can disable this with `--no-build-isolation` as long as you have CMake 3.15+
353
- installed)
354
- 2. The environment variable `PYBIND11_GLOBAL_SDIST` is checked - if it is set
355
- and truthy, this will be make the accessory `pybind11-global` package,
356
- instead of the normal `pybind11` package. This package is used for
357
- installing the files directly to your environment root directory, using
358
- `pybind11[global]`.
359
- 2. `setup.py` reads the version from `pybind11/_version.py` and verifies it
360
- matches `includes/pybind11/detail/common.h`.
361
- 3. CMake is run with `-DCMAKE_INSTALL_PREIFX=pybind11`. Since the CMake install
362
- procedure uses only relative paths and is identical on all platforms, these
363
- files are valid as long as they stay in the correct relative position to the
364
- includes. `pybind11/share/cmake/pybind11` has the CMake files, and
365
- `pybind11/include` has the includes. The build directory is discarded.
366
- 4. Simpler files are placed in the SDist: `tools/setup_*.py.in`,
367
- `tools/pyproject.toml` (`main` or `global`)
368
- 5. The package is created by running the setup function in the
369
- `tools/setup_*.py`. `setup_main.py` fills in Python packages, and
370
- `setup_global.py` fills in only the data/header slots.
371
- 6. A context manager cleans up the temporary CMake install directory (even if
372
- an error is thrown).
373
-
374
- ### 2. Building from SDist
375
-
376
- Since the SDist has the rendered template files in `tools` along with the
377
- includes and CMake files in the correct locations, the builds are completely
378
- trivial and simple. No extra requirements are required. You can even use Pip 9
379
- if you really want to.
380
-
381
-
382
- [pre-commit]: https://pre-commit.com
383
- [clang-format]: https://clang.llvm.org/docs/ClangFormat.html
384
- [clang-tidy]: https://clang.llvm.org/extra/clang-tidy/
385
- [pybind11.readthedocs.org]: http://pybind11.readthedocs.org/en/latest
386
- [issue tracker]: https://github.com/pybind/pybind11/issues
387
- [gitter]: https://gitter.im/pybind/Lobby
388
- [using pull requests]: https://help.github.com/articles/using-pull-requests
 
1
+ Thank you for your interest in this project! Please refer to the following
2
+ sections on how to contribute code and bug reports.
3
+
4
+ ### Reporting bugs
5
+
6
+ Before submitting a question or bug report, please take a moment of your time
7
+ and ensure that your issue isn't already discussed in the project documentation
8
+ provided at [pybind11.readthedocs.org][] or in the [issue tracker][]. You can
9
+ also check [gitter][] to see if it came up before.
10
+
11
+ Assuming that you have identified a previously unknown problem or an important
12
+ question, it's essential that you submit a self-contained and minimal piece of
13
+ code that reproduces the problem. In other words: no external dependencies,
14
+ isolate the function(s) that cause breakage, submit matched and complete C++
15
+ and Python snippets that can be easily compiled and run in isolation; or
16
+ ideally make a small PR with a failing test case that can be used as a starting
17
+ point.
18
+
19
+ ## Pull requests
20
+
21
+ Contributions are submitted, reviewed, and accepted using GitHub pull requests.
22
+ Please refer to [this article][using pull requests] for details and adhere to
23
+ the following rules to make the process as smooth as possible:
24
+
25
+ * Make a new branch for every feature you're working on.
26
+ * Make small and clean pull requests that are easy to review but make sure they
27
+ do add value by themselves.
28
+ * Add tests for any new functionality and run the test suite (`cmake --build
29
+ build --target pytest`) to ensure that no existing features break.
30
+ * Please run [`pre-commit`][pre-commit] to check your code matches the
31
+ project style. (Note that `gawk` is required.) Use `pre-commit run
32
+ --all-files` before committing (or use installed-mode, check pre-commit docs)
33
+ to verify your code passes before pushing to save time.
34
+ * This project has a strong focus on providing general solutions using a
35
+ minimal amount of code, thus small pull requests are greatly preferred.
36
+
37
+ ### Licensing of contributions
38
+
39
+ pybind11 is provided under a BSD-style license that can be found in the
40
+ ``LICENSE`` file. By using, distributing, or contributing to this project, you
41
+ agree to the terms and conditions of this license.
42
+
43
+ You are under no obligation whatsoever to provide any bug fixes, patches, or
44
+ upgrades to the features, functionality or performance of the source code
45
+ ("Enhancements") to anyone; however, if you choose to make your Enhancements
46
+ available either publicly, or directly to the author of this software, without
47
+ imposing a separate written license agreement for such Enhancements, then you
48
+ hereby grant the following license: a non-exclusive, royalty-free perpetual
49
+ license to install, use, modify, prepare derivative works, incorporate into
50
+ other computer software, distribute, and sublicense such enhancements or
51
+ derivative works thereof, in binary and source code form.
52
+
53
+
54
+ ## Development of pybind11
55
+
56
+ ### Quick setup
57
+
58
+ To setup a quick development environment, use [`nox`](https://nox.thea.codes).
59
+ This will allow you to do some common tasks with minimal setup effort, but will
60
+ take more time to run and be less flexible than a full development environment.
61
+ If you use [`pipx run nox`](https://pipx.pypa.io), you don't even need to
62
+ install `nox`. Examples:
63
+
64
+ ```bash
65
+ # List all available sessions
66
+ nox -l
67
+
68
+ # Run linters
69
+ nox -s lint
70
+
71
+ # Run tests on Python 3.9
72
+ nox -s tests-3.9
73
+
74
+ # Build and preview docs
75
+ nox -s docs -- serve
76
+
77
+ # Build SDists and wheels
78
+ nox -s build
79
+ ```
80
+
81
+ ### Full setup
82
+
83
+ To setup an ideal development environment, run the following commands on a
84
+ system with CMake 3.14+:
85
+
86
+ ```bash
87
+ python3 -m venv venv
88
+ source venv/bin/activate
89
+ pip install -r tests/requirements.txt
90
+ cmake -S . -B build -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON
91
+ cmake --build build -j4
92
+ ```
93
+
94
+ Tips:
95
+
96
+ * You can use `virtualenv` (faster, from PyPI) instead of `venv`.
97
+ * You can select any name for your environment folder; if it contains "env" it
98
+ will be ignored by git.
99
+ * If you don't have CMake 3.14+, just add "cmake" to the pip install command.
100
+ * You can use `-DPYBIND11_FINDPYTHON=ON` to use FindPython on CMake 3.12+
101
+ * In classic mode, you may need to set `-DPYTHON_EXECUTABLE=/path/to/python`.
102
+ FindPython uses `-DPython_ROOT_DIR=/path/to` or
103
+ `-DPython_EXECUTABLE=/path/to/python`.
104
+
105
+ ### Configuration options
106
+
107
+ In CMake, configuration options are given with "-D". Options are stored in the
108
+ build directory, in the `CMakeCache.txt` file, so they are remembered for each
109
+ build directory. Two selections are special - the generator, given with `-G`,
110
+ and the compiler, which is selected based on environment variables `CXX` and
111
+ similar, or `-DCMAKE_CXX_COMPILER=`. Unlike the others, these cannot be changed
112
+ after the initial run.
113
+
114
+ The valid options are:
115
+
116
+ * `-DCMAKE_BUILD_TYPE`: Release, Debug, MinSizeRel, RelWithDebInfo
117
+ * `-DPYBIND11_FINDPYTHON=ON`: Use CMake 3.12+'s FindPython instead of the
118
+ classic, deprecated, custom FindPythonLibs
119
+ * `-DPYBIND11_NOPYTHON=ON`: Disable all Python searching (disables tests)
120
+ * `-DBUILD_TESTING=ON`: Enable the tests
121
+ * `-DDOWNLOAD_CATCH=ON`: Download catch to build the C++ tests
122
+ * `-DDOWNLOAD_EIGEN=ON`: Download Eigen for the NumPy tests
123
+ * `-DPYBIND11_INSTALL=ON/OFF`: Enable the install target (on by default for the
124
+ master project)
125
+ * `-DUSE_PYTHON_INSTALL_DIR=ON`: Try to install into the python dir
126
+
127
+
128
+ <details><summary>A few standard CMake tricks: (click to expand)</summary><p>
129
+
130
+ * Use `cmake --build build -v` to see the commands used to build the files.
131
+ * Use `cmake build -LH` to list the CMake options with help.
132
+ * Use `ccmake` if available to see a curses (terminal) gui, or `cmake-gui` for
133
+ a completely graphical interface (not present in the PyPI package).
134
+ * Use `cmake --build build -j12` to build with 12 cores (for example).
135
+ * Use `-G` and the name of a generator to use something different. `cmake
136
+ --help` lists the generators available.
137
+ - On Unix, setting `CMAKE_GENERATER=Ninja` in your environment will give
138
+ you automatic multithreading on all your CMake projects!
139
+ * Open the `CMakeLists.txt` with QtCreator to generate for that IDE.
140
+ * You can use `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON` to generate the `.json` file
141
+ that some tools expect.
142
+
143
+ </p></details>
144
+
145
+
146
+ To run the tests, you can "build" the check target:
147
+
148
+ ```bash
149
+ cmake --build build --target check
150
+ ```
151
+
152
+ `--target` can be spelled `-t` in CMake 3.15+. You can also run individual
153
+ tests with these targets:
154
+
155
+ * `pytest`: Python tests only, using the
156
+ [pytest](https://docs.pytest.org/en/stable/) framework
157
+ * `cpptest`: C++ tests only
158
+ * `test_cmake_build`: Install / subdirectory tests
159
+
160
+ If you want to build just a subset of tests, use
161
+ `-DPYBIND11_TEST_OVERRIDE="test_callbacks;test_pickling"`. If this is
162
+ empty, all tests will be built. Tests are specified without an extension if they need both a .py and
163
+ .cpp file.
164
+
165
+ You may also pass flags to the `pytest` target by editing `tests/pytest.ini` or
166
+ by using the `PYTEST_ADDOPTS` environment variable
167
+ (see [`pytest` docs](https://docs.pytest.org/en/2.7.3/customize.html#adding-default-options)). As an example:
168
+
169
+ ```bash
170
+ env PYTEST_ADDOPTS="--capture=no --exitfirst" \
171
+ cmake --build build --target pytest
172
+ # Or using abbreviated flags
173
+ env PYTEST_ADDOPTS="-s -x" cmake --build build --target pytest
174
+ ```
175
+
176
+ ### Formatting
177
+
178
+ All formatting is handled by pre-commit.
179
+
180
+ Install with brew (macOS) or pip (any OS):
181
+
182
+ ```bash
183
+ # Any OS
184
+ python3 -m pip install pre-commit
185
+
186
+ # OR macOS with homebrew:
187
+ brew install pre-commit
188
+ ```
189
+
190
+ Then, you can run it on the items you've added to your staging area, or all
191
+ files:
192
+
193
+ ```bash
194
+ pre-commit run
195
+ # OR
196
+ pre-commit run --all-files
197
+ ```
198
+
199
+ And, if you want to always use it, you can install it as a git hook (hence the
200
+ name, pre-commit):
201
+
202
+ ```bash
203
+ pre-commit install
204
+ ```
205
+
206
+ ### Clang-Format
207
+
208
+ As of v2.6.2, pybind11 ships with a [`clang-format`][clang-format]
209
+ configuration file at the top level of the repo (the filename is
210
+ `.clang-format`). Currently, formatting is NOT applied automatically, but
211
+ manually using `clang-format` for newly developed files is highly encouraged.
212
+ To check if a file needs formatting:
213
+
214
+ ```bash
215
+ clang-format -style=file --dry-run some.cpp
216
+ ```
217
+
218
+ The output will show things to be fixed, if any. To actually format the file:
219
+
220
+ ```bash
221
+ clang-format -style=file -i some.cpp
222
+ ```
223
+
224
+ Note that the `-style-file` option searches the parent directories for the
225
+ `.clang-format` file, i.e. the commands above can be run in any subdirectory
226
+ of the pybind11 repo.
227
+
228
+ ### Clang-Tidy
229
+
230
+ [`clang-tidy`][clang-tidy] performs deeper static code analyses and is
231
+ more complex to run, compared to `clang-format`, but support for `clang-tidy`
232
+ is built into the pybind11 CMake configuration. To run `clang-tidy`, the
233
+ following recipe should work. Run the `docker` command from the top-level
234
+ directory inside your pybind11 git clone. Files will be modified in place,
235
+ so you can use git to monitor the changes.
236
+
237
+ ```bash
238
+ docker run --rm -v $PWD:/mounted_pybind11 -it silkeh/clang:15-bullseye
239
+ apt-get update && apt-get install -y git python3-dev python3-pytest
240
+ cmake -S /mounted_pybind11/ -B build -DCMAKE_CXX_CLANG_TIDY="$(which clang-tidy);--use-color" -DDOWNLOAD_EIGEN=ON -DDOWNLOAD_CATCH=ON -DCMAKE_CXX_STANDARD=17
241
+ cmake --build build -j 2
242
+ ```
243
+
244
+ You can add `--fix` to the options list if you want.
245
+
246
+ ### Include what you use
247
+
248
+ To run include what you use, install (`brew install include-what-you-use` on
249
+ macOS), then run:
250
+
251
+ ```bash
252
+ cmake -S . -B build-iwyu -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=$(which include-what-you-use)
253
+ cmake --build build
254
+ ```
255
+
256
+ The report is sent to stderr; you can pipe it into a file if you wish.
257
+
258
+ ### Build recipes
259
+
260
+ This builds with the Intel compiler (assuming it is in your path, along with a
261
+ recent CMake and Python):
262
+
263
+ ```bash
264
+ python3 -m venv venv
265
+ . venv/bin/activate
266
+ pip install pytest
267
+ cmake -S . -B build-intel -DCMAKE_CXX_COMPILER=$(which icpc) -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON -DPYBIND11_WERROR=ON
268
+ ```
269
+
270
+ This will test the PGI compilers:
271
+
272
+ ```bash
273
+ docker run --rm -it -v $PWD:/pybind11 nvcr.io/hpc/pgi-compilers:ce
274
+ apt-get update && apt-get install -y python3-dev python3-pip python3-pytest
275
+ wget -qO- "https://cmake.org/files/v3.18/cmake-3.18.2-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local
276
+ cmake -S pybind11/ -B build
277
+ cmake --build build
278
+ ```
279
+
280
+ ### Explanation of the SDist/wheel building design
281
+
282
+ > These details below are _only_ for packaging the Python sources from git. The
283
+ > SDists and wheels created do not have any extra requirements at all and are
284
+ > completely normal.
285
+
286
+ The main objective of the packaging system is to create SDists (Python's source
287
+ distribution packages) and wheels (Python's binary distribution packages) that
288
+ include everything that is needed to work with pybind11, and which can be
289
+ installed without any additional dependencies. This is more complex than it
290
+ appears: in order to support CMake as a first class language even when using
291
+ the PyPI package, they must include the _generated_ CMake files (so as not to
292
+ require CMake when installing the `pybind11` package itself). They should also
293
+ provide the option to install to the "standard" location
294
+ (`<ENVROOT>/include/pybind11` and `<ENVROOT>/share/cmake/pybind11`) so they are
295
+ easy to find with CMake, but this can cause problems if you are not an
296
+ environment or using ``pyproject.toml`` requirements. This was solved by having
297
+ two packages; the "nice" pybind11 package that stores the includes and CMake
298
+ files inside the package, that you get access to via functions in the package,
299
+ and a `pybind11-global` package that can be included via `pybind11[global]` if
300
+ you want the more invasive but discoverable file locations.
301
+
302
+ If you want to install or package the GitHub source, it is best to have Pip 10
303
+ or newer on Windows, macOS, or Linux (manylinux1 compatible, includes most
304
+ distributions). You can then build the SDists, or run any procedure that makes
305
+ SDists internally, like making wheels or installing.
306
+
307
+
308
+ ```bash
309
+ # Editable development install example
310
+ python3 -m pip install -e .
311
+ ```
312
+
313
+ Since Pip itself does not have an `sdist` command (it does have `wheel` and
314
+ `install`), you may want to use the upcoming `build` package:
315
+
316
+ ```bash
317
+ python3 -m pip install build
318
+
319
+ # Normal package
320
+ python3 -m build -s .
321
+
322
+ # Global extra
323
+ PYBIND11_GLOBAL_SDIST=1 python3 -m build -s .
324
+ ```
325
+
326
+ If you want to use the classic "direct" usage of `python setup.py`, you will
327
+ need CMake 3.15+ and either `make` or `ninja` preinstalled (possibly via `pip
328
+ install cmake ninja`), since directly running Python on `setup.py` cannot pick
329
+ up and install `pyproject.toml` requirements. As long as you have those two
330
+ things, though, everything works the way you would expect:
331
+
332
+ ```bash
333
+ # Normal package
334
+ python3 setup.py sdist
335
+
336
+ # Global extra
337
+ PYBIND11_GLOBAL_SDIST=1 python3 setup.py sdist
338
+ ```
339
+
340
+ A detailed explanation of the build procedure design for developers wanting to
341
+ work on or maintain the packaging system is as follows:
342
+
343
+ #### 1. Building from the source directory
344
+
345
+ When you invoke any `setup.py` command from the source directory, including
346
+ `pip wheel .` and `pip install .`, you will activate a full source build. This
347
+ is made of the following steps:
348
+
349
+ 1. If the tool is PEP 518 compliant, like Pip 10+, it will create a temporary
350
+ virtual environment and install the build requirements (mostly CMake) into
351
+ it. (if you are not on Windows, macOS, or a manylinux compliant system, you
352
+ can disable this with `--no-build-isolation` as long as you have CMake 3.15+
353
+ installed)
354
+ 2. The environment variable `PYBIND11_GLOBAL_SDIST` is checked - if it is set
355
+ and truthy, this will be make the accessory `pybind11-global` package,
356
+ instead of the normal `pybind11` package. This package is used for
357
+ installing the files directly to your environment root directory, using
358
+ `pybind11[global]`.
359
+ 2. `setup.py` reads the version from `pybind11/_version.py` and verifies it
360
+ matches `includes/pybind11/detail/common.h`.
361
+ 3. CMake is run with `-DCMAKE_INSTALL_PREIFX=pybind11`. Since the CMake install
362
+ procedure uses only relative paths and is identical on all platforms, these
363
+ files are valid as long as they stay in the correct relative position to the
364
+ includes. `pybind11/share/cmake/pybind11` has the CMake files, and
365
+ `pybind11/include` has the includes. The build directory is discarded.
366
+ 4. Simpler files are placed in the SDist: `tools/setup_*.py.in`,
367
+ `tools/pyproject.toml` (`main` or `global`)
368
+ 5. The package is created by running the setup function in the
369
+ `tools/setup_*.py`. `setup_main.py` fills in Python packages, and
370
+ `setup_global.py` fills in only the data/header slots.
371
+ 6. A context manager cleans up the temporary CMake install directory (even if
372
+ an error is thrown).
373
+
374
+ ### 2. Building from SDist
375
+
376
+ Since the SDist has the rendered template files in `tools` along with the
377
+ includes and CMake files in the correct locations, the builds are completely
378
+ trivial and simple. No extra requirements are required. You can even use Pip 9
379
+ if you really want to.
380
+
381
+
382
+ [pre-commit]: https://pre-commit.com
383
+ [clang-format]: https://clang.llvm.org/docs/ClangFormat.html
384
+ [clang-tidy]: https://clang.llvm.org/extra/clang-tidy/
385
+ [pybind11.readthedocs.org]: http://pybind11.readthedocs.org/en/latest
386
+ [issue tracker]: https://github.com/pybind/pybind11/issues
387
+ [gitter]: https://gitter.im/pybind/Lobby
388
+ [using pull requests]: https://help.github.com/articles/using-pull-requests
third_party/CityFlow/extern/pybind11/.github/dependabot.yml CHANGED
@@ -1,15 +1,15 @@
1
- version: 2
2
- updates:
3
- # Maintain dependencies for GitHub Actions
4
- - package-ecosystem: "github-actions"
5
- directory: "/"
6
- schedule:
7
- interval: "weekly"
8
- groups:
9
- actions:
10
- patterns:
11
- - "*"
12
- ignore:
13
- - dependency-name: actions/checkout
14
- versions:
15
- - "<5"
 
1
+ version: 2
2
+ updates:
3
+ # Maintain dependencies for GitHub Actions
4
+ - package-ecosystem: "github-actions"
5
+ directory: "/"
6
+ schedule:
7
+ interval: "weekly"
8
+ groups:
9
+ actions:
10
+ patterns:
11
+ - "*"
12
+ ignore:
13
+ - dependency-name: actions/checkout
14
+ versions:
15
+ - "<5"
third_party/CityFlow/extern/pybind11/.github/labeler.yml CHANGED
@@ -1,8 +1,8 @@
1
- docs:
2
- - any:
3
- - 'docs/**/*.rst'
4
- - '!docs/changelog.rst'
5
- - '!docs/upgrade.rst'
6
-
7
- ci:
8
- - '.github/workflows/*.yml'
 
1
+ docs:
2
+ - any:
3
+ - 'docs/**/*.rst'
4
+ - '!docs/changelog.rst'
5
+ - '!docs/upgrade.rst'
6
+
7
+ ci:
8
+ - '.github/workflows/*.yml'
third_party/CityFlow/extern/pybind11/.github/labeler_merged.yml CHANGED
@@ -1,3 +1,3 @@
1
- needs changelog:
2
- - all:
3
- - '!docs/changelog.rst'
 
1
+ needs changelog:
2
+ - all:
3
+ - '!docs/changelog.rst'
third_party/CityFlow/extern/pybind11/.github/pull_request_template.md CHANGED
@@ -1,19 +1,19 @@
1
- <!--
2
- Title (above): please place [branch_name] at the beginning if you are targeting a branch other than master. *Do not target stable*.
3
- It is recommended to use conventional commit format, see conventionalcommits.org, but not required.
4
- -->
5
- ## Description
6
-
7
- <!-- Include relevant issues or PRs here, describe what changed and why -->
8
-
9
-
10
- ## Suggested changelog entry:
11
-
12
- <!-- Fill in the below block with the expected RestructuredText entry. Delete if no entry needed;
13
- but do not delete header or rst block if an entry is needed! Will be collected via a script. -->
14
-
15
- ```rst
16
-
17
- ```
18
-
19
- <!-- If the upgrade guide needs updating, note that here too -->
 
1
+ <!--
2
+ Title (above): please place [branch_name] at the beginning if you are targeting a branch other than master. *Do not target stable*.
3
+ It is recommended to use conventional commit format, see conventionalcommits.org, but not required.
4
+ -->
5
+ ## Description
6
+
7
+ <!-- Include relevant issues or PRs here, describe what changed and why -->
8
+
9
+
10
+ ## Suggested changelog entry:
11
+
12
+ <!-- Fill in the below block with the expected RestructuredText entry. Delete if no entry needed;
13
+ but do not delete header or rst block if an entry is needed! Will be collected via a script. -->
14
+
15
+ ```rst
16
+
17
+ ```
18
+
19
+ <!-- If the upgrade guide needs updating, note that here too -->
third_party/CityFlow/extern/pybind11/.gitignore CHANGED
@@ -1,46 +1,46 @@
1
- CMakeCache.txt
2
- CMakeFiles
3
- Makefile
4
- cmake_install.cmake
5
- cmake_uninstall.cmake
6
- .DS_Store
7
- *.so
8
- *.pyd
9
- *.dll
10
- *.sln
11
- *.sdf
12
- *.opensdf
13
- *.vcxproj
14
- *.vcxproj.user
15
- *.filters
16
- example.dir
17
- Win32
18
- x64
19
- Release
20
- Debug
21
- .vs
22
- CTestTestfile.cmake
23
- Testing
24
- autogen
25
- MANIFEST
26
- /.ninja_*
27
- /*.ninja
28
- /docs/.build
29
- *.py[co]
30
- *.egg-info
31
- *~
32
- .*.swp
33
- .DS_Store
34
- /dist
35
- /*build*
36
- .cache/
37
- sosize-*.txt
38
- pybind11Config*.cmake
39
- pybind11Targets.cmake
40
- /*env*
41
- /.vscode
42
- /pybind11/include/*
43
- /pybind11/share/*
44
- /docs/_build/*
45
- .ipynb_checkpoints/
46
- tests/main.cpp
 
1
+ CMakeCache.txt
2
+ CMakeFiles
3
+ Makefile
4
+ cmake_install.cmake
5
+ cmake_uninstall.cmake
6
+ .DS_Store
7
+ *.so
8
+ *.pyd
9
+ *.dll
10
+ *.sln
11
+ *.sdf
12
+ *.opensdf
13
+ *.vcxproj
14
+ *.vcxproj.user
15
+ *.filters
16
+ example.dir
17
+ Win32
18
+ x64
19
+ Release
20
+ Debug
21
+ .vs
22
+ CTestTestfile.cmake
23
+ Testing
24
+ autogen
25
+ MANIFEST
26
+ /.ninja_*
27
+ /*.ninja
28
+ /docs/.build
29
+ *.py[co]
30
+ *.egg-info
31
+ *~
32
+ .*.swp
33
+ .DS_Store
34
+ /dist
35
+ /*build*
36
+ .cache/
37
+ sosize-*.txt
38
+ pybind11Config*.cmake
39
+ pybind11Targets.cmake
40
+ /*env*
41
+ /.vscode
42
+ /pybind11/include/*
43
+ /pybind11/share/*
44
+ /docs/_build/*
45
+ .ipynb_checkpoints/
46
+ tests/main.cpp
third_party/CityFlow/extern/pybind11/.pre-commit-config.yaml CHANGED
@@ -1,155 +1,155 @@
1
- # To use:
2
- #
3
- # pre-commit run -a
4
- #
5
- # Or:
6
- #
7
- # pre-commit install # (runs every time you commit in git)
8
- #
9
- # To update this file:
10
- #
11
- # pre-commit autoupdate
12
- #
13
- # See https://github.com/pre-commit/pre-commit
14
-
15
-
16
- ci:
17
- autoupdate_commit_msg: "chore(deps): update pre-commit hooks"
18
- autofix_commit_msg: "style: pre-commit fixes"
19
- autoupdate_schedule: monthly
20
-
21
- # third-party content
22
- exclude: ^tools/JoinPaths.cmake$
23
-
24
- repos:
25
-
26
- # Clang format the codebase automatically
27
- - repo: https://github.com/pre-commit/mirrors-clang-format
28
- rev: "v17.0.6"
29
- hooks:
30
- - id: clang-format
31
- types_or: [c++, c, cuda]
32
-
33
- # Ruff, the Python auto-correcting linter/formatter written in Rust
34
- - repo: https://github.com/astral-sh/ruff-pre-commit
35
- rev: v0.2.0
36
- hooks:
37
- - id: ruff
38
- args: ["--fix", "--show-fixes"]
39
- - id: ruff-format
40
-
41
- # Check static types with mypy
42
- - repo: https://github.com/pre-commit/mirrors-mypy
43
- rev: "v1.8.0"
44
- hooks:
45
- - id: mypy
46
- args: []
47
- exclude: ^(tests|docs)/
48
- additional_dependencies:
49
- - markdown-it-py<3 # Drop this together with dropping Python 3.7 support.
50
- - nox
51
- - rich
52
- - types-setuptools
53
-
54
- # CMake formatting
55
- - repo: https://github.com/cheshirekow/cmake-format-precommit
56
- rev: "v0.6.13"
57
- hooks:
58
- - id: cmake-format
59
- additional_dependencies: [pyyaml]
60
- types: [file]
61
- files: (\.cmake|CMakeLists.txt)(.in)?$
62
-
63
- # Standard hooks
64
- - repo: https://github.com/pre-commit/pre-commit-hooks
65
- rev: "v4.5.0"
66
- hooks:
67
- - id: check-added-large-files
68
- - id: check-case-conflict
69
- - id: check-docstring-first
70
- - id: check-merge-conflict
71
- - id: check-symlinks
72
- - id: check-toml
73
- - id: check-yaml
74
- - id: debug-statements
75
- - id: end-of-file-fixer
76
- - id: mixed-line-ending
77
- - id: requirements-txt-fixer
78
- - id: trailing-whitespace
79
-
80
- # Also code format the docs
81
- - repo: https://github.com/asottile/blacken-docs
82
- rev: "1.16.0"
83
- hooks:
84
- - id: blacken-docs
85
- additional_dependencies:
86
- - black==23.*
87
-
88
- # Changes tabs to spaces
89
- - repo: https://github.com/Lucas-C/pre-commit-hooks
90
- rev: "v1.5.4"
91
- hooks:
92
- - id: remove-tabs
93
-
94
- # Avoid directional quotes
95
- - repo: https://github.com/sirosen/texthooks
96
- rev: "0.6.4"
97
- hooks:
98
- - id: fix-ligatures
99
- - id: fix-smartquotes
100
-
101
- # Checking for common mistakes
102
- - repo: https://github.com/pre-commit/pygrep-hooks
103
- rev: "v1.10.0"
104
- hooks:
105
- - id: rst-backticks
106
- - id: rst-directive-colons
107
- - id: rst-inline-touching-normal
108
-
109
- # Checks the manifest for missing files (native support)
110
- - repo: https://github.com/mgedmin/check-manifest
111
- rev: "0.49"
112
- hooks:
113
- - id: check-manifest
114
- # This is a slow hook, so only run this if --hook-stage manual is passed
115
- stages: [manual]
116
- additional_dependencies: [cmake, ninja]
117
-
118
- # Check for spelling
119
- # Use tools/codespell_ignore_lines_from_errors.py
120
- # to rebuild .codespell-ignore-lines
121
- - repo: https://github.com/codespell-project/codespell
122
- rev: "v2.2.6"
123
- hooks:
124
- - id: codespell
125
- exclude: ".supp$"
126
- args: ["-x.codespell-ignore-lines", "-Lccompiler"]
127
-
128
- # Check for common shell mistakes
129
- - repo: https://github.com/shellcheck-py/shellcheck-py
130
- rev: "v0.9.0.6"
131
- hooks:
132
- - id: shellcheck
133
-
134
- # Disallow some common capitalization mistakes
135
- - repo: local
136
- hooks:
137
- - id: disallow-caps
138
- name: Disallow improper capitalization
139
- language: pygrep
140
- entry: PyBind|\bNumpy\b|Cmake|CCache|PyTest
141
- exclude: ^\.pre-commit-config.yaml$
142
-
143
- # PyLint has native support - not always usable, but works for us
144
- - repo: https://github.com/PyCQA/pylint
145
- rev: "v3.0.3"
146
- hooks:
147
- - id: pylint
148
- files: ^pybind11
149
-
150
- - repo: https://github.com/python-jsonschema/check-jsonschema
151
- rev: 0.28.0
152
- hooks:
153
- - id: check-readthedocs
154
- - id: check-github-workflows
155
- - id: check-dependabot
 
1
+ # To use:
2
+ #
3
+ # pre-commit run -a
4
+ #
5
+ # Or:
6
+ #
7
+ # pre-commit install # (runs every time you commit in git)
8
+ #
9
+ # To update this file:
10
+ #
11
+ # pre-commit autoupdate
12
+ #
13
+ # See https://github.com/pre-commit/pre-commit
14
+
15
+
16
+ ci:
17
+ autoupdate_commit_msg: "chore(deps): update pre-commit hooks"
18
+ autofix_commit_msg: "style: pre-commit fixes"
19
+ autoupdate_schedule: monthly
20
+
21
+ # third-party content
22
+ exclude: ^tools/JoinPaths.cmake$
23
+
24
+ repos:
25
+
26
+ # Clang format the codebase automatically
27
+ - repo: https://github.com/pre-commit/mirrors-clang-format
28
+ rev: "v17.0.6"
29
+ hooks:
30
+ - id: clang-format
31
+ types_or: [c++, c, cuda]
32
+
33
+ # Ruff, the Python auto-correcting linter/formatter written in Rust
34
+ - repo: https://github.com/astral-sh/ruff-pre-commit
35
+ rev: v0.2.0
36
+ hooks:
37
+ - id: ruff
38
+ args: ["--fix", "--show-fixes"]
39
+ - id: ruff-format
40
+
41
+ # Check static types with mypy
42
+ - repo: https://github.com/pre-commit/mirrors-mypy
43
+ rev: "v1.8.0"
44
+ hooks:
45
+ - id: mypy
46
+ args: []
47
+ exclude: ^(tests|docs)/
48
+ additional_dependencies:
49
+ - markdown-it-py<3 # Drop this together with dropping Python 3.7 support.
50
+ - nox
51
+ - rich
52
+ - types-setuptools
53
+
54
+ # CMake formatting
55
+ - repo: https://github.com/cheshirekow/cmake-format-precommit
56
+ rev: "v0.6.13"
57
+ hooks:
58
+ - id: cmake-format
59
+ additional_dependencies: [pyyaml]
60
+ types: [file]
61
+ files: (\.cmake|CMakeLists.txt)(.in)?$
62
+
63
+ # Standard hooks
64
+ - repo: https://github.com/pre-commit/pre-commit-hooks
65
+ rev: "v4.5.0"
66
+ hooks:
67
+ - id: check-added-large-files
68
+ - id: check-case-conflict
69
+ - id: check-docstring-first
70
+ - id: check-merge-conflict
71
+ - id: check-symlinks
72
+ - id: check-toml
73
+ - id: check-yaml
74
+ - id: debug-statements
75
+ - id: end-of-file-fixer
76
+ - id: mixed-line-ending
77
+ - id: requirements-txt-fixer
78
+ - id: trailing-whitespace
79
+
80
+ # Also code format the docs
81
+ - repo: https://github.com/asottile/blacken-docs
82
+ rev: "1.16.0"
83
+ hooks:
84
+ - id: blacken-docs
85
+ additional_dependencies:
86
+ - black==23.*
87
+
88
+ # Changes tabs to spaces
89
+ - repo: https://github.com/Lucas-C/pre-commit-hooks
90
+ rev: "v1.5.4"
91
+ hooks:
92
+ - id: remove-tabs
93
+
94
+ # Avoid directional quotes
95
+ - repo: https://github.com/sirosen/texthooks
96
+ rev: "0.6.4"
97
+ hooks:
98
+ - id: fix-ligatures
99
+ - id: fix-smartquotes
100
+
101
+ # Checking for common mistakes
102
+ - repo: https://github.com/pre-commit/pygrep-hooks
103
+ rev: "v1.10.0"
104
+ hooks:
105
+ - id: rst-backticks
106
+ - id: rst-directive-colons
107
+ - id: rst-inline-touching-normal
108
+
109
+ # Checks the manifest for missing files (native support)
110
+ - repo: https://github.com/mgedmin/check-manifest
111
+ rev: "0.49"
112
+ hooks:
113
+ - id: check-manifest
114
+ # This is a slow hook, so only run this if --hook-stage manual is passed
115
+ stages: [manual]
116
+ additional_dependencies: [cmake, ninja]
117
+
118
+ # Check for spelling
119
+ # Use tools/codespell_ignore_lines_from_errors.py
120
+ # to rebuild .codespell-ignore-lines
121
+ - repo: https://github.com/codespell-project/codespell
122
+ rev: "v2.2.6"
123
+ hooks:
124
+ - id: codespell
125
+ exclude: ".supp$"
126
+ args: ["-x.codespell-ignore-lines", "-Lccompiler"]
127
+
128
+ # Check for common shell mistakes
129
+ - repo: https://github.com/shellcheck-py/shellcheck-py
130
+ rev: "v0.9.0.6"
131
+ hooks:
132
+ - id: shellcheck
133
+
134
+ # Disallow some common capitalization mistakes
135
+ - repo: local
136
+ hooks:
137
+ - id: disallow-caps
138
+ name: Disallow improper capitalization
139
+ language: pygrep
140
+ entry: PyBind|\bNumpy\b|Cmake|CCache|PyTest
141
+ exclude: ^\.pre-commit-config.yaml$
142
+
143
+ # PyLint has native support - not always usable, but works for us
144
+ - repo: https://github.com/PyCQA/pylint
145
+ rev: "v3.0.3"
146
+ hooks:
147
+ - id: pylint
148
+ files: ^pybind11
149
+
150
+ - repo: https://github.com/python-jsonschema/check-jsonschema
151
+ rev: 0.28.0
152
+ hooks:
153
+ - id: check-readthedocs
154
+ - id: check-github-workflows
155
+ - id: check-dependabot
third_party/CityFlow/extern/pybind11/.readthedocs.yml CHANGED
@@ -1,20 +1,20 @@
1
- # https://blog.readthedocs.com/migrate-configuration-v2/
2
-
3
- version: 2
4
-
5
- build:
6
- os: ubuntu-22.04
7
- apt_packages:
8
- - librsvg2-bin
9
- tools:
10
- python: "3.11"
11
-
12
- sphinx:
13
- configuration: docs/conf.py
14
-
15
- python:
16
- install:
17
- - requirements: docs/requirements.txt
18
-
19
- formats:
20
- - pdf
 
1
+ # https://blog.readthedocs.com/migrate-configuration-v2/
2
+
3
+ version: 2
4
+
5
+ build:
6
+ os: ubuntu-22.04
7
+ apt_packages:
8
+ - librsvg2-bin
9
+ tools:
10
+ python: "3.11"
11
+
12
+ sphinx:
13
+ configuration: docs/conf.py
14
+
15
+ python:
16
+ install:
17
+ - requirements: docs/requirements.txt
18
+
19
+ formats:
20
+ - pdf
third_party/CityFlow/extern/pybind11/CMakeLists.txt CHANGED
@@ -1,373 +1,373 @@
1
- # CMakeLists.txt -- Build system for the pybind11 modules
2
- #
3
- # Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
4
- #
5
- # All rights reserved. Use of this source code is governed by a
6
- # BSD-style license that can be found in the LICENSE file.
7
-
8
- # Propagate this policy (FindPythonInterp removal) so it can be detected later
9
- if(NOT CMAKE_VERSION VERSION_LESS "3.27")
10
- cmake_policy(GET CMP0148 _pybind11_cmp0148)
11
- endif()
12
-
13
- cmake_minimum_required(VERSION 3.5)
14
-
15
- # The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with
16
- # some versions of VS that have a patched CMake 3.11. This forces us to emulate
17
- # the behavior using the following workaround:
18
- if(${CMAKE_VERSION} VERSION_LESS 3.27)
19
- cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
20
- else()
21
- cmake_policy(VERSION 3.27)
22
- endif()
23
-
24
- if(_pybind11_cmp0148)
25
- cmake_policy(SET CMP0148 ${_pybind11_cmp0148})
26
- unset(_pybind11_cmp0148)
27
- endif()
28
-
29
- # Avoid infinite recursion if tests include this as a subdirectory
30
- if(DEFINED PYBIND11_MASTER_PROJECT)
31
- return()
32
- endif()
33
-
34
- # Extract project version from source
35
- file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/pybind11/detail/common.h"
36
- pybind11_version_defines REGEX "#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) ")
37
-
38
- foreach(ver ${pybind11_version_defines})
39
- if(ver MATCHES [[#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$]])
40
- set(PYBIND11_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}")
41
- endif()
42
- endforeach()
43
-
44
- if(PYBIND11_VERSION_PATCH MATCHES [[\.([a-zA-Z0-9]+)$]])
45
- set(pybind11_VERSION_TYPE "${CMAKE_MATCH_1}")
46
- endif()
47
- string(REGEX MATCH "^[0-9]+" PYBIND11_VERSION_PATCH "${PYBIND11_VERSION_PATCH}")
48
-
49
- project(
50
- pybind11
51
- LANGUAGES CXX
52
- VERSION "${PYBIND11_VERSION_MAJOR}.${PYBIND11_VERSION_MINOR}.${PYBIND11_VERSION_PATCH}")
53
-
54
- # Standard includes
55
- include(GNUInstallDirs)
56
- include(CMakePackageConfigHelpers)
57
- include(CMakeDependentOption)
58
-
59
- if(NOT pybind11_FIND_QUIETLY)
60
- message(STATUS "pybind11 v${pybind11_VERSION} ${pybind11_VERSION_TYPE}")
61
- endif()
62
-
63
- # Check if pybind11 is being used directly or via add_subdirectory
64
- if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
65
- ### Warn if not an out-of-source builds
66
- if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
67
- set(lines
68
- "You are building in-place. If that is not what you intended to "
69
- "do, you can clean the source directory with:\n"
70
- "rm -r CMakeCache.txt CMakeFiles/ cmake_uninstall.cmake pybind11Config.cmake "
71
- "pybind11ConfigVersion.cmake tests/CMakeFiles/\n")
72
- message(AUTHOR_WARNING ${lines})
73
- endif()
74
-
75
- set(PYBIND11_MASTER_PROJECT ON)
76
-
77
- if(OSX AND CMAKE_VERSION VERSION_LESS 3.7)
78
- # Bug in macOS CMake < 3.7 is unable to download catch
79
- message(WARNING "CMAKE 3.7+ needed on macOS to download catch, and newer HIGHLY recommended")
80
- elseif(WINDOWS AND CMAKE_VERSION VERSION_LESS 3.8)
81
- # Only tested with 3.8+ in CI.
82
- message(WARNING "CMAKE 3.8+ tested on Windows, previous versions untested")
83
- endif()
84
-
85
- message(STATUS "CMake ${CMAKE_VERSION}")
86
-
87
- if(CMAKE_CXX_STANDARD)
88
- set(CMAKE_CXX_EXTENSIONS OFF)
89
- set(CMAKE_CXX_STANDARD_REQUIRED ON)
90
- endif()
91
-
92
- set(pybind11_system "")
93
-
94
- set_property(GLOBAL PROPERTY USE_FOLDERS ON)
95
- if(CMAKE_VERSION VERSION_LESS "3.18")
96
- set(_pybind11_findpython_default OFF)
97
- else()
98
- set(_pybind11_findpython_default ON)
99
- endif()
100
- else()
101
- set(PYBIND11_MASTER_PROJECT OFF)
102
- set(pybind11_system SYSTEM)
103
- set(_pybind11_findpython_default OFF)
104
- endif()
105
-
106
- # Options
107
- option(PYBIND11_INSTALL "Install pybind11 header files?" ${PYBIND11_MASTER_PROJECT})
108
- option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT})
109
- option(PYBIND11_NOPYTHON "Disable search for Python" OFF)
110
- option(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION
111
- "To enforce that a handle_type_name<> specialization exists" OFF)
112
- option(PYBIND11_SIMPLE_GIL_MANAGEMENT
113
- "Use simpler GIL management logic that does not support disassociation" OFF)
114
- option(PYBIND11_NUMPY_1_ONLY
115
- "Disable NumPy 2 support to avoid changes to previous pybind11 versions." OFF)
116
- set(PYBIND11_INTERNALS_VERSION
117
- ""
118
- CACHE STRING "Override the ABI version, may be used to enable the unstable ABI.")
119
-
120
- if(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION)
121
- add_compile_definitions(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION)
122
- endif()
123
- if(PYBIND11_SIMPLE_GIL_MANAGEMENT)
124
- add_compile_definitions(PYBIND11_SIMPLE_GIL_MANAGEMENT)
125
- endif()
126
- if(PYBIND11_NUMPY_1_ONLY)
127
- add_compile_definitions(PYBIND11_NUMPY_1_ONLY)
128
- endif()
129
-
130
- cmake_dependent_option(
131
- USE_PYTHON_INCLUDE_DIR
132
- "Install pybind11 headers in Python include directory instead of default installation prefix"
133
- OFF "PYBIND11_INSTALL" OFF)
134
-
135
- cmake_dependent_option(PYBIND11_FINDPYTHON "Force new FindPython" ${_pybind11_findpython_default}
136
- "NOT CMAKE_VERSION VERSION_LESS 3.12" OFF)
137
-
138
- # Allow PYTHON_EXECUTABLE if in FINDPYTHON mode and building pybind11's tests
139
- # (makes transition easier while we support both modes).
140
- if(PYBIND11_MASTER_PROJECT
141
- AND PYBIND11_FINDPYTHON
142
- AND DEFINED PYTHON_EXECUTABLE
143
- AND NOT DEFINED Python_EXECUTABLE)
144
- set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
145
- endif()
146
-
147
- # NB: when adding a header don't forget to also add it to setup.py
148
- set(PYBIND11_HEADERS
149
- include/pybind11/detail/class.h
150
- include/pybind11/detail/common.h
151
- include/pybind11/detail/descr.h
152
- include/pybind11/detail/init.h
153
- include/pybind11/detail/internals.h
154
- include/pybind11/detail/type_caster_base.h
155
- include/pybind11/detail/typeid.h
156
- include/pybind11/attr.h
157
- include/pybind11/buffer_info.h
158
- include/pybind11/cast.h
159
- include/pybind11/chrono.h
160
- include/pybind11/common.h
161
- include/pybind11/complex.h
162
- include/pybind11/options.h
163
- include/pybind11/eigen.h
164
- include/pybind11/eigen/common.h
165
- include/pybind11/eigen/matrix.h
166
- include/pybind11/eigen/tensor.h
167
- include/pybind11/embed.h
168
- include/pybind11/eval.h
169
- include/pybind11/gil.h
170
- include/pybind11/gil_safe_call_once.h
171
- include/pybind11/iostream.h
172
- include/pybind11/functional.h
173
- include/pybind11/numpy.h
174
- include/pybind11/operators.h
175
- include/pybind11/pybind11.h
176
- include/pybind11/pytypes.h
177
- include/pybind11/stl.h
178
- include/pybind11/stl_bind.h
179
- include/pybind11/stl/filesystem.h
180
- include/pybind11/type_caster_pyobject_ptr.h
181
- include/pybind11/typing.h)
182
-
183
- # Compare with grep and warn if mismatched
184
- if(PYBIND11_MASTER_PROJECT AND NOT CMAKE_VERSION VERSION_LESS 3.12)
185
- file(
186
- GLOB_RECURSE _pybind11_header_check
187
- LIST_DIRECTORIES false
188
- RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
189
- CONFIGURE_DEPENDS "include/pybind11/*.h")
190
- set(_pybind11_here_only ${PYBIND11_HEADERS})
191
- set(_pybind11_disk_only ${_pybind11_header_check})
192
- list(REMOVE_ITEM _pybind11_here_only ${_pybind11_header_check})
193
- list(REMOVE_ITEM _pybind11_disk_only ${PYBIND11_HEADERS})
194
- if(_pybind11_here_only)
195
- message(AUTHOR_WARNING "PYBIND11_HEADERS has extra files:" ${_pybind11_here_only})
196
- endif()
197
- if(_pybind11_disk_only)
198
- message(AUTHOR_WARNING "PYBIND11_HEADERS is missing files:" ${_pybind11_disk_only})
199
- endif()
200
- endif()
201
-
202
- # CMake 3.12 added list(TRANSFORM <list> PREPEND
203
- # But we can't use it yet
204
- string(REPLACE "include/" "${CMAKE_CURRENT_SOURCE_DIR}/include/" PYBIND11_HEADERS
205
- "${PYBIND11_HEADERS}")
206
-
207
- # Cache variable so this can be used in parent projects
208
- set(pybind11_INCLUDE_DIR
209
- "${CMAKE_CURRENT_LIST_DIR}/include"
210
- CACHE INTERNAL "Directory where pybind11 headers are located")
211
-
212
- # Backward compatible variable for add_subdirectory mode
213
- if(NOT PYBIND11_MASTER_PROJECT)
214
- set(PYBIND11_INCLUDE_DIR
215
- "${pybind11_INCLUDE_DIR}"
216
- CACHE INTERNAL "")
217
- endif()
218
-
219
- # Note: when creating targets, you cannot use if statements at configure time -
220
- # you need generator expressions, because those will be placed in the target file.
221
- # You can also place ifs *in* the Config.in, but not here.
222
-
223
- # This section builds targets, but does *not* touch Python
224
- # Non-IMPORT targets cannot be defined twice
225
- if(NOT TARGET pybind11_headers)
226
- # Build the headers-only target (no Python included):
227
- # (long name used here to keep this from clashing in subdirectory mode)
228
- add_library(pybind11_headers INTERFACE)
229
- add_library(pybind11::pybind11_headers ALIAS pybind11_headers) # to match exported target
230
- add_library(pybind11::headers ALIAS pybind11_headers) # easier to use/remember
231
-
232
- target_include_directories(
233
- pybind11_headers ${pybind11_system} INTERFACE $<BUILD_INTERFACE:${pybind11_INCLUDE_DIR}>
234
- $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
235
-
236
- target_compile_features(pybind11_headers INTERFACE cxx_inheriting_constructors cxx_user_literals
237
- cxx_right_angle_brackets)
238
- if(NOT "${PYBIND11_INTERNALS_VERSION}" STREQUAL "")
239
- target_compile_definitions(
240
- pybind11_headers INTERFACE "PYBIND11_INTERNALS_VERSION=${PYBIND11_INTERNALS_VERSION}")
241
- endif()
242
- else()
243
- # It is invalid to install a target twice, too.
244
- set(PYBIND11_INSTALL OFF)
245
- endif()
246
-
247
- include("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11Common.cmake")
248
- # https://github.com/jtojnar/cmake-snips/#concatenating-paths-when-building-pkg-config-files
249
- # TODO: cmake 3.20 adds the cmake_path() function, which obsoletes this snippet
250
- include("${CMAKE_CURRENT_SOURCE_DIR}/tools/JoinPaths.cmake")
251
-
252
- # Relative directory setting
253
- if(USE_PYTHON_INCLUDE_DIR AND DEFINED Python_INCLUDE_DIRS)
254
- file(RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX} ${Python_INCLUDE_DIRS})
255
- elseif(USE_PYTHON_INCLUDE_DIR AND DEFINED PYTHON_INCLUDE_DIR)
256
- file(RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX} ${PYTHON_INCLUDE_DIRS})
257
- endif()
258
-
259
- if(PYBIND11_INSTALL)
260
- install(DIRECTORY ${pybind11_INCLUDE_DIR}/pybind11 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
261
- set(PYBIND11_CMAKECONFIG_INSTALL_DIR
262
- "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}"
263
- CACHE STRING "install path for pybind11Config.cmake")
264
-
265
- if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
266
- set(pybind11_INCLUDEDIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
267
- else()
268
- set(pybind11_INCLUDEDIR "\$\{PACKAGE_PREFIX_DIR\}/${CMAKE_INSTALL_INCLUDEDIR}")
269
- endif()
270
-
271
- configure_package_config_file(
272
- tools/${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
273
- INSTALL_DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
274
-
275
- if(CMAKE_VERSION VERSION_LESS 3.14)
276
- # Remove CMAKE_SIZEOF_VOID_P from ConfigVersion.cmake since the library does
277
- # not depend on architecture specific settings or libraries.
278
- set(_PYBIND11_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
279
- unset(CMAKE_SIZEOF_VOID_P)
280
-
281
- write_basic_package_version_file(
282
- ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
283
- VERSION ${PROJECT_VERSION}
284
- COMPATIBILITY AnyNewerVersion)
285
-
286
- set(CMAKE_SIZEOF_VOID_P ${_PYBIND11_CMAKE_SIZEOF_VOID_P})
287
- else()
288
- # CMake 3.14+ natively supports header-only libraries
289
- write_basic_package_version_file(
290
- ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
291
- VERSION ${PROJECT_VERSION}
292
- COMPATIBILITY AnyNewerVersion ARCH_INDEPENDENT)
293
- endif()
294
-
295
- install(
296
- FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
297
- ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
298
- tools/FindPythonLibsNew.cmake
299
- tools/pybind11Common.cmake
300
- tools/pybind11Tools.cmake
301
- tools/pybind11NewTools.cmake
302
- DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
303
-
304
- if(NOT PYBIND11_EXPORT_NAME)
305
- set(PYBIND11_EXPORT_NAME "${PROJECT_NAME}Targets")
306
- endif()
307
-
308
- install(TARGETS pybind11_headers EXPORT "${PYBIND11_EXPORT_NAME}")
309
-
310
- install(
311
- EXPORT "${PYBIND11_EXPORT_NAME}"
312
- NAMESPACE "pybind11::"
313
- DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
314
-
315
- # pkg-config support
316
- if(NOT prefix_for_pc_file)
317
- if(IS_ABSOLUTE "${CMAKE_INSTALL_DATAROOTDIR}")
318
- set(prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}")
319
- else()
320
- set(pc_datarootdir "${CMAKE_INSTALL_DATAROOTDIR}")
321
- if(CMAKE_VERSION VERSION_LESS 3.20)
322
- set(prefix_for_pc_file "\${pcfiledir}/..")
323
- while(pc_datarootdir)
324
- get_filename_component(pc_datarootdir "${pc_datarootdir}" DIRECTORY)
325
- string(APPEND prefix_for_pc_file "/..")
326
- endwhile()
327
- else()
328
- cmake_path(RELATIVE_PATH CMAKE_INSTALL_PREFIX BASE_DIRECTORY CMAKE_INSTALL_DATAROOTDIR
329
- OUTPUT_VARIABLE prefix_for_pc_file)
330
- endif()
331
- endif()
332
- endif()
333
- join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
334
- configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11.pc.in"
335
- "${CMAKE_CURRENT_BINARY_DIR}/pybind11.pc" @ONLY)
336
- install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pybind11.pc"
337
- DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig/")
338
-
339
- # Uninstall target
340
- if(PYBIND11_MASTER_PROJECT)
341
- configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake_uninstall.cmake.in"
342
- "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
343
-
344
- add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P
345
- ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
346
- endif()
347
- endif()
348
-
349
- # BUILD_TESTING takes priority, but only if this is the master project
350
- if(PYBIND11_MASTER_PROJECT AND DEFINED BUILD_TESTING)
351
- if(BUILD_TESTING)
352
- if(_pybind11_nopython)
353
- message(FATAL_ERROR "Cannot activate tests in NOPYTHON mode")
354
- else()
355
- add_subdirectory(tests)
356
- endif()
357
- endif()
358
- else()
359
- if(PYBIND11_TEST)
360
- if(_pybind11_nopython)
361
- message(FATAL_ERROR "Cannot activate tests in NOPYTHON mode")
362
- else()
363
- add_subdirectory(tests)
364
- endif()
365
- endif()
366
- endif()
367
-
368
- # Better symmetry with find_package(pybind11 CONFIG) mode.
369
- if(NOT PYBIND11_MASTER_PROJECT)
370
- set(pybind11_FOUND
371
- TRUE
372
- CACHE INTERNAL "True if pybind11 and all required components found on the system")
373
- endif()
 
1
+ # CMakeLists.txt -- Build system for the pybind11 modules
2
+ #
3
+ # Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
4
+ #
5
+ # All rights reserved. Use of this source code is governed by a
6
+ # BSD-style license that can be found in the LICENSE file.
7
+
8
+ # Propagate this policy (FindPythonInterp removal) so it can be detected later
9
+ if(NOT CMAKE_VERSION VERSION_LESS "3.27")
10
+ cmake_policy(GET CMP0148 _pybind11_cmp0148)
11
+ endif()
12
+
13
+ cmake_minimum_required(VERSION 3.5)
14
+
15
+ # The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with
16
+ # some versions of VS that have a patched CMake 3.11. This forces us to emulate
17
+ # the behavior using the following workaround:
18
+ if(${CMAKE_VERSION} VERSION_LESS 3.27)
19
+ cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
20
+ else()
21
+ cmake_policy(VERSION 3.27)
22
+ endif()
23
+
24
+ if(_pybind11_cmp0148)
25
+ cmake_policy(SET CMP0148 ${_pybind11_cmp0148})
26
+ unset(_pybind11_cmp0148)
27
+ endif()
28
+
29
+ # Avoid infinite recursion if tests include this as a subdirectory
30
+ if(DEFINED PYBIND11_MASTER_PROJECT)
31
+ return()
32
+ endif()
33
+
34
+ # Extract project version from source
35
+ file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/pybind11/detail/common.h"
36
+ pybind11_version_defines REGEX "#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) ")
37
+
38
+ foreach(ver ${pybind11_version_defines})
39
+ if(ver MATCHES [[#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$]])
40
+ set(PYBIND11_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}")
41
+ endif()
42
+ endforeach()
43
+
44
+ if(PYBIND11_VERSION_PATCH MATCHES [[\.([a-zA-Z0-9]+)$]])
45
+ set(pybind11_VERSION_TYPE "${CMAKE_MATCH_1}")
46
+ endif()
47
+ string(REGEX MATCH "^[0-9]+" PYBIND11_VERSION_PATCH "${PYBIND11_VERSION_PATCH}")
48
+
49
+ project(
50
+ pybind11
51
+ LANGUAGES CXX
52
+ VERSION "${PYBIND11_VERSION_MAJOR}.${PYBIND11_VERSION_MINOR}.${PYBIND11_VERSION_PATCH}")
53
+
54
+ # Standard includes
55
+ include(GNUInstallDirs)
56
+ include(CMakePackageConfigHelpers)
57
+ include(CMakeDependentOption)
58
+
59
+ if(NOT pybind11_FIND_QUIETLY)
60
+ message(STATUS "pybind11 v${pybind11_VERSION} ${pybind11_VERSION_TYPE}")
61
+ endif()
62
+
63
+ # Check if pybind11 is being used directly or via add_subdirectory
64
+ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
65
+ ### Warn if not an out-of-source builds
66
+ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
67
+ set(lines
68
+ "You are building in-place. If that is not what you intended to "
69
+ "do, you can clean the source directory with:\n"
70
+ "rm -r CMakeCache.txt CMakeFiles/ cmake_uninstall.cmake pybind11Config.cmake "
71
+ "pybind11ConfigVersion.cmake tests/CMakeFiles/\n")
72
+ message(AUTHOR_WARNING ${lines})
73
+ endif()
74
+
75
+ set(PYBIND11_MASTER_PROJECT ON)
76
+
77
+ if(OSX AND CMAKE_VERSION VERSION_LESS 3.7)
78
+ # Bug in macOS CMake < 3.7 is unable to download catch
79
+ message(WARNING "CMAKE 3.7+ needed on macOS to download catch, and newer HIGHLY recommended")
80
+ elseif(WINDOWS AND CMAKE_VERSION VERSION_LESS 3.8)
81
+ # Only tested with 3.8+ in CI.
82
+ message(WARNING "CMAKE 3.8+ tested on Windows, previous versions untested")
83
+ endif()
84
+
85
+ message(STATUS "CMake ${CMAKE_VERSION}")
86
+
87
+ if(CMAKE_CXX_STANDARD)
88
+ set(CMAKE_CXX_EXTENSIONS OFF)
89
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
90
+ endif()
91
+
92
+ set(pybind11_system "")
93
+
94
+ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
95
+ if(CMAKE_VERSION VERSION_LESS "3.18")
96
+ set(_pybind11_findpython_default OFF)
97
+ else()
98
+ set(_pybind11_findpython_default ON)
99
+ endif()
100
+ else()
101
+ set(PYBIND11_MASTER_PROJECT OFF)
102
+ set(pybind11_system SYSTEM)
103
+ set(_pybind11_findpython_default OFF)
104
+ endif()
105
+
106
+ # Options
107
+ option(PYBIND11_INSTALL "Install pybind11 header files?" ${PYBIND11_MASTER_PROJECT})
108
+ option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT})
109
+ option(PYBIND11_NOPYTHON "Disable search for Python" OFF)
110
+ option(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION
111
+ "To enforce that a handle_type_name<> specialization exists" OFF)
112
+ option(PYBIND11_SIMPLE_GIL_MANAGEMENT
113
+ "Use simpler GIL management logic that does not support disassociation" OFF)
114
+ option(PYBIND11_NUMPY_1_ONLY
115
+ "Disable NumPy 2 support to avoid changes to previous pybind11 versions." OFF)
116
+ set(PYBIND11_INTERNALS_VERSION
117
+ ""
118
+ CACHE STRING "Override the ABI version, may be used to enable the unstable ABI.")
119
+
120
+ if(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION)
121
+ add_compile_definitions(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION)
122
+ endif()
123
+ if(PYBIND11_SIMPLE_GIL_MANAGEMENT)
124
+ add_compile_definitions(PYBIND11_SIMPLE_GIL_MANAGEMENT)
125
+ endif()
126
+ if(PYBIND11_NUMPY_1_ONLY)
127
+ add_compile_definitions(PYBIND11_NUMPY_1_ONLY)
128
+ endif()
129
+
130
+ cmake_dependent_option(
131
+ USE_PYTHON_INCLUDE_DIR
132
+ "Install pybind11 headers in Python include directory instead of default installation prefix"
133
+ OFF "PYBIND11_INSTALL" OFF)
134
+
135
+ cmake_dependent_option(PYBIND11_FINDPYTHON "Force new FindPython" ${_pybind11_findpython_default}
136
+ "NOT CMAKE_VERSION VERSION_LESS 3.12" OFF)
137
+
138
+ # Allow PYTHON_EXECUTABLE if in FINDPYTHON mode and building pybind11's tests
139
+ # (makes transition easier while we support both modes).
140
+ if(PYBIND11_MASTER_PROJECT
141
+ AND PYBIND11_FINDPYTHON
142
+ AND DEFINED PYTHON_EXECUTABLE
143
+ AND NOT DEFINED Python_EXECUTABLE)
144
+ set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
145
+ endif()
146
+
147
+ # NB: when adding a header don't forget to also add it to setup.py
148
+ set(PYBIND11_HEADERS
149
+ include/pybind11/detail/class.h
150
+ include/pybind11/detail/common.h
151
+ include/pybind11/detail/descr.h
152
+ include/pybind11/detail/init.h
153
+ include/pybind11/detail/internals.h
154
+ include/pybind11/detail/type_caster_base.h
155
+ include/pybind11/detail/typeid.h
156
+ include/pybind11/attr.h
157
+ include/pybind11/buffer_info.h
158
+ include/pybind11/cast.h
159
+ include/pybind11/chrono.h
160
+ include/pybind11/common.h
161
+ include/pybind11/complex.h
162
+ include/pybind11/options.h
163
+ include/pybind11/eigen.h
164
+ include/pybind11/eigen/common.h
165
+ include/pybind11/eigen/matrix.h
166
+ include/pybind11/eigen/tensor.h
167
+ include/pybind11/embed.h
168
+ include/pybind11/eval.h
169
+ include/pybind11/gil.h
170
+ include/pybind11/gil_safe_call_once.h
171
+ include/pybind11/iostream.h
172
+ include/pybind11/functional.h
173
+ include/pybind11/numpy.h
174
+ include/pybind11/operators.h
175
+ include/pybind11/pybind11.h
176
+ include/pybind11/pytypes.h
177
+ include/pybind11/stl.h
178
+ include/pybind11/stl_bind.h
179
+ include/pybind11/stl/filesystem.h
180
+ include/pybind11/type_caster_pyobject_ptr.h
181
+ include/pybind11/typing.h)
182
+
183
+ # Compare with grep and warn if mismatched
184
+ if(PYBIND11_MASTER_PROJECT AND NOT CMAKE_VERSION VERSION_LESS 3.12)
185
+ file(
186
+ GLOB_RECURSE _pybind11_header_check
187
+ LIST_DIRECTORIES false
188
+ RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
189
+ CONFIGURE_DEPENDS "include/pybind11/*.h")
190
+ set(_pybind11_here_only ${PYBIND11_HEADERS})
191
+ set(_pybind11_disk_only ${_pybind11_header_check})
192
+ list(REMOVE_ITEM _pybind11_here_only ${_pybind11_header_check})
193
+ list(REMOVE_ITEM _pybind11_disk_only ${PYBIND11_HEADERS})
194
+ if(_pybind11_here_only)
195
+ message(AUTHOR_WARNING "PYBIND11_HEADERS has extra files:" ${_pybind11_here_only})
196
+ endif()
197
+ if(_pybind11_disk_only)
198
+ message(AUTHOR_WARNING "PYBIND11_HEADERS is missing files:" ${_pybind11_disk_only})
199
+ endif()
200
+ endif()
201
+
202
+ # CMake 3.12 added list(TRANSFORM <list> PREPEND
203
+ # But we can't use it yet
204
+ string(REPLACE "include/" "${CMAKE_CURRENT_SOURCE_DIR}/include/" PYBIND11_HEADERS
205
+ "${PYBIND11_HEADERS}")
206
+
207
+ # Cache variable so this can be used in parent projects
208
+ set(pybind11_INCLUDE_DIR
209
+ "${CMAKE_CURRENT_LIST_DIR}/include"
210
+ CACHE INTERNAL "Directory where pybind11 headers are located")
211
+
212
+ # Backward compatible variable for add_subdirectory mode
213
+ if(NOT PYBIND11_MASTER_PROJECT)
214
+ set(PYBIND11_INCLUDE_DIR
215
+ "${pybind11_INCLUDE_DIR}"
216
+ CACHE INTERNAL "")
217
+ endif()
218
+
219
+ # Note: when creating targets, you cannot use if statements at configure time -
220
+ # you need generator expressions, because those will be placed in the target file.
221
+ # You can also place ifs *in* the Config.in, but not here.
222
+
223
+ # This section builds targets, but does *not* touch Python
224
+ # Non-IMPORT targets cannot be defined twice
225
+ if(NOT TARGET pybind11_headers)
226
+ # Build the headers-only target (no Python included):
227
+ # (long name used here to keep this from clashing in subdirectory mode)
228
+ add_library(pybind11_headers INTERFACE)
229
+ add_library(pybind11::pybind11_headers ALIAS pybind11_headers) # to match exported target
230
+ add_library(pybind11::headers ALIAS pybind11_headers) # easier to use/remember
231
+
232
+ target_include_directories(
233
+ pybind11_headers ${pybind11_system} INTERFACE $<BUILD_INTERFACE:${pybind11_INCLUDE_DIR}>
234
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
235
+
236
+ target_compile_features(pybind11_headers INTERFACE cxx_inheriting_constructors cxx_user_literals
237
+ cxx_right_angle_brackets)
238
+ if(NOT "${PYBIND11_INTERNALS_VERSION}" STREQUAL "")
239
+ target_compile_definitions(
240
+ pybind11_headers INTERFACE "PYBIND11_INTERNALS_VERSION=${PYBIND11_INTERNALS_VERSION}")
241
+ endif()
242
+ else()
243
+ # It is invalid to install a target twice, too.
244
+ set(PYBIND11_INSTALL OFF)
245
+ endif()
246
+
247
+ include("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11Common.cmake")
248
+ # https://github.com/jtojnar/cmake-snips/#concatenating-paths-when-building-pkg-config-files
249
+ # TODO: cmake 3.20 adds the cmake_path() function, which obsoletes this snippet
250
+ include("${CMAKE_CURRENT_SOURCE_DIR}/tools/JoinPaths.cmake")
251
+
252
+ # Relative directory setting
253
+ if(USE_PYTHON_INCLUDE_DIR AND DEFINED Python_INCLUDE_DIRS)
254
+ file(RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX} ${Python_INCLUDE_DIRS})
255
+ elseif(USE_PYTHON_INCLUDE_DIR AND DEFINED PYTHON_INCLUDE_DIR)
256
+ file(RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX} ${PYTHON_INCLUDE_DIRS})
257
+ endif()
258
+
259
+ if(PYBIND11_INSTALL)
260
+ install(DIRECTORY ${pybind11_INCLUDE_DIR}/pybind11 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
261
+ set(PYBIND11_CMAKECONFIG_INSTALL_DIR
262
+ "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}"
263
+ CACHE STRING "install path for pybind11Config.cmake")
264
+
265
+ if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
266
+ set(pybind11_INCLUDEDIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
267
+ else()
268
+ set(pybind11_INCLUDEDIR "\$\{PACKAGE_PREFIX_DIR\}/${CMAKE_INSTALL_INCLUDEDIR}")
269
+ endif()
270
+
271
+ configure_package_config_file(
272
+ tools/${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
273
+ INSTALL_DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
274
+
275
+ if(CMAKE_VERSION VERSION_LESS 3.14)
276
+ # Remove CMAKE_SIZEOF_VOID_P from ConfigVersion.cmake since the library does
277
+ # not depend on architecture specific settings or libraries.
278
+ set(_PYBIND11_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
279
+ unset(CMAKE_SIZEOF_VOID_P)
280
+
281
+ write_basic_package_version_file(
282
+ ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
283
+ VERSION ${PROJECT_VERSION}
284
+ COMPATIBILITY AnyNewerVersion)
285
+
286
+ set(CMAKE_SIZEOF_VOID_P ${_PYBIND11_CMAKE_SIZEOF_VOID_P})
287
+ else()
288
+ # CMake 3.14+ natively supports header-only libraries
289
+ write_basic_package_version_file(
290
+ ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
291
+ VERSION ${PROJECT_VERSION}
292
+ COMPATIBILITY AnyNewerVersion ARCH_INDEPENDENT)
293
+ endif()
294
+
295
+ install(
296
+ FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
297
+ ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
298
+ tools/FindPythonLibsNew.cmake
299
+ tools/pybind11Common.cmake
300
+ tools/pybind11Tools.cmake
301
+ tools/pybind11NewTools.cmake
302
+ DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
303
+
304
+ if(NOT PYBIND11_EXPORT_NAME)
305
+ set(PYBIND11_EXPORT_NAME "${PROJECT_NAME}Targets")
306
+ endif()
307
+
308
+ install(TARGETS pybind11_headers EXPORT "${PYBIND11_EXPORT_NAME}")
309
+
310
+ install(
311
+ EXPORT "${PYBIND11_EXPORT_NAME}"
312
+ NAMESPACE "pybind11::"
313
+ DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
314
+
315
+ # pkg-config support
316
+ if(NOT prefix_for_pc_file)
317
+ if(IS_ABSOLUTE "${CMAKE_INSTALL_DATAROOTDIR}")
318
+ set(prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}")
319
+ else()
320
+ set(pc_datarootdir "${CMAKE_INSTALL_DATAROOTDIR}")
321
+ if(CMAKE_VERSION VERSION_LESS 3.20)
322
+ set(prefix_for_pc_file "\${pcfiledir}/..")
323
+ while(pc_datarootdir)
324
+ get_filename_component(pc_datarootdir "${pc_datarootdir}" DIRECTORY)
325
+ string(APPEND prefix_for_pc_file "/..")
326
+ endwhile()
327
+ else()
328
+ cmake_path(RELATIVE_PATH CMAKE_INSTALL_PREFIX BASE_DIRECTORY CMAKE_INSTALL_DATAROOTDIR
329
+ OUTPUT_VARIABLE prefix_for_pc_file)
330
+ endif()
331
+ endif()
332
+ endif()
333
+ join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
334
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11.pc.in"
335
+ "${CMAKE_CURRENT_BINARY_DIR}/pybind11.pc" @ONLY)
336
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pybind11.pc"
337
+ DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig/")
338
+
339
+ # Uninstall target
340
+ if(PYBIND11_MASTER_PROJECT)
341
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake_uninstall.cmake.in"
342
+ "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
343
+
344
+ add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P
345
+ ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
346
+ endif()
347
+ endif()
348
+
349
+ # BUILD_TESTING takes priority, but only if this is the master project
350
+ if(PYBIND11_MASTER_PROJECT AND DEFINED BUILD_TESTING)
351
+ if(BUILD_TESTING)
352
+ if(_pybind11_nopython)
353
+ message(FATAL_ERROR "Cannot activate tests in NOPYTHON mode")
354
+ else()
355
+ add_subdirectory(tests)
356
+ endif()
357
+ endif()
358
+ else()
359
+ if(PYBIND11_TEST)
360
+ if(_pybind11_nopython)
361
+ message(FATAL_ERROR "Cannot activate tests in NOPYTHON mode")
362
+ else()
363
+ add_subdirectory(tests)
364
+ endif()
365
+ endif()
366
+ endif()
367
+
368
+ # Better symmetry with find_package(pybind11 CONFIG) mode.
369
+ if(NOT PYBIND11_MASTER_PROJECT)
370
+ set(pybind11_FOUND
371
+ TRUE
372
+ CACHE INTERNAL "True if pybind11 and all required components found on the system")
373
+ endif()
third_party/CityFlow/extern/pybind11/LICENSE CHANGED
@@ -1,29 +1,29 @@
1
- Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>, All rights reserved.
2
-
3
- Redistribution and use in source and binary forms, with or without
4
- modification, are permitted provided that the following conditions are met:
5
-
6
- 1. Redistributions of source code must retain the above copyright notice, this
7
- list of conditions and the following disclaimer.
8
-
9
- 2. Redistributions in binary form must reproduce the above copyright notice,
10
- this list of conditions and the following disclaimer in the documentation
11
- and/or other materials provided with the distribution.
12
-
13
- 3. Neither the name of the copyright holder nor the names of its contributors
14
- may be used to endorse or promote products derived from this software
15
- without specific prior written permission.
16
-
17
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
-
28
- Please also refer to the file .github/CONTRIBUTING.md, which clarifies licensing of
29
- external contributions to this project including patches, pull requests, etc.
 
1
+ Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>, All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this
7
+ list of conditions and the following disclaimer.
8
+
9
+ 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+
13
+ 3. Neither the name of the copyright holder nor the names of its contributors
14
+ may be used to endorse or promote products derived from this software
15
+ without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ Please also refer to the file .github/CONTRIBUTING.md, which clarifies licensing of
29
+ external contributions to this project including patches, pull requests, etc.
third_party/CityFlow/extern/pybind11/MANIFEST.in CHANGED
@@ -1,6 +1,6 @@
1
- prune tests
2
- recursive-include pybind11/include/pybind11 *.h
3
- recursive-include pybind11 *.py
4
- recursive-include pybind11 py.typed
5
- include pybind11/share/cmake/pybind11/*.cmake
6
- include LICENSE README.rst SECURITY.md pyproject.toml setup.py setup.cfg
 
1
+ prune tests
2
+ recursive-include pybind11/include/pybind11 *.h
3
+ recursive-include pybind11 *.py
4
+ recursive-include pybind11 py.typed
5
+ include pybind11/share/cmake/pybind11/*.cmake
6
+ include LICENSE README.rst SECURITY.md pyproject.toml setup.py setup.cfg
third_party/CityFlow/extern/pybind11/README.rst CHANGED
@@ -1,181 +1,181 @@
1
- .. figure:: https://github.com/pybind/pybind11/raw/master/docs/pybind11-logo.png
2
- :alt: pybind11 logo
3
-
4
- **pybind11 — Seamless operability between C++11 and Python**
5
-
6
- |Latest Documentation Status| |Stable Documentation Status| |Gitter chat| |GitHub Discussions| |CI| |Build status|
7
-
8
- |Repology| |PyPI package| |Conda-forge| |Python Versions|
9
-
10
- `Setuptools example <https://github.com/pybind/python_example>`_
11
- • `Scikit-build example <https://github.com/pybind/scikit_build_example>`_
12
- • `CMake example <https://github.com/pybind/cmake_example>`_
13
-
14
- .. start
15
-
16
-
17
- **pybind11** is a lightweight header-only library that exposes C++ types
18
- in Python and vice versa, mainly to create Python bindings of existing
19
- C++ code. Its goals and syntax are similar to the excellent
20
- `Boost.Python <http://www.boost.org/doc/libs/1_58_0/libs/python/doc/>`_
21
- library by David Abrahams: to minimize boilerplate code in traditional
22
- extension modules by inferring type information using compile-time
23
- introspection.
24
-
25
- The main issue with Boost.Python—and the reason for creating such a
26
- similar project—is Boost. Boost is an enormously large and complex suite
27
- of utility libraries that works with almost every C++ compiler in
28
- existence. This compatibility has its cost: arcane template tricks and
29
- workarounds are necessary to support the oldest and buggiest of compiler
30
- specimens. Now that C++11-compatible compilers are widely available,
31
- this heavy machinery has become an excessively large and unnecessary
32
- dependency.
33
-
34
- Think of this library as a tiny self-contained version of Boost.Python
35
- with everything stripped away that isn't relevant for binding
36
- generation. Without comments, the core header files only require ~4K
37
- lines of code and depend on Python (3.6+, or PyPy) and the C++
38
- standard library. This compact implementation was possible thanks to
39
- some C++11 language features (specifically: tuples, lambda functions and
40
- variadic templates). Since its creation, this library has grown beyond
41
- Boost.Python in many ways, leading to dramatically simpler binding code in many
42
- common situations.
43
-
44
- Tutorial and reference documentation is provided at
45
- `pybind11.readthedocs.io <https://pybind11.readthedocs.io/en/latest>`_.
46
- A PDF version of the manual is available
47
- `here <https://pybind11.readthedocs.io/_/downloads/en/latest/pdf/>`_.
48
- And the source code is always available at
49
- `github.com/pybind/pybind11 <https://github.com/pybind/pybind11>`_.
50
-
51
-
52
- Core features
53
- -------------
54
-
55
-
56
- pybind11 can map the following core C++ features to Python:
57
-
58
- - Functions accepting and returning custom data structures per value,
59
- reference, or pointer
60
- - Instance methods and static methods
61
- - Overloaded functions
62
- - Instance attributes and static attributes
63
- - Arbitrary exception types
64
- - Enumerations
65
- - Callbacks
66
- - Iterators and ranges
67
- - Custom operators
68
- - Single and multiple inheritance
69
- - STL data structures
70
- - Smart pointers with reference counting like ``std::shared_ptr``
71
- - Internal references with correct reference counting
72
- - C++ classes with virtual (and pure virtual) methods can be extended
73
- in Python
74
- - Integrated NumPy support (NumPy 2 requires pybind11 2.12+)
75
-
76
- Goodies
77
- -------
78
-
79
- In addition to the core functionality, pybind11 provides some extra
80
- goodies:
81
-
82
- - Python 3.6+, and PyPy3 7.3 are supported with an implementation-agnostic
83
- interface (pybind11 2.9 was the last version to support Python 2 and 3.5).
84
-
85
- - It is possible to bind C++11 lambda functions with captured
86
- variables. The lambda capture data is stored inside the resulting
87
- Python function object.
88
-
89
- - pybind11 uses C++11 move constructors and move assignment operators
90
- whenever possible to efficiently transfer custom data types.
91
-
92
- - It's easy to expose the internal storage of custom data types through
93
- Pythons' buffer protocols. This is handy e.g. for fast conversion
94
- between C++ matrix classes like Eigen and NumPy without expensive
95
- copy operations.
96
-
97
- - pybind11 can automatically vectorize functions so that they are
98
- transparently applied to all entries of one or more NumPy array
99
- arguments.
100
-
101
- - Python's slice-based access and assignment operations can be
102
- supported with just a few lines of code.
103
-
104
- - Everything is contained in just a few header files; there is no need
105
- to link against any additional libraries.
106
-
107
- - Binaries are generally smaller by a factor of at least 2 compared to
108
- equivalent bindings generated by Boost.Python. A recent pybind11
109
- conversion of PyRosetta, an enormous Boost.Python binding project,
110
- `reported <https://graylab.jhu.edu/Sergey/2016.RosettaCon/PyRosetta-4.pdf>`_
111
- a binary size reduction of **5.4x** and compile time reduction by
112
- **5.8x**.
113
-
114
- - Function signatures are precomputed at compile time (using
115
- ``constexpr``), leading to smaller binaries.
116
-
117
- - With little extra effort, C++ types can be pickled and unpickled
118
- similar to regular Python objects.
119
-
120
- Supported compilers
121
- -------------------
122
-
123
- 1. Clang/LLVM 3.3 or newer (for Apple Xcode's clang, this is 5.0.0 or
124
- newer)
125
- 2. GCC 4.8 or newer
126
- 3. Microsoft Visual Studio 2017 or newer
127
- 4. Intel classic C++ compiler 18 or newer (ICC 20.2 tested in CI)
128
- 5. Cygwin/GCC (previously tested on 2.5.1)
129
- 6. NVCC (CUDA 11.0 tested in CI)
130
- 7. NVIDIA PGI (20.9 tested in CI)
131
-
132
- About
133
- -----
134
-
135
- This project was created by `Wenzel
136
- Jakob <http://rgl.epfl.ch/people/wjakob>`_. Significant features and/or
137
- improvements to the code were contributed by Jonas Adler, Lori A. Burns,
138
- Sylvain Corlay, Eric Cousineau, Aaron Gokaslan, Ralf Grosse-Kunstleve, Trent Houliston, Axel
139
- Huebl, @hulucc, Yannick Jadoul, Sergey Lyskov, Johan Mabille, Tomasz Miąsko,
140
- Dean Moldovan, Ben Pritchard, Jason Rhinelander, Boris Schäling, Pim
141
- Schellart, Henry Schreiner, Ivan Smirnov, Boris Staletic, and Patrick Stewart.
142
-
143
- We thank Google for a generous financial contribution to the continuous
144
- integration infrastructure used by this project.
145
-
146
-
147
- Contributing
148
- ~~~~~~~~~~~~
149
-
150
- See the `contributing
151
- guide <https://github.com/pybind/pybind11/blob/master/.github/CONTRIBUTING.md>`_
152
- for information on building and contributing to pybind11.
153
-
154
- License
155
- ~~~~~~~
156
-
157
- pybind11 is provided under a BSD-style license that can be found in the
158
- `LICENSE <https://github.com/pybind/pybind11/blob/master/LICENSE>`_
159
- file. By using, distributing, or contributing to this project, you agree
160
- to the terms and conditions of this license.
161
-
162
- .. |Latest Documentation Status| image:: https://readthedocs.org/projects/pybind11/badge?version=latest
163
- :target: http://pybind11.readthedocs.org/en/latest
164
- .. |Stable Documentation Status| image:: https://img.shields.io/badge/docs-stable-blue.svg
165
- :target: http://pybind11.readthedocs.org/en/stable
166
- .. |Gitter chat| image:: https://img.shields.io/gitter/room/gitterHQ/gitter.svg
167
- :target: https://gitter.im/pybind/Lobby
168
- .. |CI| image:: https://github.com/pybind/pybind11/workflows/CI/badge.svg
169
- :target: https://github.com/pybind/pybind11/actions
170
- .. |Build status| image:: https://ci.appveyor.com/api/projects/status/riaj54pn4h08xy40?svg=true
171
- :target: https://ci.appveyor.com/project/wjakob/pybind11
172
- .. |PyPI package| image:: https://img.shields.io/pypi/v/pybind11.svg
173
- :target: https://pypi.org/project/pybind11/
174
- .. |Conda-forge| image:: https://img.shields.io/conda/vn/conda-forge/pybind11.svg
175
- :target: https://github.com/conda-forge/pybind11-feedstock
176
- .. |Repology| image:: https://repology.org/badge/latest-versions/python:pybind11.svg
177
- :target: https://repology.org/project/python:pybind11/versions
178
- .. |Python Versions| image:: https://img.shields.io/pypi/pyversions/pybind11.svg
179
- :target: https://pypi.org/project/pybind11/
180
- .. |GitHub Discussions| image:: https://img.shields.io/static/v1?label=Discussions&message=Ask&color=blue&logo=github
181
- :target: https://github.com/pybind/pybind11/discussions
 
1
+ .. figure:: https://github.com/pybind/pybind11/raw/master/docs/pybind11-logo.png
2
+ :alt: pybind11 logo
3
+
4
+ **pybind11 — Seamless operability between C++11 and Python**
5
+
6
+ |Latest Documentation Status| |Stable Documentation Status| |Gitter chat| |GitHub Discussions| |CI| |Build status|
7
+
8
+ |Repology| |PyPI package| |Conda-forge| |Python Versions|
9
+
10
+ `Setuptools example <https://github.com/pybind/python_example>`_
11
+ • `Scikit-build example <https://github.com/pybind/scikit_build_example>`_
12
+ • `CMake example <https://github.com/pybind/cmake_example>`_
13
+
14
+ .. start
15
+
16
+
17
+ **pybind11** is a lightweight header-only library that exposes C++ types
18
+ in Python and vice versa, mainly to create Python bindings of existing
19
+ C++ code. Its goals and syntax are similar to the excellent
20
+ `Boost.Python <http://www.boost.org/doc/libs/1_58_0/libs/python/doc/>`_
21
+ library by David Abrahams: to minimize boilerplate code in traditional
22
+ extension modules by inferring type information using compile-time
23
+ introspection.
24
+
25
+ The main issue with Boost.Python—and the reason for creating such a
26
+ similar project—is Boost. Boost is an enormously large and complex suite
27
+ of utility libraries that works with almost every C++ compiler in
28
+ existence. This compatibility has its cost: arcane template tricks and
29
+ workarounds are necessary to support the oldest and buggiest of compiler
30
+ specimens. Now that C++11-compatible compilers are widely available,
31
+ this heavy machinery has become an excessively large and unnecessary
32
+ dependency.
33
+
34
+ Think of this library as a tiny self-contained version of Boost.Python
35
+ with everything stripped away that isn't relevant for binding
36
+ generation. Without comments, the core header files only require ~4K
37
+ lines of code and depend on Python (3.6+, or PyPy) and the C++
38
+ standard library. This compact implementation was possible thanks to
39
+ some C++11 language features (specifically: tuples, lambda functions and
40
+ variadic templates). Since its creation, this library has grown beyond
41
+ Boost.Python in many ways, leading to dramatically simpler binding code in many
42
+ common situations.
43
+
44
+ Tutorial and reference documentation is provided at
45
+ `pybind11.readthedocs.io <https://pybind11.readthedocs.io/en/latest>`_.
46
+ A PDF version of the manual is available
47
+ `here <https://pybind11.readthedocs.io/_/downloads/en/latest/pdf/>`_.
48
+ And the source code is always available at
49
+ `github.com/pybind/pybind11 <https://github.com/pybind/pybind11>`_.
50
+
51
+
52
+ Core features
53
+ -------------
54
+
55
+
56
+ pybind11 can map the following core C++ features to Python:
57
+
58
+ - Functions accepting and returning custom data structures per value,
59
+ reference, or pointer
60
+ - Instance methods and static methods
61
+ - Overloaded functions
62
+ - Instance attributes and static attributes
63
+ - Arbitrary exception types
64
+ - Enumerations
65
+ - Callbacks
66
+ - Iterators and ranges
67
+ - Custom operators
68
+ - Single and multiple inheritance
69
+ - STL data structures
70
+ - Smart pointers with reference counting like ``std::shared_ptr``
71
+ - Internal references with correct reference counting
72
+ - C++ classes with virtual (and pure virtual) methods can be extended
73
+ in Python
74
+ - Integrated NumPy support (NumPy 2 requires pybind11 2.12+)
75
+
76
+ Goodies
77
+ -------
78
+
79
+ In addition to the core functionality, pybind11 provides some extra
80
+ goodies:
81
+
82
+ - Python 3.6+, and PyPy3 7.3 are supported with an implementation-agnostic
83
+ interface (pybind11 2.9 was the last version to support Python 2 and 3.5).
84
+
85
+ - It is possible to bind C++11 lambda functions with captured
86
+ variables. The lambda capture data is stored inside the resulting
87
+ Python function object.
88
+
89
+ - pybind11 uses C++11 move constructors and move assignment operators
90
+ whenever possible to efficiently transfer custom data types.
91
+
92
+ - It's easy to expose the internal storage of custom data types through
93
+ Pythons' buffer protocols. This is handy e.g. for fast conversion
94
+ between C++ matrix classes like Eigen and NumPy without expensive
95
+ copy operations.
96
+
97
+ - pybind11 can automatically vectorize functions so that they are
98
+ transparently applied to all entries of one or more NumPy array
99
+ arguments.
100
+
101
+ - Python's slice-based access and assignment operations can be
102
+ supported with just a few lines of code.
103
+
104
+ - Everything is contained in just a few header files; there is no need
105
+ to link against any additional libraries.
106
+
107
+ - Binaries are generally smaller by a factor of at least 2 compared to
108
+ equivalent bindings generated by Boost.Python. A recent pybind11
109
+ conversion of PyRosetta, an enormous Boost.Python binding project,
110
+ `reported <https://graylab.jhu.edu/Sergey/2016.RosettaCon/PyRosetta-4.pdf>`_
111
+ a binary size reduction of **5.4x** and compile time reduction by
112
+ **5.8x**.
113
+
114
+ - Function signatures are precomputed at compile time (using
115
+ ``constexpr``), leading to smaller binaries.
116
+
117
+ - With little extra effort, C++ types can be pickled and unpickled
118
+ similar to regular Python objects.
119
+
120
+ Supported compilers
121
+ -------------------
122
+
123
+ 1. Clang/LLVM 3.3 or newer (for Apple Xcode's clang, this is 5.0.0 or
124
+ newer)
125
+ 2. GCC 4.8 or newer
126
+ 3. Microsoft Visual Studio 2017 or newer
127
+ 4. Intel classic C++ compiler 18 or newer (ICC 20.2 tested in CI)
128
+ 5. Cygwin/GCC (previously tested on 2.5.1)
129
+ 6. NVCC (CUDA 11.0 tested in CI)
130
+ 7. NVIDIA PGI (20.9 tested in CI)
131
+
132
+ About
133
+ -----
134
+
135
+ This project was created by `Wenzel
136
+ Jakob <http://rgl.epfl.ch/people/wjakob>`_. Significant features and/or
137
+ improvements to the code were contributed by Jonas Adler, Lori A. Burns,
138
+ Sylvain Corlay, Eric Cousineau, Aaron Gokaslan, Ralf Grosse-Kunstleve, Trent Houliston, Axel
139
+ Huebl, @hulucc, Yannick Jadoul, Sergey Lyskov, Johan Mabille, Tomasz Miąsko,
140
+ Dean Moldovan, Ben Pritchard, Jason Rhinelander, Boris Schäling, Pim
141
+ Schellart, Henry Schreiner, Ivan Smirnov, Boris Staletic, and Patrick Stewart.
142
+
143
+ We thank Google for a generous financial contribution to the continuous
144
+ integration infrastructure used by this project.
145
+
146
+
147
+ Contributing
148
+ ~~~~~~~~~~~~
149
+
150
+ See the `contributing
151
+ guide <https://github.com/pybind/pybind11/blob/master/.github/CONTRIBUTING.md>`_
152
+ for information on building and contributing to pybind11.
153
+
154
+ License
155
+ ~~~~~~~
156
+
157
+ pybind11 is provided under a BSD-style license that can be found in the
158
+ `LICENSE <https://github.com/pybind/pybind11/blob/master/LICENSE>`_
159
+ file. By using, distributing, or contributing to this project, you agree
160
+ to the terms and conditions of this license.
161
+
162
+ .. |Latest Documentation Status| image:: https://readthedocs.org/projects/pybind11/badge?version=latest
163
+ :target: http://pybind11.readthedocs.org/en/latest
164
+ .. |Stable Documentation Status| image:: https://img.shields.io/badge/docs-stable-blue.svg
165
+ :target: http://pybind11.readthedocs.org/en/stable
166
+ .. |Gitter chat| image:: https://img.shields.io/gitter/room/gitterHQ/gitter.svg
167
+ :target: https://gitter.im/pybind/Lobby
168
+ .. |CI| image:: https://github.com/pybind/pybind11/workflows/CI/badge.svg
169
+ :target: https://github.com/pybind/pybind11/actions
170
+ .. |Build status| image:: https://ci.appveyor.com/api/projects/status/riaj54pn4h08xy40?svg=true
171
+ :target: https://ci.appveyor.com/project/wjakob/pybind11
172
+ .. |PyPI package| image:: https://img.shields.io/pypi/v/pybind11.svg
173
+ :target: https://pypi.org/project/pybind11/
174
+ .. |Conda-forge| image:: https://img.shields.io/conda/vn/conda-forge/pybind11.svg
175
+ :target: https://github.com/conda-forge/pybind11-feedstock
176
+ .. |Repology| image:: https://repology.org/badge/latest-versions/python:pybind11.svg
177
+ :target: https://repology.org/project/python:pybind11/versions
178
+ .. |Python Versions| image:: https://img.shields.io/pypi/pyversions/pybind11.svg
179
+ :target: https://pypi.org/project/pybind11/
180
+ .. |GitHub Discussions| image:: https://img.shields.io/static/v1?label=Discussions&message=Ask&color=blue&logo=github
181
+ :target: https://github.com/pybind/pybind11/discussions
third_party/CityFlow/extern/pybind11/SECURITY.md CHANGED
@@ -1,13 +1,13 @@
1
- # Security Policy
2
-
3
- ## Supported Versions
4
-
5
- Security updates are applied only to the latest release.
6
-
7
- ## Reporting a Vulnerability
8
-
9
- If you have discovered a security vulnerability in this project, please report it privately. **Do not disclose it as a public issue.** This gives us time to work with you to fix the issue before public exposure, reducing the chance that the exploit will be used before a patch is released.
10
-
11
- Please disclose it at [security advisory](https://github.com/pybind/pybind11/security/advisories/new).
12
-
13
- This project is maintained by a team of volunteers on a reasonable-effort basis. As such, please give us at least 90 days to work on a fix before public exposure.
 
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Security updates are applied only to the latest release.
6
+
7
+ ## Reporting a Vulnerability
8
+
9
+ If you have discovered a security vulnerability in this project, please report it privately. **Do not disclose it as a public issue.** This gives us time to work with you to fix the issue before public exposure, reducing the chance that the exploit will be used before a patch is released.
10
+
11
+ Please disclose it at [security advisory](https://github.com/pybind/pybind11/security/advisories/new).
12
+
13
+ This project is maintained by a team of volunteers on a reasonable-effort basis. As such, please give us at least 90 days to work on a fix before public exposure.
third_party/CityFlow/extern/pybind11/docs/Doxyfile CHANGED
@@ -1,21 +1,21 @@
1
- PROJECT_NAME = pybind11
2
- INPUT = ../include/pybind11/
3
- RECURSIVE = YES
4
-
5
- GENERATE_HTML = NO
6
- GENERATE_LATEX = NO
7
- GENERATE_XML = YES
8
- XML_OUTPUT = .build/doxygenxml
9
- XML_PROGRAMLISTING = YES
10
-
11
- MACRO_EXPANSION = YES
12
- EXPAND_ONLY_PREDEF = YES
13
- EXPAND_AS_DEFINED = PYBIND11_RUNTIME_EXCEPTION
14
-
15
- ALIASES = "rst=\verbatim embed:rst"
16
- ALIASES += "endrst=\endverbatim"
17
-
18
- QUIET = YES
19
- WARNINGS = YES
20
- WARN_IF_UNDOCUMENTED = NO
21
- PREDEFINED = PYBIND11_NOINLINE
 
1
+ PROJECT_NAME = pybind11
2
+ INPUT = ../include/pybind11/
3
+ RECURSIVE = YES
4
+
5
+ GENERATE_HTML = NO
6
+ GENERATE_LATEX = NO
7
+ GENERATE_XML = YES
8
+ XML_OUTPUT = .build/doxygenxml
9
+ XML_PROGRAMLISTING = YES
10
+
11
+ MACRO_EXPANSION = YES
12
+ EXPAND_ONLY_PREDEF = YES
13
+ EXPAND_AS_DEFINED = PYBIND11_RUNTIME_EXCEPTION
14
+
15
+ ALIASES = "rst=\verbatim embed:rst"
16
+ ALIASES += "endrst=\endverbatim"
17
+
18
+ QUIET = YES
19
+ WARNINGS = YES
20
+ WARN_IF_UNDOCUMENTED = NO
21
+ PREDEFINED = PYBIND11_NOINLINE
third_party/CityFlow/extern/pybind11/docs/basics.rst CHANGED
@@ -1,307 +1,307 @@
1
- .. _basics:
2
-
3
- First steps
4
- ###########
5
-
6
- This sections demonstrates the basic features of pybind11. Before getting
7
- started, make sure that development environment is set up to compile the
8
- included set of test cases.
9
-
10
-
11
- Compiling the test cases
12
- ========================
13
-
14
- Linux/macOS
15
- -----------
16
-
17
- On Linux you'll need to install the **python-dev** or **python3-dev** packages as
18
- well as **cmake**. On macOS, the included python version works out of the box,
19
- but **cmake** must still be installed.
20
-
21
- After installing the prerequisites, run
22
-
23
- .. code-block:: bash
24
-
25
- mkdir build
26
- cd build
27
- cmake ..
28
- make check -j 4
29
-
30
- The last line will both compile and run the tests.
31
-
32
- Windows
33
- -------
34
-
35
- On Windows, only **Visual Studio 2017** and newer are supported.
36
-
37
- .. Note::
38
-
39
- To use the C++17 in Visual Studio 2017 (MSVC 14.1), pybind11 requires the flag
40
- ``/permissive-`` to be passed to the compiler `to enforce standard conformance`_. When
41
- building with Visual Studio 2019, this is not strictly necessary, but still advised.
42
-
43
- .. _`to enforce standard conformance`: https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=vs-2017
44
-
45
- To compile and run the tests:
46
-
47
- .. code-block:: batch
48
-
49
- mkdir build
50
- cd build
51
- cmake ..
52
- cmake --build . --config Release --target check
53
-
54
- This will create a Visual Studio project, compile and run the target, all from the
55
- command line.
56
-
57
- .. Note::
58
-
59
- If all tests fail, make sure that the Python binary and the testcases are compiled
60
- for the same processor type and bitness (i.e. either **i386** or **x86_64**). You
61
- can specify **x86_64** as the target architecture for the generated Visual Studio
62
- project using ``cmake -A x64 ..``.
63
-
64
- .. seealso::
65
-
66
- Advanced users who are already familiar with Boost.Python may want to skip
67
- the tutorial and look at the test cases in the :file:`tests` directory,
68
- which exercise all features of pybind11.
69
-
70
- Header and namespace conventions
71
- ================================
72
-
73
- For brevity, all code examples assume that the following two lines are present:
74
-
75
- .. code-block:: cpp
76
-
77
- #include <pybind11/pybind11.h>
78
-
79
- namespace py = pybind11;
80
-
81
- Some features may require additional headers, but those will be specified as needed.
82
-
83
- .. _simple_example:
84
-
85
- Creating bindings for a simple function
86
- =======================================
87
-
88
- Let's start by creating Python bindings for an extremely simple function, which
89
- adds two numbers and returns their result:
90
-
91
- .. code-block:: cpp
92
-
93
- int add(int i, int j) {
94
- return i + j;
95
- }
96
-
97
- For simplicity [#f1]_, we'll put both this function and the binding code into
98
- a file named :file:`example.cpp` with the following contents:
99
-
100
- .. code-block:: cpp
101
-
102
- #include <pybind11/pybind11.h>
103
-
104
- int add(int i, int j) {
105
- return i + j;
106
- }
107
-
108
- PYBIND11_MODULE(example, m) {
109
- m.doc() = "pybind11 example plugin"; // optional module docstring
110
-
111
- m.def("add", &add, "A function that adds two numbers");
112
- }
113
-
114
- .. [#f1] In practice, implementation and binding code will generally be located
115
- in separate files.
116
-
117
- The :func:`PYBIND11_MODULE` macro creates a function that will be called when an
118
- ``import`` statement is issued from within Python. The module name (``example``)
119
- is given as the first macro argument (it should not be in quotes). The second
120
- argument (``m``) defines a variable of type :class:`py::module_ <module>` which
121
- is the main interface for creating bindings. The method :func:`module_::def`
122
- generates binding code that exposes the ``add()`` function to Python.
123
-
124
- .. note::
125
-
126
- Notice how little code was needed to expose our function to Python: all
127
- details regarding the function's parameters and return value were
128
- automatically inferred using template metaprogramming. This overall
129
- approach and the used syntax are borrowed from Boost.Python, though the
130
- underlying implementation is very different.
131
-
132
- pybind11 is a header-only library, hence it is not necessary to link against
133
- any special libraries and there are no intermediate (magic) translation steps.
134
- On Linux, the above example can be compiled using the following command:
135
-
136
- .. code-block:: bash
137
-
138
- $ c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3 -m pybind11 --includes) example.cpp -o example$(python3-config --extension-suffix)
139
-
140
- .. note::
141
-
142
- If you used :ref:`include_as_a_submodule` to get the pybind11 source, then
143
- use ``$(python3-config --includes) -Iextern/pybind11/include`` instead of
144
- ``$(python3 -m pybind11 --includes)`` in the above compilation, as
145
- explained in :ref:`building_manually`.
146
-
147
- For more details on the required compiler flags on Linux and macOS, see
148
- :ref:`building_manually`. For complete cross-platform compilation instructions,
149
- refer to the :ref:`compiling` page.
150
-
151
- The `python_example`_ and `cmake_example`_ repositories are also a good place
152
- to start. They are both complete project examples with cross-platform build
153
- systems. The only difference between the two is that `python_example`_ uses
154
- Python's ``setuptools`` to build the module, while `cmake_example`_ uses CMake
155
- (which may be preferable for existing C++ projects).
156
-
157
- .. _python_example: https://github.com/pybind/python_example
158
- .. _cmake_example: https://github.com/pybind/cmake_example
159
-
160
- Building the above C++ code will produce a binary module file that can be
161
- imported to Python. Assuming that the compiled module is located in the
162
- current directory, the following interactive Python session shows how to
163
- load and execute the example:
164
-
165
- .. code-block:: pycon
166
-
167
- $ python
168
- Python 3.9.10 (main, Jan 15 2022, 11:48:04)
169
- [Clang 13.0.0 (clang-1300.0.29.3)] on darwin
170
- Type "help", "copyright", "credits" or "license" for more information.
171
- >>> import example
172
- >>> example.add(1, 2)
173
- 3
174
- >>>
175
-
176
- .. _keyword_args:
177
-
178
- Keyword arguments
179
- =================
180
-
181
- With a simple code modification, it is possible to inform Python about the
182
- names of the arguments ("i" and "j" in this case).
183
-
184
- .. code-block:: cpp
185
-
186
- m.def("add", &add, "A function which adds two numbers",
187
- py::arg("i"), py::arg("j"));
188
-
189
- :class:`arg` is one of several special tag classes which can be used to pass
190
- metadata into :func:`module_::def`. With this modified binding code, we can now
191
- call the function using keyword arguments, which is a more readable alternative
192
- particularly for functions taking many parameters:
193
-
194
- .. code-block:: pycon
195
-
196
- >>> import example
197
- >>> example.add(i=1, j=2)
198
- 3L
199
-
200
- The keyword names also appear in the function signatures within the documentation.
201
-
202
- .. code-block:: pycon
203
-
204
- >>> help(example)
205
-
206
- ....
207
-
208
- FUNCTIONS
209
- add(...)
210
- Signature : (i: int, j: int) -> int
211
-
212
- A function which adds two numbers
213
-
214
- A shorter notation for named arguments is also available:
215
-
216
- .. code-block:: cpp
217
-
218
- // regular notation
219
- m.def("add1", &add, py::arg("i"), py::arg("j"));
220
- // shorthand
221
- using namespace pybind11::literals;
222
- m.def("add2", &add, "i"_a, "j"_a);
223
-
224
- The :var:`_a` suffix forms a C++11 literal which is equivalent to :class:`arg`.
225
- Note that the literal operator must first be made visible with the directive
226
- ``using namespace pybind11::literals``. This does not bring in anything else
227
- from the ``pybind11`` namespace except for literals.
228
-
229
- .. _default_args:
230
-
231
- Default arguments
232
- =================
233
-
234
- Suppose now that the function to be bound has default arguments, e.g.:
235
-
236
- .. code-block:: cpp
237
-
238
- int add(int i = 1, int j = 2) {
239
- return i + j;
240
- }
241
-
242
- Unfortunately, pybind11 cannot automatically extract these parameters, since they
243
- are not part of the function's type information. However, they are simple to specify
244
- using an extension of :class:`arg`:
245
-
246
- .. code-block:: cpp
247
-
248
- m.def("add", &add, "A function which adds two numbers",
249
- py::arg("i") = 1, py::arg("j") = 2);
250
-
251
- The default values also appear within the documentation.
252
-
253
- .. code-block:: pycon
254
-
255
- >>> help(example)
256
-
257
- ....
258
-
259
- FUNCTIONS
260
- add(...)
261
- Signature : (i: int = 1, j: int = 2) -> int
262
-
263
- A function which adds two numbers
264
-
265
- The shorthand notation is also available for default arguments:
266
-
267
- .. code-block:: cpp
268
-
269
- // regular notation
270
- m.def("add1", &add, py::arg("i") = 1, py::arg("j") = 2);
271
- // shorthand
272
- m.def("add2", &add, "i"_a=1, "j"_a=2);
273
-
274
- Exporting variables
275
- ===================
276
-
277
- To expose a value from C++, use the ``attr`` function to register it in a
278
- module as shown below. Built-in types and general objects (more on that later)
279
- are automatically converted when assigned as attributes, and can be explicitly
280
- converted using the function ``py::cast``.
281
-
282
- .. code-block:: cpp
283
-
284
- PYBIND11_MODULE(example, m) {
285
- m.attr("the_answer") = 42;
286
- py::object world = py::cast("World");
287
- m.attr("what") = world;
288
- }
289
-
290
- These are then accessible from Python:
291
-
292
- .. code-block:: pycon
293
-
294
- >>> import example
295
- >>> example.the_answer
296
- 42
297
- >>> example.what
298
- 'World'
299
-
300
- .. _supported_types:
301
-
302
- Supported data types
303
- ====================
304
-
305
- A large number of data types are supported out of the box and can be used
306
- seamlessly as functions arguments, return values or with ``py::cast`` in general.
307
- For a full overview, see the :doc:`advanced/cast/index` section.
 
1
+ .. _basics:
2
+
3
+ First steps
4
+ ###########
5
+
6
+ This sections demonstrates the basic features of pybind11. Before getting
7
+ started, make sure that development environment is set up to compile the
8
+ included set of test cases.
9
+
10
+
11
+ Compiling the test cases
12
+ ========================
13
+
14
+ Linux/macOS
15
+ -----------
16
+
17
+ On Linux you'll need to install the **python-dev** or **python3-dev** packages as
18
+ well as **cmake**. On macOS, the included python version works out of the box,
19
+ but **cmake** must still be installed.
20
+
21
+ After installing the prerequisites, run
22
+
23
+ .. code-block:: bash
24
+
25
+ mkdir build
26
+ cd build
27
+ cmake ..
28
+ make check -j 4
29
+
30
+ The last line will both compile and run the tests.
31
+
32
+ Windows
33
+ -------
34
+
35
+ On Windows, only **Visual Studio 2017** and newer are supported.
36
+
37
+ .. Note::
38
+
39
+ To use the C++17 in Visual Studio 2017 (MSVC 14.1), pybind11 requires the flag
40
+ ``/permissive-`` to be passed to the compiler `to enforce standard conformance`_. When
41
+ building with Visual Studio 2019, this is not strictly necessary, but still advised.
42
+
43
+ .. _`to enforce standard conformance`: https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=vs-2017
44
+
45
+ To compile and run the tests:
46
+
47
+ .. code-block:: batch
48
+
49
+ mkdir build
50
+ cd build
51
+ cmake ..
52
+ cmake --build . --config Release --target check
53
+
54
+ This will create a Visual Studio project, compile and run the target, all from the
55
+ command line.
56
+
57
+ .. Note::
58
+
59
+ If all tests fail, make sure that the Python binary and the testcases are compiled
60
+ for the same processor type and bitness (i.e. either **i386** or **x86_64**). You
61
+ can specify **x86_64** as the target architecture for the generated Visual Studio
62
+ project using ``cmake -A x64 ..``.
63
+
64
+ .. seealso::
65
+
66
+ Advanced users who are already familiar with Boost.Python may want to skip
67
+ the tutorial and look at the test cases in the :file:`tests` directory,
68
+ which exercise all features of pybind11.
69
+
70
+ Header and namespace conventions
71
+ ================================
72
+
73
+ For brevity, all code examples assume that the following two lines are present:
74
+
75
+ .. code-block:: cpp
76
+
77
+ #include <pybind11/pybind11.h>
78
+
79
+ namespace py = pybind11;
80
+
81
+ Some features may require additional headers, but those will be specified as needed.
82
+
83
+ .. _simple_example:
84
+
85
+ Creating bindings for a simple function
86
+ =======================================
87
+
88
+ Let's start by creating Python bindings for an extremely simple function, which
89
+ adds two numbers and returns their result:
90
+
91
+ .. code-block:: cpp
92
+
93
+ int add(int i, int j) {
94
+ return i + j;
95
+ }
96
+
97
+ For simplicity [#f1]_, we'll put both this function and the binding code into
98
+ a file named :file:`example.cpp` with the following contents:
99
+
100
+ .. code-block:: cpp
101
+
102
+ #include <pybind11/pybind11.h>
103
+
104
+ int add(int i, int j) {
105
+ return i + j;
106
+ }
107
+
108
+ PYBIND11_MODULE(example, m) {
109
+ m.doc() = "pybind11 example plugin"; // optional module docstring
110
+
111
+ m.def("add", &add, "A function that adds two numbers");
112
+ }
113
+
114
+ .. [#f1] In practice, implementation and binding code will generally be located
115
+ in separate files.
116
+
117
+ The :func:`PYBIND11_MODULE` macro creates a function that will be called when an
118
+ ``import`` statement is issued from within Python. The module name (``example``)
119
+ is given as the first macro argument (it should not be in quotes). The second
120
+ argument (``m``) defines a variable of type :class:`py::module_ <module>` which
121
+ is the main interface for creating bindings. The method :func:`module_::def`
122
+ generates binding code that exposes the ``add()`` function to Python.
123
+
124
+ .. note::
125
+
126
+ Notice how little code was needed to expose our function to Python: all
127
+ details regarding the function's parameters and return value were
128
+ automatically inferred using template metaprogramming. This overall
129
+ approach and the used syntax are borrowed from Boost.Python, though the
130
+ underlying implementation is very different.
131
+
132
+ pybind11 is a header-only library, hence it is not necessary to link against
133
+ any special libraries and there are no intermediate (magic) translation steps.
134
+ On Linux, the above example can be compiled using the following command:
135
+
136
+ .. code-block:: bash
137
+
138
+ $ c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3 -m pybind11 --includes) example.cpp -o example$(python3-config --extension-suffix)
139
+
140
+ .. note::
141
+
142
+ If you used :ref:`include_as_a_submodule` to get the pybind11 source, then
143
+ use ``$(python3-config --includes) -Iextern/pybind11/include`` instead of
144
+ ``$(python3 -m pybind11 --includes)`` in the above compilation, as
145
+ explained in :ref:`building_manually`.
146
+
147
+ For more details on the required compiler flags on Linux and macOS, see
148
+ :ref:`building_manually`. For complete cross-platform compilation instructions,
149
+ refer to the :ref:`compiling` page.
150
+
151
+ The `python_example`_ and `cmake_example`_ repositories are also a good place
152
+ to start. They are both complete project examples with cross-platform build
153
+ systems. The only difference between the two is that `python_example`_ uses
154
+ Python's ``setuptools`` to build the module, while `cmake_example`_ uses CMake
155
+ (which may be preferable for existing C++ projects).
156
+
157
+ .. _python_example: https://github.com/pybind/python_example
158
+ .. _cmake_example: https://github.com/pybind/cmake_example
159
+
160
+ Building the above C++ code will produce a binary module file that can be
161
+ imported to Python. Assuming that the compiled module is located in the
162
+ current directory, the following interactive Python session shows how to
163
+ load and execute the example:
164
+
165
+ .. code-block:: pycon
166
+
167
+ $ python
168
+ Python 3.9.10 (main, Jan 15 2022, 11:48:04)
169
+ [Clang 13.0.0 (clang-1300.0.29.3)] on darwin
170
+ Type "help", "copyright", "credits" or "license" for more information.
171
+ >>> import example
172
+ >>> example.add(1, 2)
173
+ 3
174
+ >>>
175
+
176
+ .. _keyword_args:
177
+
178
+ Keyword arguments
179
+ =================
180
+
181
+ With a simple code modification, it is possible to inform Python about the
182
+ names of the arguments ("i" and "j" in this case).
183
+
184
+ .. code-block:: cpp
185
+
186
+ m.def("add", &add, "A function which adds two numbers",
187
+ py::arg("i"), py::arg("j"));
188
+
189
+ :class:`arg` is one of several special tag classes which can be used to pass
190
+ metadata into :func:`module_::def`. With this modified binding code, we can now
191
+ call the function using keyword arguments, which is a more readable alternative
192
+ particularly for functions taking many parameters:
193
+
194
+ .. code-block:: pycon
195
+
196
+ >>> import example
197
+ >>> example.add(i=1, j=2)
198
+ 3L
199
+
200
+ The keyword names also appear in the function signatures within the documentation.
201
+
202
+ .. code-block:: pycon
203
+
204
+ >>> help(example)
205
+
206
+ ....
207
+
208
+ FUNCTIONS
209
+ add(...)
210
+ Signature : (i: int, j: int) -> int
211
+
212
+ A function which adds two numbers
213
+
214
+ A shorter notation for named arguments is also available:
215
+
216
+ .. code-block:: cpp
217
+
218
+ // regular notation
219
+ m.def("add1", &add, py::arg("i"), py::arg("j"));
220
+ // shorthand
221
+ using namespace pybind11::literals;
222
+ m.def("add2", &add, "i"_a, "j"_a);
223
+
224
+ The :var:`_a` suffix forms a C++11 literal which is equivalent to :class:`arg`.
225
+ Note that the literal operator must first be made visible with the directive
226
+ ``using namespace pybind11::literals``. This does not bring in anything else
227
+ from the ``pybind11`` namespace except for literals.
228
+
229
+ .. _default_args:
230
+
231
+ Default arguments
232
+ =================
233
+
234
+ Suppose now that the function to be bound has default arguments, e.g.:
235
+
236
+ .. code-block:: cpp
237
+
238
+ int add(int i = 1, int j = 2) {
239
+ return i + j;
240
+ }
241
+
242
+ Unfortunately, pybind11 cannot automatically extract these parameters, since they
243
+ are not part of the function's type information. However, they are simple to specify
244
+ using an extension of :class:`arg`:
245
+
246
+ .. code-block:: cpp
247
+
248
+ m.def("add", &add, "A function which adds two numbers",
249
+ py::arg("i") = 1, py::arg("j") = 2);
250
+
251
+ The default values also appear within the documentation.
252
+
253
+ .. code-block:: pycon
254
+
255
+ >>> help(example)
256
+
257
+ ....
258
+
259
+ FUNCTIONS
260
+ add(...)
261
+ Signature : (i: int = 1, j: int = 2) -> int
262
+
263
+ A function which adds two numbers
264
+
265
+ The shorthand notation is also available for default arguments:
266
+
267
+ .. code-block:: cpp
268
+
269
+ // regular notation
270
+ m.def("add1", &add, py::arg("i") = 1, py::arg("j") = 2);
271
+ // shorthand
272
+ m.def("add2", &add, "i"_a=1, "j"_a=2);
273
+
274
+ Exporting variables
275
+ ===================
276
+
277
+ To expose a value from C++, use the ``attr`` function to register it in a
278
+ module as shown below. Built-in types and general objects (more on that later)
279
+ are automatically converted when assigned as attributes, and can be explicitly
280
+ converted using the function ``py::cast``.
281
+
282
+ .. code-block:: cpp
283
+
284
+ PYBIND11_MODULE(example, m) {
285
+ m.attr("the_answer") = 42;
286
+ py::object world = py::cast("World");
287
+ m.attr("what") = world;
288
+ }
289
+
290
+ These are then accessible from Python:
291
+
292
+ .. code-block:: pycon
293
+
294
+ >>> import example
295
+ >>> example.the_answer
296
+ 42
297
+ >>> example.what
298
+ 'World'
299
+
300
+ .. _supported_types:
301
+
302
+ Supported data types
303
+ ====================
304
+
305
+ A large number of data types are supported out of the box and can be used
306
+ seamlessly as functions arguments, return values or with ``py::cast`` in general.
307
+ For a full overview, see the :doc:`advanced/cast/index` section.
third_party/CityFlow/extern/pybind11/docs/benchmark.py CHANGED
@@ -1,87 +1,87 @@
1
- import datetime as dt
2
- import os
3
- import random
4
-
5
- nfns = 4 # Functions per class
6
- nargs = 4 # Arguments per function
7
-
8
-
9
- def generate_dummy_code_pybind11(nclasses=10):
10
- decl = ""
11
- bindings = ""
12
-
13
- for cl in range(nclasses):
14
- decl += f"class cl{cl:03};\n"
15
- decl += "\n"
16
-
17
- for cl in range(nclasses):
18
- decl += f"class {cl:03} {{\n"
19
- decl += "public:\n"
20
- bindings += f' py::class_<cl{cl:03}>(m, "cl{cl:03}")\n'
21
- for fn in range(nfns):
22
- ret = random.randint(0, nclasses - 1)
23
- params = [random.randint(0, nclasses - 1) for i in range(nargs)]
24
- decl += f" cl{ret:03} *fn_{fn:03}("
25
- decl += ", ".join(f"cl{p:03} *" for p in params)
26
- decl += ");\n"
27
- bindings += f' .def("fn_{fn:03}", &cl{cl:03}::fn_{fn:03})\n'
28
- decl += "};\n\n"
29
- bindings += " ;\n"
30
-
31
- result = "#include <pybind11/pybind11.h>\n\n"
32
- result += "namespace py = pybind11;\n\n"
33
- result += decl + "\n"
34
- result += "PYBIND11_MODULE(example, m) {\n"
35
- result += bindings
36
- result += "}"
37
- return result
38
-
39
-
40
- def generate_dummy_code_boost(nclasses=10):
41
- decl = ""
42
- bindings = ""
43
-
44
- for cl in range(nclasses):
45
- decl += f"class cl{cl:03};\n"
46
- decl += "\n"
47
-
48
- for cl in range(nclasses):
49
- decl += "class cl%03i {\n" % cl
50
- decl += "public:\n"
51
- bindings += f' py::class_<cl{cl:03}>("cl{cl:03}")\n'
52
- for fn in range(nfns):
53
- ret = random.randint(0, nclasses - 1)
54
- params = [random.randint(0, nclasses - 1) for i in range(nargs)]
55
- decl += f" cl{ret:03} *fn_{fn:03}("
56
- decl += ", ".join(f"cl{p:03} *" for p in params)
57
- decl += ");\n"
58
- bindings += f' .def("fn_{fn:03}", &cl{cl:03}::fn_{fn:03}, py::return_value_policy<py::manage_new_object>())\n'
59
- decl += "};\n\n"
60
- bindings += " ;\n"
61
-
62
- result = "#include <boost/python.hpp>\n\n"
63
- result += "namespace py = boost::python;\n\n"
64
- result += decl + "\n"
65
- result += "BOOST_PYTHON_MODULE(example) {\n"
66
- result += bindings
67
- result += "}"
68
- return result
69
-
70
-
71
- for codegen in [generate_dummy_code_pybind11, generate_dummy_code_boost]:
72
- print("{")
73
- for i in range(10):
74
- nclasses = 2**i
75
- with open("test.cpp", "w") as f:
76
- f.write(codegen(nclasses))
77
- n1 = dt.datetime.now()
78
- os.system(
79
- "g++ -Os -shared -rdynamic -undefined dynamic_lookup "
80
- "-fvisibility=hidden -std=c++14 test.cpp -I include "
81
- "-I /System/Library/Frameworks/Python.framework/Headers -o test.so"
82
- )
83
- n2 = dt.datetime.now()
84
- elapsed = (n2 - n1).total_seconds()
85
- size = os.stat("test.so").st_size
86
- print(" {%i, %f, %i}," % (nclasses * nfns, elapsed, size))
87
- print("}")
 
1
+ import datetime as dt
2
+ import os
3
+ import random
4
+
5
+ nfns = 4 # Functions per class
6
+ nargs = 4 # Arguments per function
7
+
8
+
9
+ def generate_dummy_code_pybind11(nclasses=10):
10
+ decl = ""
11
+ bindings = ""
12
+
13
+ for cl in range(nclasses):
14
+ decl += f"class cl{cl:03};\n"
15
+ decl += "\n"
16
+
17
+ for cl in range(nclasses):
18
+ decl += f"class {cl:03} {{\n"
19
+ decl += "public:\n"
20
+ bindings += f' py::class_<cl{cl:03}>(m, "cl{cl:03}")\n'
21
+ for fn in range(nfns):
22
+ ret = random.randint(0, nclasses - 1)
23
+ params = [random.randint(0, nclasses - 1) for i in range(nargs)]
24
+ decl += f" cl{ret:03} *fn_{fn:03}("
25
+ decl += ", ".join(f"cl{p:03} *" for p in params)
26
+ decl += ");\n"
27
+ bindings += f' .def("fn_{fn:03}", &cl{cl:03}::fn_{fn:03})\n'
28
+ decl += "};\n\n"
29
+ bindings += " ;\n"
30
+
31
+ result = "#include <pybind11/pybind11.h>\n\n"
32
+ result += "namespace py = pybind11;\n\n"
33
+ result += decl + "\n"
34
+ result += "PYBIND11_MODULE(example, m) {\n"
35
+ result += bindings
36
+ result += "}"
37
+ return result
38
+
39
+
40
+ def generate_dummy_code_boost(nclasses=10):
41
+ decl = ""
42
+ bindings = ""
43
+
44
+ for cl in range(nclasses):
45
+ decl += f"class cl{cl:03};\n"
46
+ decl += "\n"
47
+
48
+ for cl in range(nclasses):
49
+ decl += "class cl%03i {\n" % cl
50
+ decl += "public:\n"
51
+ bindings += f' py::class_<cl{cl:03}>("cl{cl:03}")\n'
52
+ for fn in range(nfns):
53
+ ret = random.randint(0, nclasses - 1)
54
+ params = [random.randint(0, nclasses - 1) for i in range(nargs)]
55
+ decl += f" cl{ret:03} *fn_{fn:03}("
56
+ decl += ", ".join(f"cl{p:03} *" for p in params)
57
+ decl += ");\n"
58
+ bindings += f' .def("fn_{fn:03}", &cl{cl:03}::fn_{fn:03}, py::return_value_policy<py::manage_new_object>())\n'
59
+ decl += "};\n\n"
60
+ bindings += " ;\n"
61
+
62
+ result = "#include <boost/python.hpp>\n\n"
63
+ result += "namespace py = boost::python;\n\n"
64
+ result += decl + "\n"
65
+ result += "BOOST_PYTHON_MODULE(example) {\n"
66
+ result += bindings
67
+ result += "}"
68
+ return result
69
+
70
+
71
+ for codegen in [generate_dummy_code_pybind11, generate_dummy_code_boost]:
72
+ print("{")
73
+ for i in range(10):
74
+ nclasses = 2**i
75
+ with open("test.cpp", "w") as f:
76
+ f.write(codegen(nclasses))
77
+ n1 = dt.datetime.now()
78
+ os.system(
79
+ "g++ -Os -shared -rdynamic -undefined dynamic_lookup "
80
+ "-fvisibility=hidden -std=c++14 test.cpp -I include "
81
+ "-I /System/Library/Frameworks/Python.framework/Headers -o test.so"
82
+ )
83
+ n2 = dt.datetime.now()
84
+ elapsed = (n2 - n1).total_seconds()
85
+ size = os.stat("test.so").st_size
86
+ print(" {%i, %f, %i}," % (nclasses * nfns, elapsed, size))
87
+ print("}")
third_party/CityFlow/extern/pybind11/docs/benchmark.rst CHANGED
@@ -1,95 +1,95 @@
1
- Benchmark
2
- =========
3
-
4
- The following is the result of a synthetic benchmark comparing both compilation
5
- time and module size of pybind11 against Boost.Python. A detailed report about a
6
- Boost.Python to pybind11 conversion of a real project is available here: [#f1]_.
7
-
8
- .. [#f1] http://graylab.jhu.edu/RosettaCon2016/PyRosetta-4.pdf
9
-
10
- Setup
11
- -----
12
-
13
- A python script (see the ``docs/benchmark.py`` file) was used to generate a set
14
- of files with dummy classes whose count increases for each successive benchmark
15
- (between 1 and 2048 classes in powers of two). Each class has four methods with
16
- a randomly generated signature with a return value and four arguments. (There
17
- was no particular reason for this setup other than the desire to generate many
18
- unique function signatures whose count could be controlled in a simple way.)
19
-
20
- Here is an example of the binding code for one class:
21
-
22
- .. code-block:: cpp
23
-
24
- ...
25
- class cl034 {
26
- public:
27
- cl279 *fn_000(cl084 *, cl057 *, cl065 *, cl042 *);
28
- cl025 *fn_001(cl098 *, cl262 *, cl414 *, cl121 *);
29
- cl085 *fn_002(cl445 *, cl297 *, cl145 *, cl421 *);
30
- cl470 *fn_003(cl200 *, cl323 *, cl332 *, cl492 *);
31
- };
32
- ...
33
-
34
- PYBIND11_MODULE(example, m) {
35
- ...
36
- py::class_<cl034>(m, "cl034")
37
- .def("fn_000", &cl034::fn_000)
38
- .def("fn_001", &cl034::fn_001)
39
- .def("fn_002", &cl034::fn_002)
40
- .def("fn_003", &cl034::fn_003)
41
- ...
42
- }
43
-
44
- The Boost.Python version looks almost identical except that a return value
45
- policy had to be specified as an argument to ``def()``. For both libraries,
46
- compilation was done with
47
-
48
- .. code-block:: bash
49
-
50
- Apple LLVM version 7.0.2 (clang-700.1.81)
51
-
52
- and the following compilation flags
53
-
54
- .. code-block:: bash
55
-
56
- g++ -Os -shared -rdynamic -undefined dynamic_lookup -fvisibility=hidden -std=c++14
57
-
58
- Compilation time
59
- ----------------
60
-
61
- The following log-log plot shows how the compilation time grows for an
62
- increasing number of class and function declarations. pybind11 includes many
63
- fewer headers, which initially leads to shorter compilation times, but the
64
- performance is ultimately fairly similar (pybind11 is 19.8 seconds faster for
65
- the largest largest file with 2048 classes and a total of 8192 methods -- a
66
- modest **1.2x** speedup relative to Boost.Python, which required 116.35
67
- seconds).
68
-
69
- .. only:: not latex
70
-
71
- .. image:: pybind11_vs_boost_python1.svg
72
-
73
- .. only:: latex
74
-
75
- .. image:: pybind11_vs_boost_python1.png
76
-
77
- Module size
78
- -----------
79
-
80
- Differences between the two libraries become much more pronounced when
81
- considering the file size of the generated Python plugin: for the largest file,
82
- the binary generated by Boost.Python required 16.8 MiB, which was **2.17
83
- times** / **9.1 megabytes** larger than the output generated by pybind11. For
84
- very small inputs, Boost.Python has an edge in the plot below -- however, note
85
- that it stores many definitions in an external library, whose size was not
86
- included here, hence the comparison is slightly shifted in Boost.Python's
87
- favor.
88
-
89
- .. only:: not latex
90
-
91
- .. image:: pybind11_vs_boost_python2.svg
92
-
93
- .. only:: latex
94
-
95
- .. image:: pybind11_vs_boost_python2.png
 
1
+ Benchmark
2
+ =========
3
+
4
+ The following is the result of a synthetic benchmark comparing both compilation
5
+ time and module size of pybind11 against Boost.Python. A detailed report about a
6
+ Boost.Python to pybind11 conversion of a real project is available here: [#f1]_.
7
+
8
+ .. [#f1] http://graylab.jhu.edu/RosettaCon2016/PyRosetta-4.pdf
9
+
10
+ Setup
11
+ -----
12
+
13
+ A python script (see the ``docs/benchmark.py`` file) was used to generate a set
14
+ of files with dummy classes whose count increases for each successive benchmark
15
+ (between 1 and 2048 classes in powers of two). Each class has four methods with
16
+ a randomly generated signature with a return value and four arguments. (There
17
+ was no particular reason for this setup other than the desire to generate many
18
+ unique function signatures whose count could be controlled in a simple way.)
19
+
20
+ Here is an example of the binding code for one class:
21
+
22
+ .. code-block:: cpp
23
+
24
+ ...
25
+ class cl034 {
26
+ public:
27
+ cl279 *fn_000(cl084 *, cl057 *, cl065 *, cl042 *);
28
+ cl025 *fn_001(cl098 *, cl262 *, cl414 *, cl121 *);
29
+ cl085 *fn_002(cl445 *, cl297 *, cl145 *, cl421 *);
30
+ cl470 *fn_003(cl200 *, cl323 *, cl332 *, cl492 *);
31
+ };
32
+ ...
33
+
34
+ PYBIND11_MODULE(example, m) {
35
+ ...
36
+ py::class_<cl034>(m, "cl034")
37
+ .def("fn_000", &cl034::fn_000)
38
+ .def("fn_001", &cl034::fn_001)
39
+ .def("fn_002", &cl034::fn_002)
40
+ .def("fn_003", &cl034::fn_003)
41
+ ...
42
+ }
43
+
44
+ The Boost.Python version looks almost identical except that a return value
45
+ policy had to be specified as an argument to ``def()``. For both libraries,
46
+ compilation was done with
47
+
48
+ .. code-block:: bash
49
+
50
+ Apple LLVM version 7.0.2 (clang-700.1.81)
51
+
52
+ and the following compilation flags
53
+
54
+ .. code-block:: bash
55
+
56
+ g++ -Os -shared -rdynamic -undefined dynamic_lookup -fvisibility=hidden -std=c++14
57
+
58
+ Compilation time
59
+ ----------------
60
+
61
+ The following log-log plot shows how the compilation time grows for an
62
+ increasing number of class and function declarations. pybind11 includes many
63
+ fewer headers, which initially leads to shorter compilation times, but the
64
+ performance is ultimately fairly similar (pybind11 is 19.8 seconds faster for
65
+ the largest largest file with 2048 classes and a total of 8192 methods -- a
66
+ modest **1.2x** speedup relative to Boost.Python, which required 116.35
67
+ seconds).
68
+
69
+ .. only:: not latex
70
+
71
+ .. image:: pybind11_vs_boost_python1.svg
72
+
73
+ .. only:: latex
74
+
75
+ .. image:: pybind11_vs_boost_python1.png
76
+
77
+ Module size
78
+ -----------
79
+
80
+ Differences between the two libraries become much more pronounced when
81
+ considering the file size of the generated Python plugin: for the largest file,
82
+ the binary generated by Boost.Python required 16.8 MiB, which was **2.17
83
+ times** / **9.1 megabytes** larger than the output generated by pybind11. For
84
+ very small inputs, Boost.Python has an edge in the plot below -- however, note
85
+ that it stores many definitions in an external library, whose size was not
86
+ included here, hence the comparison is slightly shifted in Boost.Python's
87
+ favor.
88
+
89
+ .. only:: not latex
90
+
91
+ .. image:: pybind11_vs_boost_python2.svg
92
+
93
+ .. only:: latex
94
+
95
+ .. image:: pybind11_vs_boost_python2.png
third_party/CityFlow/extern/pybind11/docs/changelog.rst CHANGED
The diff for this file is too large to render. See raw diff
 
third_party/CityFlow/extern/pybind11/docs/classes.rst CHANGED
@@ -1,555 +1,555 @@
1
- .. _classes:
2
-
3
- Object-oriented code
4
- ####################
5
-
6
- Creating bindings for a custom type
7
- ===================================
8
-
9
- Let's now look at a more complex example where we'll create bindings for a
10
- custom C++ data structure named ``Pet``. Its definition is given below:
11
-
12
- .. code-block:: cpp
13
-
14
- struct Pet {
15
- Pet(const std::string &name) : name(name) { }
16
- void setName(const std::string &name_) { name = name_; }
17
- const std::string &getName() const { return name; }
18
-
19
- std::string name;
20
- };
21
-
22
- The binding code for ``Pet`` looks as follows:
23
-
24
- .. code-block:: cpp
25
-
26
- #include <pybind11/pybind11.h>
27
-
28
- namespace py = pybind11;
29
-
30
- PYBIND11_MODULE(example, m) {
31
- py::class_<Pet>(m, "Pet")
32
- .def(py::init<const std::string &>())
33
- .def("setName", &Pet::setName)
34
- .def("getName", &Pet::getName);
35
- }
36
-
37
- :class:`class_` creates bindings for a C++ *class* or *struct*-style data
38
- structure. :func:`init` is a convenience function that takes the types of a
39
- constructor's parameters as template arguments and wraps the corresponding
40
- constructor (see the :ref:`custom_constructors` section for details). An
41
- interactive Python session demonstrating this example is shown below:
42
-
43
- .. code-block:: pycon
44
-
45
- % python
46
- >>> import example
47
- >>> p = example.Pet("Molly")
48
- >>> print(p)
49
- <example.Pet object at 0x10cd98060>
50
- >>> p.getName()
51
- 'Molly'
52
- >>> p.setName("Charly")
53
- >>> p.getName()
54
- 'Charly'
55
-
56
- .. seealso::
57
-
58
- Static member functions can be bound in the same way using
59
- :func:`class_::def_static`.
60
-
61
- .. note::
62
-
63
- Binding C++ types in unnamed namespaces (also known as anonymous namespaces)
64
- works reliably on many platforms, but not all. The `XFAIL_CONDITION` in
65
- tests/test_unnamed_namespace_a.py encodes the currently known conditions.
66
- For background see `#4319 <https://github.com/pybind/pybind11/pull/4319>`_.
67
- If portability is a concern, it is therefore not recommended to bind C++
68
- types in unnamed namespaces. It will be safest to manually pick unique
69
- namespace names.
70
-
71
- Keyword and default arguments
72
- =============================
73
- It is possible to specify keyword and default arguments using the syntax
74
- discussed in the previous chapter. Refer to the sections :ref:`keyword_args`
75
- and :ref:`default_args` for details.
76
-
77
- Binding lambda functions
78
- ========================
79
-
80
- Note how ``print(p)`` produced a rather useless summary of our data structure in the example above:
81
-
82
- .. code-block:: pycon
83
-
84
- >>> print(p)
85
- <example.Pet object at 0x10cd98060>
86
-
87
- To address this, we could bind a utility function that returns a human-readable
88
- summary to the special method slot named ``__repr__``. Unfortunately, there is no
89
- suitable functionality in the ``Pet`` data structure, and it would be nice if
90
- we did not have to change it. This can easily be accomplished by binding a
91
- Lambda function instead:
92
-
93
- .. code-block:: cpp
94
-
95
- py::class_<Pet>(m, "Pet")
96
- .def(py::init<const std::string &>())
97
- .def("setName", &Pet::setName)
98
- .def("getName", &Pet::getName)
99
- .def("__repr__",
100
- [](const Pet &a) {
101
- return "<example.Pet named '" + a.name + "'>";
102
- }
103
- );
104
-
105
- Both stateless [#f1]_ and stateful lambda closures are supported by pybind11.
106
- With the above change, the same Python code now produces the following output:
107
-
108
- .. code-block:: pycon
109
-
110
- >>> print(p)
111
- <example.Pet named 'Molly'>
112
-
113
- .. [#f1] Stateless closures are those with an empty pair of brackets ``[]`` as the capture object.
114
-
115
- .. _properties:
116
-
117
- Instance and static fields
118
- ==========================
119
-
120
- We can also directly expose the ``name`` field using the
121
- :func:`class_::def_readwrite` method. A similar :func:`class_::def_readonly`
122
- method also exists for ``const`` fields.
123
-
124
- .. code-block:: cpp
125
-
126
- py::class_<Pet>(m, "Pet")
127
- .def(py::init<const std::string &>())
128
- .def_readwrite("name", &Pet::name)
129
- // ... remainder ...
130
-
131
- This makes it possible to write
132
-
133
- .. code-block:: pycon
134
-
135
- >>> p = example.Pet("Molly")
136
- >>> p.name
137
- 'Molly'
138
- >>> p.name = "Charly"
139
- >>> p.name
140
- 'Charly'
141
-
142
- Now suppose that ``Pet::name`` was a private internal variable
143
- that can only be accessed via setters and getters.
144
-
145
- .. code-block:: cpp
146
-
147
- class Pet {
148
- public:
149
- Pet(const std::string &name) : name(name) { }
150
- void setName(const std::string &name_) { name = name_; }
151
- const std::string &getName() const { return name; }
152
- private:
153
- std::string name;
154
- };
155
-
156
- In this case, the method :func:`class_::def_property`
157
- (:func:`class_::def_property_readonly` for read-only data) can be used to
158
- provide a field-like interface within Python that will transparently call
159
- the setter and getter functions:
160
-
161
- .. code-block:: cpp
162
-
163
- py::class_<Pet>(m, "Pet")
164
- .def(py::init<const std::string &>())
165
- .def_property("name", &Pet::getName, &Pet::setName)
166
- // ... remainder ...
167
-
168
- Write only properties can be defined by passing ``nullptr`` as the
169
- input for the read function.
170
-
171
- .. seealso::
172
-
173
- Similar functions :func:`class_::def_readwrite_static`,
174
- :func:`class_::def_readonly_static` :func:`class_::def_property_static`,
175
- and :func:`class_::def_property_readonly_static` are provided for binding
176
- static variables and properties. Please also see the section on
177
- :ref:`static_properties` in the advanced part of the documentation.
178
-
179
- Dynamic attributes
180
- ==================
181
-
182
- Native Python classes can pick up new attributes dynamically:
183
-
184
- .. code-block:: pycon
185
-
186
- >>> class Pet:
187
- ... name = "Molly"
188
- ...
189
- >>> p = Pet()
190
- >>> p.name = "Charly" # overwrite existing
191
- >>> p.age = 2 # dynamically add a new attribute
192
-
193
- By default, classes exported from C++ do not support this and the only writable
194
- attributes are the ones explicitly defined using :func:`class_::def_readwrite`
195
- or :func:`class_::def_property`.
196
-
197
- .. code-block:: cpp
198
-
199
- py::class_<Pet>(m, "Pet")
200
- .def(py::init<>())
201
- .def_readwrite("name", &Pet::name);
202
-
203
- Trying to set any other attribute results in an error:
204
-
205
- .. code-block:: pycon
206
-
207
- >>> p = example.Pet()
208
- >>> p.name = "Charly" # OK, attribute defined in C++
209
- >>> p.age = 2 # fail
210
- AttributeError: 'Pet' object has no attribute 'age'
211
-
212
- To enable dynamic attributes for C++ classes, the :class:`py::dynamic_attr` tag
213
- must be added to the :class:`py::class_` constructor:
214
-
215
- .. code-block:: cpp
216
-
217
- py::class_<Pet>(m, "Pet", py::dynamic_attr())
218
- .def(py::init<>())
219
- .def_readwrite("name", &Pet::name);
220
-
221
- Now everything works as expected:
222
-
223
- .. code-block:: pycon
224
-
225
- >>> p = example.Pet()
226
- >>> p.name = "Charly" # OK, overwrite value in C++
227
- >>> p.age = 2 # OK, dynamically add a new attribute
228
- >>> p.__dict__ # just like a native Python class
229
- {'age': 2}
230
-
231
- Note that there is a small runtime cost for a class with dynamic attributes.
232
- Not only because of the addition of a ``__dict__``, but also because of more
233
- expensive garbage collection tracking which must be activated to resolve
234
- possible circular references. Native Python classes incur this same cost by
235
- default, so this is not anything to worry about. By default, pybind11 classes
236
- are more efficient than native Python classes. Enabling dynamic attributes
237
- just brings them on par.
238
-
239
- .. _inheritance:
240
-
241
- Inheritance and automatic downcasting
242
- =====================================
243
-
244
- Suppose now that the example consists of two data structures with an
245
- inheritance relationship:
246
-
247
- .. code-block:: cpp
248
-
249
- struct Pet {
250
- Pet(const std::string &name) : name(name) { }
251
- std::string name;
252
- };
253
-
254
- struct Dog : Pet {
255
- Dog(const std::string &name) : Pet(name) { }
256
- std::string bark() const { return "woof!"; }
257
- };
258
-
259
- There are two different ways of indicating a hierarchical relationship to
260
- pybind11: the first specifies the C++ base class as an extra template
261
- parameter of the :class:`class_`:
262
-
263
- .. code-block:: cpp
264
-
265
- py::class_<Pet>(m, "Pet")
266
- .def(py::init<const std::string &>())
267
- .def_readwrite("name", &Pet::name);
268
-
269
- // Method 1: template parameter:
270
- py::class_<Dog, Pet /* <- specify C++ parent type */>(m, "Dog")
271
- .def(py::init<const std::string &>())
272
- .def("bark", &Dog::bark);
273
-
274
- Alternatively, we can also assign a name to the previously bound ``Pet``
275
- :class:`class_` object and reference it when binding the ``Dog`` class:
276
-
277
- .. code-block:: cpp
278
-
279
- py::class_<Pet> pet(m, "Pet");
280
- pet.def(py::init<const std::string &>())
281
- .def_readwrite("name", &Pet::name);
282
-
283
- // Method 2: pass parent class_ object:
284
- py::class_<Dog>(m, "Dog", pet /* <- specify Python parent type */)
285
- .def(py::init<const std::string &>())
286
- .def("bark", &Dog::bark);
287
-
288
- Functionality-wise, both approaches are equivalent. Afterwards, instances will
289
- expose fields and methods of both types:
290
-
291
- .. code-block:: pycon
292
-
293
- >>> p = example.Dog("Molly")
294
- >>> p.name
295
- 'Molly'
296
- >>> p.bark()
297
- 'woof!'
298
-
299
- The C++ classes defined above are regular non-polymorphic types with an
300
- inheritance relationship. This is reflected in Python:
301
-
302
- .. code-block:: cpp
303
-
304
- // Return a base pointer to a derived instance
305
- m.def("pet_store", []() { return std::unique_ptr<Pet>(new Dog("Molly")); });
306
-
307
- .. code-block:: pycon
308
-
309
- >>> p = example.pet_store()
310
- >>> type(p) # `Dog` instance behind `Pet` pointer
311
- Pet # no pointer downcasting for regular non-polymorphic types
312
- >>> p.bark()
313
- AttributeError: 'Pet' object has no attribute 'bark'
314
-
315
- The function returned a ``Dog`` instance, but because it's a non-polymorphic
316
- type behind a base pointer, Python only sees a ``Pet``. In C++, a type is only
317
- considered polymorphic if it has at least one virtual function and pybind11
318
- will automatically recognize this:
319
-
320
- .. code-block:: cpp
321
-
322
- struct PolymorphicPet {
323
- virtual ~PolymorphicPet() = default;
324
- };
325
-
326
- struct PolymorphicDog : PolymorphicPet {
327
- std::string bark() const { return "woof!"; }
328
- };
329
-
330
- // Same binding code
331
- py::class_<PolymorphicPet>(m, "PolymorphicPet");
332
- py::class_<PolymorphicDog, PolymorphicPet>(m, "PolymorphicDog")
333
- .def(py::init<>())
334
- .def("bark", &PolymorphicDog::bark);
335
-
336
- // Again, return a base pointer to a derived instance
337
- m.def("pet_store2", []() { return std::unique_ptr<PolymorphicPet>(new PolymorphicDog); });
338
-
339
- .. code-block:: pycon
340
-
341
- >>> p = example.pet_store2()
342
- >>> type(p)
343
- PolymorphicDog # automatically downcast
344
- >>> p.bark()
345
- 'woof!'
346
-
347
- Given a pointer to a polymorphic base, pybind11 performs automatic downcasting
348
- to the actual derived type. Note that this goes beyond the usual situation in
349
- C++: we don't just get access to the virtual functions of the base, we get the
350
- concrete derived type including functions and attributes that the base type may
351
- not even be aware of.
352
-
353
- .. seealso::
354
-
355
- For more information about polymorphic behavior see :ref:`overriding_virtuals`.
356
-
357
-
358
- Overloaded methods
359
- ==================
360
-
361
- Sometimes there are several overloaded C++ methods with the same name taking
362
- different kinds of input arguments:
363
-
364
- .. code-block:: cpp
365
-
366
- struct Pet {
367
- Pet(const std::string &name, int age) : name(name), age(age) { }
368
-
369
- void set(int age_) { age = age_; }
370
- void set(const std::string &name_) { name = name_; }
371
-
372
- std::string name;
373
- int age;
374
- };
375
-
376
- Attempting to bind ``Pet::set`` will cause an error since the compiler does not
377
- know which method the user intended to select. We can disambiguate by casting
378
- them to function pointers. Binding multiple functions to the same Python name
379
- automatically creates a chain of function overloads that will be tried in
380
- sequence.
381
-
382
- .. code-block:: cpp
383
-
384
- py::class_<Pet>(m, "Pet")
385
- .def(py::init<const std::string &, int>())
386
- .def("set", static_cast<void (Pet::*)(int)>(&Pet::set), "Set the pet's age")
387
- .def("set", static_cast<void (Pet::*)(const std::string &)>(&Pet::set), "Set the pet's name");
388
-
389
- The overload signatures are also visible in the method's docstring:
390
-
391
- .. code-block:: pycon
392
-
393
- >>> help(example.Pet)
394
-
395
- class Pet(__builtin__.object)
396
- | Methods defined here:
397
- |
398
- | __init__(...)
399
- | Signature : (Pet, str, int) -> NoneType
400
- |
401
- | set(...)
402
- | 1. Signature : (Pet, int) -> NoneType
403
- |
404
- | Set the pet's age
405
- |
406
- | 2. Signature : (Pet, str) -> NoneType
407
- |
408
- | Set the pet's name
409
-
410
- If you have a C++14 compatible compiler [#cpp14]_, you can use an alternative
411
- syntax to cast the overloaded function:
412
-
413
- .. code-block:: cpp
414
-
415
- py::class_<Pet>(m, "Pet")
416
- .def("set", py::overload_cast<int>(&Pet::set), "Set the pet's age")
417
- .def("set", py::overload_cast<const std::string &>(&Pet::set), "Set the pet's name");
418
-
419
- Here, ``py::overload_cast`` only requires the parameter types to be specified.
420
- The return type and class are deduced. This avoids the additional noise of
421
- ``void (Pet::*)()`` as seen in the raw cast. If a function is overloaded based
422
- on constness, the ``py::const_`` tag should be used:
423
-
424
- .. code-block:: cpp
425
-
426
- struct Widget {
427
- int foo(int x, float y);
428
- int foo(int x, float y) const;
429
- };
430
-
431
- py::class_<Widget>(m, "Widget")
432
- .def("foo_mutable", py::overload_cast<int, float>(&Widget::foo))
433
- .def("foo_const", py::overload_cast<int, float>(&Widget::foo, py::const_));
434
-
435
- If you prefer the ``py::overload_cast`` syntax but have a C++11 compatible compiler only,
436
- you can use ``py::detail::overload_cast_impl`` with an additional set of parentheses:
437
-
438
- .. code-block:: cpp
439
-
440
- template <typename... Args>
441
- using overload_cast_ = pybind11::detail::overload_cast_impl<Args...>;
442
-
443
- py::class_<Pet>(m, "Pet")
444
- .def("set", overload_cast_<int>()(&Pet::set), "Set the pet's age")
445
- .def("set", overload_cast_<const std::string &>()(&Pet::set), "Set the pet's name");
446
-
447
- .. [#cpp14] A compiler which supports the ``-std=c++14`` flag.
448
-
449
- .. note::
450
-
451
- To define multiple overloaded constructors, simply declare one after the
452
- other using the ``.def(py::init<...>())`` syntax. The existing machinery
453
- for specifying keyword and default arguments also works.
454
-
455
- Enumerations and internal types
456
- ===============================
457
-
458
- Let's now suppose that the example class contains internal types like enumerations, e.g.:
459
-
460
- .. code-block:: cpp
461
-
462
- struct Pet {
463
- enum Kind {
464
- Dog = 0,
465
- Cat
466
- };
467
-
468
- struct Attributes {
469
- float age = 0;
470
- };
471
-
472
- Pet(const std::string &name, Kind type) : name(name), type(type) { }
473
-
474
- std::string name;
475
- Kind type;
476
- Attributes attr;
477
- };
478
-
479
- The binding code for this example looks as follows:
480
-
481
- .. code-block:: cpp
482
-
483
- py::class_<Pet> pet(m, "Pet");
484
-
485
- pet.def(py::init<const std::string &, Pet::Kind>())
486
- .def_readwrite("name", &Pet::name)
487
- .def_readwrite("type", &Pet::type)
488
- .def_readwrite("attr", &Pet::attr);
489
-
490
- py::enum_<Pet::Kind>(pet, "Kind")
491
- .value("Dog", Pet::Kind::Dog)
492
- .value("Cat", Pet::Kind::Cat)
493
- .export_values();
494
-
495
- py::class_<Pet::Attributes>(pet, "Attributes")
496
- .def(py::init<>())
497
- .def_readwrite("age", &Pet::Attributes::age);
498
-
499
-
500
- To ensure that the nested types ``Kind`` and ``Attributes`` are created within the scope of ``Pet``, the
501
- ``pet`` :class:`class_` instance must be supplied to the :class:`enum_` and :class:`class_`
502
- constructor. The :func:`enum_::export_values` function exports the enum entries
503
- into the parent scope, which should be skipped for newer C++11-style strongly
504
- typed enums.
505
-
506
- .. code-block:: pycon
507
-
508
- >>> p = Pet("Lucy", Pet.Cat)
509
- >>> p.type
510
- Kind.Cat
511
- >>> int(p.type)
512
- 1L
513
-
514
- The entries defined by the enumeration type are exposed in the ``__members__`` property:
515
-
516
- .. code-block:: pycon
517
-
518
- >>> Pet.Kind.__members__
519
- {'Dog': Kind.Dog, 'Cat': Kind.Cat}
520
-
521
- The ``name`` property returns the name of the enum value as a unicode string.
522
-
523
- .. note::
524
-
525
- It is also possible to use ``str(enum)``, however these accomplish different
526
- goals. The following shows how these two approaches differ.
527
-
528
- .. code-block:: pycon
529
-
530
- >>> p = Pet("Lucy", Pet.Cat)
531
- >>> pet_type = p.type
532
- >>> pet_type
533
- Pet.Cat
534
- >>> str(pet_type)
535
- 'Pet.Cat'
536
- >>> pet_type.name
537
- 'Cat'
538
-
539
- .. note::
540
-
541
- When the special tag ``py::arithmetic()`` is specified to the ``enum_``
542
- constructor, pybind11 creates an enumeration that also supports rudimentary
543
- arithmetic and bit-level operations like comparisons, and, or, xor, negation,
544
- etc.
545
-
546
- .. code-block:: cpp
547
-
548
- py::enum_<Pet::Kind>(pet, "Kind", py::arithmetic())
549
- ...
550
-
551
- By default, these are omitted to conserve space.
552
-
553
- .. warning::
554
-
555
- Contrary to Python customs, enum values from the wrappers should not be compared using ``is``, but with ``==`` (see `#1177 <https://github.com/pybind/pybind11/issues/1177>`_ for background).
 
1
+ .. _classes:
2
+
3
+ Object-oriented code
4
+ ####################
5
+
6
+ Creating bindings for a custom type
7
+ ===================================
8
+
9
+ Let's now look at a more complex example where we'll create bindings for a
10
+ custom C++ data structure named ``Pet``. Its definition is given below:
11
+
12
+ .. code-block:: cpp
13
+
14
+ struct Pet {
15
+ Pet(const std::string &name) : name(name) { }
16
+ void setName(const std::string &name_) { name = name_; }
17
+ const std::string &getName() const { return name; }
18
+
19
+ std::string name;
20
+ };
21
+
22
+ The binding code for ``Pet`` looks as follows:
23
+
24
+ .. code-block:: cpp
25
+
26
+ #include <pybind11/pybind11.h>
27
+
28
+ namespace py = pybind11;
29
+
30
+ PYBIND11_MODULE(example, m) {
31
+ py::class_<Pet>(m, "Pet")
32
+ .def(py::init<const std::string &>())
33
+ .def("setName", &Pet::setName)
34
+ .def("getName", &Pet::getName);
35
+ }
36
+
37
+ :class:`class_` creates bindings for a C++ *class* or *struct*-style data
38
+ structure. :func:`init` is a convenience function that takes the types of a
39
+ constructor's parameters as template arguments and wraps the corresponding
40
+ constructor (see the :ref:`custom_constructors` section for details). An
41
+ interactive Python session demonstrating this example is shown below:
42
+
43
+ .. code-block:: pycon
44
+
45
+ % python
46
+ >>> import example
47
+ >>> p = example.Pet("Molly")
48
+ >>> print(p)
49
+ <example.Pet object at 0x10cd98060>
50
+ >>> p.getName()
51
+ 'Molly'
52
+ >>> p.setName("Charly")
53
+ >>> p.getName()
54
+ 'Charly'
55
+
56
+ .. seealso::
57
+
58
+ Static member functions can be bound in the same way using
59
+ :func:`class_::def_static`.
60
+
61
+ .. note::
62
+
63
+ Binding C++ types in unnamed namespaces (also known as anonymous namespaces)
64
+ works reliably on many platforms, but not all. The `XFAIL_CONDITION` in
65
+ tests/test_unnamed_namespace_a.py encodes the currently known conditions.
66
+ For background see `#4319 <https://github.com/pybind/pybind11/pull/4319>`_.
67
+ If portability is a concern, it is therefore not recommended to bind C++
68
+ types in unnamed namespaces. It will be safest to manually pick unique
69
+ namespace names.
70
+
71
+ Keyword and default arguments
72
+ =============================
73
+ It is possible to specify keyword and default arguments using the syntax
74
+ discussed in the previous chapter. Refer to the sections :ref:`keyword_args`
75
+ and :ref:`default_args` for details.
76
+
77
+ Binding lambda functions
78
+ ========================
79
+
80
+ Note how ``print(p)`` produced a rather useless summary of our data structure in the example above:
81
+
82
+ .. code-block:: pycon
83
+
84
+ >>> print(p)
85
+ <example.Pet object at 0x10cd98060>
86
+
87
+ To address this, we could bind a utility function that returns a human-readable
88
+ summary to the special method slot named ``__repr__``. Unfortunately, there is no
89
+ suitable functionality in the ``Pet`` data structure, and it would be nice if
90
+ we did not have to change it. This can easily be accomplished by binding a
91
+ Lambda function instead:
92
+
93
+ .. code-block:: cpp
94
+
95
+ py::class_<Pet>(m, "Pet")
96
+ .def(py::init<const std::string &>())
97
+ .def("setName", &Pet::setName)
98
+ .def("getName", &Pet::getName)
99
+ .def("__repr__",
100
+ [](const Pet &a) {
101
+ return "<example.Pet named '" + a.name + "'>";
102
+ }
103
+ );
104
+
105
+ Both stateless [#f1]_ and stateful lambda closures are supported by pybind11.
106
+ With the above change, the same Python code now produces the following output:
107
+
108
+ .. code-block:: pycon
109
+
110
+ >>> print(p)
111
+ <example.Pet named 'Molly'>
112
+
113
+ .. [#f1] Stateless closures are those with an empty pair of brackets ``[]`` as the capture object.
114
+
115
+ .. _properties:
116
+
117
+ Instance and static fields
118
+ ==========================
119
+
120
+ We can also directly expose the ``name`` field using the
121
+ :func:`class_::def_readwrite` method. A similar :func:`class_::def_readonly`
122
+ method also exists for ``const`` fields.
123
+
124
+ .. code-block:: cpp
125
+
126
+ py::class_<Pet>(m, "Pet")
127
+ .def(py::init<const std::string &>())
128
+ .def_readwrite("name", &Pet::name)
129
+ // ... remainder ...
130
+
131
+ This makes it possible to write
132
+
133
+ .. code-block:: pycon
134
+
135
+ >>> p = example.Pet("Molly")
136
+ >>> p.name
137
+ 'Molly'
138
+ >>> p.name = "Charly"
139
+ >>> p.name
140
+ 'Charly'
141
+
142
+ Now suppose that ``Pet::name`` was a private internal variable
143
+ that can only be accessed via setters and getters.
144
+
145
+ .. code-block:: cpp
146
+
147
+ class Pet {
148
+ public:
149
+ Pet(const std::string &name) : name(name) { }
150
+ void setName(const std::string &name_) { name = name_; }
151
+ const std::string &getName() const { return name; }
152
+ private:
153
+ std::string name;
154
+ };
155
+
156
+ In this case, the method :func:`class_::def_property`
157
+ (:func:`class_::def_property_readonly` for read-only data) can be used to
158
+ provide a field-like interface within Python that will transparently call
159
+ the setter and getter functions:
160
+
161
+ .. code-block:: cpp
162
+
163
+ py::class_<Pet>(m, "Pet")
164
+ .def(py::init<const std::string &>())
165
+ .def_property("name", &Pet::getName, &Pet::setName)
166
+ // ... remainder ...
167
+
168
+ Write only properties can be defined by passing ``nullptr`` as the
169
+ input for the read function.
170
+
171
+ .. seealso::
172
+
173
+ Similar functions :func:`class_::def_readwrite_static`,
174
+ :func:`class_::def_readonly_static` :func:`class_::def_property_static`,
175
+ and :func:`class_::def_property_readonly_static` are provided for binding
176
+ static variables and properties. Please also see the section on
177
+ :ref:`static_properties` in the advanced part of the documentation.
178
+
179
+ Dynamic attributes
180
+ ==================
181
+
182
+ Native Python classes can pick up new attributes dynamically:
183
+
184
+ .. code-block:: pycon
185
+
186
+ >>> class Pet:
187
+ ... name = "Molly"
188
+ ...
189
+ >>> p = Pet()
190
+ >>> p.name = "Charly" # overwrite existing
191
+ >>> p.age = 2 # dynamically add a new attribute
192
+
193
+ By default, classes exported from C++ do not support this and the only writable
194
+ attributes are the ones explicitly defined using :func:`class_::def_readwrite`
195
+ or :func:`class_::def_property`.
196
+
197
+ .. code-block:: cpp
198
+
199
+ py::class_<Pet>(m, "Pet")
200
+ .def(py::init<>())
201
+ .def_readwrite("name", &Pet::name);
202
+
203
+ Trying to set any other attribute results in an error:
204
+
205
+ .. code-block:: pycon
206
+
207
+ >>> p = example.Pet()
208
+ >>> p.name = "Charly" # OK, attribute defined in C++
209
+ >>> p.age = 2 # fail
210
+ AttributeError: 'Pet' object has no attribute 'age'
211
+
212
+ To enable dynamic attributes for C++ classes, the :class:`py::dynamic_attr` tag
213
+ must be added to the :class:`py::class_` constructor:
214
+
215
+ .. code-block:: cpp
216
+
217
+ py::class_<Pet>(m, "Pet", py::dynamic_attr())
218
+ .def(py::init<>())
219
+ .def_readwrite("name", &Pet::name);
220
+
221
+ Now everything works as expected:
222
+
223
+ .. code-block:: pycon
224
+
225
+ >>> p = example.Pet()
226
+ >>> p.name = "Charly" # OK, overwrite value in C++
227
+ >>> p.age = 2 # OK, dynamically add a new attribute
228
+ >>> p.__dict__ # just like a native Python class
229
+ {'age': 2}
230
+
231
+ Note that there is a small runtime cost for a class with dynamic attributes.
232
+ Not only because of the addition of a ``__dict__``, but also because of more
233
+ expensive garbage collection tracking which must be activated to resolve
234
+ possible circular references. Native Python classes incur this same cost by
235
+ default, so this is not anything to worry about. By default, pybind11 classes
236
+ are more efficient than native Python classes. Enabling dynamic attributes
237
+ just brings them on par.
238
+
239
+ .. _inheritance:
240
+
241
+ Inheritance and automatic downcasting
242
+ =====================================
243
+
244
+ Suppose now that the example consists of two data structures with an
245
+ inheritance relationship:
246
+
247
+ .. code-block:: cpp
248
+
249
+ struct Pet {
250
+ Pet(const std::string &name) : name(name) { }
251
+ std::string name;
252
+ };
253
+
254
+ struct Dog : Pet {
255
+ Dog(const std::string &name) : Pet(name) { }
256
+ std::string bark() const { return "woof!"; }
257
+ };
258
+
259
+ There are two different ways of indicating a hierarchical relationship to
260
+ pybind11: the first specifies the C++ base class as an extra template
261
+ parameter of the :class:`class_`:
262
+
263
+ .. code-block:: cpp
264
+
265
+ py::class_<Pet>(m, "Pet")
266
+ .def(py::init<const std::string &>())
267
+ .def_readwrite("name", &Pet::name);
268
+
269
+ // Method 1: template parameter:
270
+ py::class_<Dog, Pet /* <- specify C++ parent type */>(m, "Dog")
271
+ .def(py::init<const std::string &>())
272
+ .def("bark", &Dog::bark);
273
+
274
+ Alternatively, we can also assign a name to the previously bound ``Pet``
275
+ :class:`class_` object and reference it when binding the ``Dog`` class:
276
+
277
+ .. code-block:: cpp
278
+
279
+ py::class_<Pet> pet(m, "Pet");
280
+ pet.def(py::init<const std::string &>())
281
+ .def_readwrite("name", &Pet::name);
282
+
283
+ // Method 2: pass parent class_ object:
284
+ py::class_<Dog>(m, "Dog", pet /* <- specify Python parent type */)
285
+ .def(py::init<const std::string &>())
286
+ .def("bark", &Dog::bark);
287
+
288
+ Functionality-wise, both approaches are equivalent. Afterwards, instances will
289
+ expose fields and methods of both types:
290
+
291
+ .. code-block:: pycon
292
+
293
+ >>> p = example.Dog("Molly")
294
+ >>> p.name
295
+ 'Molly'
296
+ >>> p.bark()
297
+ 'woof!'
298
+
299
+ The C++ classes defined above are regular non-polymorphic types with an
300
+ inheritance relationship. This is reflected in Python:
301
+
302
+ .. code-block:: cpp
303
+
304
+ // Return a base pointer to a derived instance
305
+ m.def("pet_store", []() { return std::unique_ptr<Pet>(new Dog("Molly")); });
306
+
307
+ .. code-block:: pycon
308
+
309
+ >>> p = example.pet_store()
310
+ >>> type(p) # `Dog` instance behind `Pet` pointer
311
+ Pet # no pointer downcasting for regular non-polymorphic types
312
+ >>> p.bark()
313
+ AttributeError: 'Pet' object has no attribute 'bark'
314
+
315
+ The function returned a ``Dog`` instance, but because it's a non-polymorphic
316
+ type behind a base pointer, Python only sees a ``Pet``. In C++, a type is only
317
+ considered polymorphic if it has at least one virtual function and pybind11
318
+ will automatically recognize this:
319
+
320
+ .. code-block:: cpp
321
+
322
+ struct PolymorphicPet {
323
+ virtual ~PolymorphicPet() = default;
324
+ };
325
+
326
+ struct PolymorphicDog : PolymorphicPet {
327
+ std::string bark() const { return "woof!"; }
328
+ };
329
+
330
+ // Same binding code
331
+ py::class_<PolymorphicPet>(m, "PolymorphicPet");
332
+ py::class_<PolymorphicDog, PolymorphicPet>(m, "PolymorphicDog")
333
+ .def(py::init<>())
334
+ .def("bark", &PolymorphicDog::bark);
335
+
336
+ // Again, return a base pointer to a derived instance
337
+ m.def("pet_store2", []() { return std::unique_ptr<PolymorphicPet>(new PolymorphicDog); });
338
+
339
+ .. code-block:: pycon
340
+
341
+ >>> p = example.pet_store2()
342
+ >>> type(p)
343
+ PolymorphicDog # automatically downcast
344
+ >>> p.bark()
345
+ 'woof!'
346
+
347
+ Given a pointer to a polymorphic base, pybind11 performs automatic downcasting
348
+ to the actual derived type. Note that this goes beyond the usual situation in
349
+ C++: we don't just get access to the virtual functions of the base, we get the
350
+ concrete derived type including functions and attributes that the base type may
351
+ not even be aware of.
352
+
353
+ .. seealso::
354
+
355
+ For more information about polymorphic behavior see :ref:`overriding_virtuals`.
356
+
357
+
358
+ Overloaded methods
359
+ ==================
360
+
361
+ Sometimes there are several overloaded C++ methods with the same name taking
362
+ different kinds of input arguments:
363
+
364
+ .. code-block:: cpp
365
+
366
+ struct Pet {
367
+ Pet(const std::string &name, int age) : name(name), age(age) { }
368
+
369
+ void set(int age_) { age = age_; }
370
+ void set(const std::string &name_) { name = name_; }
371
+
372
+ std::string name;
373
+ int age;
374
+ };
375
+
376
+ Attempting to bind ``Pet::set`` will cause an error since the compiler does not
377
+ know which method the user intended to select. We can disambiguate by casting
378
+ them to function pointers. Binding multiple functions to the same Python name
379
+ automatically creates a chain of function overloads that will be tried in
380
+ sequence.
381
+
382
+ .. code-block:: cpp
383
+
384
+ py::class_<Pet>(m, "Pet")
385
+ .def(py::init<const std::string &, int>())
386
+ .def("set", static_cast<void (Pet::*)(int)>(&Pet::set), "Set the pet's age")
387
+ .def("set", static_cast<void (Pet::*)(const std::string &)>(&Pet::set), "Set the pet's name");
388
+
389
+ The overload signatures are also visible in the method's docstring:
390
+
391
+ .. code-block:: pycon
392
+
393
+ >>> help(example.Pet)
394
+
395
+ class Pet(__builtin__.object)
396
+ | Methods defined here:
397
+ |
398
+ | __init__(...)
399
+ | Signature : (Pet, str, int) -> NoneType
400
+ |
401
+ | set(...)
402
+ | 1. Signature : (Pet, int) -> NoneType
403
+ |
404
+ | Set the pet's age
405
+ |
406
+ | 2. Signature : (Pet, str) -> NoneType
407
+ |
408
+ | Set the pet's name
409
+
410
+ If you have a C++14 compatible compiler [#cpp14]_, you can use an alternative
411
+ syntax to cast the overloaded function:
412
+
413
+ .. code-block:: cpp
414
+
415
+ py::class_<Pet>(m, "Pet")
416
+ .def("set", py::overload_cast<int>(&Pet::set), "Set the pet's age")
417
+ .def("set", py::overload_cast<const std::string &>(&Pet::set), "Set the pet's name");
418
+
419
+ Here, ``py::overload_cast`` only requires the parameter types to be specified.
420
+ The return type and class are deduced. This avoids the additional noise of
421
+ ``void (Pet::*)()`` as seen in the raw cast. If a function is overloaded based
422
+ on constness, the ``py::const_`` tag should be used:
423
+
424
+ .. code-block:: cpp
425
+
426
+ struct Widget {
427
+ int foo(int x, float y);
428
+ int foo(int x, float y) const;
429
+ };
430
+
431
+ py::class_<Widget>(m, "Widget")
432
+ .def("foo_mutable", py::overload_cast<int, float>(&Widget::foo))
433
+ .def("foo_const", py::overload_cast<int, float>(&Widget::foo, py::const_));
434
+
435
+ If you prefer the ``py::overload_cast`` syntax but have a C++11 compatible compiler only,
436
+ you can use ``py::detail::overload_cast_impl`` with an additional set of parentheses:
437
+
438
+ .. code-block:: cpp
439
+
440
+ template <typename... Args>
441
+ using overload_cast_ = pybind11::detail::overload_cast_impl<Args...>;
442
+
443
+ py::class_<Pet>(m, "Pet")
444
+ .def("set", overload_cast_<int>()(&Pet::set), "Set the pet's age")
445
+ .def("set", overload_cast_<const std::string &>()(&Pet::set), "Set the pet's name");
446
+
447
+ .. [#cpp14] A compiler which supports the ``-std=c++14`` flag.
448
+
449
+ .. note::
450
+
451
+ To define multiple overloaded constructors, simply declare one after the
452
+ other using the ``.def(py::init<...>())`` syntax. The existing machinery
453
+ for specifying keyword and default arguments also works.
454
+
455
+ Enumerations and internal types
456
+ ===============================
457
+
458
+ Let's now suppose that the example class contains internal types like enumerations, e.g.:
459
+
460
+ .. code-block:: cpp
461
+
462
+ struct Pet {
463
+ enum Kind {
464
+ Dog = 0,
465
+ Cat
466
+ };
467
+
468
+ struct Attributes {
469
+ float age = 0;
470
+ };
471
+
472
+ Pet(const std::string &name, Kind type) : name(name), type(type) { }
473
+
474
+ std::string name;
475
+ Kind type;
476
+ Attributes attr;
477
+ };
478
+
479
+ The binding code for this example looks as follows:
480
+
481
+ .. code-block:: cpp
482
+
483
+ py::class_<Pet> pet(m, "Pet");
484
+
485
+ pet.def(py::init<const std::string &, Pet::Kind>())
486
+ .def_readwrite("name", &Pet::name)
487
+ .def_readwrite("type", &Pet::type)
488
+ .def_readwrite("attr", &Pet::attr);
489
+
490
+ py::enum_<Pet::Kind>(pet, "Kind")
491
+ .value("Dog", Pet::Kind::Dog)
492
+ .value("Cat", Pet::Kind::Cat)
493
+ .export_values();
494
+
495
+ py::class_<Pet::Attributes>(pet, "Attributes")
496
+ .def(py::init<>())
497
+ .def_readwrite("age", &Pet::Attributes::age);
498
+
499
+
500
+ To ensure that the nested types ``Kind`` and ``Attributes`` are created within the scope of ``Pet``, the
501
+ ``pet`` :class:`class_` instance must be supplied to the :class:`enum_` and :class:`class_`
502
+ constructor. The :func:`enum_::export_values` function exports the enum entries
503
+ into the parent scope, which should be skipped for newer C++11-style strongly
504
+ typed enums.
505
+
506
+ .. code-block:: pycon
507
+
508
+ >>> p = Pet("Lucy", Pet.Cat)
509
+ >>> p.type
510
+ Kind.Cat
511
+ >>> int(p.type)
512
+ 1L
513
+
514
+ The entries defined by the enumeration type are exposed in the ``__members__`` property:
515
+
516
+ .. code-block:: pycon
517
+
518
+ >>> Pet.Kind.__members__
519
+ {'Dog': Kind.Dog, 'Cat': Kind.Cat}
520
+
521
+ The ``name`` property returns the name of the enum value as a unicode string.
522
+
523
+ .. note::
524
+
525
+ It is also possible to use ``str(enum)``, however these accomplish different
526
+ goals. The following shows how these two approaches differ.
527
+
528
+ .. code-block:: pycon
529
+
530
+ >>> p = Pet("Lucy", Pet.Cat)
531
+ >>> pet_type = p.type
532
+ >>> pet_type
533
+ Pet.Cat
534
+ >>> str(pet_type)
535
+ 'Pet.Cat'
536
+ >>> pet_type.name
537
+ 'Cat'
538
+
539
+ .. note::
540
+
541
+ When the special tag ``py::arithmetic()`` is specified to the ``enum_``
542
+ constructor, pybind11 creates an enumeration that also supports rudimentary
543
+ arithmetic and bit-level operations like comparisons, and, or, xor, negation,
544
+ etc.
545
+
546
+ .. code-block:: cpp
547
+
548
+ py::enum_<Pet::Kind>(pet, "Kind", py::arithmetic())
549
+ ...
550
+
551
+ By default, these are omitted to conserve space.
552
+
553
+ .. warning::
554
+
555
+ Contrary to Python customs, enum values from the wrappers should not be compared using ``is``, but with ``==`` (see `#1177 <https://github.com/pybind/pybind11/issues/1177>`_ for background).
third_party/CityFlow/extern/pybind11/docs/compiling.rst CHANGED
@@ -1,649 +1,649 @@
1
- .. _compiling:
2
-
3
- Build systems
4
- #############
5
-
6
- .. _build-setuptools:
7
-
8
- Building with setuptools
9
- ========================
10
-
11
- For projects on PyPI, building with setuptools is the way to go. Sylvain Corlay
12
- has kindly provided an example project which shows how to set up everything,
13
- including automatic generation of documentation using Sphinx. Please refer to
14
- the [python_example]_ repository.
15
-
16
- .. [python_example] https://github.com/pybind/python_example
17
-
18
- A helper file is provided with pybind11 that can simplify usage with setuptools.
19
-
20
- To use pybind11 inside your ``setup.py``, you have to have some system to
21
- ensure that ``pybind11`` is installed when you build your package. There are
22
- four possible ways to do this, and pybind11 supports all four: You can ask all
23
- users to install pybind11 beforehand (bad), you can use
24
- :ref:`setup_helpers-pep518` (good, but very new and requires Pip 10),
25
- :ref:`setup_helpers-setup_requires` (discouraged by Python packagers now that
26
- PEP 518 is available, but it still works everywhere), or you can
27
- :ref:`setup_helpers-copy-manually` (always works but you have to manually sync
28
- your copy to get updates).
29
-
30
- An example of a ``setup.py`` using pybind11's helpers:
31
-
32
- .. code-block:: python
33
-
34
- from glob import glob
35
- from setuptools import setup
36
- from pybind11.setup_helpers import Pybind11Extension
37
-
38
- ext_modules = [
39
- Pybind11Extension(
40
- "python_example",
41
- sorted(glob("src/*.cpp")), # Sort source files for reproducibility
42
- ),
43
- ]
44
-
45
- setup(..., ext_modules=ext_modules)
46
-
47
- If you want to do an automatic search for the highest supported C++ standard,
48
- that is supported via a ``build_ext`` command override; it will only affect
49
- ``Pybind11Extensions``:
50
-
51
- .. code-block:: python
52
-
53
- from glob import glob
54
- from setuptools import setup
55
- from pybind11.setup_helpers import Pybind11Extension, build_ext
56
-
57
- ext_modules = [
58
- Pybind11Extension(
59
- "python_example",
60
- sorted(glob("src/*.cpp")),
61
- ),
62
- ]
63
-
64
- setup(..., cmdclass={"build_ext": build_ext}, ext_modules=ext_modules)
65
-
66
- If you have single-file extension modules that are directly stored in the
67
- Python source tree (``foo.cpp`` in the same directory as where a ``foo.py``
68
- would be located), you can also generate ``Pybind11Extensions`` using
69
- ``setup_helpers.intree_extensions``: ``intree_extensions(["path/to/foo.cpp",
70
- ...])`` returns a list of ``Pybind11Extensions`` which can be passed to
71
- ``ext_modules``, possibly after further customizing their attributes
72
- (``libraries``, ``include_dirs``, etc.). By doing so, a ``foo.*.so`` extension
73
- module will be generated and made available upon installation.
74
-
75
- ``intree_extension`` will automatically detect if you are using a ``src``-style
76
- layout (as long as no namespace packages are involved), but you can also
77
- explicitly pass ``package_dir`` to it (as in ``setuptools.setup``).
78
-
79
- Since pybind11 does not require NumPy when building, a light-weight replacement
80
- for NumPy's parallel compilation distutils tool is included. Use it like this:
81
-
82
- .. code-block:: python
83
-
84
- from pybind11.setup_helpers import ParallelCompile
85
-
86
- # Optional multithreaded build
87
- ParallelCompile("NPY_NUM_BUILD_JOBS").install()
88
-
89
- setup(...)
90
-
91
- The argument is the name of an environment variable to control the number of
92
- threads, such as ``NPY_NUM_BUILD_JOBS`` (as used by NumPy), though you can set
93
- something different if you want; ``CMAKE_BUILD_PARALLEL_LEVEL`` is another choice
94
- a user might expect. You can also pass ``default=N`` to set the default number
95
- of threads (0 will take the number of threads available) and ``max=N``, the
96
- maximum number of threads; if you have a large extension you may want set this
97
- to a memory dependent number.
98
-
99
- If you are developing rapidly and have a lot of C++ files, you may want to
100
- avoid rebuilding files that have not changed. For simple cases were you are
101
- using ``pip install -e .`` and do not have local headers, you can skip the
102
- rebuild if an object file is newer than its source (headers are not checked!)
103
- with the following:
104
-
105
- .. code-block:: python
106
-
107
- from pybind11.setup_helpers import ParallelCompile, naive_recompile
108
-
109
- ParallelCompile("NPY_NUM_BUILD_JOBS", needs_recompile=naive_recompile).install()
110
-
111
-
112
- If you have a more complex build, you can implement a smarter function and pass
113
- it to ``needs_recompile``, or you can use [Ccache]_ instead. ``CXX="cache g++"
114
- pip install -e .`` would be the way to use it with GCC, for example. Unlike the
115
- simple solution, this even works even when not compiling in editable mode, but
116
- it does require Ccache to be installed.
117
-
118
- Keep in mind that Pip will not even attempt to rebuild if it thinks it has
119
- already built a copy of your code, which it deduces from the version number.
120
- One way to avoid this is to use [setuptools_scm]_, which will generate a
121
- version number that includes the number of commits since your last tag and a
122
- hash for a dirty directory. Another way to force a rebuild is purge your cache
123
- or use Pip's ``--no-cache-dir`` option.
124
-
125
- .. [Ccache] https://ccache.dev
126
-
127
- .. [setuptools_scm] https://github.com/pypa/setuptools_scm
128
-
129
- .. _setup_helpers-pep518:
130
-
131
- PEP 518 requirements (Pip 10+ required)
132
- ---------------------------------------
133
-
134
- If you use `PEP 518's <https://www.python.org/dev/peps/pep-0518/>`_
135
- ``pyproject.toml`` file, you can ensure that ``pybind11`` is available during
136
- the compilation of your project. When this file exists, Pip will make a new
137
- virtual environment, download just the packages listed here in ``requires=``,
138
- and build a wheel (binary Python package). It will then throw away the
139
- environment, and install your wheel.
140
-
141
- Your ``pyproject.toml`` file will likely look something like this:
142
-
143
- .. code-block:: toml
144
-
145
- [build-system]
146
- requires = ["setuptools>=42", "pybind11>=2.6.1"]
147
- build-backend = "setuptools.build_meta"
148
-
149
- .. note::
150
-
151
- The main drawback to this method is that a `PEP 517`_ compliant build tool,
152
- such as Pip 10+, is required for this approach to work; older versions of
153
- Pip completely ignore this file. If you distribute binaries (called wheels
154
- in Python) using something like `cibuildwheel`_, remember that ``setup.py``
155
- and ``pyproject.toml`` are not even contained in the wheel, so this high
156
- Pip requirement is only for source builds, and will not affect users of
157
- your binary wheels. If you are building SDists and wheels, then
158
- `pypa-build`_ is the recommended official tool.
159
-
160
- .. _PEP 517: https://www.python.org/dev/peps/pep-0517/
161
- .. _cibuildwheel: https://cibuildwheel.readthedocs.io
162
- .. _pypa-build: https://pypa-build.readthedocs.io/en/latest/
163
-
164
- .. _setup_helpers-setup_requires:
165
-
166
- Classic ``setup_requires``
167
- --------------------------
168
-
169
- If you want to support old versions of Pip with the classic
170
- ``setup_requires=["pybind11"]`` keyword argument to setup, which triggers a
171
- two-phase ``setup.py`` run, then you will need to use something like this to
172
- ensure the first pass works (which has not yet installed the ``setup_requires``
173
- packages, since it can't install something it does not know about):
174
-
175
- .. code-block:: python
176
-
177
- try:
178
- from pybind11.setup_helpers import Pybind11Extension
179
- except ImportError:
180
- from setuptools import Extension as Pybind11Extension
181
-
182
-
183
- It doesn't matter that the Extension class is not the enhanced subclass for the
184
- first pass run; and the second pass will have the ``setup_requires``
185
- requirements.
186
-
187
- This is obviously more of a hack than the PEP 518 method, but it supports
188
- ancient versions of Pip.
189
-
190
- .. _setup_helpers-copy-manually:
191
-
192
- Copy manually
193
- -------------
194
-
195
- You can also copy ``setup_helpers.py`` directly to your project; it was
196
- designed to be usable standalone, like the old example ``setup.py``. You can
197
- set ``include_pybind11=False`` to skip including the pybind11 package headers,
198
- so you can use it with git submodules and a specific git version. If you use
199
- this, you will need to import from a local file in ``setup.py`` and ensure the
200
- helper file is part of your MANIFEST.
201
-
202
-
203
- Closely related, if you include pybind11 as a subproject, you can run the
204
- ``setup_helpers.py`` inplace. If loaded correctly, this should even pick up
205
- the correct include for pybind11, though you can turn it off as shown above if
206
- you want to input it manually.
207
-
208
- Suggested usage if you have pybind11 as a submodule in ``extern/pybind11``:
209
-
210
- .. code-block:: python
211
-
212
- DIR = os.path.abspath(os.path.dirname(__file__))
213
-
214
- sys.path.append(os.path.join(DIR, "extern", "pybind11"))
215
- from pybind11.setup_helpers import Pybind11Extension # noqa: E402
216
-
217
- del sys.path[-1]
218
-
219
-
220
- .. versionchanged:: 2.6
221
-
222
- Added ``setup_helpers`` file.
223
-
224
- Building with cppimport
225
- ========================
226
-
227
- [cppimport]_ is a small Python import hook that determines whether there is a C++
228
- source file whose name matches the requested module. If there is, the file is
229
- compiled as a Python extension using pybind11 and placed in the same folder as
230
- the C++ source file. Python is then able to find the module and load it.
231
-
232
- .. [cppimport] https://github.com/tbenthompson/cppimport
233
-
234
- .. _cmake:
235
-
236
- Building with CMake
237
- ===================
238
-
239
- For C++ codebases that have an existing CMake-based build system, a Python
240
- extension module can be created with just a few lines of code:
241
-
242
- .. code-block:: cmake
243
-
244
- cmake_minimum_required(VERSION 3.5...3.27)
245
- project(example LANGUAGES CXX)
246
-
247
- add_subdirectory(pybind11)
248
- pybind11_add_module(example example.cpp)
249
-
250
- This assumes that the pybind11 repository is located in a subdirectory named
251
- :file:`pybind11` and that the code is located in a file named :file:`example.cpp`.
252
- The CMake command ``add_subdirectory`` will import the pybind11 project which
253
- provides the ``pybind11_add_module`` function. It will take care of all the
254
- details needed to build a Python extension module on any platform.
255
-
256
- A working sample project, including a way to invoke CMake from :file:`setup.py` for
257
- PyPI integration, can be found in the [cmake_example]_ repository.
258
-
259
- .. [cmake_example] https://github.com/pybind/cmake_example
260
-
261
- .. versionchanged:: 2.6
262
- CMake 3.4+ is required.
263
-
264
- .. versionchanged:: 2.11
265
- CMake 3.5+ is required.
266
-
267
- Further information can be found at :doc:`cmake/index`.
268
-
269
- pybind11_add_module
270
- -------------------
271
-
272
- To ease the creation of Python extension modules, pybind11 provides a CMake
273
- function with the following signature:
274
-
275
- .. code-block:: cmake
276
-
277
- pybind11_add_module(<name> [MODULE | SHARED] [EXCLUDE_FROM_ALL]
278
- [NO_EXTRAS] [THIN_LTO] [OPT_SIZE] source1 [source2 ...])
279
-
280
- This function behaves very much like CMake's builtin ``add_library`` (in fact,
281
- it's a wrapper function around that command). It will add a library target
282
- called ``<name>`` to be built from the listed source files. In addition, it
283
- will take care of all the Python-specific compiler and linker flags as well
284
- as the OS- and Python-version-specific file extension. The produced target
285
- ``<name>`` can be further manipulated with regular CMake commands.
286
-
287
- ``MODULE`` or ``SHARED`` may be given to specify the type of library. If no
288
- type is given, ``MODULE`` is used by default which ensures the creation of a
289
- Python-exclusive module. Specifying ``SHARED`` will create a more traditional
290
- dynamic library which can also be linked from elsewhere. ``EXCLUDE_FROM_ALL``
291
- removes this target from the default build (see CMake docs for details).
292
-
293
- Since pybind11 is a template library, ``pybind11_add_module`` adds compiler
294
- flags to ensure high quality code generation without bloat arising from long
295
- symbol names and duplication of code in different translation units. It
296
- sets default visibility to *hidden*, which is required for some pybind11
297
- features and functionality when attempting to load multiple pybind11 modules
298
- compiled under different pybind11 versions. It also adds additional flags
299
- enabling LTO (Link Time Optimization) and strip unneeded symbols. See the
300
- :ref:`FAQ entry <faq:symhidden>` for a more detailed explanation. These
301
- latter optimizations are never applied in ``Debug`` mode. If ``NO_EXTRAS`` is
302
- given, they will always be disabled, even in ``Release`` mode. However, this
303
- will result in code bloat and is generally not recommended.
304
-
305
- As stated above, LTO is enabled by default. Some newer compilers also support
306
- different flavors of LTO such as `ThinLTO`_. Setting ``THIN_LTO`` will cause
307
- the function to prefer this flavor if available. The function falls back to
308
- regular LTO if ``-flto=thin`` is not available. If
309
- ``CMAKE_INTERPROCEDURAL_OPTIMIZATION`` is set (either ``ON`` or ``OFF``), then
310
- that will be respected instead of the built-in flag search.
311
-
312
- .. note::
313
-
314
- If you want to set the property form on targets or the
315
- ``CMAKE_INTERPROCEDURAL_OPTIMIZATION_<CONFIG>`` versions of this, you should
316
- still use ``set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)`` (otherwise a
317
- no-op) to disable pybind11's ipo flags.
318
-
319
- The ``OPT_SIZE`` flag enables size-based optimization equivalent to the
320
- standard ``/Os`` or ``-Os`` compiler flags and the ``MinSizeRel`` build type,
321
- which avoid optimizations that that can substantially increase the size of the
322
- resulting binary. This flag is particularly useful in projects that are split
323
- into performance-critical parts and associated bindings. In this case, we can
324
- compile the project in release mode (and hence, optimize performance globally),
325
- and specify ``OPT_SIZE`` for the binding target, where size might be the main
326
- concern as performance is often less critical here. A ~25% size reduction has
327
- been observed in practice. This flag only changes the optimization behavior at
328
- a per-target level and takes precedence over the global CMake build type
329
- (``Release``, ``RelWithDebInfo``) except for ``Debug`` builds, where
330
- optimizations remain disabled.
331
-
332
- .. _ThinLTO: http://clang.llvm.org/docs/ThinLTO.html
333
-
334
- Configuration variables
335
- -----------------------
336
-
337
- By default, pybind11 will compile modules with the compiler default or the
338
- minimum standard required by pybind11, whichever is higher. You can set the
339
- standard explicitly with
340
- `CMAKE_CXX_STANDARD <https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_STANDARD.html>`_:
341
-
342
- .. code-block:: cmake
343
-
344
- set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ version selection") # or 11, 14, 17, 20
345
- set(CMAKE_CXX_STANDARD_REQUIRED ON) # optional, ensure standard is supported
346
- set(CMAKE_CXX_EXTENSIONS OFF) # optional, keep compiler extensions off
347
-
348
- The variables can also be set when calling CMake from the command line using
349
- the ``-D<variable>=<value>`` flag. You can also manually set ``CXX_STANDARD``
350
- on a target or use ``target_compile_features`` on your targets - anything that
351
- CMake supports.
352
-
353
- Classic Python support: The target Python version can be selected by setting
354
- ``PYBIND11_PYTHON_VERSION`` or an exact Python installation can be specified
355
- with ``PYTHON_EXECUTABLE``. For example:
356
-
357
- .. code-block:: bash
358
-
359
- cmake -DPYBIND11_PYTHON_VERSION=3.6 ..
360
-
361
- # Another method:
362
- cmake -DPYTHON_EXECUTABLE=/path/to/python ..
363
-
364
- # This often is a good way to get the current Python, works in environments:
365
- cmake -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") ..
366
-
367
-
368
- find_package vs. add_subdirectory
369
- ---------------------------------
370
-
371
- For CMake-based projects that don't include the pybind11 repository internally,
372
- an external installation can be detected through ``find_package(pybind11)``.
373
- See the `Config file`_ docstring for details of relevant CMake variables.
374
-
375
- .. code-block:: cmake
376
-
377
- cmake_minimum_required(VERSION 3.4...3.18)
378
- project(example LANGUAGES CXX)
379
-
380
- find_package(pybind11 REQUIRED)
381
- pybind11_add_module(example example.cpp)
382
-
383
- Note that ``find_package(pybind11)`` will only work correctly if pybind11
384
- has been correctly installed on the system, e. g. after downloading or cloning
385
- the pybind11 repository :
386
-
387
- .. code-block:: bash
388
-
389
- # Classic CMake
390
- cd pybind11
391
- mkdir build
392
- cd build
393
- cmake ..
394
- make install
395
-
396
- # CMake 3.15+
397
- cd pybind11
398
- cmake -S . -B build
399
- cmake --build build -j 2 # Build on 2 cores
400
- cmake --install build
401
-
402
- Once detected, the aforementioned ``pybind11_add_module`` can be employed as
403
- before. The function usage and configuration variables are identical no matter
404
- if pybind11 is added as a subdirectory or found as an installed package. You
405
- can refer to the same [cmake_example]_ repository for a full sample project
406
- -- just swap out ``add_subdirectory`` for ``find_package``.
407
-
408
- .. _Config file: https://github.com/pybind/pybind11/blob/master/tools/pybind11Config.cmake.in
409
-
410
-
411
- .. _find-python-mode:
412
-
413
- FindPython mode
414
- ---------------
415
-
416
- CMake 3.12+ (3.15+ recommended, 3.18.2+ ideal) added a new module called
417
- FindPython that had a highly improved search algorithm and modern targets
418
- and tools. If you use FindPython, pybind11 will detect this and use the
419
- existing targets instead:
420
-
421
- .. code-block:: cmake
422
-
423
- cmake_minimum_required(VERSION 3.15...3.22)
424
- project(example LANGUAGES CXX)
425
-
426
- find_package(Python 3.6 COMPONENTS Interpreter Development REQUIRED)
427
- find_package(pybind11 CONFIG REQUIRED)
428
- # or add_subdirectory(pybind11)
429
-
430
- pybind11_add_module(example example.cpp)
431
-
432
- You can also use the targets (as listed below) with FindPython. If you define
433
- ``PYBIND11_FINDPYTHON``, pybind11 will perform the FindPython step for you
434
- (mostly useful when building pybind11's own tests, or as a way to change search
435
- algorithms from the CMake invocation, with ``-DPYBIND11_FINDPYTHON=ON``.
436
-
437
- .. warning::
438
-
439
- If you use FindPython to multi-target Python versions, use the individual
440
- targets listed below, and avoid targets that directly include Python parts.
441
-
442
- There are `many ways to hint or force a discovery of a specific Python
443
- installation <https://cmake.org/cmake/help/latest/module/FindPython.html>`_),
444
- setting ``Python_ROOT_DIR`` may be the most common one (though with
445
- virtualenv/venv support, and Conda support, this tends to find the correct
446
- Python version more often than the old system did).
447
-
448
- .. warning::
449
-
450
- When the Python libraries (i.e. ``libpythonXX.a`` and ``libpythonXX.so``
451
- on Unix) are not available, as is the case on a manylinux image, the
452
- ``Development`` component will not be resolved by ``FindPython``. When not
453
- using the embedding functionality, CMake 3.18+ allows you to specify
454
- ``Development.Module`` instead of ``Development`` to resolve this issue.
455
-
456
- .. versionadded:: 2.6
457
-
458
- Advanced: interface library targets
459
- -----------------------------------
460
-
461
- Pybind11 supports modern CMake usage patterns with a set of interface targets,
462
- available in all modes. The targets provided are:
463
-
464
- ``pybind11::headers``
465
- Just the pybind11 headers and minimum compile requirements
466
-
467
- ``pybind11::pybind11``
468
- Python headers + ``pybind11::headers``
469
-
470
- ``pybind11::python_link_helper``
471
- Just the "linking" part of pybind11:module
472
-
473
- ``pybind11::module``
474
- Everything for extension modules - ``pybind11::pybind11`` + ``Python::Module`` (FindPython CMake 3.15+) or ``pybind11::python_link_helper``
475
-
476
- ``pybind11::embed``
477
- Everything for embedding the Python interpreter - ``pybind11::pybind11`` + ``Python::Python`` (FindPython) or Python libs
478
-
479
- ``pybind11::lto`` / ``pybind11::thin_lto``
480
- An alternative to `INTERPROCEDURAL_OPTIMIZATION` for adding link-time optimization.
481
-
482
- ``pybind11::windows_extras``
483
- ``/bigobj`` and ``/mp`` for MSVC.
484
-
485
- ``pybind11::opt_size``
486
- ``/Os`` for MSVC, ``-Os`` for other compilers. Does nothing for debug builds.
487
-
488
- Two helper functions are also provided:
489
-
490
- ``pybind11_strip(target)``
491
- Strips a target (uses ``CMAKE_STRIP`` after the target is built)
492
-
493
- ``pybind11_extension(target)``
494
- Sets the correct extension (with SOABI) for a target.
495
-
496
- You can use these targets to build complex applications. For example, the
497
- ``add_python_module`` function is identical to:
498
-
499
- .. code-block:: cmake
500
-
501
- cmake_minimum_required(VERSION 3.5...3.27)
502
- project(example LANGUAGES CXX)
503
-
504
- find_package(pybind11 REQUIRED) # or add_subdirectory(pybind11)
505
-
506
- add_library(example MODULE main.cpp)
507
-
508
- target_link_libraries(example PRIVATE pybind11::module pybind11::lto pybind11::windows_extras)
509
-
510
- pybind11_extension(example)
511
- if(NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo)
512
- # Strip unnecessary sections of the binary on Linux/macOS
513
- pybind11_strip(example)
514
- endif()
515
-
516
- set_target_properties(example PROPERTIES CXX_VISIBILITY_PRESET "hidden"
517
- CUDA_VISIBILITY_PRESET "hidden")
518
-
519
- Instead of setting properties, you can set ``CMAKE_*`` variables to initialize these correctly.
520
-
521
- .. warning::
522
-
523
- Since pybind11 is a metatemplate library, it is crucial that certain
524
- compiler flags are provided to ensure high quality code generation. In
525
- contrast to the ``pybind11_add_module()`` command, the CMake interface
526
- provides a *composable* set of targets to ensure that you retain flexibility.
527
- It can be especially important to provide or set these properties; the
528
- :ref:`FAQ <faq:symhidden>` contains an explanation on why these are needed.
529
-
530
- .. versionadded:: 2.6
531
-
532
- .. _nopython-mode:
533
-
534
- Advanced: NOPYTHON mode
535
- -----------------------
536
-
537
- If you want complete control, you can set ``PYBIND11_NOPYTHON`` to completely
538
- disable Python integration (this also happens if you run ``FindPython2`` and
539
- ``FindPython3`` without running ``FindPython``). This gives you complete
540
- freedom to integrate into an existing system (like `Scikit-Build's
541
- <https://scikit-build.readthedocs.io>`_ ``PythonExtensions``).
542
- ``pybind11_add_module`` and ``pybind11_extension`` will be unavailable, and the
543
- targets will be missing any Python specific behavior.
544
-
545
- .. versionadded:: 2.6
546
-
547
- Embedding the Python interpreter
548
- --------------------------------
549
-
550
- In addition to extension modules, pybind11 also supports embedding Python into
551
- a C++ executable or library. In CMake, simply link with the ``pybind11::embed``
552
- target. It provides everything needed to get the interpreter running. The Python
553
- headers and libraries are attached to the target. Unlike ``pybind11::module``,
554
- there is no need to manually set any additional properties here. For more
555
- information about usage in C++, see :doc:`/advanced/embedding`.
556
-
557
- .. code-block:: cmake
558
-
559
- cmake_minimum_required(VERSION 3.5...3.27)
560
- project(example LANGUAGES CXX)
561
-
562
- find_package(pybind11 REQUIRED) # or add_subdirectory(pybind11)
563
-
564
- add_executable(example main.cpp)
565
- target_link_libraries(example PRIVATE pybind11::embed)
566
-
567
- .. _building_manually:
568
-
569
- Building manually
570
- =================
571
-
572
- pybind11 is a header-only library, hence it is not necessary to link against
573
- any special libraries and there are no intermediate (magic) translation steps.
574
-
575
- On Linux, you can compile an example such as the one given in
576
- :ref:`simple_example` using the following command:
577
-
578
- .. code-block:: bash
579
-
580
- $ c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3 -m pybind11 --includes) example.cpp -o example$(python3-config --extension-suffix)
581
-
582
- The ``python3 -m pybind11 --includes`` command fetches the include paths for
583
- both pybind11 and Python headers. This assumes that pybind11 has been installed
584
- using ``pip`` or ``conda``. If it hasn't, you can also manually specify
585
- ``-I <path-to-pybind11>/include`` together with the Python includes path
586
- ``python3-config --includes``.
587
-
588
- On macOS: the build command is almost the same but it also requires passing
589
- the ``-undefined dynamic_lookup`` flag so as to ignore missing symbols when
590
- building the module:
591
-
592
- .. code-block:: bash
593
-
594
- $ c++ -O3 -Wall -shared -std=c++11 -undefined dynamic_lookup $(python3 -m pybind11 --includes) example.cpp -o example$(python3-config --extension-suffix)
595
-
596
- In general, it is advisable to include several additional build parameters
597
- that can considerably reduce the size of the created binary. Refer to section
598
- :ref:`cmake` for a detailed example of a suitable cross-platform CMake-based
599
- build system that works on all platforms including Windows.
600
-
601
- .. note::
602
-
603
- On Linux and macOS, it's better to (intentionally) not link against
604
- ``libpython``. The symbols will be resolved when the extension library
605
- is loaded into a Python binary. This is preferable because you might
606
- have several different installations of a given Python version (e.g. the
607
- system-provided Python, and one that ships with a piece of commercial
608
- software). In this way, the plugin will work with both versions, instead
609
- of possibly importing a second Python library into a process that already
610
- contains one (which will lead to a segfault).
611
-
612
-
613
- Building with Bazel
614
- ===================
615
-
616
- You can build with the Bazel build system using the `pybind11_bazel
617
- <https://github.com/pybind/pybind11_bazel>`_ repository.
618
-
619
- Generating binding code automatically
620
- =====================================
621
-
622
- The ``Binder`` project is a tool for automatic generation of pybind11 binding
623
- code by introspecting existing C++ codebases using LLVM/Clang. See the
624
- [binder]_ documentation for details.
625
-
626
- .. [binder] http://cppbinder.readthedocs.io/en/latest/about.html
627
-
628
- [AutoWIG]_ is a Python library that wraps automatically compiled libraries into
629
- high-level languages. It parses C++ code using LLVM/Clang technologies and
630
- generates the wrappers using the Mako templating engine. The approach is automatic,
631
- extensible, and applies to very complex C++ libraries, composed of thousands of
632
- classes or incorporating modern meta-programming constructs.
633
-
634
- .. [AutoWIG] https://github.com/StatisKit/AutoWIG
635
-
636
- [robotpy-build]_ is a is a pure python, cross platform build tool that aims to
637
- simplify creation of python wheels for pybind11 projects, and provide
638
- cross-project dependency management. Additionally, it is able to autogenerate
639
- customizable pybind11-based wrappers by parsing C++ header files.
640
-
641
- .. [robotpy-build] https://robotpy-build.readthedocs.io
642
-
643
- [litgen]_ is an automatic python bindings generator with a focus on generating
644
- documented and discoverable bindings: bindings will nicely reproduce the documentation
645
- found in headers. It is is based on srcML (srcml.org), a highly scalable, multi-language
646
- parsing tool with a developer centric approach. The API that you want to expose to python
647
- must be C++14 compatible (but your implementation can use more modern constructs).
648
-
649
- .. [litgen] https://pthom.github.io/litgen
 
1
+ .. _compiling:
2
+
3
+ Build systems
4
+ #############
5
+
6
+ .. _build-setuptools:
7
+
8
+ Building with setuptools
9
+ ========================
10
+
11
+ For projects on PyPI, building with setuptools is the way to go. Sylvain Corlay
12
+ has kindly provided an example project which shows how to set up everything,
13
+ including automatic generation of documentation using Sphinx. Please refer to
14
+ the [python_example]_ repository.
15
+
16
+ .. [python_example] https://github.com/pybind/python_example
17
+
18
+ A helper file is provided with pybind11 that can simplify usage with setuptools.
19
+
20
+ To use pybind11 inside your ``setup.py``, you have to have some system to
21
+ ensure that ``pybind11`` is installed when you build your package. There are
22
+ four possible ways to do this, and pybind11 supports all four: You can ask all
23
+ users to install pybind11 beforehand (bad), you can use
24
+ :ref:`setup_helpers-pep518` (good, but very new and requires Pip 10),
25
+ :ref:`setup_helpers-setup_requires` (discouraged by Python packagers now that
26
+ PEP 518 is available, but it still works everywhere), or you can
27
+ :ref:`setup_helpers-copy-manually` (always works but you have to manually sync
28
+ your copy to get updates).
29
+
30
+ An example of a ``setup.py`` using pybind11's helpers:
31
+
32
+ .. code-block:: python
33
+
34
+ from glob import glob
35
+ from setuptools import setup
36
+ from pybind11.setup_helpers import Pybind11Extension
37
+
38
+ ext_modules = [
39
+ Pybind11Extension(
40
+ "python_example",
41
+ sorted(glob("src/*.cpp")), # Sort source files for reproducibility
42
+ ),
43
+ ]
44
+
45
+ setup(..., ext_modules=ext_modules)
46
+
47
+ If you want to do an automatic search for the highest supported C++ standard,
48
+ that is supported via a ``build_ext`` command override; it will only affect
49
+ ``Pybind11Extensions``:
50
+
51
+ .. code-block:: python
52
+
53
+ from glob import glob
54
+ from setuptools import setup
55
+ from pybind11.setup_helpers import Pybind11Extension, build_ext
56
+
57
+ ext_modules = [
58
+ Pybind11Extension(
59
+ "python_example",
60
+ sorted(glob("src/*.cpp")),
61
+ ),
62
+ ]
63
+
64
+ setup(..., cmdclass={"build_ext": build_ext}, ext_modules=ext_modules)
65
+
66
+ If you have single-file extension modules that are directly stored in the
67
+ Python source tree (``foo.cpp`` in the same directory as where a ``foo.py``
68
+ would be located), you can also generate ``Pybind11Extensions`` using
69
+ ``setup_helpers.intree_extensions``: ``intree_extensions(["path/to/foo.cpp",
70
+ ...])`` returns a list of ``Pybind11Extensions`` which can be passed to
71
+ ``ext_modules``, possibly after further customizing their attributes
72
+ (``libraries``, ``include_dirs``, etc.). By doing so, a ``foo.*.so`` extension
73
+ module will be generated and made available upon installation.
74
+
75
+ ``intree_extension`` will automatically detect if you are using a ``src``-style
76
+ layout (as long as no namespace packages are involved), but you can also
77
+ explicitly pass ``package_dir`` to it (as in ``setuptools.setup``).
78
+
79
+ Since pybind11 does not require NumPy when building, a light-weight replacement
80
+ for NumPy's parallel compilation distutils tool is included. Use it like this:
81
+
82
+ .. code-block:: python
83
+
84
+ from pybind11.setup_helpers import ParallelCompile
85
+
86
+ # Optional multithreaded build
87
+ ParallelCompile("NPY_NUM_BUILD_JOBS").install()
88
+
89
+ setup(...)
90
+
91
+ The argument is the name of an environment variable to control the number of
92
+ threads, such as ``NPY_NUM_BUILD_JOBS`` (as used by NumPy), though you can set
93
+ something different if you want; ``CMAKE_BUILD_PARALLEL_LEVEL`` is another choice
94
+ a user might expect. You can also pass ``default=N`` to set the default number
95
+ of threads (0 will take the number of threads available) and ``max=N``, the
96
+ maximum number of threads; if you have a large extension you may want set this
97
+ to a memory dependent number.
98
+
99
+ If you are developing rapidly and have a lot of C++ files, you may want to
100
+ avoid rebuilding files that have not changed. For simple cases were you are
101
+ using ``pip install -e .`` and do not have local headers, you can skip the
102
+ rebuild if an object file is newer than its source (headers are not checked!)
103
+ with the following:
104
+
105
+ .. code-block:: python
106
+
107
+ from pybind11.setup_helpers import ParallelCompile, naive_recompile
108
+
109
+ ParallelCompile("NPY_NUM_BUILD_JOBS", needs_recompile=naive_recompile).install()
110
+
111
+
112
+ If you have a more complex build, you can implement a smarter function and pass
113
+ it to ``needs_recompile``, or you can use [Ccache]_ instead. ``CXX="cache g++"
114
+ pip install -e .`` would be the way to use it with GCC, for example. Unlike the
115
+ simple solution, this even works even when not compiling in editable mode, but
116
+ it does require Ccache to be installed.
117
+
118
+ Keep in mind that Pip will not even attempt to rebuild if it thinks it has
119
+ already built a copy of your code, which it deduces from the version number.
120
+ One way to avoid this is to use [setuptools_scm]_, which will generate a
121
+ version number that includes the number of commits since your last tag and a
122
+ hash for a dirty directory. Another way to force a rebuild is purge your cache
123
+ or use Pip's ``--no-cache-dir`` option.
124
+
125
+ .. [Ccache] https://ccache.dev
126
+
127
+ .. [setuptools_scm] https://github.com/pypa/setuptools_scm
128
+
129
+ .. _setup_helpers-pep518:
130
+
131
+ PEP 518 requirements (Pip 10+ required)
132
+ ---------------------------------------
133
+
134
+ If you use `PEP 518's <https://www.python.org/dev/peps/pep-0518/>`_
135
+ ``pyproject.toml`` file, you can ensure that ``pybind11`` is available during
136
+ the compilation of your project. When this file exists, Pip will make a new
137
+ virtual environment, download just the packages listed here in ``requires=``,
138
+ and build a wheel (binary Python package). It will then throw away the
139
+ environment, and install your wheel.
140
+
141
+ Your ``pyproject.toml`` file will likely look something like this:
142
+
143
+ .. code-block:: toml
144
+
145
+ [build-system]
146
+ requires = ["setuptools>=42", "pybind11>=2.6.1"]
147
+ build-backend = "setuptools.build_meta"
148
+
149
+ .. note::
150
+
151
+ The main drawback to this method is that a `PEP 517`_ compliant build tool,
152
+ such as Pip 10+, is required for this approach to work; older versions of
153
+ Pip completely ignore this file. If you distribute binaries (called wheels
154
+ in Python) using something like `cibuildwheel`_, remember that ``setup.py``
155
+ and ``pyproject.toml`` are not even contained in the wheel, so this high
156
+ Pip requirement is only for source builds, and will not affect users of
157
+ your binary wheels. If you are building SDists and wheels, then
158
+ `pypa-build`_ is the recommended official tool.
159
+
160
+ .. _PEP 517: https://www.python.org/dev/peps/pep-0517/
161
+ .. _cibuildwheel: https://cibuildwheel.readthedocs.io
162
+ .. _pypa-build: https://pypa-build.readthedocs.io/en/latest/
163
+
164
+ .. _setup_helpers-setup_requires:
165
+
166
+ Classic ``setup_requires``
167
+ --------------------------
168
+
169
+ If you want to support old versions of Pip with the classic
170
+ ``setup_requires=["pybind11"]`` keyword argument to setup, which triggers a
171
+ two-phase ``setup.py`` run, then you will need to use something like this to
172
+ ensure the first pass works (which has not yet installed the ``setup_requires``
173
+ packages, since it can't install something it does not know about):
174
+
175
+ .. code-block:: python
176
+
177
+ try:
178
+ from pybind11.setup_helpers import Pybind11Extension
179
+ except ImportError:
180
+ from setuptools import Extension as Pybind11Extension
181
+
182
+
183
+ It doesn't matter that the Extension class is not the enhanced subclass for the
184
+ first pass run; and the second pass will have the ``setup_requires``
185
+ requirements.
186
+
187
+ This is obviously more of a hack than the PEP 518 method, but it supports
188
+ ancient versions of Pip.
189
+
190
+ .. _setup_helpers-copy-manually:
191
+
192
+ Copy manually
193
+ -------------
194
+
195
+ You can also copy ``setup_helpers.py`` directly to your project; it was
196
+ designed to be usable standalone, like the old example ``setup.py``. You can
197
+ set ``include_pybind11=False`` to skip including the pybind11 package headers,
198
+ so you can use it with git submodules and a specific git version. If you use
199
+ this, you will need to import from a local file in ``setup.py`` and ensure the
200
+ helper file is part of your MANIFEST.
201
+
202
+
203
+ Closely related, if you include pybind11 as a subproject, you can run the
204
+ ``setup_helpers.py`` inplace. If loaded correctly, this should even pick up
205
+ the correct include for pybind11, though you can turn it off as shown above if
206
+ you want to input it manually.
207
+
208
+ Suggested usage if you have pybind11 as a submodule in ``extern/pybind11``:
209
+
210
+ .. code-block:: python
211
+
212
+ DIR = os.path.abspath(os.path.dirname(__file__))
213
+
214
+ sys.path.append(os.path.join(DIR, "extern", "pybind11"))
215
+ from pybind11.setup_helpers import Pybind11Extension # noqa: E402
216
+
217
+ del sys.path[-1]
218
+
219
+
220
+ .. versionchanged:: 2.6
221
+
222
+ Added ``setup_helpers`` file.
223
+
224
+ Building with cppimport
225
+ ========================
226
+
227
+ [cppimport]_ is a small Python import hook that determines whether there is a C++
228
+ source file whose name matches the requested module. If there is, the file is
229
+ compiled as a Python extension using pybind11 and placed in the same folder as
230
+ the C++ source file. Python is then able to find the module and load it.
231
+
232
+ .. [cppimport] https://github.com/tbenthompson/cppimport
233
+
234
+ .. _cmake:
235
+
236
+ Building with CMake
237
+ ===================
238
+
239
+ For C++ codebases that have an existing CMake-based build system, a Python
240
+ extension module can be created with just a few lines of code:
241
+
242
+ .. code-block:: cmake
243
+
244
+ cmake_minimum_required(VERSION 3.5...3.27)
245
+ project(example LANGUAGES CXX)
246
+
247
+ add_subdirectory(pybind11)
248
+ pybind11_add_module(example example.cpp)
249
+
250
+ This assumes that the pybind11 repository is located in a subdirectory named
251
+ :file:`pybind11` and that the code is located in a file named :file:`example.cpp`.
252
+ The CMake command ``add_subdirectory`` will import the pybind11 project which
253
+ provides the ``pybind11_add_module`` function. It will take care of all the
254
+ details needed to build a Python extension module on any platform.
255
+
256
+ A working sample project, including a way to invoke CMake from :file:`setup.py` for
257
+ PyPI integration, can be found in the [cmake_example]_ repository.
258
+
259
+ .. [cmake_example] https://github.com/pybind/cmake_example
260
+
261
+ .. versionchanged:: 2.6
262
+ CMake 3.4+ is required.
263
+
264
+ .. versionchanged:: 2.11
265
+ CMake 3.5+ is required.
266
+
267
+ Further information can be found at :doc:`cmake/index`.
268
+
269
+ pybind11_add_module
270
+ -------------------
271
+
272
+ To ease the creation of Python extension modules, pybind11 provides a CMake
273
+ function with the following signature:
274
+
275
+ .. code-block:: cmake
276
+
277
+ pybind11_add_module(<name> [MODULE | SHARED] [EXCLUDE_FROM_ALL]
278
+ [NO_EXTRAS] [THIN_LTO] [OPT_SIZE] source1 [source2 ...])
279
+
280
+ This function behaves very much like CMake's builtin ``add_library`` (in fact,
281
+ it's a wrapper function around that command). It will add a library target
282
+ called ``<name>`` to be built from the listed source files. In addition, it
283
+ will take care of all the Python-specific compiler and linker flags as well
284
+ as the OS- and Python-version-specific file extension. The produced target
285
+ ``<name>`` can be further manipulated with regular CMake commands.
286
+
287
+ ``MODULE`` or ``SHARED`` may be given to specify the type of library. If no
288
+ type is given, ``MODULE`` is used by default which ensures the creation of a
289
+ Python-exclusive module. Specifying ``SHARED`` will create a more traditional
290
+ dynamic library which can also be linked from elsewhere. ``EXCLUDE_FROM_ALL``
291
+ removes this target from the default build (see CMake docs for details).
292
+
293
+ Since pybind11 is a template library, ``pybind11_add_module`` adds compiler
294
+ flags to ensure high quality code generation without bloat arising from long
295
+ symbol names and duplication of code in different translation units. It
296
+ sets default visibility to *hidden*, which is required for some pybind11
297
+ features and functionality when attempting to load multiple pybind11 modules
298
+ compiled under different pybind11 versions. It also adds additional flags
299
+ enabling LTO (Link Time Optimization) and strip unneeded symbols. See the
300
+ :ref:`FAQ entry <faq:symhidden>` for a more detailed explanation. These
301
+ latter optimizations are never applied in ``Debug`` mode. If ``NO_EXTRAS`` is
302
+ given, they will always be disabled, even in ``Release`` mode. However, this
303
+ will result in code bloat and is generally not recommended.
304
+
305
+ As stated above, LTO is enabled by default. Some newer compilers also support
306
+ different flavors of LTO such as `ThinLTO`_. Setting ``THIN_LTO`` will cause
307
+ the function to prefer this flavor if available. The function falls back to
308
+ regular LTO if ``-flto=thin`` is not available. If
309
+ ``CMAKE_INTERPROCEDURAL_OPTIMIZATION`` is set (either ``ON`` or ``OFF``), then
310
+ that will be respected instead of the built-in flag search.
311
+
312
+ .. note::
313
+
314
+ If you want to set the property form on targets or the
315
+ ``CMAKE_INTERPROCEDURAL_OPTIMIZATION_<CONFIG>`` versions of this, you should
316
+ still use ``set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)`` (otherwise a
317
+ no-op) to disable pybind11's ipo flags.
318
+
319
+ The ``OPT_SIZE`` flag enables size-based optimization equivalent to the
320
+ standard ``/Os`` or ``-Os`` compiler flags and the ``MinSizeRel`` build type,
321
+ which avoid optimizations that that can substantially increase the size of the
322
+ resulting binary. This flag is particularly useful in projects that are split
323
+ into performance-critical parts and associated bindings. In this case, we can
324
+ compile the project in release mode (and hence, optimize performance globally),
325
+ and specify ``OPT_SIZE`` for the binding target, where size might be the main
326
+ concern as performance is often less critical here. A ~25% size reduction has
327
+ been observed in practice. This flag only changes the optimization behavior at
328
+ a per-target level and takes precedence over the global CMake build type
329
+ (``Release``, ``RelWithDebInfo``) except for ``Debug`` builds, where
330
+ optimizations remain disabled.
331
+
332
+ .. _ThinLTO: http://clang.llvm.org/docs/ThinLTO.html
333
+
334
+ Configuration variables
335
+ -----------------------
336
+
337
+ By default, pybind11 will compile modules with the compiler default or the
338
+ minimum standard required by pybind11, whichever is higher. You can set the
339
+ standard explicitly with
340
+ `CMAKE_CXX_STANDARD <https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_STANDARD.html>`_:
341
+
342
+ .. code-block:: cmake
343
+
344
+ set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ version selection") # or 11, 14, 17, 20
345
+ set(CMAKE_CXX_STANDARD_REQUIRED ON) # optional, ensure standard is supported
346
+ set(CMAKE_CXX_EXTENSIONS OFF) # optional, keep compiler extensions off
347
+
348
+ The variables can also be set when calling CMake from the command line using
349
+ the ``-D<variable>=<value>`` flag. You can also manually set ``CXX_STANDARD``
350
+ on a target or use ``target_compile_features`` on your targets - anything that
351
+ CMake supports.
352
+
353
+ Classic Python support: The target Python version can be selected by setting
354
+ ``PYBIND11_PYTHON_VERSION`` or an exact Python installation can be specified
355
+ with ``PYTHON_EXECUTABLE``. For example:
356
+
357
+ .. code-block:: bash
358
+
359
+ cmake -DPYBIND11_PYTHON_VERSION=3.6 ..
360
+
361
+ # Another method:
362
+ cmake -DPYTHON_EXECUTABLE=/path/to/python ..
363
+
364
+ # This often is a good way to get the current Python, works in environments:
365
+ cmake -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") ..
366
+
367
+
368
+ find_package vs. add_subdirectory
369
+ ---------------------------------
370
+
371
+ For CMake-based projects that don't include the pybind11 repository internally,
372
+ an external installation can be detected through ``find_package(pybind11)``.
373
+ See the `Config file`_ docstring for details of relevant CMake variables.
374
+
375
+ .. code-block:: cmake
376
+
377
+ cmake_minimum_required(VERSION 3.4...3.18)
378
+ project(example LANGUAGES CXX)
379
+
380
+ find_package(pybind11 REQUIRED)
381
+ pybind11_add_module(example example.cpp)
382
+
383
+ Note that ``find_package(pybind11)`` will only work correctly if pybind11
384
+ has been correctly installed on the system, e. g. after downloading or cloning
385
+ the pybind11 repository :
386
+
387
+ .. code-block:: bash
388
+
389
+ # Classic CMake
390
+ cd pybind11
391
+ mkdir build
392
+ cd build
393
+ cmake ..
394
+ make install
395
+
396
+ # CMake 3.15+
397
+ cd pybind11
398
+ cmake -S . -B build
399
+ cmake --build build -j 2 # Build on 2 cores
400
+ cmake --install build
401
+
402
+ Once detected, the aforementioned ``pybind11_add_module`` can be employed as
403
+ before. The function usage and configuration variables are identical no matter
404
+ if pybind11 is added as a subdirectory or found as an installed package. You
405
+ can refer to the same [cmake_example]_ repository for a full sample project
406
+ -- just swap out ``add_subdirectory`` for ``find_package``.
407
+
408
+ .. _Config file: https://github.com/pybind/pybind11/blob/master/tools/pybind11Config.cmake.in
409
+
410
+
411
+ .. _find-python-mode:
412
+
413
+ FindPython mode
414
+ ---------------
415
+
416
+ CMake 3.12+ (3.15+ recommended, 3.18.2+ ideal) added a new module called
417
+ FindPython that had a highly improved search algorithm and modern targets
418
+ and tools. If you use FindPython, pybind11 will detect this and use the
419
+ existing targets instead:
420
+
421
+ .. code-block:: cmake
422
+
423
+ cmake_minimum_required(VERSION 3.15...3.22)
424
+ project(example LANGUAGES CXX)
425
+
426
+ find_package(Python 3.6 COMPONENTS Interpreter Development REQUIRED)
427
+ find_package(pybind11 CONFIG REQUIRED)
428
+ # or add_subdirectory(pybind11)
429
+
430
+ pybind11_add_module(example example.cpp)
431
+
432
+ You can also use the targets (as listed below) with FindPython. If you define
433
+ ``PYBIND11_FINDPYTHON``, pybind11 will perform the FindPython step for you
434
+ (mostly useful when building pybind11's own tests, or as a way to change search
435
+ algorithms from the CMake invocation, with ``-DPYBIND11_FINDPYTHON=ON``.
436
+
437
+ .. warning::
438
+
439
+ If you use FindPython to multi-target Python versions, use the individual
440
+ targets listed below, and avoid targets that directly include Python parts.
441
+
442
+ There are `many ways to hint or force a discovery of a specific Python
443
+ installation <https://cmake.org/cmake/help/latest/module/FindPython.html>`_),
444
+ setting ``Python_ROOT_DIR`` may be the most common one (though with
445
+ virtualenv/venv support, and Conda support, this tends to find the correct
446
+ Python version more often than the old system did).
447
+
448
+ .. warning::
449
+
450
+ When the Python libraries (i.e. ``libpythonXX.a`` and ``libpythonXX.so``
451
+ on Unix) are not available, as is the case on a manylinux image, the
452
+ ``Development`` component will not be resolved by ``FindPython``. When not
453
+ using the embedding functionality, CMake 3.18+ allows you to specify
454
+ ``Development.Module`` instead of ``Development`` to resolve this issue.
455
+
456
+ .. versionadded:: 2.6
457
+
458
+ Advanced: interface library targets
459
+ -----------------------------------
460
+
461
+ Pybind11 supports modern CMake usage patterns with a set of interface targets,
462
+ available in all modes. The targets provided are:
463
+
464
+ ``pybind11::headers``
465
+ Just the pybind11 headers and minimum compile requirements
466
+
467
+ ``pybind11::pybind11``
468
+ Python headers + ``pybind11::headers``
469
+
470
+ ``pybind11::python_link_helper``
471
+ Just the "linking" part of pybind11:module
472
+
473
+ ``pybind11::module``
474
+ Everything for extension modules - ``pybind11::pybind11`` + ``Python::Module`` (FindPython CMake 3.15+) or ``pybind11::python_link_helper``
475
+
476
+ ``pybind11::embed``
477
+ Everything for embedding the Python interpreter - ``pybind11::pybind11`` + ``Python::Python`` (FindPython) or Python libs
478
+
479
+ ``pybind11::lto`` / ``pybind11::thin_lto``
480
+ An alternative to `INTERPROCEDURAL_OPTIMIZATION` for adding link-time optimization.
481
+
482
+ ``pybind11::windows_extras``
483
+ ``/bigobj`` and ``/mp`` for MSVC.
484
+
485
+ ``pybind11::opt_size``
486
+ ``/Os`` for MSVC, ``-Os`` for other compilers. Does nothing for debug builds.
487
+
488
+ Two helper functions are also provided:
489
+
490
+ ``pybind11_strip(target)``
491
+ Strips a target (uses ``CMAKE_STRIP`` after the target is built)
492
+
493
+ ``pybind11_extension(target)``
494
+ Sets the correct extension (with SOABI) for a target.
495
+
496
+ You can use these targets to build complex applications. For example, the
497
+ ``add_python_module`` function is identical to:
498
+
499
+ .. code-block:: cmake
500
+
501
+ cmake_minimum_required(VERSION 3.5...3.27)
502
+ project(example LANGUAGES CXX)
503
+
504
+ find_package(pybind11 REQUIRED) # or add_subdirectory(pybind11)
505
+
506
+ add_library(example MODULE main.cpp)
507
+
508
+ target_link_libraries(example PRIVATE pybind11::module pybind11::lto pybind11::windows_extras)
509
+
510
+ pybind11_extension(example)
511
+ if(NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo)
512
+ # Strip unnecessary sections of the binary on Linux/macOS
513
+ pybind11_strip(example)
514
+ endif()
515
+
516
+ set_target_properties(example PROPERTIES CXX_VISIBILITY_PRESET "hidden"
517
+ CUDA_VISIBILITY_PRESET "hidden")
518
+
519
+ Instead of setting properties, you can set ``CMAKE_*`` variables to initialize these correctly.
520
+
521
+ .. warning::
522
+
523
+ Since pybind11 is a metatemplate library, it is crucial that certain
524
+ compiler flags are provided to ensure high quality code generation. In
525
+ contrast to the ``pybind11_add_module()`` command, the CMake interface
526
+ provides a *composable* set of targets to ensure that you retain flexibility.
527
+ It can be especially important to provide or set these properties; the
528
+ :ref:`FAQ <faq:symhidden>` contains an explanation on why these are needed.
529
+
530
+ .. versionadded:: 2.6
531
+
532
+ .. _nopython-mode:
533
+
534
+ Advanced: NOPYTHON mode
535
+ -----------------------
536
+
537
+ If you want complete control, you can set ``PYBIND11_NOPYTHON`` to completely
538
+ disable Python integration (this also happens if you run ``FindPython2`` and
539
+ ``FindPython3`` without running ``FindPython``). This gives you complete
540
+ freedom to integrate into an existing system (like `Scikit-Build's
541
+ <https://scikit-build.readthedocs.io>`_ ``PythonExtensions``).
542
+ ``pybind11_add_module`` and ``pybind11_extension`` will be unavailable, and the
543
+ targets will be missing any Python specific behavior.
544
+
545
+ .. versionadded:: 2.6
546
+
547
+ Embedding the Python interpreter
548
+ --------------------------------
549
+
550
+ In addition to extension modules, pybind11 also supports embedding Python into
551
+ a C++ executable or library. In CMake, simply link with the ``pybind11::embed``
552
+ target. It provides everything needed to get the interpreter running. The Python
553
+ headers and libraries are attached to the target. Unlike ``pybind11::module``,
554
+ there is no need to manually set any additional properties here. For more
555
+ information about usage in C++, see :doc:`/advanced/embedding`.
556
+
557
+ .. code-block:: cmake
558
+
559
+ cmake_minimum_required(VERSION 3.5...3.27)
560
+ project(example LANGUAGES CXX)
561
+
562
+ find_package(pybind11 REQUIRED) # or add_subdirectory(pybind11)
563
+
564
+ add_executable(example main.cpp)
565
+ target_link_libraries(example PRIVATE pybind11::embed)
566
+
567
+ .. _building_manually:
568
+
569
+ Building manually
570
+ =================
571
+
572
+ pybind11 is a header-only library, hence it is not necessary to link against
573
+ any special libraries and there are no intermediate (magic) translation steps.
574
+
575
+ On Linux, you can compile an example such as the one given in
576
+ :ref:`simple_example` using the following command:
577
+
578
+ .. code-block:: bash
579
+
580
+ $ c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3 -m pybind11 --includes) example.cpp -o example$(python3-config --extension-suffix)
581
+
582
+ The ``python3 -m pybind11 --includes`` command fetches the include paths for
583
+ both pybind11 and Python headers. This assumes that pybind11 has been installed
584
+ using ``pip`` or ``conda``. If it hasn't, you can also manually specify
585
+ ``-I <path-to-pybind11>/include`` together with the Python includes path
586
+ ``python3-config --includes``.
587
+
588
+ On macOS: the build command is almost the same but it also requires passing
589
+ the ``-undefined dynamic_lookup`` flag so as to ignore missing symbols when
590
+ building the module:
591
+
592
+ .. code-block:: bash
593
+
594
+ $ c++ -O3 -Wall -shared -std=c++11 -undefined dynamic_lookup $(python3 -m pybind11 --includes) example.cpp -o example$(python3-config --extension-suffix)
595
+
596
+ In general, it is advisable to include several additional build parameters
597
+ that can considerably reduce the size of the created binary. Refer to section
598
+ :ref:`cmake` for a detailed example of a suitable cross-platform CMake-based
599
+ build system that works on all platforms including Windows.
600
+
601
+ .. note::
602
+
603
+ On Linux and macOS, it's better to (intentionally) not link against
604
+ ``libpython``. The symbols will be resolved when the extension library
605
+ is loaded into a Python binary. This is preferable because you might
606
+ have several different installations of a given Python version (e.g. the
607
+ system-provided Python, and one that ships with a piece of commercial
608
+ software). In this way, the plugin will work with both versions, instead
609
+ of possibly importing a second Python library into a process that already
610
+ contains one (which will lead to a segfault).
611
+
612
+
613
+ Building with Bazel
614
+ ===================
615
+
616
+ You can build with the Bazel build system using the `pybind11_bazel
617
+ <https://github.com/pybind/pybind11_bazel>`_ repository.
618
+
619
+ Generating binding code automatically
620
+ =====================================
621
+
622
+ The ``Binder`` project is a tool for automatic generation of pybind11 binding
623
+ code by introspecting existing C++ codebases using LLVM/Clang. See the
624
+ [binder]_ documentation for details.
625
+
626
+ .. [binder] http://cppbinder.readthedocs.io/en/latest/about.html
627
+
628
+ [AutoWIG]_ is a Python library that wraps automatically compiled libraries into
629
+ high-level languages. It parses C++ code using LLVM/Clang technologies and
630
+ generates the wrappers using the Mako templating engine. The approach is automatic,
631
+ extensible, and applies to very complex C++ libraries, composed of thousands of
632
+ classes or incorporating modern meta-programming constructs.
633
+
634
+ .. [AutoWIG] https://github.com/StatisKit/AutoWIG
635
+
636
+ [robotpy-build]_ is a is a pure python, cross platform build tool that aims to
637
+ simplify creation of python wheels for pybind11 projects, and provide
638
+ cross-project dependency management. Additionally, it is able to autogenerate
639
+ customizable pybind11-based wrappers by parsing C++ header files.
640
+
641
+ .. [robotpy-build] https://robotpy-build.readthedocs.io
642
+
643
+ [litgen]_ is an automatic python bindings generator with a focus on generating
644
+ documented and discoverable bindings: bindings will nicely reproduce the documentation
645
+ found in headers. It is is based on srcML (srcml.org), a highly scalable, multi-language
646
+ parsing tool with a developer centric approach. The API that you want to expose to python
647
+ must be C++14 compatible (but your implementation can use more modern constructs).
648
+
649
+ .. [litgen] https://pthom.github.io/litgen
third_party/CityFlow/extern/pybind11/docs/conf.py CHANGED
@@ -1,368 +1,368 @@
1
- #!/usr/bin/env python3
2
- #
3
- # pybind11 documentation build configuration file, created by
4
- # sphinx-quickstart on Sun Oct 11 19:23:48 2015.
5
- #
6
- # This file is execfile()d with the current directory set to its
7
- # containing dir.
8
- #
9
- # Note that not all possible configuration values are present in this
10
- # autogenerated file.
11
- #
12
- # All configuration values have a default; values that are commented out
13
- # serve to show the default.
14
-
15
- import os
16
- import re
17
- import subprocess
18
- import sys
19
- from pathlib import Path
20
-
21
- DIR = Path(__file__).parent.resolve()
22
-
23
- # If extensions (or modules to document with autodoc) are in another directory,
24
- # add these directories to sys.path here. If the directory is relative to the
25
- # documentation root, use os.path.abspath to make it absolute, like shown here.
26
- # sys.path.insert(0, os.path.abspath('.'))
27
-
28
- # -- General configuration ------------------------------------------------
29
-
30
- # If your documentation needs a minimal Sphinx version, state it here.
31
- # needs_sphinx = '1.0'
32
-
33
- # Add any Sphinx extension module names here, as strings. They can be
34
- # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
35
- # ones.
36
- extensions = [
37
- "breathe",
38
- "sphinx_copybutton",
39
- "sphinxcontrib.rsvgconverter",
40
- "sphinxcontrib.moderncmakedomain",
41
- ]
42
-
43
- breathe_projects = {"pybind11": ".build/doxygenxml/"}
44
- breathe_default_project = "pybind11"
45
- breathe_domain_by_extension = {"h": "cpp"}
46
-
47
- # Add any paths that contain templates here, relative to this directory.
48
- templates_path = [".templates"]
49
-
50
- # The suffix(es) of source filenames.
51
- # You can specify multiple suffix as a list of string:
52
- # source_suffix = ['.rst', '.md']
53
- source_suffix = ".rst"
54
-
55
- # The encoding of source files.
56
- # source_encoding = 'utf-8-sig'
57
-
58
- # The master toctree document.
59
- master_doc = "index"
60
-
61
- # General information about the project.
62
- project = "pybind11"
63
- copyright = "2017, Wenzel Jakob"
64
- author = "Wenzel Jakob"
65
-
66
- # The version info for the project you're documenting, acts as replacement for
67
- # |version| and |release|, also used in various other places throughout the
68
- # built documents.
69
-
70
- # Read the listed version
71
- with open("../pybind11/_version.py") as f:
72
- code = compile(f.read(), "../pybind11/_version.py", "exec")
73
- loc = {}
74
- exec(code, loc)
75
-
76
- # The full version, including alpha/beta/rc tags.
77
- version = loc["__version__"]
78
-
79
- # The language for content autogenerated by Sphinx. Refer to documentation
80
- # for a list of supported languages.
81
- #
82
- # This is also used if you do content translation via gettext catalogs.
83
- # Usually you set "language" from the command line for these cases.
84
- language = None
85
-
86
- # There are two options for replacing |today|: either, you set today to some
87
- # non-false value, then it is used:
88
- # today = ''
89
- # Else, today_fmt is used as the format for a strftime call.
90
- # today_fmt = '%B %d, %Y'
91
-
92
- # List of patterns, relative to source directory, that match files and
93
- # directories to ignore when looking for source files.
94
- exclude_patterns = [".build", "release.rst"]
95
-
96
- # The reST default role (used for this markup: `text`) to use for all
97
- # documents.
98
- default_role = "any"
99
-
100
- # If true, '()' will be appended to :func: etc. cross-reference text.
101
- # add_function_parentheses = True
102
-
103
- # If true, the current module name will be prepended to all description
104
- # unit titles (such as .. function::).
105
- # add_module_names = True
106
-
107
- # If true, sectionauthor and moduleauthor directives will be shown in the
108
- # output. They are ignored by default.
109
- # show_authors = False
110
-
111
- # The name of the Pygments (syntax highlighting) style to use.
112
- # pygments_style = 'monokai'
113
-
114
- # A list of ignored prefixes for module index sorting.
115
- # modindex_common_prefix = []
116
-
117
- # If true, keep warnings as "system message" paragraphs in the built documents.
118
- # keep_warnings = False
119
-
120
- # If true, `todo` and `todoList` produce output, else they produce nothing.
121
- todo_include_todos = False
122
-
123
-
124
- # -- Options for HTML output ----------------------------------------------
125
-
126
- # The theme to use for HTML and HTML Help pages. See the documentation for
127
- # a list of builtin themes.
128
-
129
- html_theme = "furo"
130
-
131
- # Theme options are theme-specific and customize the look and feel of a theme
132
- # further. For a list of options available for each theme, see the
133
- # documentation.
134
- # html_theme_options = {}
135
-
136
- # Add any paths that contain custom themes here, relative to this directory.
137
- # html_theme_path = []
138
-
139
- # The name for this set of Sphinx documents. If None, it defaults to
140
- # "<project> v<version> documentation".
141
- # html_title = None
142
-
143
- # A shorter title for the navigation bar. Default is the same as html_title.
144
- # html_short_title = None
145
-
146
- # The name of an image file (relative to this directory) to place at the top
147
- # of the sidebar.
148
- # html_logo = None
149
-
150
- # The name of an image file (within the static path) to use as favicon of the
151
- # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
152
- # pixels large.
153
- # html_favicon = None
154
-
155
- # Add any paths that contain custom static files (such as style sheets) here,
156
- # relative to this directory. They are copied after the builtin static files,
157
- # so a file named "default.css" will overwrite the builtin "default.css".
158
- html_static_path = ["_static"]
159
-
160
- html_css_files = [
161
- "css/custom.css",
162
- ]
163
-
164
- # Add any extra paths that contain custom files (such as robots.txt or
165
- # .htaccess) here, relative to this directory. These files are copied
166
- # directly to the root of the documentation.
167
- # html_extra_path = []
168
-
169
- # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
170
- # using the given strftime format.
171
- # html_last_updated_fmt = '%b %d, %Y'
172
-
173
- # If true, SmartyPants will be used to convert quotes and dashes to
174
- # typographically correct entities.
175
- # html_use_smartypants = True
176
-
177
- # Custom sidebar templates, maps document names to template names.
178
- # html_sidebars = {}
179
-
180
- # Additional templates that should be rendered to pages, maps page names to
181
- # template names.
182
- # html_additional_pages = {}
183
-
184
- # If false, no module index is generated.
185
- # html_domain_indices = True
186
-
187
- # If false, no index is generated.
188
- # html_use_index = True
189
-
190
- # If true, the index is split into individual pages for each letter.
191
- # html_split_index = False
192
-
193
- # If true, links to the reST sources are added to the pages.
194
- # html_show_sourcelink = True
195
-
196
- # If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
197
- # html_show_sphinx = True
198
-
199
- # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
200
- # html_show_copyright = True
201
-
202
- # If true, an OpenSearch description file will be output, and all pages will
203
- # contain a <link> tag referring to it. The value of this option must be the
204
- # base URL from which the finished HTML is served.
205
- # html_use_opensearch = ''
206
-
207
- # This is the file name suffix for HTML files (e.g. ".xhtml").
208
- # html_file_suffix = None
209
-
210
- # Language to be used for generating the HTML full-text search index.
211
- # Sphinx supports the following languages:
212
- # 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja'
213
- # 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr'
214
- # html_search_language = 'en'
215
-
216
- # A dictionary with options for the search language support, empty by default.
217
- # Now only 'ja' uses this config value
218
- # html_search_options = {'type': 'default'}
219
-
220
- # The name of a javascript file (relative to the configuration directory) that
221
- # implements a search results scorer. If empty, the default will be used.
222
- # html_search_scorer = 'scorer.js'
223
-
224
- # Output file base name for HTML help builder.
225
- htmlhelp_basename = "pybind11doc"
226
-
227
- # -- Options for LaTeX output ---------------------------------------------
228
-
229
- latex_engine = "pdflatex"
230
-
231
- latex_elements = {
232
- # The paper size ('letterpaper' or 'a4paper').
233
- # 'papersize': 'letterpaper',
234
- #
235
- # The font size ('10pt', '11pt' or '12pt').
236
- # 'pointsize': '10pt',
237
- #
238
- # Additional stuff for the LaTeX preamble.
239
- # remove blank pages (between the title page and the TOC, etc.)
240
- "classoptions": ",openany,oneside",
241
- "preamble": r"""
242
- \usepackage{fontawesome}
243
- \usepackage{textgreek}
244
- \DeclareUnicodeCharacter{00A0}{}
245
- \DeclareUnicodeCharacter{2194}{\faArrowsH}
246
- \DeclareUnicodeCharacter{1F382}{\faBirthdayCake}
247
- \DeclareUnicodeCharacter{1F355}{\faAdjust}
248
- \DeclareUnicodeCharacter{0301}{'}
249
- \DeclareUnicodeCharacter{03C0}{\textpi}
250
-
251
- """,
252
- # Latex figure (float) alignment
253
- # 'figure_align': 'htbp',
254
- }
255
-
256
- # Grouping the document tree into LaTeX files. List of tuples
257
- # (source start file, target name, title,
258
- # author, documentclass [howto, manual, or own class]).
259
- latex_documents = [
260
- (master_doc, "pybind11.tex", "pybind11 Documentation", "Wenzel Jakob", "manual"),
261
- ]
262
-
263
- # The name of an image file (relative to this directory) to place at the top of
264
- # the title page.
265
- # latex_logo = 'pybind11-logo.png'
266
-
267
- # For "manual" documents, if this is true, then toplevel headings are parts,
268
- # not chapters.
269
- # latex_use_parts = False
270
-
271
- # If true, show page references after internal links.
272
- # latex_show_pagerefs = False
273
-
274
- # If true, show URL addresses after external links.
275
- # latex_show_urls = False
276
-
277
- # Documents to append as an appendix to all manuals.
278
- # latex_appendices = []
279
-
280
- # If false, no module index is generated.
281
- # latex_domain_indices = True
282
-
283
-
284
- # -- Options for manual page output ---------------------------------------
285
-
286
- # One entry per manual page. List of tuples
287
- # (source start file, name, description, authors, manual section).
288
- man_pages = [(master_doc, "pybind11", "pybind11 Documentation", [author], 1)]
289
-
290
- # If true, show URL addresses after external links.
291
- # man_show_urls = False
292
-
293
-
294
- # -- Options for Texinfo output -------------------------------------------
295
-
296
- # Grouping the document tree into Texinfo files. List of tuples
297
- # (source start file, target name, title, author,
298
- # dir menu entry, description, category)
299
- texinfo_documents = [
300
- (
301
- master_doc,
302
- "pybind11",
303
- "pybind11 Documentation",
304
- author,
305
- "pybind11",
306
- "One line description of project.",
307
- "Miscellaneous",
308
- ),
309
- ]
310
-
311
- # Documents to append as an appendix to all manuals.
312
- # texinfo_appendices = []
313
-
314
- # If false, no module index is generated.
315
- # texinfo_domain_indices = True
316
-
317
- # How to display URL addresses: 'footnote', 'no', or 'inline'.
318
- # texinfo_show_urls = 'footnote'
319
-
320
- # If true, do not generate a @detailmenu in the "Top" node's menu.
321
- # texinfo_no_detailmenu = False
322
-
323
- primary_domain = "cpp"
324
- highlight_language = "cpp"
325
-
326
-
327
- def generate_doxygen_xml(app):
328
- build_dir = os.path.join(app.confdir, ".build")
329
- if not os.path.exists(build_dir):
330
- os.mkdir(build_dir)
331
-
332
- try:
333
- subprocess.call(["doxygen", "--version"])
334
- retcode = subprocess.call(["doxygen"], cwd=app.confdir)
335
- if retcode < 0:
336
- sys.stderr.write(f"doxygen error code: {-retcode}\n")
337
- except OSError as e:
338
- sys.stderr.write(f"doxygen execution failed: {e}\n")
339
-
340
-
341
- def prepare(app):
342
- with open(DIR.parent / "README.rst") as f:
343
- contents = f.read()
344
-
345
- if app.builder.name == "latex":
346
- # Remove badges and stuff from start
347
- contents = contents[contents.find(r".. start") :]
348
-
349
- # Filter out section titles for index.rst for LaTeX
350
- contents = re.sub(r"^(.*)\n[-~]{3,}$", r"**\1**", contents, flags=re.MULTILINE)
351
-
352
- with open(DIR / "readme.rst", "w") as f:
353
- f.write(contents)
354
-
355
-
356
- def clean_up(app, exception): # noqa: ARG001
357
- (DIR / "readme.rst").unlink()
358
-
359
-
360
- def setup(app):
361
- # Add hook for building doxygen xml when needed
362
- app.connect("builder-inited", generate_doxygen_xml)
363
-
364
- # Copy the readme in
365
- app.connect("builder-inited", prepare)
366
-
367
- # Clean up the generated readme
368
- app.connect("build-finished", clean_up)
 
1
+ #!/usr/bin/env python3
2
+ #
3
+ # pybind11 documentation build configuration file, created by
4
+ # sphinx-quickstart on Sun Oct 11 19:23:48 2015.
5
+ #
6
+ # This file is execfile()d with the current directory set to its
7
+ # containing dir.
8
+ #
9
+ # Note that not all possible configuration values are present in this
10
+ # autogenerated file.
11
+ #
12
+ # All configuration values have a default; values that are commented out
13
+ # serve to show the default.
14
+
15
+ import os
16
+ import re
17
+ import subprocess
18
+ import sys
19
+ from pathlib import Path
20
+
21
+ DIR = Path(__file__).parent.resolve()
22
+
23
+ # If extensions (or modules to document with autodoc) are in another directory,
24
+ # add these directories to sys.path here. If the directory is relative to the
25
+ # documentation root, use os.path.abspath to make it absolute, like shown here.
26
+ # sys.path.insert(0, os.path.abspath('.'))
27
+
28
+ # -- General configuration ------------------------------------------------
29
+
30
+ # If your documentation needs a minimal Sphinx version, state it here.
31
+ # needs_sphinx = '1.0'
32
+
33
+ # Add any Sphinx extension module names here, as strings. They can be
34
+ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
35
+ # ones.
36
+ extensions = [
37
+ "breathe",
38
+ "sphinx_copybutton",
39
+ "sphinxcontrib.rsvgconverter",
40
+ "sphinxcontrib.moderncmakedomain",
41
+ ]
42
+
43
+ breathe_projects = {"pybind11": ".build/doxygenxml/"}
44
+ breathe_default_project = "pybind11"
45
+ breathe_domain_by_extension = {"h": "cpp"}
46
+
47
+ # Add any paths that contain templates here, relative to this directory.
48
+ templates_path = [".templates"]
49
+
50
+ # The suffix(es) of source filenames.
51
+ # You can specify multiple suffix as a list of string:
52
+ # source_suffix = ['.rst', '.md']
53
+ source_suffix = ".rst"
54
+
55
+ # The encoding of source files.
56
+ # source_encoding = 'utf-8-sig'
57
+
58
+ # The master toctree document.
59
+ master_doc = "index"
60
+
61
+ # General information about the project.
62
+ project = "pybind11"
63
+ copyright = "2017, Wenzel Jakob"
64
+ author = "Wenzel Jakob"
65
+
66
+ # The version info for the project you're documenting, acts as replacement for
67
+ # |version| and |release|, also used in various other places throughout the
68
+ # built documents.
69
+
70
+ # Read the listed version
71
+ with open("../pybind11/_version.py") as f:
72
+ code = compile(f.read(), "../pybind11/_version.py", "exec")
73
+ loc = {}
74
+ exec(code, loc)
75
+
76
+ # The full version, including alpha/beta/rc tags.
77
+ version = loc["__version__"]
78
+
79
+ # The language for content autogenerated by Sphinx. Refer to documentation
80
+ # for a list of supported languages.
81
+ #
82
+ # This is also used if you do content translation via gettext catalogs.
83
+ # Usually you set "language" from the command line for these cases.
84
+ language = None
85
+
86
+ # There are two options for replacing |today|: either, you set today to some
87
+ # non-false value, then it is used:
88
+ # today = ''
89
+ # Else, today_fmt is used as the format for a strftime call.
90
+ # today_fmt = '%B %d, %Y'
91
+
92
+ # List of patterns, relative to source directory, that match files and
93
+ # directories to ignore when looking for source files.
94
+ exclude_patterns = [".build", "release.rst"]
95
+
96
+ # The reST default role (used for this markup: `text`) to use for all
97
+ # documents.
98
+ default_role = "any"
99
+
100
+ # If true, '()' will be appended to :func: etc. cross-reference text.
101
+ # add_function_parentheses = True
102
+
103
+ # If true, the current module name will be prepended to all description
104
+ # unit titles (such as .. function::).
105
+ # add_module_names = True
106
+
107
+ # If true, sectionauthor and moduleauthor directives will be shown in the
108
+ # output. They are ignored by default.
109
+ # show_authors = False
110
+
111
+ # The name of the Pygments (syntax highlighting) style to use.
112
+ # pygments_style = 'monokai'
113
+
114
+ # A list of ignored prefixes for module index sorting.
115
+ # modindex_common_prefix = []
116
+
117
+ # If true, keep warnings as "system message" paragraphs in the built documents.
118
+ # keep_warnings = False
119
+
120
+ # If true, `todo` and `todoList` produce output, else they produce nothing.
121
+ todo_include_todos = False
122
+
123
+
124
+ # -- Options for HTML output ----------------------------------------------
125
+
126
+ # The theme to use for HTML and HTML Help pages. See the documentation for
127
+ # a list of builtin themes.
128
+
129
+ html_theme = "furo"
130
+
131
+ # Theme options are theme-specific and customize the look and feel of a theme
132
+ # further. For a list of options available for each theme, see the
133
+ # documentation.
134
+ # html_theme_options = {}
135
+
136
+ # Add any paths that contain custom themes here, relative to this directory.
137
+ # html_theme_path = []
138
+
139
+ # The name for this set of Sphinx documents. If None, it defaults to
140
+ # "<project> v<version> documentation".
141
+ # html_title = None
142
+
143
+ # A shorter title for the navigation bar. Default is the same as html_title.
144
+ # html_short_title = None
145
+
146
+ # The name of an image file (relative to this directory) to place at the top
147
+ # of the sidebar.
148
+ # html_logo = None
149
+
150
+ # The name of an image file (within the static path) to use as favicon of the
151
+ # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
152
+ # pixels large.
153
+ # html_favicon = None
154
+
155
+ # Add any paths that contain custom static files (such as style sheets) here,
156
+ # relative to this directory. They are copied after the builtin static files,
157
+ # so a file named "default.css" will overwrite the builtin "default.css".
158
+ html_static_path = ["_static"]
159
+
160
+ html_css_files = [
161
+ "css/custom.css",
162
+ ]
163
+
164
+ # Add any extra paths that contain custom files (such as robots.txt or
165
+ # .htaccess) here, relative to this directory. These files are copied
166
+ # directly to the root of the documentation.
167
+ # html_extra_path = []
168
+
169
+ # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
170
+ # using the given strftime format.
171
+ # html_last_updated_fmt = '%b %d, %Y'
172
+
173
+ # If true, SmartyPants will be used to convert quotes and dashes to
174
+ # typographically correct entities.
175
+ # html_use_smartypants = True
176
+
177
+ # Custom sidebar templates, maps document names to template names.
178
+ # html_sidebars = {}
179
+
180
+ # Additional templates that should be rendered to pages, maps page names to
181
+ # template names.
182
+ # html_additional_pages = {}
183
+
184
+ # If false, no module index is generated.
185
+ # html_domain_indices = True
186
+
187
+ # If false, no index is generated.
188
+ # html_use_index = True
189
+
190
+ # If true, the index is split into individual pages for each letter.
191
+ # html_split_index = False
192
+
193
+ # If true, links to the reST sources are added to the pages.
194
+ # html_show_sourcelink = True
195
+
196
+ # If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
197
+ # html_show_sphinx = True
198
+
199
+ # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
200
+ # html_show_copyright = True
201
+
202
+ # If true, an OpenSearch description file will be output, and all pages will
203
+ # contain a <link> tag referring to it. The value of this option must be the
204
+ # base URL from which the finished HTML is served.
205
+ # html_use_opensearch = ''
206
+
207
+ # This is the file name suffix for HTML files (e.g. ".xhtml").
208
+ # html_file_suffix = None
209
+
210
+ # Language to be used for generating the HTML full-text search index.
211
+ # Sphinx supports the following languages:
212
+ # 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja'
213
+ # 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr'
214
+ # html_search_language = 'en'
215
+
216
+ # A dictionary with options for the search language support, empty by default.
217
+ # Now only 'ja' uses this config value
218
+ # html_search_options = {'type': 'default'}
219
+
220
+ # The name of a javascript file (relative to the configuration directory) that
221
+ # implements a search results scorer. If empty, the default will be used.
222
+ # html_search_scorer = 'scorer.js'
223
+
224
+ # Output file base name for HTML help builder.
225
+ htmlhelp_basename = "pybind11doc"
226
+
227
+ # -- Options for LaTeX output ---------------------------------------------
228
+
229
+ latex_engine = "pdflatex"
230
+
231
+ latex_elements = {
232
+ # The paper size ('letterpaper' or 'a4paper').
233
+ # 'papersize': 'letterpaper',
234
+ #
235
+ # The font size ('10pt', '11pt' or '12pt').
236
+ # 'pointsize': '10pt',
237
+ #
238
+ # Additional stuff for the LaTeX preamble.
239
+ # remove blank pages (between the title page and the TOC, etc.)
240
+ "classoptions": ",openany,oneside",
241
+ "preamble": r"""
242
+ \usepackage{fontawesome}
243
+ \usepackage{textgreek}
244
+ \DeclareUnicodeCharacter{00A0}{}
245
+ \DeclareUnicodeCharacter{2194}{\faArrowsH}
246
+ \DeclareUnicodeCharacter{1F382}{\faBirthdayCake}
247
+ \DeclareUnicodeCharacter{1F355}{\faAdjust}
248
+ \DeclareUnicodeCharacter{0301}{'}
249
+ \DeclareUnicodeCharacter{03C0}{\textpi}
250
+
251
+ """,
252
+ # Latex figure (float) alignment
253
+ # 'figure_align': 'htbp',
254
+ }
255
+
256
+ # Grouping the document tree into LaTeX files. List of tuples
257
+ # (source start file, target name, title,
258
+ # author, documentclass [howto, manual, or own class]).
259
+ latex_documents = [
260
+ (master_doc, "pybind11.tex", "pybind11 Documentation", "Wenzel Jakob", "manual"),
261
+ ]
262
+
263
+ # The name of an image file (relative to this directory) to place at the top of
264
+ # the title page.
265
+ # latex_logo = 'pybind11-logo.png'
266
+
267
+ # For "manual" documents, if this is true, then toplevel headings are parts,
268
+ # not chapters.
269
+ # latex_use_parts = False
270
+
271
+ # If true, show page references after internal links.
272
+ # latex_show_pagerefs = False
273
+
274
+ # If true, show URL addresses after external links.
275
+ # latex_show_urls = False
276
+
277
+ # Documents to append as an appendix to all manuals.
278
+ # latex_appendices = []
279
+
280
+ # If false, no module index is generated.
281
+ # latex_domain_indices = True
282
+
283
+
284
+ # -- Options for manual page output ---------------------------------------
285
+
286
+ # One entry per manual page. List of tuples
287
+ # (source start file, name, description, authors, manual section).
288
+ man_pages = [(master_doc, "pybind11", "pybind11 Documentation", [author], 1)]
289
+
290
+ # If true, show URL addresses after external links.
291
+ # man_show_urls = False
292
+
293
+
294
+ # -- Options for Texinfo output -------------------------------------------
295
+
296
+ # Grouping the document tree into Texinfo files. List of tuples
297
+ # (source start file, target name, title, author,
298
+ # dir menu entry, description, category)
299
+ texinfo_documents = [
300
+ (
301
+ master_doc,
302
+ "pybind11",
303
+ "pybind11 Documentation",
304
+ author,
305
+ "pybind11",
306
+ "One line description of project.",
307
+ "Miscellaneous",
308
+ ),
309
+ ]
310
+
311
+ # Documents to append as an appendix to all manuals.
312
+ # texinfo_appendices = []
313
+
314
+ # If false, no module index is generated.
315
+ # texinfo_domain_indices = True
316
+
317
+ # How to display URL addresses: 'footnote', 'no', or 'inline'.
318
+ # texinfo_show_urls = 'footnote'
319
+
320
+ # If true, do not generate a @detailmenu in the "Top" node's menu.
321
+ # texinfo_no_detailmenu = False
322
+
323
+ primary_domain = "cpp"
324
+ highlight_language = "cpp"
325
+
326
+
327
+ def generate_doxygen_xml(app):
328
+ build_dir = os.path.join(app.confdir, ".build")
329
+ if not os.path.exists(build_dir):
330
+ os.mkdir(build_dir)
331
+
332
+ try:
333
+ subprocess.call(["doxygen", "--version"])
334
+ retcode = subprocess.call(["doxygen"], cwd=app.confdir)
335
+ if retcode < 0:
336
+ sys.stderr.write(f"doxygen error code: {-retcode}\n")
337
+ except OSError as e:
338
+ sys.stderr.write(f"doxygen execution failed: {e}\n")
339
+
340
+
341
+ def prepare(app):
342
+ with open(DIR.parent / "README.rst") as f:
343
+ contents = f.read()
344
+
345
+ if app.builder.name == "latex":
346
+ # Remove badges and stuff from start
347
+ contents = contents[contents.find(r".. start") :]
348
+
349
+ # Filter out section titles for index.rst for LaTeX
350
+ contents = re.sub(r"^(.*)\n[-~]{3,}$", r"**\1**", contents, flags=re.MULTILINE)
351
+
352
+ with open(DIR / "readme.rst", "w") as f:
353
+ f.write(contents)
354
+
355
+
356
+ def clean_up(app, exception): # noqa: ARG001
357
+ (DIR / "readme.rst").unlink()
358
+
359
+
360
+ def setup(app):
361
+ # Add hook for building doxygen xml when needed
362
+ app.connect("builder-inited", generate_doxygen_xml)
363
+
364
+ # Copy the readme in
365
+ app.connect("builder-inited", prepare)
366
+
367
+ # Clean up the generated readme
368
+ app.connect("build-finished", clean_up)
third_party/CityFlow/extern/pybind11/docs/faq.rst CHANGED
@@ -1,308 +1,308 @@
1
- Frequently asked questions
2
- ##########################
3
-
4
- "ImportError: dynamic module does not define init function"
5
- ===========================================================
6
-
7
- 1. Make sure that the name specified in PYBIND11_MODULE is identical to the
8
- filename of the extension library (without suffixes such as ``.so``).
9
-
10
- 2. If the above did not fix the issue, you are likely using an incompatible
11
- version of Python that does not match what you compiled with.
12
-
13
- "Symbol not found: ``__Py_ZeroStruct`` / ``_PyInstanceMethod_Type``"
14
- ========================================================================
15
-
16
- See the first answer.
17
-
18
- "SystemError: dynamic module not initialized properly"
19
- ======================================================
20
-
21
- See the first answer.
22
-
23
- The Python interpreter immediately crashes when importing my module
24
- ===================================================================
25
-
26
- See the first answer.
27
-
28
- .. _faq_reference_arguments:
29
-
30
- Limitations involving reference arguments
31
- =========================================
32
-
33
- In C++, it's fairly common to pass arguments using mutable references or
34
- mutable pointers, which allows both read and write access to the value
35
- supplied by the caller. This is sometimes done for efficiency reasons, or to
36
- realize functions that have multiple return values. Here are two very basic
37
- examples:
38
-
39
- .. code-block:: cpp
40
-
41
- void increment(int &i) { i++; }
42
- void increment_ptr(int *i) { (*i)++; }
43
-
44
- In Python, all arguments are passed by reference, so there is no general
45
- issue in binding such code from Python.
46
-
47
- However, certain basic Python types (like ``str``, ``int``, ``bool``,
48
- ``float``, etc.) are **immutable**. This means that the following attempt
49
- to port the function to Python doesn't have the same effect on the value
50
- provided by the caller -- in fact, it does nothing at all.
51
-
52
- .. code-block:: python
53
-
54
- def increment(i):
55
- i += 1 # nope..
56
-
57
- pybind11 is also affected by such language-level conventions, which means that
58
- binding ``increment`` or ``increment_ptr`` will also create Python functions
59
- that don't modify their arguments.
60
-
61
- Although inconvenient, one workaround is to encapsulate the immutable types in
62
- a custom type that does allow modifications.
63
-
64
- An other alternative involves binding a small wrapper lambda function that
65
- returns a tuple with all output arguments (see the remainder of the
66
- documentation for examples on binding lambda functions). An example:
67
-
68
- .. code-block:: cpp
69
-
70
- int foo(int &i) { i++; return 123; }
71
-
72
- and the binding code
73
-
74
- .. code-block:: cpp
75
-
76
- m.def("foo", [](int i) { int rv = foo(i); return std::make_tuple(rv, i); });
77
-
78
-
79
- How can I reduce the build time?
80
- ================================
81
-
82
- It's good practice to split binding code over multiple files, as in the
83
- following example:
84
-
85
- :file:`example.cpp`:
86
-
87
- .. code-block:: cpp
88
-
89
- void init_ex1(py::module_ &);
90
- void init_ex2(py::module_ &);
91
- /* ... */
92
-
93
- PYBIND11_MODULE(example, m) {
94
- init_ex1(m);
95
- init_ex2(m);
96
- /* ... */
97
- }
98
-
99
- :file:`ex1.cpp`:
100
-
101
- .. code-block:: cpp
102
-
103
- void init_ex1(py::module_ &m) {
104
- m.def("add", [](int a, int b) { return a + b; });
105
- }
106
-
107
- :file:`ex2.cpp`:
108
-
109
- .. code-block:: cpp
110
-
111
- void init_ex2(py::module_ &m) {
112
- m.def("sub", [](int a, int b) { return a - b; });
113
- }
114
-
115
- :command:`python`:
116
-
117
- .. code-block:: pycon
118
-
119
- >>> import example
120
- >>> example.add(1, 2)
121
- 3
122
- >>> example.sub(1, 1)
123
- 0
124
-
125
- As shown above, the various ``init_ex`` functions should be contained in
126
- separate files that can be compiled independently from one another, and then
127
- linked together into the same final shared object. Following this approach
128
- will:
129
-
130
- 1. reduce memory requirements per compilation unit.
131
-
132
- 2. enable parallel builds (if desired).
133
-
134
- 3. allow for faster incremental builds. For instance, when a single class
135
- definition is changed, only a subset of the binding code will generally need
136
- to be recompiled.
137
-
138
- "recursive template instantiation exceeded maximum depth of 256"
139
- ================================================================
140
-
141
- If you receive an error about excessive recursive template evaluation, try
142
- specifying a larger value, e.g. ``-ftemplate-depth=1024`` on GCC/Clang. The
143
- culprit is generally the generation of function signatures at compile time
144
- using C++14 template metaprogramming.
145
-
146
- .. _`faq:hidden_visibility`:
147
-
148
- "'SomeClass' declared with greater visibility than the type of its field 'SomeClass::member' [-Wattributes]"
149
- ============================================================================================================
150
-
151
- This error typically indicates that you are compiling without the required
152
- ``-fvisibility`` flag. pybind11 code internally forces hidden visibility on
153
- all internal code, but if non-hidden (and thus *exported*) code attempts to
154
- include a pybind type (for example, ``py::object`` or ``py::list``) you can run
155
- into this warning.
156
-
157
- To avoid it, make sure you are specifying ``-fvisibility=hidden`` when
158
- compiling pybind code.
159
-
160
- As to why ``-fvisibility=hidden`` is necessary, because pybind modules could
161
- have been compiled under different versions of pybind itself, it is also
162
- important that the symbols defined in one module do not clash with the
163
- potentially-incompatible symbols defined in another. While Python extension
164
- modules are usually loaded with localized symbols (under POSIX systems
165
- typically using ``dlopen`` with the ``RTLD_LOCAL`` flag), this Python default
166
- can be changed, but even if it isn't it is not always enough to guarantee
167
- complete independence of the symbols involved when not using
168
- ``-fvisibility=hidden``.
169
-
170
- Additionally, ``-fvisibility=hidden`` can deliver considerably binary size
171
- savings. (See the following section for more details.)
172
-
173
-
174
- .. _`faq:symhidden`:
175
-
176
- How can I create smaller binaries?
177
- ==================================
178
-
179
- To do its job, pybind11 extensively relies on a programming technique known as
180
- *template metaprogramming*, which is a way of performing computation at compile
181
- time using type information. Template metaprogramming usually instantiates code
182
- involving significant numbers of deeply nested types that are either completely
183
- removed or reduced to just a few instructions during the compiler's optimization
184
- phase. However, due to the nested nature of these types, the resulting symbol
185
- names in the compiled extension library can be extremely long. For instance,
186
- the included test suite contains the following symbol:
187
-
188
- .. only:: html
189
-
190
- .. code-block:: none
191
-
192
- _​_​Z​N​8​p​y​b​i​n​d​1​1​1​2​c​p​p​_​f​u​n​c​t​i​o​n​C​1​I​v​8​E​x​a​m​p​l​e​2​J​R​N​S​t​3​_​_​1​6​v​e​c​t​o​r​I​N​S​3​_​1​2​b​a​s​i​c​_​s​t​r​i​n​g​I​w​N​S​3​_​1​1​c​h​a​r​_​t​r​a​i​t​s​I​w​E​E​N​S​3​_​9​a​l​l​o​c​a​t​o​r​I​w​E​E​E​E​N​S​8​_​I​S​A​_​E​E​E​E​E​J​N​S​_​4​n​a​m​e​E​N​S​_​7​s​i​b​l​i​n​g​E​N​S​_​9​i​s​_​m​e​t​h​o​d​E​A​2​8​_​c​E​E​E​M​T​0​_​F​T​_​D​p​T​1​_​E​D​p​R​K​T​2​_
193
-
194
- .. only:: not html
195
-
196
- .. code-block:: cpp
197
-
198
- __ZN8pybind1112cpp_functionC1Iv8Example2JRNSt3__16vectorINS3_12basic_stringIwNS3_11char_traitsIwEENS3_9allocatorIwEEEENS8_ISA_EEEEEJNS_4nameENS_7siblingENS_9is_methodEA28_cEEEMT0_FT_DpT1_EDpRKT2_
199
-
200
- which is the mangled form of the following function type:
201
-
202
- .. code-block:: cpp
203
-
204
- pybind11::cpp_function::cpp_function<void, Example2, std::__1::vector<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, std::__1::allocator<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > > >&, pybind11::name, pybind11::sibling, pybind11::is_method, char [28]>(void (Example2::*)(std::__1::vector<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, std::__1::allocator<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > > >&), pybind11::name const&, pybind11::sibling const&, pybind11::is_method const&, char const (&) [28])
205
-
206
- The memory needed to store just the mangled name of this function (196 bytes)
207
- is larger than the actual piece of code (111 bytes) it represents! On the other
208
- hand, it's silly to even give this function a name -- after all, it's just a
209
- tiny cog in a bigger piece of machinery that is not exposed to the outside
210
- world. So we'll generally only want to export symbols for those functions which
211
- are actually called from the outside.
212
-
213
- This can be achieved by specifying the parameter ``-fvisibility=hidden`` to GCC
214
- and Clang, which sets the default symbol visibility to *hidden*, which has a
215
- tremendous impact on the final binary size of the resulting extension library.
216
- (On Visual Studio, symbols are already hidden by default, so nothing needs to
217
- be done there.)
218
-
219
- In addition to decreasing binary size, ``-fvisibility=hidden`` also avoids
220
- potential serious issues when loading multiple modules and is required for
221
- proper pybind operation. See the previous FAQ entry for more details.
222
-
223
- How can I properly handle Ctrl-C in long-running functions?
224
- ===========================================================
225
-
226
- Ctrl-C is received by the Python interpreter, and holds it until the GIL
227
- is released, so a long-running function won't be interrupted.
228
-
229
- To interrupt from inside your function, you can use the ``PyErr_CheckSignals()``
230
- function, that will tell if a signal has been raised on the Python side. This
231
- function merely checks a flag, so its impact is negligible. When a signal has
232
- been received, you must either explicitly interrupt execution by throwing
233
- ``py::error_already_set`` (which will propagate the existing
234
- ``KeyboardInterrupt``), or clear the error (which you usually will not want):
235
-
236
- .. code-block:: cpp
237
-
238
- PYBIND11_MODULE(example, m)
239
- {
240
- m.def("long running_func", []()
241
- {
242
- for (;;) {
243
- if (PyErr_CheckSignals() != 0)
244
- throw py::error_already_set();
245
- // Long running iteration
246
- }
247
- });
248
- }
249
-
250
- CMake doesn't detect the right Python version
251
- =============================================
252
-
253
- The CMake-based build system will try to automatically detect the installed
254
- version of Python and link against that. When this fails, or when there are
255
- multiple versions of Python and it finds the wrong one, delete
256
- ``CMakeCache.txt`` and then add ``-DPYTHON_EXECUTABLE=$(which python)`` to your
257
- CMake configure line. (Replace ``$(which python)`` with a path to python if
258
- your prefer.)
259
-
260
- You can alternatively try ``-DPYBIND11_FINDPYTHON=ON``, which will activate the
261
- new CMake FindPython support instead of pybind11's custom search. Requires
262
- CMake 3.12+, and 3.15+ or 3.18.2+ are even better. You can set this in your
263
- ``CMakeLists.txt`` before adding or finding pybind11, as well.
264
-
265
- Inconsistent detection of Python version in CMake and pybind11
266
- ==============================================================
267
-
268
- The functions ``find_package(PythonInterp)`` and ``find_package(PythonLibs)``
269
- provided by CMake for Python version detection are modified by pybind11 due to
270
- unreliability and limitations that make them unsuitable for pybind11's needs.
271
- Instead pybind11 provides its own, more reliable Python detection CMake code.
272
- Conflicts can arise, however, when using pybind11 in a project that *also* uses
273
- the CMake Python detection in a system with several Python versions installed.
274
-
275
- This difference may cause inconsistencies and errors if *both* mechanisms are
276
- used in the same project.
277
-
278
- There are three possible solutions:
279
-
280
- 1. Avoid using ``find_package(PythonInterp)`` and ``find_package(PythonLibs)``
281
- from CMake and rely on pybind11 in detecting Python version. If this is not
282
- possible, the CMake machinery should be called *before* including pybind11.
283
- 2. Set ``PYBIND11_FINDPYTHON`` to ``True`` or use ``find_package(Python
284
- COMPONENTS Interpreter Development)`` on modern CMake (3.12+, 3.15+ better,
285
- 3.18.2+ best). Pybind11 in these cases uses the new CMake FindPython instead
286
- of the old, deprecated search tools, and these modules are much better at
287
- finding the correct Python. If FindPythonLibs/Interp are not available
288
- (CMake 3.27+), then this will be ignored and FindPython will be used.
289
- 3. Set ``PYBIND11_NOPYTHON`` to ``TRUE``. Pybind11 will not search for Python.
290
- However, you will have to use the target-based system, and do more setup
291
- yourself, because it does not know about or include things that depend on
292
- Python, like ``pybind11_add_module``. This might be ideal for integrating
293
- into an existing system, like scikit-build's Python helpers.
294
-
295
- How to cite this project?
296
- =========================
297
-
298
- We suggest the following BibTeX template to cite pybind11 in scientific
299
- discourse:
300
-
301
- .. code-block:: bash
302
-
303
- @misc{pybind11,
304
- author = {Wenzel Jakob and Jason Rhinelander and Dean Moldovan},
305
- year = {2017},
306
- note = {https://github.com/pybind/pybind11},
307
- title = {pybind11 -- Seamless operability between C++11 and Python}
308
- }
 
1
+ Frequently asked questions
2
+ ##########################
3
+
4
+ "ImportError: dynamic module does not define init function"
5
+ ===========================================================
6
+
7
+ 1. Make sure that the name specified in PYBIND11_MODULE is identical to the
8
+ filename of the extension library (without suffixes such as ``.so``).
9
+
10
+ 2. If the above did not fix the issue, you are likely using an incompatible
11
+ version of Python that does not match what you compiled with.
12
+
13
+ "Symbol not found: ``__Py_ZeroStruct`` / ``_PyInstanceMethod_Type``"
14
+ ========================================================================
15
+
16
+ See the first answer.
17
+
18
+ "SystemError: dynamic module not initialized properly"
19
+ ======================================================
20
+
21
+ See the first answer.
22
+
23
+ The Python interpreter immediately crashes when importing my module
24
+ ===================================================================
25
+
26
+ See the first answer.
27
+
28
+ .. _faq_reference_arguments:
29
+
30
+ Limitations involving reference arguments
31
+ =========================================
32
+
33
+ In C++, it's fairly common to pass arguments using mutable references or
34
+ mutable pointers, which allows both read and write access to the value
35
+ supplied by the caller. This is sometimes done for efficiency reasons, or to
36
+ realize functions that have multiple return values. Here are two very basic
37
+ examples:
38
+
39
+ .. code-block:: cpp
40
+
41
+ void increment(int &i) { i++; }
42
+ void increment_ptr(int *i) { (*i)++; }
43
+
44
+ In Python, all arguments are passed by reference, so there is no general
45
+ issue in binding such code from Python.
46
+
47
+ However, certain basic Python types (like ``str``, ``int``, ``bool``,
48
+ ``float``, etc.) are **immutable**. This means that the following attempt
49
+ to port the function to Python doesn't have the same effect on the value
50
+ provided by the caller -- in fact, it does nothing at all.
51
+
52
+ .. code-block:: python
53
+
54
+ def increment(i):
55
+ i += 1 # nope..
56
+
57
+ pybind11 is also affected by such language-level conventions, which means that
58
+ binding ``increment`` or ``increment_ptr`` will also create Python functions
59
+ that don't modify their arguments.
60
+
61
+ Although inconvenient, one workaround is to encapsulate the immutable types in
62
+ a custom type that does allow modifications.
63
+
64
+ An other alternative involves binding a small wrapper lambda function that
65
+ returns a tuple with all output arguments (see the remainder of the
66
+ documentation for examples on binding lambda functions). An example:
67
+
68
+ .. code-block:: cpp
69
+
70
+ int foo(int &i) { i++; return 123; }
71
+
72
+ and the binding code
73
+
74
+ .. code-block:: cpp
75
+
76
+ m.def("foo", [](int i) { int rv = foo(i); return std::make_tuple(rv, i); });
77
+
78
+
79
+ How can I reduce the build time?
80
+ ================================
81
+
82
+ It's good practice to split binding code over multiple files, as in the
83
+ following example:
84
+
85
+ :file:`example.cpp`:
86
+
87
+ .. code-block:: cpp
88
+
89
+ void init_ex1(py::module_ &);
90
+ void init_ex2(py::module_ &);
91
+ /* ... */
92
+
93
+ PYBIND11_MODULE(example, m) {
94
+ init_ex1(m);
95
+ init_ex2(m);
96
+ /* ... */
97
+ }
98
+
99
+ :file:`ex1.cpp`:
100
+
101
+ .. code-block:: cpp
102
+
103
+ void init_ex1(py::module_ &m) {
104
+ m.def("add", [](int a, int b) { return a + b; });
105
+ }
106
+
107
+ :file:`ex2.cpp`:
108
+
109
+ .. code-block:: cpp
110
+
111
+ void init_ex2(py::module_ &m) {
112
+ m.def("sub", [](int a, int b) { return a - b; });
113
+ }
114
+
115
+ :command:`python`:
116
+
117
+ .. code-block:: pycon
118
+
119
+ >>> import example
120
+ >>> example.add(1, 2)
121
+ 3
122
+ >>> example.sub(1, 1)
123
+ 0
124
+
125
+ As shown above, the various ``init_ex`` functions should be contained in
126
+ separate files that can be compiled independently from one another, and then
127
+ linked together into the same final shared object. Following this approach
128
+ will:
129
+
130
+ 1. reduce memory requirements per compilation unit.
131
+
132
+ 2. enable parallel builds (if desired).
133
+
134
+ 3. allow for faster incremental builds. For instance, when a single class
135
+ definition is changed, only a subset of the binding code will generally need
136
+ to be recompiled.
137
+
138
+ "recursive template instantiation exceeded maximum depth of 256"
139
+ ================================================================
140
+
141
+ If you receive an error about excessive recursive template evaluation, try
142
+ specifying a larger value, e.g. ``-ftemplate-depth=1024`` on GCC/Clang. The
143
+ culprit is generally the generation of function signatures at compile time
144
+ using C++14 template metaprogramming.
145
+
146
+ .. _`faq:hidden_visibility`:
147
+
148
+ "'SomeClass' declared with greater visibility than the type of its field 'SomeClass::member' [-Wattributes]"
149
+ ============================================================================================================
150
+
151
+ This error typically indicates that you are compiling without the required
152
+ ``-fvisibility`` flag. pybind11 code internally forces hidden visibility on
153
+ all internal code, but if non-hidden (and thus *exported*) code attempts to
154
+ include a pybind type (for example, ``py::object`` or ``py::list``) you can run
155
+ into this warning.
156
+
157
+ To avoid it, make sure you are specifying ``-fvisibility=hidden`` when
158
+ compiling pybind code.
159
+
160
+ As to why ``-fvisibility=hidden`` is necessary, because pybind modules could
161
+ have been compiled under different versions of pybind itself, it is also
162
+ important that the symbols defined in one module do not clash with the
163
+ potentially-incompatible symbols defined in another. While Python extension
164
+ modules are usually loaded with localized symbols (under POSIX systems
165
+ typically using ``dlopen`` with the ``RTLD_LOCAL`` flag), this Python default
166
+ can be changed, but even if it isn't it is not always enough to guarantee
167
+ complete independence of the symbols involved when not using
168
+ ``-fvisibility=hidden``.
169
+
170
+ Additionally, ``-fvisibility=hidden`` can deliver considerably binary size
171
+ savings. (See the following section for more details.)
172
+
173
+
174
+ .. _`faq:symhidden`:
175
+
176
+ How can I create smaller binaries?
177
+ ==================================
178
+
179
+ To do its job, pybind11 extensively relies on a programming technique known as
180
+ *template metaprogramming*, which is a way of performing computation at compile
181
+ time using type information. Template metaprogramming usually instantiates code
182
+ involving significant numbers of deeply nested types that are either completely
183
+ removed or reduced to just a few instructions during the compiler's optimization
184
+ phase. However, due to the nested nature of these types, the resulting symbol
185
+ names in the compiled extension library can be extremely long. For instance,
186
+ the included test suite contains the following symbol:
187
+
188
+ .. only:: html
189
+
190
+ .. code-block:: none
191
+
192
+ _​_​Z​N​8​p​y​b​i​n​d​1​1​1​2​c​p​p​_​f​u​n​c​t​i​o​n​C​1​I​v​8​E​x​a​m​p​l​e​2​J​R​N​S​t​3​_​_​1​6​v​e​c​t​o​r​I​N​S​3​_​1​2​b​a​s​i​c​_​s​t​r​i​n​g​I​w​N​S​3​_​1​1​c​h​a​r​_​t​r​a​i​t​s​I​w​E​E​N​S​3​_​9​a​l​l​o​c​a​t​o​r​I​w​E​E​E​E​N​S​8​_​I​S​A​_​E​E​E​E​E​J​N​S​_​4​n​a​m​e​E​N​S​_​7​s​i​b​l​i​n​g​E​N​S​_​9​i​s​_​m​e​t​h​o​d​E​A​2​8​_​c​E​E​E​M​T​0​_​F​T​_​D​p​T​1​_​E​D​p​R​K​T​2​_
193
+
194
+ .. only:: not html
195
+
196
+ .. code-block:: cpp
197
+
198
+ __ZN8pybind1112cpp_functionC1Iv8Example2JRNSt3__16vectorINS3_12basic_stringIwNS3_11char_traitsIwEENS3_9allocatorIwEEEENS8_ISA_EEEEEJNS_4nameENS_7siblingENS_9is_methodEA28_cEEEMT0_FT_DpT1_EDpRKT2_
199
+
200
+ which is the mangled form of the following function type:
201
+
202
+ .. code-block:: cpp
203
+
204
+ pybind11::cpp_function::cpp_function<void, Example2, std::__1::vector<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, std::__1::allocator<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > > >&, pybind11::name, pybind11::sibling, pybind11::is_method, char [28]>(void (Example2::*)(std::__1::vector<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, std::__1::allocator<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > > >&), pybind11::name const&, pybind11::sibling const&, pybind11::is_method const&, char const (&) [28])
205
+
206
+ The memory needed to store just the mangled name of this function (196 bytes)
207
+ is larger than the actual piece of code (111 bytes) it represents! On the other
208
+ hand, it's silly to even give this function a name -- after all, it's just a
209
+ tiny cog in a bigger piece of machinery that is not exposed to the outside
210
+ world. So we'll generally only want to export symbols for those functions which
211
+ are actually called from the outside.
212
+
213
+ This can be achieved by specifying the parameter ``-fvisibility=hidden`` to GCC
214
+ and Clang, which sets the default symbol visibility to *hidden*, which has a
215
+ tremendous impact on the final binary size of the resulting extension library.
216
+ (On Visual Studio, symbols are already hidden by default, so nothing needs to
217
+ be done there.)
218
+
219
+ In addition to decreasing binary size, ``-fvisibility=hidden`` also avoids
220
+ potential serious issues when loading multiple modules and is required for
221
+ proper pybind operation. See the previous FAQ entry for more details.
222
+
223
+ How can I properly handle Ctrl-C in long-running functions?
224
+ ===========================================================
225
+
226
+ Ctrl-C is received by the Python interpreter, and holds it until the GIL
227
+ is released, so a long-running function won't be interrupted.
228
+
229
+ To interrupt from inside your function, you can use the ``PyErr_CheckSignals()``
230
+ function, that will tell if a signal has been raised on the Python side. This
231
+ function merely checks a flag, so its impact is negligible. When a signal has
232
+ been received, you must either explicitly interrupt execution by throwing
233
+ ``py::error_already_set`` (which will propagate the existing
234
+ ``KeyboardInterrupt``), or clear the error (which you usually will not want):
235
+
236
+ .. code-block:: cpp
237
+
238
+ PYBIND11_MODULE(example, m)
239
+ {
240
+ m.def("long running_func", []()
241
+ {
242
+ for (;;) {
243
+ if (PyErr_CheckSignals() != 0)
244
+ throw py::error_already_set();
245
+ // Long running iteration
246
+ }
247
+ });
248
+ }
249
+
250
+ CMake doesn't detect the right Python version
251
+ =============================================
252
+
253
+ The CMake-based build system will try to automatically detect the installed
254
+ version of Python and link against that. When this fails, or when there are
255
+ multiple versions of Python and it finds the wrong one, delete
256
+ ``CMakeCache.txt`` and then add ``-DPYTHON_EXECUTABLE=$(which python)`` to your
257
+ CMake configure line. (Replace ``$(which python)`` with a path to python if
258
+ your prefer.)
259
+
260
+ You can alternatively try ``-DPYBIND11_FINDPYTHON=ON``, which will activate the
261
+ new CMake FindPython support instead of pybind11's custom search. Requires
262
+ CMake 3.12+, and 3.15+ or 3.18.2+ are even better. You can set this in your
263
+ ``CMakeLists.txt`` before adding or finding pybind11, as well.
264
+
265
+ Inconsistent detection of Python version in CMake and pybind11
266
+ ==============================================================
267
+
268
+ The functions ``find_package(PythonInterp)`` and ``find_package(PythonLibs)``
269
+ provided by CMake for Python version detection are modified by pybind11 due to
270
+ unreliability and limitations that make them unsuitable for pybind11's needs.
271
+ Instead pybind11 provides its own, more reliable Python detection CMake code.
272
+ Conflicts can arise, however, when using pybind11 in a project that *also* uses
273
+ the CMake Python detection in a system with several Python versions installed.
274
+
275
+ This difference may cause inconsistencies and errors if *both* mechanisms are
276
+ used in the same project.
277
+
278
+ There are three possible solutions:
279
+
280
+ 1. Avoid using ``find_package(PythonInterp)`` and ``find_package(PythonLibs)``
281
+ from CMake and rely on pybind11 in detecting Python version. If this is not
282
+ possible, the CMake machinery should be called *before* including pybind11.
283
+ 2. Set ``PYBIND11_FINDPYTHON`` to ``True`` or use ``find_package(Python
284
+ COMPONENTS Interpreter Development)`` on modern CMake (3.12+, 3.15+ better,
285
+ 3.18.2+ best). Pybind11 in these cases uses the new CMake FindPython instead
286
+ of the old, deprecated search tools, and these modules are much better at
287
+ finding the correct Python. If FindPythonLibs/Interp are not available
288
+ (CMake 3.27+), then this will be ignored and FindPython will be used.
289
+ 3. Set ``PYBIND11_NOPYTHON`` to ``TRUE``. Pybind11 will not search for Python.
290
+ However, you will have to use the target-based system, and do more setup
291
+ yourself, because it does not know about or include things that depend on
292
+ Python, like ``pybind11_add_module``. This might be ideal for integrating
293
+ into an existing system, like scikit-build's Python helpers.
294
+
295
+ How to cite this project?
296
+ =========================
297
+
298
+ We suggest the following BibTeX template to cite pybind11 in scientific
299
+ discourse:
300
+
301
+ .. code-block:: bash
302
+
303
+ @misc{pybind11,
304
+ author = {Wenzel Jakob and Jason Rhinelander and Dean Moldovan},
305
+ year = {2017},
306
+ note = {https://github.com/pybind/pybind11},
307
+ title = {pybind11 -- Seamless operability between C++11 and Python}
308
+ }
third_party/CityFlow/extern/pybind11/docs/index.rst CHANGED
@@ -1,48 +1,48 @@
1
- .. only:: latex
2
-
3
- Intro
4
- =====
5
-
6
- .. include:: readme.rst
7
-
8
- .. only:: not latex
9
-
10
- Contents:
11
-
12
- .. toctree::
13
- :maxdepth: 1
14
-
15
- changelog
16
- upgrade
17
-
18
- .. toctree::
19
- :caption: The Basics
20
- :maxdepth: 2
21
-
22
- installing
23
- basics
24
- classes
25
- compiling
26
-
27
- .. toctree::
28
- :caption: Advanced Topics
29
- :maxdepth: 2
30
-
31
- advanced/functions
32
- advanced/classes
33
- advanced/exceptions
34
- advanced/smart_ptrs
35
- advanced/cast/index
36
- advanced/pycpp/index
37
- advanced/embedding
38
- advanced/misc
39
-
40
- .. toctree::
41
- :caption: Extra Information
42
- :maxdepth: 1
43
-
44
- faq
45
- benchmark
46
- limitations
47
- reference
48
- cmake/index
 
1
+ .. only:: latex
2
+
3
+ Intro
4
+ =====
5
+
6
+ .. include:: readme.rst
7
+
8
+ .. only:: not latex
9
+
10
+ Contents:
11
+
12
+ .. toctree::
13
+ :maxdepth: 1
14
+
15
+ changelog
16
+ upgrade
17
+
18
+ .. toctree::
19
+ :caption: The Basics
20
+ :maxdepth: 2
21
+
22
+ installing
23
+ basics
24
+ classes
25
+ compiling
26
+
27
+ .. toctree::
28
+ :caption: Advanced Topics
29
+ :maxdepth: 2
30
+
31
+ advanced/functions
32
+ advanced/classes
33
+ advanced/exceptions
34
+ advanced/smart_ptrs
35
+ advanced/cast/index
36
+ advanced/pycpp/index
37
+ advanced/embedding
38
+ advanced/misc
39
+
40
+ .. toctree::
41
+ :caption: Extra Information
42
+ :maxdepth: 1
43
+
44
+ faq
45
+ benchmark
46
+ limitations
47
+ reference
48
+ cmake/index
third_party/CityFlow/extern/pybind11/docs/installing.rst CHANGED
@@ -1,105 +1,105 @@
1
- .. _installing:
2
-
3
- Installing the library
4
- ######################
5
-
6
- There are several ways to get the pybind11 source, which lives at
7
- `pybind/pybind11 on GitHub <https://github.com/pybind/pybind11>`_. The pybind11
8
- developers recommend one of the first three ways listed here, submodule, PyPI,
9
- or conda-forge, for obtaining pybind11.
10
-
11
- .. _include_as_a_submodule:
12
-
13
- Include as a submodule
14
- ======================
15
-
16
- When you are working on a project in Git, you can use the pybind11 repository
17
- as a submodule. From your git repository, use:
18
-
19
- .. code-block:: bash
20
-
21
- git submodule add -b stable ../../pybind/pybind11 extern/pybind11
22
- git submodule update --init
23
-
24
- This assumes you are placing your dependencies in ``extern/``, and that you are
25
- using GitHub; if you are not using GitHub, use the full https or ssh URL
26
- instead of the relative URL ``../../pybind/pybind11`` above. Some other servers
27
- also require the ``.git`` extension (GitHub does not).
28
-
29
- From here, you can now include ``extern/pybind11/include``, or you can use
30
- the various integration tools (see :ref:`compiling`) pybind11 provides directly
31
- from the local folder.
32
-
33
- Include with PyPI
34
- =================
35
-
36
- You can download the sources and CMake files as a Python package from PyPI
37
- using Pip. Just use:
38
-
39
- .. code-block:: bash
40
-
41
- pip install pybind11
42
-
43
- This will provide pybind11 in a standard Python package format. If you want
44
- pybind11 available directly in your environment root, you can use:
45
-
46
- .. code-block:: bash
47
-
48
- pip install "pybind11[global]"
49
-
50
- This is not recommended if you are installing with your system Python, as it
51
- will add files to ``/usr/local/include/pybind11`` and
52
- ``/usr/local/share/cmake/pybind11``, so unless that is what you want, it is
53
- recommended only for use in virtual environments or your ``pyproject.toml``
54
- file (see :ref:`compiling`).
55
-
56
- Include with conda-forge
57
- ========================
58
-
59
- You can use pybind11 with conda packaging via `conda-forge
60
- <https://github.com/conda-forge/pybind11-feedstock>`_:
61
-
62
- .. code-block:: bash
63
-
64
- conda install -c conda-forge pybind11
65
-
66
-
67
- Include with vcpkg
68
- ==================
69
- You can download and install pybind11 using the Microsoft `vcpkg
70
- <https://github.com/Microsoft/vcpkg/>`_ dependency manager:
71
-
72
- .. code-block:: bash
73
-
74
- git clone https://github.com/Microsoft/vcpkg.git
75
- cd vcpkg
76
- ./bootstrap-vcpkg.sh
77
- ./vcpkg integrate install
78
- vcpkg install pybind11
79
-
80
- The pybind11 port in vcpkg is kept up to date by Microsoft team members and
81
- community contributors. If the version is out of date, please `create an issue
82
- or pull request <https://github.com/Microsoft/vcpkg/>`_ on the vcpkg
83
- repository.
84
-
85
- Global install with brew
86
- ========================
87
-
88
- The brew package manager (Homebrew on macOS, or Linuxbrew on Linux) has a
89
- `pybind11 package
90
- <https://github.com/Homebrew/homebrew-core/blob/master/Formula/pybind11.rb>`_.
91
- To install:
92
-
93
- .. code-block:: bash
94
-
95
- brew install pybind11
96
-
97
- .. We should list Conan, and possibly a few other C++ package managers (hunter,
98
- .. perhaps). Conan has a very clean CMake integration that would be good to show.
99
-
100
- Other options
101
- =============
102
-
103
- Other locations you can find pybind11 are `listed here
104
- <https://repology.org/project/python:pybind11/versions>`_; these are maintained
105
- by various packagers and the community.
 
1
+ .. _installing:
2
+
3
+ Installing the library
4
+ ######################
5
+
6
+ There are several ways to get the pybind11 source, which lives at
7
+ `pybind/pybind11 on GitHub <https://github.com/pybind/pybind11>`_. The pybind11
8
+ developers recommend one of the first three ways listed here, submodule, PyPI,
9
+ or conda-forge, for obtaining pybind11.
10
+
11
+ .. _include_as_a_submodule:
12
+
13
+ Include as a submodule
14
+ ======================
15
+
16
+ When you are working on a project in Git, you can use the pybind11 repository
17
+ as a submodule. From your git repository, use:
18
+
19
+ .. code-block:: bash
20
+
21
+ git submodule add -b stable ../../pybind/pybind11 extern/pybind11
22
+ git submodule update --init
23
+
24
+ This assumes you are placing your dependencies in ``extern/``, and that you are
25
+ using GitHub; if you are not using GitHub, use the full https or ssh URL
26
+ instead of the relative URL ``../../pybind/pybind11`` above. Some other servers
27
+ also require the ``.git`` extension (GitHub does not).
28
+
29
+ From here, you can now include ``extern/pybind11/include``, or you can use
30
+ the various integration tools (see :ref:`compiling`) pybind11 provides directly
31
+ from the local folder.
32
+
33
+ Include with PyPI
34
+ =================
35
+
36
+ You can download the sources and CMake files as a Python package from PyPI
37
+ using Pip. Just use:
38
+
39
+ .. code-block:: bash
40
+
41
+ pip install pybind11
42
+
43
+ This will provide pybind11 in a standard Python package format. If you want
44
+ pybind11 available directly in your environment root, you can use:
45
+
46
+ .. code-block:: bash
47
+
48
+ pip install "pybind11[global]"
49
+
50
+ This is not recommended if you are installing with your system Python, as it
51
+ will add files to ``/usr/local/include/pybind11`` and
52
+ ``/usr/local/share/cmake/pybind11``, so unless that is what you want, it is
53
+ recommended only for use in virtual environments or your ``pyproject.toml``
54
+ file (see :ref:`compiling`).
55
+
56
+ Include with conda-forge
57
+ ========================
58
+
59
+ You can use pybind11 with conda packaging via `conda-forge
60
+ <https://github.com/conda-forge/pybind11-feedstock>`_:
61
+
62
+ .. code-block:: bash
63
+
64
+ conda install -c conda-forge pybind11
65
+
66
+
67
+ Include with vcpkg
68
+ ==================
69
+ You can download and install pybind11 using the Microsoft `vcpkg
70
+ <https://github.com/Microsoft/vcpkg/>`_ dependency manager:
71
+
72
+ .. code-block:: bash
73
+
74
+ git clone https://github.com/Microsoft/vcpkg.git
75
+ cd vcpkg
76
+ ./bootstrap-vcpkg.sh
77
+ ./vcpkg integrate install
78
+ vcpkg install pybind11
79
+
80
+ The pybind11 port in vcpkg is kept up to date by Microsoft team members and
81
+ community contributors. If the version is out of date, please `create an issue
82
+ or pull request <https://github.com/Microsoft/vcpkg/>`_ on the vcpkg
83
+ repository.
84
+
85
+ Global install with brew
86
+ ========================
87
+
88
+ The brew package manager (Homebrew on macOS, or Linuxbrew on Linux) has a
89
+ `pybind11 package
90
+ <https://github.com/Homebrew/homebrew-core/blob/master/Formula/pybind11.rb>`_.
91
+ To install:
92
+
93
+ .. code-block:: bash
94
+
95
+ brew install pybind11
96
+
97
+ .. We should list Conan, and possibly a few other C++ package managers (hunter,
98
+ .. perhaps). Conan has a very clean CMake integration that would be good to show.
99
+
100
+ Other options
101
+ =============
102
+
103
+ Other locations you can find pybind11 are `listed here
104
+ <https://repology.org/project/python:pybind11/versions>`_; these are maintained
105
+ by various packagers and the community.
third_party/CityFlow/extern/pybind11/docs/limitations.rst CHANGED
@@ -1,72 +1,72 @@
1
- Limitations
2
- ###########
3
-
4
- Design choices
5
- ^^^^^^^^^^^^^^
6
-
7
- pybind11 strives to be a general solution to binding generation, but it also has
8
- certain limitations:
9
-
10
- - pybind11 casts away ``const``-ness in function arguments and return values.
11
- This is in line with the Python language, which has no concept of ``const``
12
- values. This means that some additional care is needed to avoid bugs that
13
- would be caught by the type checker in a traditional C++ program.
14
-
15
- - The NumPy interface ``pybind11::array`` greatly simplifies accessing
16
- numerical data from C++ (and vice versa), but it's not a full-blown array
17
- class like ``Eigen::Array`` or ``boost.multi_array``. ``Eigen`` objects are
18
- directly supported, however, with ``pybind11/eigen.h``.
19
-
20
- Large but useful features could be implemented in pybind11 but would lead to a
21
- significant increase in complexity. Pybind11 strives to be simple and compact.
22
- Users who require large new features are encouraged to write an extension to
23
- pybind11; see `pybind11_json <https://github.com/pybind/pybind11_json>`_ for an
24
- example.
25
-
26
-
27
- Known bugs
28
- ^^^^^^^^^^
29
-
30
- These are issues that hopefully will one day be fixed, but currently are
31
- unsolved. If you know how to help with one of these issues, contributions
32
- are welcome!
33
-
34
- - Intel 20.2 is currently having an issue with the test suite.
35
- `#2573 <https://github.com/pybind/pybind11/pull/2573>`_
36
-
37
- - Debug mode Python does not support 1-5 tests in the test suite currently.
38
- `#2422 <https://github.com/pybind/pybind11/pull/2422>`_
39
-
40
- - PyPy3 7.3.1 and 7.3.2 have issues with several tests on 32-bit Windows.
41
-
42
- Known limitations
43
- ^^^^^^^^^^^^^^^^^
44
-
45
- These are issues that are probably solvable, but have not been fixed yet. A
46
- clean, well written patch would likely be accepted to solve them.
47
-
48
- - Type casters are not kept alive recursively.
49
- `#2527 <https://github.com/pybind/pybind11/issues/2527>`_
50
- One consequence is that containers of ``char *`` are currently not supported.
51
- `#2245 <https://github.com/pybind/pybind11/issues/2245>`_
52
-
53
- - The ``cpptest`` does not run on Windows with Python 3.8 or newer, due to DLL
54
- loader changes. User code that is correctly installed should not be affected.
55
- `#2560 <https://github.com/pybind/pybind11/issue/2560>`_
56
-
57
- Python 3.9.0 warning
58
- ^^^^^^^^^^^^^^^^^^^^
59
-
60
- Combining older versions of pybind11 (< 2.6.0) with Python on exactly 3.9.0
61
- will trigger undefined behavior that typically manifests as crashes during
62
- interpreter shutdown (but could also destroy your data. **You have been
63
- warned**).
64
-
65
- This issue was `fixed in Python <https://github.com/python/cpython/pull/22670>`_.
66
- As a mitigation for this bug, pybind11 2.6.0 or newer includes a workaround
67
- specifically when Python 3.9.0 is detected at runtime, leaking about 50 bytes
68
- of memory when a callback function is garbage collected. For reference, the
69
- pybind11 test suite has about 2,000 such callbacks, but only 49 are garbage
70
- collected before the end-of-process. Wheels (even if built with Python 3.9.0)
71
- will correctly avoid the leak when run in Python 3.9.1, and this does not
72
- affect other 3.X versions.
 
1
+ Limitations
2
+ ###########
3
+
4
+ Design choices
5
+ ^^^^^^^^^^^^^^
6
+
7
+ pybind11 strives to be a general solution to binding generation, but it also has
8
+ certain limitations:
9
+
10
+ - pybind11 casts away ``const``-ness in function arguments and return values.
11
+ This is in line with the Python language, which has no concept of ``const``
12
+ values. This means that some additional care is needed to avoid bugs that
13
+ would be caught by the type checker in a traditional C++ program.
14
+
15
+ - The NumPy interface ``pybind11::array`` greatly simplifies accessing
16
+ numerical data from C++ (and vice versa), but it's not a full-blown array
17
+ class like ``Eigen::Array`` or ``boost.multi_array``. ``Eigen`` objects are
18
+ directly supported, however, with ``pybind11/eigen.h``.
19
+
20
+ Large but useful features could be implemented in pybind11 but would lead to a
21
+ significant increase in complexity. Pybind11 strives to be simple and compact.
22
+ Users who require large new features are encouraged to write an extension to
23
+ pybind11; see `pybind11_json <https://github.com/pybind/pybind11_json>`_ for an
24
+ example.
25
+
26
+
27
+ Known bugs
28
+ ^^^^^^^^^^
29
+
30
+ These are issues that hopefully will one day be fixed, but currently are
31
+ unsolved. If you know how to help with one of these issues, contributions
32
+ are welcome!
33
+
34
+ - Intel 20.2 is currently having an issue with the test suite.
35
+ `#2573 <https://github.com/pybind/pybind11/pull/2573>`_
36
+
37
+ - Debug mode Python does not support 1-5 tests in the test suite currently.
38
+ `#2422 <https://github.com/pybind/pybind11/pull/2422>`_
39
+
40
+ - PyPy3 7.3.1 and 7.3.2 have issues with several tests on 32-bit Windows.
41
+
42
+ Known limitations
43
+ ^^^^^^^^^^^^^^^^^
44
+
45
+ These are issues that are probably solvable, but have not been fixed yet. A
46
+ clean, well written patch would likely be accepted to solve them.
47
+
48
+ - Type casters are not kept alive recursively.
49
+ `#2527 <https://github.com/pybind/pybind11/issues/2527>`_
50
+ One consequence is that containers of ``char *`` are currently not supported.
51
+ `#2245 <https://github.com/pybind/pybind11/issues/2245>`_
52
+
53
+ - The ``cpptest`` does not run on Windows with Python 3.8 or newer, due to DLL
54
+ loader changes. User code that is correctly installed should not be affected.
55
+ `#2560 <https://github.com/pybind/pybind11/issue/2560>`_
56
+
57
+ Python 3.9.0 warning
58
+ ^^^^^^^^^^^^^^^^^^^^
59
+
60
+ Combining older versions of pybind11 (< 2.6.0) with Python on exactly 3.9.0
61
+ will trigger undefined behavior that typically manifests as crashes during
62
+ interpreter shutdown (but could also destroy your data. **You have been
63
+ warned**).
64
+
65
+ This issue was `fixed in Python <https://github.com/python/cpython/pull/22670>`_.
66
+ As a mitigation for this bug, pybind11 2.6.0 or newer includes a workaround
67
+ specifically when Python 3.9.0 is detected at runtime, leaking about 50 bytes
68
+ of memory when a callback function is garbage collected. For reference, the
69
+ pybind11 test suite has about 2,000 such callbacks, but only 49 are garbage
70
+ collected before the end-of-process. Wheels (even if built with Python 3.9.0)
71
+ will correctly avoid the leak when run in Python 3.9.1, and this does not
72
+ affect other 3.X versions.
third_party/CityFlow/extern/pybind11/docs/reference.rst CHANGED
@@ -1,130 +1,130 @@
1
- .. _reference:
2
-
3
- .. warning::
4
-
5
- Please be advised that the reference documentation discussing pybind11
6
- internals is currently incomplete. Please refer to the previous sections
7
- and the pybind11 header files for the nitty gritty details.
8
-
9
- Reference
10
- #########
11
-
12
- .. _macros:
13
-
14
- Macros
15
- ======
16
-
17
- .. doxygendefine:: PYBIND11_MODULE
18
-
19
- .. _core_types:
20
-
21
- Convenience classes for arbitrary Python types
22
- ==============================================
23
-
24
- Common member functions
25
- -----------------------
26
-
27
- .. doxygenclass:: object_api
28
- :members:
29
-
30
- Without reference counting
31
- --------------------------
32
-
33
- .. doxygenclass:: handle
34
- :members:
35
-
36
- With reference counting
37
- -----------------------
38
-
39
- .. doxygenclass:: object
40
- :members:
41
-
42
- .. doxygenfunction:: reinterpret_borrow
43
-
44
- .. doxygenfunction:: reinterpret_steal
45
-
46
- Convenience classes for specific Python types
47
- =============================================
48
-
49
- .. doxygenclass:: module_
50
- :members:
51
-
52
- .. doxygengroup:: pytypes
53
- :members:
54
-
55
- Convenience functions converting to Python types
56
- ================================================
57
-
58
- .. doxygenfunction:: make_tuple(Args&&...)
59
-
60
- .. doxygenfunction:: make_iterator(Iterator, Sentinel, Extra &&...)
61
- .. doxygenfunction:: make_iterator(Type &, Extra&&...)
62
-
63
- .. doxygenfunction:: make_key_iterator(Iterator, Sentinel, Extra &&...)
64
- .. doxygenfunction:: make_key_iterator(Type &, Extra&&...)
65
-
66
- .. doxygenfunction:: make_value_iterator(Iterator, Sentinel, Extra &&...)
67
- .. doxygenfunction:: make_value_iterator(Type &, Extra&&...)
68
-
69
- .. _extras:
70
-
71
- Passing extra arguments to ``def`` or ``class_``
72
- ================================================
73
-
74
- .. doxygengroup:: annotations
75
- :members:
76
-
77
- Embedding the interpreter
78
- =========================
79
-
80
- .. doxygendefine:: PYBIND11_EMBEDDED_MODULE
81
-
82
- .. doxygenfunction:: initialize_interpreter
83
-
84
- .. doxygenfunction:: finalize_interpreter
85
-
86
- .. doxygenclass:: scoped_interpreter
87
-
88
- Redirecting C++ streams
89
- =======================
90
-
91
- .. doxygenclass:: scoped_ostream_redirect
92
-
93
- .. doxygenclass:: scoped_estream_redirect
94
-
95
- .. doxygenfunction:: add_ostream_redirect
96
-
97
- Python built-in functions
98
- =========================
99
-
100
- .. doxygengroup:: python_builtins
101
- :members:
102
-
103
- Inheritance
104
- ===========
105
-
106
- See :doc:`/classes` and :doc:`/advanced/classes` for more detail.
107
-
108
- .. doxygendefine:: PYBIND11_OVERRIDE
109
-
110
- .. doxygendefine:: PYBIND11_OVERRIDE_PURE
111
-
112
- .. doxygendefine:: PYBIND11_OVERRIDE_NAME
113
-
114
- .. doxygendefine:: PYBIND11_OVERRIDE_PURE_NAME
115
-
116
- .. doxygenfunction:: get_override
117
-
118
- Exceptions
119
- ==========
120
-
121
- .. doxygenclass:: error_already_set
122
- :members:
123
-
124
- .. doxygenclass:: builtin_exception
125
- :members:
126
-
127
- Literals
128
- ========
129
-
130
- .. doxygennamespace:: literals
 
1
+ .. _reference:
2
+
3
+ .. warning::
4
+
5
+ Please be advised that the reference documentation discussing pybind11
6
+ internals is currently incomplete. Please refer to the previous sections
7
+ and the pybind11 header files for the nitty gritty details.
8
+
9
+ Reference
10
+ #########
11
+
12
+ .. _macros:
13
+
14
+ Macros
15
+ ======
16
+
17
+ .. doxygendefine:: PYBIND11_MODULE
18
+
19
+ .. _core_types:
20
+
21
+ Convenience classes for arbitrary Python types
22
+ ==============================================
23
+
24
+ Common member functions
25
+ -----------------------
26
+
27
+ .. doxygenclass:: object_api
28
+ :members:
29
+
30
+ Without reference counting
31
+ --------------------------
32
+
33
+ .. doxygenclass:: handle
34
+ :members:
35
+
36
+ With reference counting
37
+ -----------------------
38
+
39
+ .. doxygenclass:: object
40
+ :members:
41
+
42
+ .. doxygenfunction:: reinterpret_borrow
43
+
44
+ .. doxygenfunction:: reinterpret_steal
45
+
46
+ Convenience classes for specific Python types
47
+ =============================================
48
+
49
+ .. doxygenclass:: module_
50
+ :members:
51
+
52
+ .. doxygengroup:: pytypes
53
+ :members:
54
+
55
+ Convenience functions converting to Python types
56
+ ================================================
57
+
58
+ .. doxygenfunction:: make_tuple(Args&&...)
59
+
60
+ .. doxygenfunction:: make_iterator(Iterator, Sentinel, Extra &&...)
61
+ .. doxygenfunction:: make_iterator(Type &, Extra&&...)
62
+
63
+ .. doxygenfunction:: make_key_iterator(Iterator, Sentinel, Extra &&...)
64
+ .. doxygenfunction:: make_key_iterator(Type &, Extra&&...)
65
+
66
+ .. doxygenfunction:: make_value_iterator(Iterator, Sentinel, Extra &&...)
67
+ .. doxygenfunction:: make_value_iterator(Type &, Extra&&...)
68
+
69
+ .. _extras:
70
+
71
+ Passing extra arguments to ``def`` or ``class_``
72
+ ================================================
73
+
74
+ .. doxygengroup:: annotations
75
+ :members:
76
+
77
+ Embedding the interpreter
78
+ =========================
79
+
80
+ .. doxygendefine:: PYBIND11_EMBEDDED_MODULE
81
+
82
+ .. doxygenfunction:: initialize_interpreter
83
+
84
+ .. doxygenfunction:: finalize_interpreter
85
+
86
+ .. doxygenclass:: scoped_interpreter
87
+
88
+ Redirecting C++ streams
89
+ =======================
90
+
91
+ .. doxygenclass:: scoped_ostream_redirect
92
+
93
+ .. doxygenclass:: scoped_estream_redirect
94
+
95
+ .. doxygenfunction:: add_ostream_redirect
96
+
97
+ Python built-in functions
98
+ =========================
99
+
100
+ .. doxygengroup:: python_builtins
101
+ :members:
102
+
103
+ Inheritance
104
+ ===========
105
+
106
+ See :doc:`/classes` and :doc:`/advanced/classes` for more detail.
107
+
108
+ .. doxygendefine:: PYBIND11_OVERRIDE
109
+
110
+ .. doxygendefine:: PYBIND11_OVERRIDE_PURE
111
+
112
+ .. doxygendefine:: PYBIND11_OVERRIDE_NAME
113
+
114
+ .. doxygendefine:: PYBIND11_OVERRIDE_PURE_NAME
115
+
116
+ .. doxygenfunction:: get_override
117
+
118
+ Exceptions
119
+ ==========
120
+
121
+ .. doxygenclass:: error_already_set
122
+ :members:
123
+
124
+ .. doxygenclass:: builtin_exception
125
+ :members:
126
+
127
+ Literals
128
+ ========
129
+
130
+ .. doxygennamespace:: literals
third_party/CityFlow/extern/pybind11/docs/release.rst CHANGED
@@ -1,143 +1,143 @@
1
- On version numbers
2
- ^^^^^^^^^^^^^^^^^^
3
-
4
- The two version numbers (C++ and Python) must match when combined (checked when
5
- you build the PyPI package), and must be a valid `PEP 440
6
- <https://www.python.org/dev/peps/pep-0440>`_ version when combined.
7
-
8
- For example:
9
-
10
- .. code-block:: C++
11
-
12
- #define PYBIND11_VERSION_MAJOR X
13
- #define PYBIND11_VERSION_MINOR Y
14
- #define PYBIND11_VERSION_PATCH Z.dev1
15
-
16
- For beta, ``PYBIND11_VERSION_PATCH`` should be ``Z.b1``. RC's can be ``Z.rc1``.
17
- Always include the dot (even though PEP 440 allows it to be dropped). For a
18
- final release, this must be a simple integer. There is also
19
- ``PYBIND11_VERSION_HEX`` just below that needs to be updated.
20
-
21
-
22
- To release a new version of pybind11:
23
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24
-
25
- If you don't have nox, you should either use ``pipx run nox`` instead, or use
26
- ``pipx install nox`` or ``brew install nox`` (Unix).
27
-
28
- - Update the version number
29
-
30
- - Update ``PYBIND11_VERSION_MAJOR`` etc. in
31
- ``include/pybind11/detail/common.h``. PATCH should be a simple integer.
32
-
33
- - Update ``PYBIND11_VERSION_HEX`` just below as well.
34
-
35
- - Update ``pybind11/_version.py`` (match above).
36
-
37
- - Run ``nox -s tests_packaging`` to ensure this was done correctly.
38
-
39
- - Ensure that all the information in ``setup.cfg`` is up-to-date, like
40
- supported Python versions.
41
-
42
- - Add release date in ``docs/changelog.rst`` and integrate the output of
43
- ``nox -s make_changelog``.
44
-
45
- - Note that the ``nox -s make_changelog`` command inspects
46
- `needs changelog <https://github.com/pybind/pybind11/pulls?q=is%3Apr+is%3Aclosed+label%3A%22needs+changelog%22>`_.
47
-
48
- - Manually clear the ``needs changelog`` labels using the GitHub web
49
- interface (very easy: start by clicking the link above).
50
-
51
- - ``git add`` and ``git commit``, ``git push``. **Ensure CI passes**. (If it
52
- fails due to a known flake issue, either ignore or restart CI.)
53
-
54
- - Add a release branch if this is a new MINOR version, or update the existing
55
- release branch if it is a patch version
56
-
57
- - New branch: ``git checkout -b vX.Y``, ``git push -u origin vX.Y``
58
-
59
- - Update branch: ``git checkout vX.Y``, ``git merge <release branch>``, ``git push``
60
-
61
- - Update tags (optional; if you skip this, the GitHub release makes a
62
- non-annotated tag for you)
63
-
64
- - ``git tag -a vX.Y.Z -m 'vX.Y.Z release'``
65
-
66
- - ``grep ^__version__ pybind11/_version.py``
67
-
68
- - Last-minute consistency check: same as tag?
69
-
70
- - ``git push --tags``
71
-
72
- - Update stable
73
-
74
- - ``git checkout stable``
75
-
76
- - ``git merge -X theirs vX.Y.Z``
77
-
78
- - ``git diff vX.Y.Z``
79
-
80
- - Carefully review and reconcile any diffs. There should be none.
81
-
82
- - ``git push``
83
-
84
- - Make a GitHub release (this shows up in the UI, sends new release
85
- notifications to users watching releases, and also uploads PyPI packages).
86
- (Note: if you do not use an existing tag, this creates a new lightweight tag
87
- for you, so you could skip the above step.)
88
-
89
- - GUI method: Under `releases <https://github.com/pybind/pybind11/releases>`_
90
- click "Draft a new release" on the far right, fill in the tag name
91
- (if you didn't tag above, it will be made here), fill in a release name
92
- like "Version X.Y.Z", and copy-and-paste the markdown-formatted (!) changelog
93
- into the description. You can use ``cat docs/changelog.rst | pandoc -f rst -t gfm``,
94
- then manually remove line breaks and strip links to PRs and issues,
95
- e.g. to a bare ``#1234``, without the surrounding ``<...>_`` hyperlink markup.
96
- Check "pre-release" if this is a beta/RC.
97
-
98
- - CLI method: with ``gh`` installed, run ``gh release create vX.Y.Z -t "Version X.Y.Z"``
99
- If this is a pre-release, add ``-p``.
100
-
101
- - Get back to work
102
-
103
- - Make sure you are on master, not somewhere else: ``git checkout master``
104
-
105
- - Update version macros in ``include/pybind11/detail/common.h`` (set PATCH to
106
- ``0.dev1`` and increment MINOR).
107
-
108
- - Update ``pybind11/_version.py`` to match.
109
-
110
- - Run ``nox -s tests_packaging`` to ensure this was done correctly.
111
-
112
- - If the release was a new MINOR version, add a new ``IN DEVELOPMENT``
113
- section in ``docs/changelog.rst``.
114
-
115
- - ``git add``, ``git commit``, ``git push``
116
-
117
- If a version branch is updated, remember to set PATCH to ``1.dev1``.
118
-
119
- If you'd like to bump homebrew, run:
120
-
121
- .. code-block:: console
122
-
123
- brew bump-formula-pr --url https://github.com/pybind/pybind11/archive/vX.Y.Z.tar.gz
124
-
125
- Conda-forge should automatically make a PR in a few hours, and automatically
126
- merge it if there are no issues.
127
-
128
-
129
- Manual packaging
130
- ^^^^^^^^^^^^^^^^
131
-
132
- If you need to manually upload releases, you can download the releases from
133
- the job artifacts and upload them with twine. You can also make the files
134
- locally (not recommended in general, as your local directory is more likely
135
- to be "dirty" and SDists love picking up random unrelated/hidden files);
136
- this is the procedure:
137
-
138
- .. code-block:: bash
139
-
140
- nox -s build
141
- twine upload dist/*
142
-
143
- This makes SDists and wheels, and the final line uploads them.
 
1
+ On version numbers
2
+ ^^^^^^^^^^^^^^^^^^
3
+
4
+ The two version numbers (C++ and Python) must match when combined (checked when
5
+ you build the PyPI package), and must be a valid `PEP 440
6
+ <https://www.python.org/dev/peps/pep-0440>`_ version when combined.
7
+
8
+ For example:
9
+
10
+ .. code-block:: C++
11
+
12
+ #define PYBIND11_VERSION_MAJOR X
13
+ #define PYBIND11_VERSION_MINOR Y
14
+ #define PYBIND11_VERSION_PATCH Z.dev1
15
+
16
+ For beta, ``PYBIND11_VERSION_PATCH`` should be ``Z.b1``. RC's can be ``Z.rc1``.
17
+ Always include the dot (even though PEP 440 allows it to be dropped). For a
18
+ final release, this must be a simple integer. There is also
19
+ ``PYBIND11_VERSION_HEX`` just below that needs to be updated.
20
+
21
+
22
+ To release a new version of pybind11:
23
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24
+
25
+ If you don't have nox, you should either use ``pipx run nox`` instead, or use
26
+ ``pipx install nox`` or ``brew install nox`` (Unix).
27
+
28
+ - Update the version number
29
+
30
+ - Update ``PYBIND11_VERSION_MAJOR`` etc. in
31
+ ``include/pybind11/detail/common.h``. PATCH should be a simple integer.
32
+
33
+ - Update ``PYBIND11_VERSION_HEX`` just below as well.
34
+
35
+ - Update ``pybind11/_version.py`` (match above).
36
+
37
+ - Run ``nox -s tests_packaging`` to ensure this was done correctly.
38
+
39
+ - Ensure that all the information in ``setup.cfg`` is up-to-date, like
40
+ supported Python versions.
41
+
42
+ - Add release date in ``docs/changelog.rst`` and integrate the output of
43
+ ``nox -s make_changelog``.
44
+
45
+ - Note that the ``nox -s make_changelog`` command inspects
46
+ `needs changelog <https://github.com/pybind/pybind11/pulls?q=is%3Apr+is%3Aclosed+label%3A%22needs+changelog%22>`_.
47
+
48
+ - Manually clear the ``needs changelog`` labels using the GitHub web
49
+ interface (very easy: start by clicking the link above).
50
+
51
+ - ``git add`` and ``git commit``, ``git push``. **Ensure CI passes**. (If it
52
+ fails due to a known flake issue, either ignore or restart CI.)
53
+
54
+ - Add a release branch if this is a new MINOR version, or update the existing
55
+ release branch if it is a patch version
56
+
57
+ - New branch: ``git checkout -b vX.Y``, ``git push -u origin vX.Y``
58
+
59
+ - Update branch: ``git checkout vX.Y``, ``git merge <release branch>``, ``git push``
60
+
61
+ - Update tags (optional; if you skip this, the GitHub release makes a
62
+ non-annotated tag for you)
63
+
64
+ - ``git tag -a vX.Y.Z -m 'vX.Y.Z release'``
65
+
66
+ - ``grep ^__version__ pybind11/_version.py``
67
+
68
+ - Last-minute consistency check: same as tag?
69
+
70
+ - ``git push --tags``
71
+
72
+ - Update stable
73
+
74
+ - ``git checkout stable``
75
+
76
+ - ``git merge -X theirs vX.Y.Z``
77
+
78
+ - ``git diff vX.Y.Z``
79
+
80
+ - Carefully review and reconcile any diffs. There should be none.
81
+
82
+ - ``git push``
83
+
84
+ - Make a GitHub release (this shows up in the UI, sends new release
85
+ notifications to users watching releases, and also uploads PyPI packages).
86
+ (Note: if you do not use an existing tag, this creates a new lightweight tag
87
+ for you, so you could skip the above step.)
88
+
89
+ - GUI method: Under `releases <https://github.com/pybind/pybind11/releases>`_
90
+ click "Draft a new release" on the far right, fill in the tag name
91
+ (if you didn't tag above, it will be made here), fill in a release name
92
+ like "Version X.Y.Z", and copy-and-paste the markdown-formatted (!) changelog
93
+ into the description. You can use ``cat docs/changelog.rst | pandoc -f rst -t gfm``,
94
+ then manually remove line breaks and strip links to PRs and issues,
95
+ e.g. to a bare ``#1234``, without the surrounding ``<...>_`` hyperlink markup.
96
+ Check "pre-release" if this is a beta/RC.
97
+
98
+ - CLI method: with ``gh`` installed, run ``gh release create vX.Y.Z -t "Version X.Y.Z"``
99
+ If this is a pre-release, add ``-p``.
100
+
101
+ - Get back to work
102
+
103
+ - Make sure you are on master, not somewhere else: ``git checkout master``
104
+
105
+ - Update version macros in ``include/pybind11/detail/common.h`` (set PATCH to
106
+ ``0.dev1`` and increment MINOR).
107
+
108
+ - Update ``pybind11/_version.py`` to match.
109
+
110
+ - Run ``nox -s tests_packaging`` to ensure this was done correctly.
111
+
112
+ - If the release was a new MINOR version, add a new ``IN DEVELOPMENT``
113
+ section in ``docs/changelog.rst``.
114
+
115
+ - ``git add``, ``git commit``, ``git push``
116
+
117
+ If a version branch is updated, remember to set PATCH to ``1.dev1``.
118
+
119
+ If you'd like to bump homebrew, run:
120
+
121
+ .. code-block:: console
122
+
123
+ brew bump-formula-pr --url https://github.com/pybind/pybind11/archive/vX.Y.Z.tar.gz
124
+
125
+ Conda-forge should automatically make a PR in a few hours, and automatically
126
+ merge it if there are no issues.
127
+
128
+
129
+ Manual packaging
130
+ ^^^^^^^^^^^^^^^^
131
+
132
+ If you need to manually upload releases, you can download the releases from
133
+ the job artifacts and upload them with twine. You can also make the files
134
+ locally (not recommended in general, as your local directory is more likely
135
+ to be "dirty" and SDists love picking up random unrelated/hidden files);
136
+ this is the procedure:
137
+
138
+ .. code-block:: bash
139
+
140
+ nox -s build
141
+ twine upload dist/*
142
+
143
+ This makes SDists and wheels, and the final line uploads them.
third_party/CityFlow/extern/pybind11/docs/requirements.txt CHANGED
@@ -1,6 +1,6 @@
1
- breathe==4.34.0
2
- furo==2022.6.21
3
- sphinx==5.0.2
4
- sphinx-copybutton==0.5.0
5
- sphinxcontrib-moderncmakedomain==3.21.4
6
- sphinxcontrib-svg2pdfconverter==1.2.0
 
1
+ breathe==4.34.0
2
+ furo==2022.6.21
3
+ sphinx==5.0.2
4
+ sphinx-copybutton==0.5.0
5
+ sphinxcontrib-moderncmakedomain==3.21.4
6
+ sphinxcontrib-svg2pdfconverter==1.2.0
third_party/CityFlow/extern/pybind11/docs/upgrade.rst CHANGED
@@ -1,594 +1,594 @@
1
- Upgrade guide
2
- #############
3
-
4
- This is a companion guide to the :doc:`changelog`. While the changelog briefly
5
- lists all of the new features, improvements and bug fixes, this upgrade guide
6
- focuses only the subset which directly impacts your experience when upgrading
7
- to a new version. But it goes into more detail. This includes things like
8
- deprecated APIs and their replacements, build system changes, general code
9
- modernization and other useful information.
10
-
11
- .. _upgrade-guide-2.12:
12
-
13
- v2.12
14
- =====
15
-
16
- NumPy support has been upgraded to support the 2.x series too. The two relevant
17
- changes are that:
18
-
19
- * ``dtype.flags()`` is now a ``uint64`` and ``dtype.alignment()`` an
20
- ``ssize_t`` (and NumPy may return an larger than integer value for
21
- ``itemsize()`` in NumPy 2.x).
22
-
23
- * The long deprecated NumPy function ``PyArray_GetArrayParamsFromObject``
24
- function is not available anymore.
25
-
26
- Due to NumPy changes, you may experience difficulties updating to NumPy 2.
27
- Please see the [NumPy 2 migration guide](https://numpy.org/devdocs/numpy_2_0_migration_guide.html) for details.
28
- For example, a more direct change could be that the default integer ``"int_"``
29
- (and ``"uint"``) is now ``ssize_t`` and not ``long`` (affects 64bit windows).
30
-
31
- If you want to only support NumPy 1.x for now and are having problems due to
32
- the two internal changes listed above, you can define
33
- ``PYBIND11_NUMPY_1_ONLY`` to disable the new support for now. Make sure you
34
- define this on all pybind11 compile units, since it could be a source of ODR
35
- violations if used inconsistently. This option will be removed in the future,
36
- so adapting your code is highly recommended.
37
-
38
-
39
- .. _upgrade-guide-2.11:
40
-
41
- v2.11
42
- =====
43
-
44
- * The minimum version of CMake is now 3.5. A future version will likely move to
45
- requiring something like CMake 3.15. Note that CMake 3.27 is removing the
46
- long-deprecated support for ``FindPythonInterp`` if you set 3.27 as the
47
- minimum or maximum supported version. To prepare for that future, CMake 3.15+
48
- using ``FindPython`` or setting ``PYBIND11_FINDPYTHON`` is highly recommended,
49
- otherwise pybind11 will automatically switch to using ``FindPython`` if
50
- ``FindPythonInterp`` is not available.
51
-
52
-
53
- .. _upgrade-guide-2.9:
54
-
55
- v2.9
56
- ====
57
-
58
- * Any usage of the recently added ``py::make_simple_namespace`` should be
59
- converted to using ``py::module_::import("types").attr("SimpleNamespace")``
60
- instead.
61
-
62
- * The use of ``_`` in custom type casters can now be replaced with the more
63
- readable ``const_name`` instead. The old ``_`` shortcut has been retained
64
- unless it is being used as a macro (like for gettext).
65
-
66
-
67
- .. _upgrade-guide-2.7:
68
-
69
- v2.7
70
- ====
71
-
72
- *Before* v2.7, ``py::str`` can hold ``PyUnicodeObject`` or ``PyBytesObject``,
73
- and ``py::isinstance<str>()`` is ``true`` for both ``py::str`` and
74
- ``py::bytes``. Starting with v2.7, ``py::str`` exclusively holds
75
- ``PyUnicodeObject`` (`#2409 <https://github.com/pybind/pybind11/pull/2409>`_),
76
- and ``py::isinstance<str>()`` is ``true`` only for ``py::str``. To help in
77
- the transition of user code, the ``PYBIND11_STR_LEGACY_PERMISSIVE`` macro
78
- is provided as an escape hatch to go back to the legacy behavior. This macro
79
- will be removed in future releases. Two types of required fixes are expected
80
- to be common:
81
-
82
- * Accidental use of ``py::str`` instead of ``py::bytes``, masked by the legacy
83
- behavior. These are probably very easy to fix, by changing from
84
- ``py::str`` to ``py::bytes``.
85
-
86
- * Reliance on py::isinstance<str>(obj) being ``true`` for
87
- ``py::bytes``. This is likely to be easy to fix in most cases by adding
88
- ``|| py::isinstance<bytes>(obj)``, but a fix may be more involved, e.g. if
89
- ``py::isinstance<T>`` appears in a template. Such situations will require
90
- careful review and custom fixes.
91
-
92
-
93
- .. _upgrade-guide-2.6:
94
-
95
- v2.6
96
- ====
97
-
98
- Usage of the ``PYBIND11_OVERLOAD*`` macros and ``get_overload`` function should
99
- be replaced by ``PYBIND11_OVERRIDE*`` and ``get_override``. In the future, the
100
- old macros may be deprecated and removed.
101
-
102
- ``py::module`` has been renamed ``py::module_``, but a backward compatible
103
- typedef has been included. This change was to avoid a language change in C++20
104
- that requires unqualified ``module`` not be placed at the start of a logical
105
- line. Qualified usage is unaffected and the typedef will remain unless the
106
- C++ language rules change again.
107
-
108
- The public constructors of ``py::module_`` have been deprecated. Use
109
- ``PYBIND11_MODULE`` or ``module_::create_extension_module`` instead.
110
-
111
- An error is now thrown when ``__init__`` is forgotten on subclasses. This was
112
- incorrect before, but was not checked. Add a call to ``__init__`` if it is
113
- missing.
114
-
115
- A ``py::type_error`` is now thrown when casting to a subclass (like
116
- ``py::bytes`` from ``py::object``) if the conversion is not valid. Make a valid
117
- conversion instead.
118
-
119
- The undocumented ``h.get_type()`` method has been deprecated and replaced by
120
- ``py::type::of(h)``.
121
-
122
- Enums now have a ``__str__`` method pre-defined; if you want to override it,
123
- the simplest fix is to add the new ``py::prepend()`` tag when defining
124
- ``"__str__"``.
125
-
126
- If ``__eq__`` defined but not ``__hash__``, ``__hash__`` is now set to
127
- ``None``, as in normal CPython. You should add ``__hash__`` if you intended the
128
- class to be hashable, possibly using the new ``py::hash`` shortcut.
129
-
130
- The constructors for ``py::array`` now always take signed integers for size,
131
- for consistency. This may lead to compiler warnings on some systems. Cast to
132
- ``py::ssize_t`` instead of ``std::size_t``.
133
-
134
- The ``tools/clang`` submodule and ``tools/mkdoc.py`` have been moved to a
135
- standalone package, `pybind11-mkdoc`_. If you were using those tools, please
136
- use them via a pip install from the new location.
137
-
138
- The ``pybind11`` package on PyPI no longer fills the wheel "headers" slot - if
139
- you were using the headers from this slot, they are available by requesting the
140
- ``global`` extra, that is, ``pip install "pybind11[global]"``. (Most users will
141
- be unaffected, as the ``pybind11/include`` location is reported by ``python -m
142
- pybind11 --includes`` and ``pybind11.get_include()`` is still correct and has
143
- not changed since 2.5).
144
-
145
- .. _pybind11-mkdoc: https://github.com/pybind/pybind11-mkdoc
146
-
147
- CMake support:
148
- --------------
149
-
150
- The minimum required version of CMake is now 3.4. Several details of the CMake
151
- support have been deprecated; warnings will be shown if you need to change
152
- something. The changes are:
153
-
154
- * ``PYBIND11_CPP_STANDARD=<platform-flag>`` is deprecated, please use
155
- ``CMAKE_CXX_STANDARD=<number>`` instead, or any other valid CMake CXX or CUDA
156
- standard selection method, like ``target_compile_features``.
157
-
158
- * If you do not request a standard, pybind11 targets will compile with the
159
- compiler default, but not less than C++11, instead of forcing C++14 always.
160
- If you depend on the old behavior, please use ``set(CMAKE_CXX_STANDARD 14 CACHE STRING "")``
161
- instead.
162
-
163
- * Direct ``pybind11::module`` usage should always be accompanied by at least
164
- ``set(CMAKE_CXX_VISIBILITY_PRESET hidden)`` or similar - it used to try to
165
- manually force this compiler flag (but not correctly on all compilers or with
166
- CUDA).
167
-
168
- * ``pybind11_add_module``'s ``SYSTEM`` argument is deprecated and does nothing;
169
- linking now behaves like other imported libraries consistently in both
170
- config and submodule mode, and behaves like a ``SYSTEM`` library by
171
- default.
172
-
173
- * If ``PYTHON_EXECUTABLE`` is not set, virtual environments (``venv``,
174
- ``virtualenv``, and ``conda``) are prioritized over the standard search
175
- (similar to the new FindPython mode).
176
-
177
- In addition, the following changes may be of interest:
178
-
179
- * ``CMAKE_INTERPROCEDURAL_OPTIMIZATION`` will be respected by
180
- ``pybind11_add_module`` if set instead of linking to ``pybind11::lto`` or
181
- ``pybind11::thin_lto``.
182
-
183
- * Using ``find_package(Python COMPONENTS Interpreter Development)`` before
184
- pybind11 will cause pybind11 to use the new Python mechanisms instead of its
185
- own custom search, based on a patched version of classic ``FindPythonInterp``
186
- / ``FindPythonLibs``. In the future, this may become the default. A recent
187
- (3.15+ or 3.18.2+) version of CMake is recommended.
188
-
189
-
190
-
191
- v2.5
192
- ====
193
-
194
- The Python package now includes the headers as data in the package itself, as
195
- well as in the "headers" wheel slot. ``pybind11 --includes`` and
196
- ``pybind11.get_include()`` report the new location, which is always correct
197
- regardless of how pybind11 was installed, making the old ``user=`` argument
198
- meaningless. If you are not using the function to get the location already, you
199
- are encouraged to switch to the package location.
200
-
201
-
202
- v2.2
203
- ====
204
-
205
- Deprecation of the ``PYBIND11_PLUGIN`` macro
206
- --------------------------------------------
207
-
208
- ``PYBIND11_MODULE`` is now the preferred way to create module entry points.
209
- The old macro emits a compile-time deprecation warning.
210
-
211
- .. code-block:: cpp
212
-
213
- // old
214
- PYBIND11_PLUGIN(example) {
215
- py::module m("example", "documentation string");
216
-
217
- m.def("add", [](int a, int b) { return a + b; });
218
-
219
- return m.ptr();
220
- }
221
-
222
- // new
223
- PYBIND11_MODULE(example, m) {
224
- m.doc() = "documentation string"; // optional
225
-
226
- m.def("add", [](int a, int b) { return a + b; });
227
- }
228
-
229
-
230
- New API for defining custom constructors and pickling functions
231
- ---------------------------------------------------------------
232
-
233
- The old placement-new custom constructors have been deprecated. The new approach
234
- uses ``py::init()`` and factory functions to greatly improve type safety.
235
-
236
- Placement-new can be called accidentally with an incompatible type (without any
237
- compiler errors or warnings), or it can initialize the same object multiple times
238
- if not careful with the Python-side ``__init__`` calls. The new-style custom
239
- constructors prevent such mistakes. See :ref:`custom_constructors` for details.
240
-
241
- .. code-block:: cpp
242
-
243
- // old -- deprecated (runtime warning shown only in debug mode)
244
- py::class<Foo>(m, "Foo")
245
- .def("__init__", [](Foo &self, ...) {
246
- new (&self) Foo(...); // uses placement-new
247
- });
248
-
249
- // new
250
- py::class<Foo>(m, "Foo")
251
- .def(py::init([](...) { // Note: no `self` argument
252
- return new Foo(...); // return by raw pointer
253
- // or: return std::make_unique<Foo>(...); // return by holder
254
- // or: return Foo(...); // return by value (move constructor)
255
- }));
256
-
257
- Mirroring the custom constructor changes, ``py::pickle()`` is now the preferred
258
- way to get and set object state. See :ref:`pickling` for details.
259
-
260
- .. code-block:: cpp
261
-
262
- // old -- deprecated (runtime warning shown only in debug mode)
263
- py::class<Foo>(m, "Foo")
264
- ...
265
- .def("__getstate__", [](const Foo &self) {
266
- return py::make_tuple(self.value1(), self.value2(), ...);
267
- })
268
- .def("__setstate__", [](Foo &self, py::tuple t) {
269
- new (&self) Foo(t[0].cast<std::string>(), ...);
270
- });
271
-
272
- // new
273
- py::class<Foo>(m, "Foo")
274
- ...
275
- .def(py::pickle(
276
- [](const Foo &self) { // __getstate__
277
- return py::make_tuple(self.value1(), self.value2(), ...); // unchanged
278
- },
279
- [](py::tuple t) { // __setstate__, note: no `self` argument
280
- return new Foo(t[0].cast<std::string>(), ...);
281
- // or: return std::make_unique<Foo>(...); // return by holder
282
- // or: return Foo(...); // return by value (move constructor)
283
- }
284
- ));
285
-
286
- For both the constructors and pickling, warnings are shown at module
287
- initialization time (on import, not when the functions are called).
288
- They're only visible when compiled in debug mode. Sample warning:
289
-
290
- .. code-block:: none
291
-
292
- pybind11-bound class 'mymodule.Foo' is using an old-style placement-new '__init__'
293
- which has been deprecated. See the upgrade guide in pybind11's docs.
294
-
295
-
296
- Stricter enforcement of hidden symbol visibility for pybind11 modules
297
- ---------------------------------------------------------------------
298
-
299
- pybind11 now tries to actively enforce hidden symbol visibility for modules.
300
- If you're using either one of pybind11's :doc:`CMake or Python build systems
301
- <compiling>` (the two example repositories) and you haven't been exporting any
302
- symbols, there's nothing to be concerned about. All the changes have been done
303
- transparently in the background. If you were building manually or relied on
304
- specific default visibility, read on.
305
-
306
- Setting default symbol visibility to *hidden* has always been recommended for
307
- pybind11 (see :ref:`faq:symhidden`). On Linux and macOS, hidden symbol
308
- visibility (in conjunction with the ``strip`` utility) yields much smaller
309
- module binaries. `CPython's extension docs`_ also recommend hiding symbols
310
- by default, with the goal of avoiding symbol name clashes between modules.
311
- Starting with v2.2, pybind11 enforces this more strictly: (1) by declaring
312
- all symbols inside the ``pybind11`` namespace as hidden and (2) by including
313
- the ``-fvisibility=hidden`` flag on Linux and macOS (only for extension
314
- modules, not for embedding the interpreter).
315
-
316
- .. _CPython's extension docs: https://docs.python.org/3/extending/extending.html#providing-a-c-api-for-an-extension-module
317
-
318
- The namespace-scope hidden visibility is done automatically in pybind11's
319
- headers and it's generally transparent to users. It ensures that:
320
-
321
- * Modules compiled with different pybind11 versions don't clash with each other.
322
-
323
- * Some new features, like ``py::module_local`` bindings, can work as intended.
324
-
325
- The ``-fvisibility=hidden`` flag applies the same visibility to user bindings
326
- outside of the ``pybind11`` namespace. It's now set automatic by pybind11's
327
- CMake and Python build systems, but this needs to be done manually by users
328
- of other build systems. Adding this flag:
329
-
330
- * Minimizes the chances of symbol conflicts between modules. E.g. if two
331
- unrelated modules were statically linked to different (ABI-incompatible)
332
- versions of the same third-party library, a symbol clash would be likely
333
- (and would end with unpredictable results).
334
-
335
- * Produces smaller binaries on Linux and macOS, as pointed out previously.
336
-
337
- Within pybind11's CMake build system, ``pybind11_add_module`` has always been
338
- setting the ``-fvisibility=hidden`` flag in release mode. From now on, it's
339
- being applied unconditionally, even in debug mode and it can no longer be opted
340
- out of with the ``NO_EXTRAS`` option. The ``pybind11::module`` target now also
341
- adds this flag to its interface. The ``pybind11::embed`` target is unchanged.
342
-
343
- The most significant change here is for the ``pybind11::module`` target. If you
344
- were previously relying on default visibility, i.e. if your Python module was
345
- doubling as a shared library with dependents, you'll need to either export
346
- symbols manually (recommended for cross-platform libraries) or factor out the
347
- shared library (and have the Python module link to it like the other
348
- dependents). As a temporary workaround, you can also restore default visibility
349
- using the CMake code below, but this is not recommended in the long run:
350
-
351
- .. code-block:: cmake
352
-
353
- target_link_libraries(mymodule PRIVATE pybind11::module)
354
-
355
- add_library(restore_default_visibility INTERFACE)
356
- target_compile_options(restore_default_visibility INTERFACE -fvisibility=default)
357
- target_link_libraries(mymodule PRIVATE restore_default_visibility)
358
-
359
-
360
- Local STL container bindings
361
- ----------------------------
362
-
363
- Previous pybind11 versions could only bind types globally -- all pybind11
364
- modules, even unrelated ones, would have access to the same exported types.
365
- However, this would also result in a conflict if two modules exported the
366
- same C++ type, which is especially problematic for very common types, e.g.
367
- ``std::vector<int>``. :ref:`module_local` were added to resolve this (see
368
- that section for a complete usage guide).
369
-
370
- ``py::class_`` still defaults to global bindings (because these types are
371
- usually unique across modules), however in order to avoid clashes of opaque
372
- types, ``py::bind_vector`` and ``py::bind_map`` will now bind STL containers
373
- as ``py::module_local`` if their elements are: builtins (``int``, ``float``,
374
- etc.), not bound using ``py::class_``, or bound as ``py::module_local``. For
375
- example, this change allows multiple modules to bind ``std::vector<int>``
376
- without causing conflicts. See :ref:`stl_bind` for more details.
377
-
378
- When upgrading to this version, if you have multiple modules which depend on
379
- a single global binding of an STL container, note that all modules can still
380
- accept foreign ``py::module_local`` types in the direction of Python-to-C++.
381
- The locality only affects the C++-to-Python direction. If this is needed in
382
- multiple modules, you'll need to either:
383
-
384
- * Add a copy of the same STL binding to all of the modules which need it.
385
-
386
- * Restore the global status of that single binding by marking it
387
- ``py::module_local(false)``.
388
-
389
- The latter is an easy workaround, but in the long run it would be best to
390
- localize all common type bindings in order to avoid conflicts with
391
- third-party modules.
392
-
393
-
394
- Negative strides for Python buffer objects and numpy arrays
395
- -----------------------------------------------------------
396
-
397
- Support for negative strides required changing the integer type from unsigned
398
- to signed in the interfaces of ``py::buffer_info`` and ``py::array``. If you
399
- have compiler warnings enabled, you may notice some new conversion warnings
400
- after upgrading. These can be resolved using ``static_cast``.
401
-
402
-
403
- Deprecation of some ``py::object`` APIs
404
- ---------------------------------------
405
-
406
- To compare ``py::object`` instances by pointer, you should now use
407
- ``obj1.is(obj2)`` which is equivalent to ``obj1 is obj2`` in Python.
408
- Previously, pybind11 used ``operator==`` for this (``obj1 == obj2``), but
409
- that could be confusing and is now deprecated (so that it can eventually
410
- be replaced with proper rich object comparison in a future release).
411
-
412
- For classes which inherit from ``py::object``, ``borrowed`` and ``stolen``
413
- were previously available as protected constructor tags. Now the types
414
- should be used directly instead: ``borrowed_t{}`` and ``stolen_t{}``
415
- (`#771 <https://github.com/pybind/pybind11/pull/771>`_).
416
-
417
-
418
- Stricter compile-time error checking
419
- ------------------------------------
420
-
421
- Some error checks have been moved from run time to compile time. Notably,
422
- automatic conversion of ``std::shared_ptr<T>`` is not possible when ``T`` is
423
- not directly registered with ``py::class_<T>`` (e.g. ``std::shared_ptr<int>``
424
- or ``std::shared_ptr<std::vector<T>>`` are not automatically convertible).
425
- Attempting to bind a function with such arguments now results in a compile-time
426
- error instead of waiting to fail at run time.
427
-
428
- ``py::init<...>()`` constructor definitions are also stricter and now prevent
429
- bindings which could cause unexpected behavior:
430
-
431
- .. code-block:: cpp
432
-
433
- struct Example {
434
- Example(int &);
435
- };
436
-
437
- py::class_<Example>(m, "Example")
438
- .def(py::init<int &>()); // OK, exact match
439
- // .def(py::init<int>()); // compile-time error, mismatch
440
-
441
- A non-``const`` lvalue reference is not allowed to bind to an rvalue. However,
442
- note that a constructor taking ``const T &`` can still be registered using
443
- ``py::init<T>()`` because a ``const`` lvalue reference can bind to an rvalue.
444
-
445
- v2.1
446
- ====
447
-
448
- Minimum compiler versions are enforced at compile time
449
- ------------------------------------------------------
450
-
451
- The minimums also apply to v2.0 but the check is now explicit and a compile-time
452
- error is raised if the compiler does not meet the requirements:
453
-
454
- * GCC >= 4.8
455
- * clang >= 3.3 (appleclang >= 5.0)
456
- * MSVC >= 2015u3
457
- * Intel C++ >= 15.0
458
-
459
-
460
- The ``py::metaclass`` attribute is not required for static properties
461
- ---------------------------------------------------------------------
462
-
463
- Binding classes with static properties is now possible by default. The
464
- zero-parameter version of ``py::metaclass()`` is deprecated. However, a new
465
- one-parameter ``py::metaclass(python_type)`` version was added for rare
466
- cases when a custom metaclass is needed to override pybind11's default.
467
-
468
- .. code-block:: cpp
469
-
470
- // old -- emits a deprecation warning
471
- py::class_<Foo>(m, "Foo", py::metaclass())
472
- .def_property_readonly_static("foo", ...);
473
-
474
- // new -- static properties work without the attribute
475
- py::class_<Foo>(m, "Foo")
476
- .def_property_readonly_static("foo", ...);
477
-
478
- // new -- advanced feature, override pybind11's default metaclass
479
- py::class_<Bar>(m, "Bar", py::metaclass(custom_python_type))
480
- ...
481
-
482
-
483
- v2.0
484
- ====
485
-
486
- Breaking changes in ``py::class_``
487
- ----------------------------------
488
-
489
- These changes were necessary to make type definitions in pybind11
490
- future-proof, to support PyPy via its ``cpyext`` mechanism (`#527
491
- <https://github.com/pybind/pybind11/pull/527>`_), and to improve efficiency
492
- (`rev. 86d825 <https://github.com/pybind/pybind11/commit/86d825>`_).
493
-
494
- 1. Declarations of types that provide access via the buffer protocol must
495
- now include the ``py::buffer_protocol()`` annotation as an argument to
496
- the ``py::class_`` constructor.
497
-
498
- .. code-block:: cpp
499
-
500
- py::class_<Matrix>("Matrix", py::buffer_protocol())
501
- .def(py::init<...>())
502
- .def_buffer(...);
503
-
504
- 2. Classes which include static properties (e.g. ``def_readwrite_static()``)
505
- must now include the ``py::metaclass()`` attribute. Note: this requirement
506
- has since been removed in v2.1. If you're upgrading from 1.x, it's
507
- recommended to skip directly to v2.1 or newer.
508
-
509
- 3. This version of pybind11 uses a redesigned mechanism for instantiating
510
- trampoline classes that are used to override virtual methods from within
511
- Python. This led to the following user-visible syntax change:
512
-
513
- .. code-block:: cpp
514
-
515
- // old v1.x syntax
516
- py::class_<TrampolineClass>("MyClass")
517
- .alias<MyClass>()
518
- ...
519
-
520
- // new v2.x syntax
521
- py::class_<MyClass, TrampolineClass>("MyClass")
522
- ...
523
-
524
- Importantly, both the original and the trampoline class are now specified
525
- as arguments to the ``py::class_`` template, and the ``alias<..>()`` call
526
- is gone. The new scheme has zero overhead in cases when Python doesn't
527
- override any functions of the underlying C++ class.
528
- `rev. 86d825 <https://github.com/pybind/pybind11/commit/86d825>`_.
529
-
530
- The class type must be the first template argument given to ``py::class_``
531
- while the trampoline can be mixed in arbitrary order with other arguments
532
- (see the following section).
533
-
534
-
535
- Deprecation of the ``py::base<T>()`` attribute
536
- ----------------------------------------------
537
-
538
- ``py::base<T>()`` was deprecated in favor of specifying ``T`` as a template
539
- argument to ``py::class_``. This new syntax also supports multiple inheritance.
540
- Note that, while the type being exported must be the first argument in the
541
- ``py::class_<Class, ...>`` template, the order of the following types (bases,
542
- holder and/or trampoline) is not important.
543
-
544
- .. code-block:: cpp
545
-
546
- // old v1.x
547
- py::class_<Derived>("Derived", py::base<Base>());
548
-
549
- // new v2.x
550
- py::class_<Derived, Base>("Derived");
551
-
552
- // new -- multiple inheritance
553
- py::class_<Derived, Base1, Base2>("Derived");
554
-
555
- // new -- apart from `Derived` the argument order can be arbitrary
556
- py::class_<Derived, Base1, Holder, Base2, Trampoline>("Derived");
557
-
558
-
559
- Out-of-the-box support for ``std::shared_ptr``
560
- ----------------------------------------------
561
-
562
- The relevant type caster is now built in, so it's no longer necessary to
563
- include a declaration of the form:
564
-
565
- .. code-block:: cpp
566
-
567
- PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>)
568
-
569
- Continuing to do so won't cause an error or even a deprecation warning,
570
- but it's completely redundant.
571
-
572
-
573
- Deprecation of a few ``py::object`` APIs
574
- ----------------------------------------
575
-
576
- All of the old-style calls emit deprecation warnings.
577
-
578
- +---------------------------------------+---------------------------------------------+
579
- | Old syntax | New syntax |
580
- +=======================================+=============================================+
581
- | ``obj.call(args...)`` | ``obj(args...)`` |
582
- +---------------------------------------+---------------------------------------------+
583
- | ``obj.str()`` | ``py::str(obj)`` |
584
- +---------------------------------------+---------------------------------------------+
585
- | ``auto l = py::list(obj); l.check()`` | ``py::isinstance<py::list>(obj)`` |
586
- +---------------------------------------+---------------------------------------------+
587
- | ``py::object(ptr, true)`` | ``py::reinterpret_borrow<py::object>(ptr)`` |
588
- +---------------------------------------+---------------------------------------------+
589
- | ``py::object(ptr, false)`` | ``py::reinterpret_steal<py::object>(ptr)`` |
590
- +---------------------------------------+---------------------------------------------+
591
- | ``if (obj.attr("foo"))`` | ``if (py::hasattr(obj, "foo"))`` |
592
- +---------------------------------------+---------------------------------------------+
593
- | ``if (obj["bar"])`` | ``if (obj.contains("bar"))`` |
594
- +---------------------------------------+---------------------------------------------+
 
1
+ Upgrade guide
2
+ #############
3
+
4
+ This is a companion guide to the :doc:`changelog`. While the changelog briefly
5
+ lists all of the new features, improvements and bug fixes, this upgrade guide
6
+ focuses only the subset which directly impacts your experience when upgrading
7
+ to a new version. But it goes into more detail. This includes things like
8
+ deprecated APIs and their replacements, build system changes, general code
9
+ modernization and other useful information.
10
+
11
+ .. _upgrade-guide-2.12:
12
+
13
+ v2.12
14
+ =====
15
+
16
+ NumPy support has been upgraded to support the 2.x series too. The two relevant
17
+ changes are that:
18
+
19
+ * ``dtype.flags()`` is now a ``uint64`` and ``dtype.alignment()`` an
20
+ ``ssize_t`` (and NumPy may return an larger than integer value for
21
+ ``itemsize()`` in NumPy 2.x).
22
+
23
+ * The long deprecated NumPy function ``PyArray_GetArrayParamsFromObject``
24
+ function is not available anymore.
25
+
26
+ Due to NumPy changes, you may experience difficulties updating to NumPy 2.
27
+ Please see the [NumPy 2 migration guide](https://numpy.org/devdocs/numpy_2_0_migration_guide.html) for details.
28
+ For example, a more direct change could be that the default integer ``"int_"``
29
+ (and ``"uint"``) is now ``ssize_t`` and not ``long`` (affects 64bit windows).
30
+
31
+ If you want to only support NumPy 1.x for now and are having problems due to
32
+ the two internal changes listed above, you can define
33
+ ``PYBIND11_NUMPY_1_ONLY`` to disable the new support for now. Make sure you
34
+ define this on all pybind11 compile units, since it could be a source of ODR
35
+ violations if used inconsistently. This option will be removed in the future,
36
+ so adapting your code is highly recommended.
37
+
38
+
39
+ .. _upgrade-guide-2.11:
40
+
41
+ v2.11
42
+ =====
43
+
44
+ * The minimum version of CMake is now 3.5. A future version will likely move to
45
+ requiring something like CMake 3.15. Note that CMake 3.27 is removing the
46
+ long-deprecated support for ``FindPythonInterp`` if you set 3.27 as the
47
+ minimum or maximum supported version. To prepare for that future, CMake 3.15+
48
+ using ``FindPython`` or setting ``PYBIND11_FINDPYTHON`` is highly recommended,
49
+ otherwise pybind11 will automatically switch to using ``FindPython`` if
50
+ ``FindPythonInterp`` is not available.
51
+
52
+
53
+ .. _upgrade-guide-2.9:
54
+
55
+ v2.9
56
+ ====
57
+
58
+ * Any usage of the recently added ``py::make_simple_namespace`` should be
59
+ converted to using ``py::module_::import("types").attr("SimpleNamespace")``
60
+ instead.
61
+
62
+ * The use of ``_`` in custom type casters can now be replaced with the more
63
+ readable ``const_name`` instead. The old ``_`` shortcut has been retained
64
+ unless it is being used as a macro (like for gettext).
65
+
66
+
67
+ .. _upgrade-guide-2.7:
68
+
69
+ v2.7
70
+ ====
71
+
72
+ *Before* v2.7, ``py::str`` can hold ``PyUnicodeObject`` or ``PyBytesObject``,
73
+ and ``py::isinstance<str>()`` is ``true`` for both ``py::str`` and
74
+ ``py::bytes``. Starting with v2.7, ``py::str`` exclusively holds
75
+ ``PyUnicodeObject`` (`#2409 <https://github.com/pybind/pybind11/pull/2409>`_),
76
+ and ``py::isinstance<str>()`` is ``true`` only for ``py::str``. To help in
77
+ the transition of user code, the ``PYBIND11_STR_LEGACY_PERMISSIVE`` macro
78
+ is provided as an escape hatch to go back to the legacy behavior. This macro
79
+ will be removed in future releases. Two types of required fixes are expected
80
+ to be common:
81
+
82
+ * Accidental use of ``py::str`` instead of ``py::bytes``, masked by the legacy
83
+ behavior. These are probably very easy to fix, by changing from
84
+ ``py::str`` to ``py::bytes``.
85
+
86
+ * Reliance on py::isinstance<str>(obj) being ``true`` for
87
+ ``py::bytes``. This is likely to be easy to fix in most cases by adding
88
+ ``|| py::isinstance<bytes>(obj)``, but a fix may be more involved, e.g. if
89
+ ``py::isinstance<T>`` appears in a template. Such situations will require
90
+ careful review and custom fixes.
91
+
92
+
93
+ .. _upgrade-guide-2.6:
94
+
95
+ v2.6
96
+ ====
97
+
98
+ Usage of the ``PYBIND11_OVERLOAD*`` macros and ``get_overload`` function should
99
+ be replaced by ``PYBIND11_OVERRIDE*`` and ``get_override``. In the future, the
100
+ old macros may be deprecated and removed.
101
+
102
+ ``py::module`` has been renamed ``py::module_``, but a backward compatible
103
+ typedef has been included. This change was to avoid a language change in C++20
104
+ that requires unqualified ``module`` not be placed at the start of a logical
105
+ line. Qualified usage is unaffected and the typedef will remain unless the
106
+ C++ language rules change again.
107
+
108
+ The public constructors of ``py::module_`` have been deprecated. Use
109
+ ``PYBIND11_MODULE`` or ``module_::create_extension_module`` instead.
110
+
111
+ An error is now thrown when ``__init__`` is forgotten on subclasses. This was
112
+ incorrect before, but was not checked. Add a call to ``__init__`` if it is
113
+ missing.
114
+
115
+ A ``py::type_error`` is now thrown when casting to a subclass (like
116
+ ``py::bytes`` from ``py::object``) if the conversion is not valid. Make a valid
117
+ conversion instead.
118
+
119
+ The undocumented ``h.get_type()`` method has been deprecated and replaced by
120
+ ``py::type::of(h)``.
121
+
122
+ Enums now have a ``__str__`` method pre-defined; if you want to override it,
123
+ the simplest fix is to add the new ``py::prepend()`` tag when defining
124
+ ``"__str__"``.
125
+
126
+ If ``__eq__`` defined but not ``__hash__``, ``__hash__`` is now set to
127
+ ``None``, as in normal CPython. You should add ``__hash__`` if you intended the
128
+ class to be hashable, possibly using the new ``py::hash`` shortcut.
129
+
130
+ The constructors for ``py::array`` now always take signed integers for size,
131
+ for consistency. This may lead to compiler warnings on some systems. Cast to
132
+ ``py::ssize_t`` instead of ``std::size_t``.
133
+
134
+ The ``tools/clang`` submodule and ``tools/mkdoc.py`` have been moved to a
135
+ standalone package, `pybind11-mkdoc`_. If you were using those tools, please
136
+ use them via a pip install from the new location.
137
+
138
+ The ``pybind11`` package on PyPI no longer fills the wheel "headers" slot - if
139
+ you were using the headers from this slot, they are available by requesting the
140
+ ``global`` extra, that is, ``pip install "pybind11[global]"``. (Most users will
141
+ be unaffected, as the ``pybind11/include`` location is reported by ``python -m
142
+ pybind11 --includes`` and ``pybind11.get_include()`` is still correct and has
143
+ not changed since 2.5).
144
+
145
+ .. _pybind11-mkdoc: https://github.com/pybind/pybind11-mkdoc
146
+
147
+ CMake support:
148
+ --------------
149
+
150
+ The minimum required version of CMake is now 3.4. Several details of the CMake
151
+ support have been deprecated; warnings will be shown if you need to change
152
+ something. The changes are:
153
+
154
+ * ``PYBIND11_CPP_STANDARD=<platform-flag>`` is deprecated, please use
155
+ ``CMAKE_CXX_STANDARD=<number>`` instead, or any other valid CMake CXX or CUDA
156
+ standard selection method, like ``target_compile_features``.
157
+
158
+ * If you do not request a standard, pybind11 targets will compile with the
159
+ compiler default, but not less than C++11, instead of forcing C++14 always.
160
+ If you depend on the old behavior, please use ``set(CMAKE_CXX_STANDARD 14 CACHE STRING "")``
161
+ instead.
162
+
163
+ * Direct ``pybind11::module`` usage should always be accompanied by at least
164
+ ``set(CMAKE_CXX_VISIBILITY_PRESET hidden)`` or similar - it used to try to
165
+ manually force this compiler flag (but not correctly on all compilers or with
166
+ CUDA).
167
+
168
+ * ``pybind11_add_module``'s ``SYSTEM`` argument is deprecated and does nothing;
169
+ linking now behaves like other imported libraries consistently in both
170
+ config and submodule mode, and behaves like a ``SYSTEM`` library by
171
+ default.
172
+
173
+ * If ``PYTHON_EXECUTABLE`` is not set, virtual environments (``venv``,
174
+ ``virtualenv``, and ``conda``) are prioritized over the standard search
175
+ (similar to the new FindPython mode).
176
+
177
+ In addition, the following changes may be of interest:
178
+
179
+ * ``CMAKE_INTERPROCEDURAL_OPTIMIZATION`` will be respected by
180
+ ``pybind11_add_module`` if set instead of linking to ``pybind11::lto`` or
181
+ ``pybind11::thin_lto``.
182
+
183
+ * Using ``find_package(Python COMPONENTS Interpreter Development)`` before
184
+ pybind11 will cause pybind11 to use the new Python mechanisms instead of its
185
+ own custom search, based on a patched version of classic ``FindPythonInterp``
186
+ / ``FindPythonLibs``. In the future, this may become the default. A recent
187
+ (3.15+ or 3.18.2+) version of CMake is recommended.
188
+
189
+
190
+
191
+ v2.5
192
+ ====
193
+
194
+ The Python package now includes the headers as data in the package itself, as
195
+ well as in the "headers" wheel slot. ``pybind11 --includes`` and
196
+ ``pybind11.get_include()`` report the new location, which is always correct
197
+ regardless of how pybind11 was installed, making the old ``user=`` argument
198
+ meaningless. If you are not using the function to get the location already, you
199
+ are encouraged to switch to the package location.
200
+
201
+
202
+ v2.2
203
+ ====
204
+
205
+ Deprecation of the ``PYBIND11_PLUGIN`` macro
206
+ --------------------------------------------
207
+
208
+ ``PYBIND11_MODULE`` is now the preferred way to create module entry points.
209
+ The old macro emits a compile-time deprecation warning.
210
+
211
+ .. code-block:: cpp
212
+
213
+ // old
214
+ PYBIND11_PLUGIN(example) {
215
+ py::module m("example", "documentation string");
216
+
217
+ m.def("add", [](int a, int b) { return a + b; });
218
+
219
+ return m.ptr();
220
+ }
221
+
222
+ // new
223
+ PYBIND11_MODULE(example, m) {
224
+ m.doc() = "documentation string"; // optional
225
+
226
+ m.def("add", [](int a, int b) { return a + b; });
227
+ }
228
+
229
+
230
+ New API for defining custom constructors and pickling functions
231
+ ---------------------------------------------------------------
232
+
233
+ The old placement-new custom constructors have been deprecated. The new approach
234
+ uses ``py::init()`` and factory functions to greatly improve type safety.
235
+
236
+ Placement-new can be called accidentally with an incompatible type (without any
237
+ compiler errors or warnings), or it can initialize the same object multiple times
238
+ if not careful with the Python-side ``__init__`` calls. The new-style custom
239
+ constructors prevent such mistakes. See :ref:`custom_constructors` for details.
240
+
241
+ .. code-block:: cpp
242
+
243
+ // old -- deprecated (runtime warning shown only in debug mode)
244
+ py::class<Foo>(m, "Foo")
245
+ .def("__init__", [](Foo &self, ...) {
246
+ new (&self) Foo(...); // uses placement-new
247
+ });
248
+
249
+ // new
250
+ py::class<Foo>(m, "Foo")
251
+ .def(py::init([](...) { // Note: no `self` argument
252
+ return new Foo(...); // return by raw pointer
253
+ // or: return std::make_unique<Foo>(...); // return by holder
254
+ // or: return Foo(...); // return by value (move constructor)
255
+ }));
256
+
257
+ Mirroring the custom constructor changes, ``py::pickle()`` is now the preferred
258
+ way to get and set object state. See :ref:`pickling` for details.
259
+
260
+ .. code-block:: cpp
261
+
262
+ // old -- deprecated (runtime warning shown only in debug mode)
263
+ py::class<Foo>(m, "Foo")
264
+ ...
265
+ .def("__getstate__", [](const Foo &self) {
266
+ return py::make_tuple(self.value1(), self.value2(), ...);
267
+ })
268
+ .def("__setstate__", [](Foo &self, py::tuple t) {
269
+ new (&self) Foo(t[0].cast<std::string>(), ...);
270
+ });
271
+
272
+ // new
273
+ py::class<Foo>(m, "Foo")
274
+ ...
275
+ .def(py::pickle(
276
+ [](const Foo &self) { // __getstate__
277
+ return py::make_tuple(self.value1(), self.value2(), ...); // unchanged
278
+ },
279
+ [](py::tuple t) { // __setstate__, note: no `self` argument
280
+ return new Foo(t[0].cast<std::string>(), ...);
281
+ // or: return std::make_unique<Foo>(...); // return by holder
282
+ // or: return Foo(...); // return by value (move constructor)
283
+ }
284
+ ));
285
+
286
+ For both the constructors and pickling, warnings are shown at module
287
+ initialization time (on import, not when the functions are called).
288
+ They're only visible when compiled in debug mode. Sample warning:
289
+
290
+ .. code-block:: none
291
+
292
+ pybind11-bound class 'mymodule.Foo' is using an old-style placement-new '__init__'
293
+ which has been deprecated. See the upgrade guide in pybind11's docs.
294
+
295
+
296
+ Stricter enforcement of hidden symbol visibility for pybind11 modules
297
+ ---------------------------------------------------------------------
298
+
299
+ pybind11 now tries to actively enforce hidden symbol visibility for modules.
300
+ If you're using either one of pybind11's :doc:`CMake or Python build systems
301
+ <compiling>` (the two example repositories) and you haven't been exporting any
302
+ symbols, there's nothing to be concerned about. All the changes have been done
303
+ transparently in the background. If you were building manually or relied on
304
+ specific default visibility, read on.
305
+
306
+ Setting default symbol visibility to *hidden* has always been recommended for
307
+ pybind11 (see :ref:`faq:symhidden`). On Linux and macOS, hidden symbol
308
+ visibility (in conjunction with the ``strip`` utility) yields much smaller
309
+ module binaries. `CPython's extension docs`_ also recommend hiding symbols
310
+ by default, with the goal of avoiding symbol name clashes between modules.
311
+ Starting with v2.2, pybind11 enforces this more strictly: (1) by declaring
312
+ all symbols inside the ``pybind11`` namespace as hidden and (2) by including
313
+ the ``-fvisibility=hidden`` flag on Linux and macOS (only for extension
314
+ modules, not for embedding the interpreter).
315
+
316
+ .. _CPython's extension docs: https://docs.python.org/3/extending/extending.html#providing-a-c-api-for-an-extension-module
317
+
318
+ The namespace-scope hidden visibility is done automatically in pybind11's
319
+ headers and it's generally transparent to users. It ensures that:
320
+
321
+ * Modules compiled with different pybind11 versions don't clash with each other.
322
+
323
+ * Some new features, like ``py::module_local`` bindings, can work as intended.
324
+
325
+ The ``-fvisibility=hidden`` flag applies the same visibility to user bindings
326
+ outside of the ``pybind11`` namespace. It's now set automatic by pybind11's
327
+ CMake and Python build systems, but this needs to be done manually by users
328
+ of other build systems. Adding this flag:
329
+
330
+ * Minimizes the chances of symbol conflicts between modules. E.g. if two
331
+ unrelated modules were statically linked to different (ABI-incompatible)
332
+ versions of the same third-party library, a symbol clash would be likely
333
+ (and would end with unpredictable results).
334
+
335
+ * Produces smaller binaries on Linux and macOS, as pointed out previously.
336
+
337
+ Within pybind11's CMake build system, ``pybind11_add_module`` has always been
338
+ setting the ``-fvisibility=hidden`` flag in release mode. From now on, it's
339
+ being applied unconditionally, even in debug mode and it can no longer be opted
340
+ out of with the ``NO_EXTRAS`` option. The ``pybind11::module`` target now also
341
+ adds this flag to its interface. The ``pybind11::embed`` target is unchanged.
342
+
343
+ The most significant change here is for the ``pybind11::module`` target. If you
344
+ were previously relying on default visibility, i.e. if your Python module was
345
+ doubling as a shared library with dependents, you'll need to either export
346
+ symbols manually (recommended for cross-platform libraries) or factor out the
347
+ shared library (and have the Python module link to it like the other
348
+ dependents). As a temporary workaround, you can also restore default visibility
349
+ using the CMake code below, but this is not recommended in the long run:
350
+
351
+ .. code-block:: cmake
352
+
353
+ target_link_libraries(mymodule PRIVATE pybind11::module)
354
+
355
+ add_library(restore_default_visibility INTERFACE)
356
+ target_compile_options(restore_default_visibility INTERFACE -fvisibility=default)
357
+ target_link_libraries(mymodule PRIVATE restore_default_visibility)
358
+
359
+
360
+ Local STL container bindings
361
+ ----------------------------
362
+
363
+ Previous pybind11 versions could only bind types globally -- all pybind11
364
+ modules, even unrelated ones, would have access to the same exported types.
365
+ However, this would also result in a conflict if two modules exported the
366
+ same C++ type, which is especially problematic for very common types, e.g.
367
+ ``std::vector<int>``. :ref:`module_local` were added to resolve this (see
368
+ that section for a complete usage guide).
369
+
370
+ ``py::class_`` still defaults to global bindings (because these types are
371
+ usually unique across modules), however in order to avoid clashes of opaque
372
+ types, ``py::bind_vector`` and ``py::bind_map`` will now bind STL containers
373
+ as ``py::module_local`` if their elements are: builtins (``int``, ``float``,
374
+ etc.), not bound using ``py::class_``, or bound as ``py::module_local``. For
375
+ example, this change allows multiple modules to bind ``std::vector<int>``
376
+ without causing conflicts. See :ref:`stl_bind` for more details.
377
+
378
+ When upgrading to this version, if you have multiple modules which depend on
379
+ a single global binding of an STL container, note that all modules can still
380
+ accept foreign ``py::module_local`` types in the direction of Python-to-C++.
381
+ The locality only affects the C++-to-Python direction. If this is needed in
382
+ multiple modules, you'll need to either:
383
+
384
+ * Add a copy of the same STL binding to all of the modules which need it.
385
+
386
+ * Restore the global status of that single binding by marking it
387
+ ``py::module_local(false)``.
388
+
389
+ The latter is an easy workaround, but in the long run it would be best to
390
+ localize all common type bindings in order to avoid conflicts with
391
+ third-party modules.
392
+
393
+
394
+ Negative strides for Python buffer objects and numpy arrays
395
+ -----------------------------------------------------------
396
+
397
+ Support for negative strides required changing the integer type from unsigned
398
+ to signed in the interfaces of ``py::buffer_info`` and ``py::array``. If you
399
+ have compiler warnings enabled, you may notice some new conversion warnings
400
+ after upgrading. These can be resolved using ``static_cast``.
401
+
402
+
403
+ Deprecation of some ``py::object`` APIs
404
+ ---------------------------------------
405
+
406
+ To compare ``py::object`` instances by pointer, you should now use
407
+ ``obj1.is(obj2)`` which is equivalent to ``obj1 is obj2`` in Python.
408
+ Previously, pybind11 used ``operator==`` for this (``obj1 == obj2``), but
409
+ that could be confusing and is now deprecated (so that it can eventually
410
+ be replaced with proper rich object comparison in a future release).
411
+
412
+ For classes which inherit from ``py::object``, ``borrowed`` and ``stolen``
413
+ were previously available as protected constructor tags. Now the types
414
+ should be used directly instead: ``borrowed_t{}`` and ``stolen_t{}``
415
+ (`#771 <https://github.com/pybind/pybind11/pull/771>`_).
416
+
417
+
418
+ Stricter compile-time error checking
419
+ ------------------------------------
420
+
421
+ Some error checks have been moved from run time to compile time. Notably,
422
+ automatic conversion of ``std::shared_ptr<T>`` is not possible when ``T`` is
423
+ not directly registered with ``py::class_<T>`` (e.g. ``std::shared_ptr<int>``
424
+ or ``std::shared_ptr<std::vector<T>>`` are not automatically convertible).
425
+ Attempting to bind a function with such arguments now results in a compile-time
426
+ error instead of waiting to fail at run time.
427
+
428
+ ``py::init<...>()`` constructor definitions are also stricter and now prevent
429
+ bindings which could cause unexpected behavior:
430
+
431
+ .. code-block:: cpp
432
+
433
+ struct Example {
434
+ Example(int &);
435
+ };
436
+
437
+ py::class_<Example>(m, "Example")
438
+ .def(py::init<int &>()); // OK, exact match
439
+ // .def(py::init<int>()); // compile-time error, mismatch
440
+
441
+ A non-``const`` lvalue reference is not allowed to bind to an rvalue. However,
442
+ note that a constructor taking ``const T &`` can still be registered using
443
+ ``py::init<T>()`` because a ``const`` lvalue reference can bind to an rvalue.
444
+
445
+ v2.1
446
+ ====
447
+
448
+ Minimum compiler versions are enforced at compile time
449
+ ------------------------------------------------------
450
+
451
+ The minimums also apply to v2.0 but the check is now explicit and a compile-time
452
+ error is raised if the compiler does not meet the requirements:
453
+
454
+ * GCC >= 4.8
455
+ * clang >= 3.3 (appleclang >= 5.0)
456
+ * MSVC >= 2015u3
457
+ * Intel C++ >= 15.0
458
+
459
+
460
+ The ``py::metaclass`` attribute is not required for static properties
461
+ ---------------------------------------------------------------------
462
+
463
+ Binding classes with static properties is now possible by default. The
464
+ zero-parameter version of ``py::metaclass()`` is deprecated. However, a new
465
+ one-parameter ``py::metaclass(python_type)`` version was added for rare
466
+ cases when a custom metaclass is needed to override pybind11's default.
467
+
468
+ .. code-block:: cpp
469
+
470
+ // old -- emits a deprecation warning
471
+ py::class_<Foo>(m, "Foo", py::metaclass())
472
+ .def_property_readonly_static("foo", ...);
473
+
474
+ // new -- static properties work without the attribute
475
+ py::class_<Foo>(m, "Foo")
476
+ .def_property_readonly_static("foo", ...);
477
+
478
+ // new -- advanced feature, override pybind11's default metaclass
479
+ py::class_<Bar>(m, "Bar", py::metaclass(custom_python_type))
480
+ ...
481
+
482
+
483
+ v2.0
484
+ ====
485
+
486
+ Breaking changes in ``py::class_``
487
+ ----------------------------------
488
+
489
+ These changes were necessary to make type definitions in pybind11
490
+ future-proof, to support PyPy via its ``cpyext`` mechanism (`#527
491
+ <https://github.com/pybind/pybind11/pull/527>`_), and to improve efficiency
492
+ (`rev. 86d825 <https://github.com/pybind/pybind11/commit/86d825>`_).
493
+
494
+ 1. Declarations of types that provide access via the buffer protocol must
495
+ now include the ``py::buffer_protocol()`` annotation as an argument to
496
+ the ``py::class_`` constructor.
497
+
498
+ .. code-block:: cpp
499
+
500
+ py::class_<Matrix>("Matrix", py::buffer_protocol())
501
+ .def(py::init<...>())
502
+ .def_buffer(...);
503
+
504
+ 2. Classes which include static properties (e.g. ``def_readwrite_static()``)
505
+ must now include the ``py::metaclass()`` attribute. Note: this requirement
506
+ has since been removed in v2.1. If you're upgrading from 1.x, it's
507
+ recommended to skip directly to v2.1 or newer.
508
+
509
+ 3. This version of pybind11 uses a redesigned mechanism for instantiating
510
+ trampoline classes that are used to override virtual methods from within
511
+ Python. This led to the following user-visible syntax change:
512
+
513
+ .. code-block:: cpp
514
+
515
+ // old v1.x syntax
516
+ py::class_<TrampolineClass>("MyClass")
517
+ .alias<MyClass>()
518
+ ...
519
+
520
+ // new v2.x syntax
521
+ py::class_<MyClass, TrampolineClass>("MyClass")
522
+ ...
523
+
524
+ Importantly, both the original and the trampoline class are now specified
525
+ as arguments to the ``py::class_`` template, and the ``alias<..>()`` call
526
+ is gone. The new scheme has zero overhead in cases when Python doesn't
527
+ override any functions of the underlying C++ class.
528
+ `rev. 86d825 <https://github.com/pybind/pybind11/commit/86d825>`_.
529
+
530
+ The class type must be the first template argument given to ``py::class_``
531
+ while the trampoline can be mixed in arbitrary order with other arguments
532
+ (see the following section).
533
+
534
+
535
+ Deprecation of the ``py::base<T>()`` attribute
536
+ ----------------------------------------------
537
+
538
+ ``py::base<T>()`` was deprecated in favor of specifying ``T`` as a template
539
+ argument to ``py::class_``. This new syntax also supports multiple inheritance.
540
+ Note that, while the type being exported must be the first argument in the
541
+ ``py::class_<Class, ...>`` template, the order of the following types (bases,
542
+ holder and/or trampoline) is not important.
543
+
544
+ .. code-block:: cpp
545
+
546
+ // old v1.x
547
+ py::class_<Derived>("Derived", py::base<Base>());
548
+
549
+ // new v2.x
550
+ py::class_<Derived, Base>("Derived");
551
+
552
+ // new -- multiple inheritance
553
+ py::class_<Derived, Base1, Base2>("Derived");
554
+
555
+ // new -- apart from `Derived` the argument order can be arbitrary
556
+ py::class_<Derived, Base1, Holder, Base2, Trampoline>("Derived");
557
+
558
+
559
+ Out-of-the-box support for ``std::shared_ptr``
560
+ ----------------------------------------------
561
+
562
+ The relevant type caster is now built in, so it's no longer necessary to
563
+ include a declaration of the form:
564
+
565
+ .. code-block:: cpp
566
+
567
+ PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>)
568
+
569
+ Continuing to do so won't cause an error or even a deprecation warning,
570
+ but it's completely redundant.
571
+
572
+
573
+ Deprecation of a few ``py::object`` APIs
574
+ ----------------------------------------
575
+
576
+ All of the old-style calls emit deprecation warnings.
577
+
578
+ +---------------------------------------+---------------------------------------------+
579
+ | Old syntax | New syntax |
580
+ +=======================================+=============================================+
581
+ | ``obj.call(args...)`` | ``obj(args...)`` |
582
+ +---------------------------------------+---------------------------------------------+
583
+ | ``obj.str()`` | ``py::str(obj)`` |
584
+ +---------------------------------------+---------------------------------------------+
585
+ | ``auto l = py::list(obj); l.check()`` | ``py::isinstance<py::list>(obj)`` |
586
+ +---------------------------------------+---------------------------------------------+
587
+ | ``py::object(ptr, true)`` | ``py::reinterpret_borrow<py::object>(ptr)`` |
588
+ +---------------------------------------+---------------------------------------------+
589
+ | ``py::object(ptr, false)`` | ``py::reinterpret_steal<py::object>(ptr)`` |
590
+ +---------------------------------------+---------------------------------------------+
591
+ | ``if (obj.attr("foo"))`` | ``if (py::hasattr(obj, "foo"))`` |
592
+ +---------------------------------------+---------------------------------------------+
593
+ | ``if (obj["bar"])`` | ``if (obj.contains("bar"))`` |
594
+ +---------------------------------------+---------------------------------------------+
third_party/CityFlow/extern/pybind11/noxfile.py CHANGED
@@ -1,107 +1,107 @@
1
- import os
2
-
3
- import nox
4
-
5
- nox.needs_version = ">=2022.1.7"
6
- nox.options.sessions = ["lint", "tests", "tests_packaging"]
7
-
8
- PYTHON_VERSIONS = [
9
- "3.6",
10
- "3.7",
11
- "3.8",
12
- "3.9",
13
- "3.10",
14
- "3.11",
15
- "pypy3.7",
16
- "pypy3.8",
17
- "pypy3.9",
18
- ]
19
-
20
- if os.environ.get("CI", None):
21
- nox.options.error_on_missing_interpreters = True
22
-
23
-
24
- @nox.session(reuse_venv=True)
25
- def lint(session: nox.Session) -> None:
26
- """
27
- Lint the codebase (except for clang-format/tidy).
28
- """
29
- session.install("pre-commit")
30
- session.run("pre-commit", "run", "-a", *session.posargs)
31
-
32
-
33
- @nox.session(python=PYTHON_VERSIONS)
34
- def tests(session: nox.Session) -> None:
35
- """
36
- Run the tests (requires a compiler).
37
- """
38
- tmpdir = session.create_tmp()
39
- session.install("cmake")
40
- session.install("-r", "tests/requirements.txt")
41
- session.run(
42
- "cmake",
43
- "-S.",
44
- f"-B{tmpdir}",
45
- "-DPYBIND11_WERROR=ON",
46
- "-DDOWNLOAD_CATCH=ON",
47
- "-DDOWNLOAD_EIGEN=ON",
48
- *session.posargs,
49
- )
50
- session.run("cmake", "--build", tmpdir)
51
- session.run("cmake", "--build", tmpdir, "--config=Release", "--target", "check")
52
-
53
-
54
- @nox.session
55
- def tests_packaging(session: nox.Session) -> None:
56
- """
57
- Run the packaging tests.
58
- """
59
-
60
- session.install("-r", "tests/requirements.txt")
61
- session.run("pytest", "tests/extra_python_package", *session.posargs)
62
-
63
-
64
- @nox.session(reuse_venv=True)
65
- def docs(session: nox.Session) -> None:
66
- """
67
- Build the docs. Pass "serve" to serve.
68
- """
69
-
70
- session.install("-r", "docs/requirements.txt")
71
- session.chdir("docs")
72
-
73
- if "pdf" in session.posargs:
74
- session.run("sphinx-build", "-M", "latexpdf", ".", "_build")
75
- return
76
-
77
- session.run("sphinx-build", "-M", "html", ".", "_build")
78
-
79
- if "serve" in session.posargs:
80
- session.log("Launching docs at http://localhost:8000/ - use Ctrl-C to quit")
81
- session.run("python", "-m", "http.server", "8000", "-d", "_build/html")
82
- elif session.posargs:
83
- session.error("Unsupported argument to docs")
84
-
85
-
86
- @nox.session(reuse_venv=True)
87
- def make_changelog(session: nox.Session) -> None:
88
- """
89
- Inspect the closed issues and make entries for a changelog.
90
- """
91
- session.install("ghapi", "rich")
92
- session.run("python", "tools/make_changelog.py")
93
-
94
-
95
- @nox.session(reuse_venv=True)
96
- def build(session: nox.Session) -> None:
97
- """
98
- Build SDists and wheels.
99
- """
100
-
101
- session.install("build")
102
- session.log("Building normal files")
103
- session.run("python", "-m", "build", *session.posargs)
104
- session.log("Building pybind11-global files (PYBIND11_GLOBAL_SDIST=1)")
105
- session.run(
106
- "python", "-m", "build", *session.posargs, env={"PYBIND11_GLOBAL_SDIST": "1"}
107
- )
 
1
+ import os
2
+
3
+ import nox
4
+
5
+ nox.needs_version = ">=2022.1.7"
6
+ nox.options.sessions = ["lint", "tests", "tests_packaging"]
7
+
8
+ PYTHON_VERSIONS = [
9
+ "3.6",
10
+ "3.7",
11
+ "3.8",
12
+ "3.9",
13
+ "3.10",
14
+ "3.11",
15
+ "pypy3.7",
16
+ "pypy3.8",
17
+ "pypy3.9",
18
+ ]
19
+
20
+ if os.environ.get("CI", None):
21
+ nox.options.error_on_missing_interpreters = True
22
+
23
+
24
+ @nox.session(reuse_venv=True)
25
+ def lint(session: nox.Session) -> None:
26
+ """
27
+ Lint the codebase (except for clang-format/tidy).
28
+ """
29
+ session.install("pre-commit")
30
+ session.run("pre-commit", "run", "-a", *session.posargs)
31
+
32
+
33
+ @nox.session(python=PYTHON_VERSIONS)
34
+ def tests(session: nox.Session) -> None:
35
+ """
36
+ Run the tests (requires a compiler).
37
+ """
38
+ tmpdir = session.create_tmp()
39
+ session.install("cmake")
40
+ session.install("-r", "tests/requirements.txt")
41
+ session.run(
42
+ "cmake",
43
+ "-S.",
44
+ f"-B{tmpdir}",
45
+ "-DPYBIND11_WERROR=ON",
46
+ "-DDOWNLOAD_CATCH=ON",
47
+ "-DDOWNLOAD_EIGEN=ON",
48
+ *session.posargs,
49
+ )
50
+ session.run("cmake", "--build", tmpdir)
51
+ session.run("cmake", "--build", tmpdir, "--config=Release", "--target", "check")
52
+
53
+
54
+ @nox.session
55
+ def tests_packaging(session: nox.Session) -> None:
56
+ """
57
+ Run the packaging tests.
58
+ """
59
+
60
+ session.install("-r", "tests/requirements.txt")
61
+ session.run("pytest", "tests/extra_python_package", *session.posargs)
62
+
63
+
64
+ @nox.session(reuse_venv=True)
65
+ def docs(session: nox.Session) -> None:
66
+ """
67
+ Build the docs. Pass "serve" to serve.
68
+ """
69
+
70
+ session.install("-r", "docs/requirements.txt")
71
+ session.chdir("docs")
72
+
73
+ if "pdf" in session.posargs:
74
+ session.run("sphinx-build", "-M", "latexpdf", ".", "_build")
75
+ return
76
+
77
+ session.run("sphinx-build", "-M", "html", ".", "_build")
78
+
79
+ if "serve" in session.posargs:
80
+ session.log("Launching docs at http://localhost:8000/ - use Ctrl-C to quit")
81
+ session.run("python", "-m", "http.server", "8000", "-d", "_build/html")
82
+ elif session.posargs:
83
+ session.error("Unsupported argument to docs")
84
+
85
+
86
+ @nox.session(reuse_venv=True)
87
+ def make_changelog(session: nox.Session) -> None:
88
+ """
89
+ Inspect the closed issues and make entries for a changelog.
90
+ """
91
+ session.install("ghapi", "rich")
92
+ session.run("python", "tools/make_changelog.py")
93
+
94
+
95
+ @nox.session(reuse_venv=True)
96
+ def build(session: nox.Session) -> None:
97
+ """
98
+ Build SDists and wheels.
99
+ """
100
+
101
+ session.install("build")
102
+ session.log("Building normal files")
103
+ session.run("python", "-m", "build", *session.posargs)
104
+ session.log("Building pybind11-global files (PYBIND11_GLOBAL_SDIST=1)")
105
+ session.run(
106
+ "python", "-m", "build", *session.posargs, env={"PYBIND11_GLOBAL_SDIST": "1"}
107
+ )
third_party/CityFlow/extern/pybind11/pybind11/__init__.py CHANGED
@@ -1,17 +1,17 @@
1
- import sys
2
-
3
- if sys.version_info < (3, 6): # noqa: UP036
4
- msg = "pybind11 does not support Python < 3.6. 2.9 was the last release supporting Python 2.7 and 3.5."
5
- raise ImportError(msg)
6
-
7
-
8
- from ._version import __version__, version_info
9
- from .commands import get_cmake_dir, get_include, get_pkgconfig_dir
10
-
11
- __all__ = (
12
- "version_info",
13
- "__version__",
14
- "get_include",
15
- "get_cmake_dir",
16
- "get_pkgconfig_dir",
17
- )
 
1
+ import sys
2
+
3
+ if sys.version_info < (3, 6): # noqa: UP036
4
+ msg = "pybind11 does not support Python < 3.6. 2.9 was the last release supporting Python 2.7 and 3.5."
5
+ raise ImportError(msg)
6
+
7
+
8
+ from ._version import __version__, version_info
9
+ from .commands import get_cmake_dir, get_include, get_pkgconfig_dir
10
+
11
+ __all__ = (
12
+ "version_info",
13
+ "__version__",
14
+ "get_include",
15
+ "get_cmake_dir",
16
+ "get_pkgconfig_dir",
17
+ )
third_party/CityFlow/extern/pybind11/pybind11/__main__.py CHANGED
@@ -1,62 +1,62 @@
1
- # pylint: disable=missing-function-docstring
2
-
3
- import argparse
4
- import sys
5
- import sysconfig
6
-
7
- from ._version import __version__
8
- from .commands import get_cmake_dir, get_include, get_pkgconfig_dir
9
-
10
-
11
- def print_includes() -> None:
12
- dirs = [
13
- sysconfig.get_path("include"),
14
- sysconfig.get_path("platinclude"),
15
- get_include(),
16
- ]
17
-
18
- # Make unique but preserve order
19
- unique_dirs = []
20
- for d in dirs:
21
- if d and d not in unique_dirs:
22
- unique_dirs.append(d)
23
-
24
- print(" ".join("-I" + d for d in unique_dirs))
25
-
26
-
27
- def main() -> None:
28
- parser = argparse.ArgumentParser()
29
- parser.add_argument(
30
- "--version",
31
- action="version",
32
- version=__version__,
33
- help="Print the version and exit.",
34
- )
35
- parser.add_argument(
36
- "--includes",
37
- action="store_true",
38
- help="Include flags for both pybind11 and Python headers.",
39
- )
40
- parser.add_argument(
41
- "--cmakedir",
42
- action="store_true",
43
- help="Print the CMake module directory, ideal for setting -Dpybind11_ROOT in CMake.",
44
- )
45
- parser.add_argument(
46
- "--pkgconfigdir",
47
- action="store_true",
48
- help="Print the pkgconfig directory, ideal for setting $PKG_CONFIG_PATH.",
49
- )
50
- args = parser.parse_args()
51
- if not sys.argv[1:]:
52
- parser.print_help()
53
- if args.includes:
54
- print_includes()
55
- if args.cmakedir:
56
- print(get_cmake_dir())
57
- if args.pkgconfigdir:
58
- print(get_pkgconfig_dir())
59
-
60
-
61
- if __name__ == "__main__":
62
- main()
 
1
+ # pylint: disable=missing-function-docstring
2
+
3
+ import argparse
4
+ import sys
5
+ import sysconfig
6
+
7
+ from ._version import __version__
8
+ from .commands import get_cmake_dir, get_include, get_pkgconfig_dir
9
+
10
+
11
+ def print_includes() -> None:
12
+ dirs = [
13
+ sysconfig.get_path("include"),
14
+ sysconfig.get_path("platinclude"),
15
+ get_include(),
16
+ ]
17
+
18
+ # Make unique but preserve order
19
+ unique_dirs = []
20
+ for d in dirs:
21
+ if d and d not in unique_dirs:
22
+ unique_dirs.append(d)
23
+
24
+ print(" ".join("-I" + d for d in unique_dirs))
25
+
26
+
27
+ def main() -> None:
28
+ parser = argparse.ArgumentParser()
29
+ parser.add_argument(
30
+ "--version",
31
+ action="version",
32
+ version=__version__,
33
+ help="Print the version and exit.",
34
+ )
35
+ parser.add_argument(
36
+ "--includes",
37
+ action="store_true",
38
+ help="Include flags for both pybind11 and Python headers.",
39
+ )
40
+ parser.add_argument(
41
+ "--cmakedir",
42
+ action="store_true",
43
+ help="Print the CMake module directory, ideal for setting -Dpybind11_ROOT in CMake.",
44
+ )
45
+ parser.add_argument(
46
+ "--pkgconfigdir",
47
+ action="store_true",
48
+ help="Print the pkgconfig directory, ideal for setting $PKG_CONFIG_PATH.",
49
+ )
50
+ args = parser.parse_args()
51
+ if not sys.argv[1:]:
52
+ parser.print_help()
53
+ if args.includes:
54
+ print_includes()
55
+ if args.cmakedir:
56
+ print(get_cmake_dir())
57
+ if args.pkgconfigdir:
58
+ print(get_pkgconfig_dir())
59
+
60
+
61
+ if __name__ == "__main__":
62
+ main()
third_party/CityFlow/extern/pybind11/pybind11/_version.py CHANGED
@@ -1,12 +1,12 @@
1
- from typing import Union
2
-
3
-
4
- def _to_int(s: str) -> Union[int, str]:
5
- try:
6
- return int(s)
7
- except ValueError:
8
- return s
9
-
10
-
11
- __version__ = "2.12.0"
12
- version_info = tuple(_to_int(s) for s in __version__.split("."))
 
1
+ from typing import Union
2
+
3
+
4
+ def _to_int(s: str) -> Union[int, str]:
5
+ try:
6
+ return int(s)
7
+ except ValueError:
8
+ return s
9
+
10
+
11
+ __version__ = "2.12.0"
12
+ version_info = tuple(_to_int(s) for s in __version__.split("."))