Skip to content

Commit 907c5d3

Browse files
committed
Tweak black_bindings
Originally, black_bindings found each contiguous "//|" block and sent it to black independently. This was slower than it needed to be. Instead, swap the comment prefix: when running black, take off "//|" prefixes and put "##|" prefixes on all un-prefixed lines. Then, after black is run, do the opposite operation This more than doubles the overall speed of "pre-commit run --all", from 3m20s to 55s CPU time on my local machine (32.5s to under 10s "elapsed" time) It also causes a small amount of churn in the bindings, because black now sees enough context to know whether one 'def' follows another or ends the 'def's in a 'class'. In the latter case, it adds an extra newline, which becomes a "//|" line. I'm less sure why a trailing comma was omitted before down in rp2pio/StateMachine.c but let's roll with it.
1 parent fcf7cfe commit 907c5d3

File tree

185 files changed

+427
-37
lines changed

Some content is hidden

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

185 files changed

+427
-37
lines changed

ports/atmel-samd/bindings/samd/Clock.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
//|
3636
//| They are fixed by the hardware so they cannot be constructed on demand. Instead, use
3737
//| ``samd.clock`` to reference the desired clock."""
38+
//|
3839

3940
STATIC void samd_clock_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
4041
samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -92,6 +93,7 @@ MP_PROPERTY_GETTER(samd_clock_frequency_obj,
9293

9394
//| calibration: int
9495
//| """Clock calibration. Not all clocks can be calibrated."""
96+
//|
9597
STATIC mp_obj_t samd_clock_get_calibration(mp_obj_t self_in) {
9698
samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in);
9799
return mp_obj_new_int_from_uint(clock_get_calibration(self->type, self->index));

ports/broadcom/bindings/videocore/Framebuffer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ MP_PROPERTY_GETTER(videocore_framebuffer_width_obj,
9898

9999
//| height: int
100100
//| """The height of the display, in pixels"""
101+
//|
101102
STATIC mp_obj_t videocore_framebuffer_get_height(mp_obj_t self_in) {
102103
videocore_framebuffer_obj_t *self = (videocore_framebuffer_obj_t *)self_in;
103104
check_for_deinit(self);

ports/espressif/bindings/esp32_camera/Camera.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,7 @@ MP_PROPERTY_GETTER(esp32_camera_camera_grab_mode_obj,
928928

929929
//| framebuffer_count: int
930930
//| """True if double buffering is used"""
931+
//|
931932
STATIC mp_obj_t esp32_camera_camera_get_framebuffer_count(const mp_obj_t self_in) {
932933
esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in);
933934
check_for_deinit(self);

ports/espressif/bindings/esp32_camera/__init__.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
//|
5555
//| LATEST: GrabMode
5656
//| """Except when 1 frame buffer is used, queue will always contain the last ``fb_count`` frames"""
57+
//|
5758

5859
MAKE_ENUM_VALUE(esp32_camera_grab_mode_type, grab_mode, WHEN_EMPTY, CAMERA_GRAB_WHEN_EMPTY);
5960
MAKE_ENUM_VALUE(esp32_camera_grab_mode_type, grab_mode, LATEST, CAMERA_GRAB_LATEST);
@@ -82,6 +83,7 @@ camera_grab_mode_t validate_grab_mode(mp_obj_t obj, qstr arg_name) {
8283
//|
8384
//| JPEG: PixelFormat
8485
//| """A compressed format"""
86+
//|
8587

8688
MAKE_ENUM_VALUE(esp32_camera_pixel_format_type, pixel_format, RGB565, PIXFORMAT_RGB565);
8789
MAKE_ENUM_VALUE(esp32_camera_pixel_format_type, pixel_format, GRAYSCALE, PIXFORMAT_GRAYSCALE);
@@ -169,6 +171,7 @@ pixformat_t validate_pixel_format(mp_obj_t obj, qstr arg_name) {
169171
//|
170172
//| QSXGA: FrameSize
171173
//| """2560x1920"""
174+
//|
172175

173176
MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, R96X96, FRAMESIZE_96X96);
174177
MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, R240X240, FRAMESIZE_240X240);
@@ -237,6 +240,7 @@ framesize_t validate_frame_size(mp_obj_t obj, qstr arg_name) {
237240
//| GAIN_32X: GainCeiling
238241
//| GAIN_64X: GainCeiling
239242
//| GAIN_128X: GainCeiling
243+
//|
240244

241245
MAKE_ENUM_VALUE(esp32_camera_gain_ceiling_type, gain_ceiling, GAIN_2X, GAINCEILING_2X);
242246
MAKE_ENUM_VALUE(esp32_camera_gain_ceiling_type, gain_ceiling, GAIN_4X, GAINCEILING_4X);

ports/espressif/bindings/espidf/__init__.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
//| def heap_caps_get_total_size() -> int:
4242
//| """Return the total size of the ESP-IDF, which includes the CircuitPython heap."""
4343
//| ...
44+
//|
4445

4546
STATIC mp_obj_t espidf_heap_caps_get_total_size(void) {
4647
return MP_OBJ_NEW_SMALL_INT(heap_caps_get_total_size(MALLOC_CAP_8BIT));
@@ -50,6 +51,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_total_size_obj, espidf_heap_caps_
5051
//| def heap_caps_get_free_size() -> int:
5152
//| """Return total free memory in the ESP-IDF heap."""
5253
//| ...
54+
//|
5355

5456
STATIC mp_obj_t espidf_heap_caps_get_free_size(void) {
5557
return MP_OBJ_NEW_SMALL_INT(heap_caps_get_free_size(MALLOC_CAP_8BIT));
@@ -59,6 +61,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_free_size_obj, espidf_heap_caps_g
5961
//| def heap_caps_get_largest_free_block() -> int:
6062
//| """Return the size of largest free memory block in the ESP-IDF heap."""
6163
//| ...
64+
//|
6265

6366
STATIC mp_obj_t espidf_heap_caps_get_largest_free_block(void) {
6467
return MP_OBJ_NEW_SMALL_INT(heap_caps_get_largest_free_block(MALLOC_CAP_8BIT));
@@ -70,6 +73,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_largest_free_block_obj, espidf_he
7073
//|
7174
//| This is necessary when upgrading from CircuitPython 6.3.0 or earlier to CircuitPython 7.0.0, because the
7275
//| layout of data in nvs has changed. The old data will be lost when you perform this operation."""
76+
//|
7377
STATIC mp_obj_t espidf_erase_nvs(void) {
7478
ESP_ERROR_CHECK(nvs_flash_deinit());
7579
ESP_ERROR_CHECK(nvs_flash_erase());
@@ -105,6 +109,7 @@ const mp_obj_type_t mp_type_espidf_IDFError = {
105109
//| """Raised when an ESP IDF memory allocation fails."""
106110
//|
107111
//| ...
112+
//|
108113
NORETURN void mp_raise_espidf_MemoryError(void) {
109114
nlr_raise(mp_obj_new_exception(&mp_type_espidf_MemoryError));
110115
}
@@ -120,13 +125,15 @@ const mp_obj_type_t mp_type_espidf_MemoryError = {
120125

121126
//| def get_total_psram() -> int:
122127
//| """Returns the number of bytes of psram detected, or 0 if psram is not present or not configured"""
128+
//|
123129
STATIC mp_obj_t espidf_get_total_psram(void) {
124130
return MP_OBJ_NEW_SMALL_INT(common_hal_espidf_get_total_psram());
125131
}
126132
MP_DEFINE_CONST_FUN_OBJ_0(espidf_get_total_psram_obj, espidf_get_total_psram);
127133

128134
//| def get_reserved_psram() -> int:
129135
//| """Returns number of bytes of psram reserved for use by esp-idf, either a board-specific default value or the value defined in ``/.env``."""
136+
//|
130137
STATIC mp_obj_t espidf_get_reserved_psram(void) {
131138
return MP_OBJ_NEW_SMALL_INT(common_hal_espidf_get_reserved_psram());
132139
}

ports/raspberrypi/bindings/cyw43/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
//| Cannot be constructed at runtime, but may be the type of a pin object
3939
//| in :py:mod:`board`. A `CywPin` can be used as a DigitalInOut, but not with other
4040
//| peripherals such as `PWMOut`."""
41+
//|
4142
const mp_obj_type_t cyw43_pin_type = {
4243
{ &mp_type_type },
4344
.flags = MP_TYPE_FLAG_EXTENDED,
@@ -57,6 +58,7 @@ const mp_obj_type_t cyw43_pin_type = {
5758
//| Besides this value, there appears to be no other public documentation
5859
//| of the values that can be used.
5960
//| """
61+
//|
6062
STATIC mp_obj_t cyw43_set_power_management(const mp_obj_t value_in) {
6163
mp_int_t value = mp_obj_get_int(value_in);
6264
cyw43_wifi_pm(&cyw43_state, value);

ports/raspberrypi/bindings/rp2pio/StateMachine.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_stop_obj, rp2pio_statemachine_stop
359359
//| *,
360360
//| start: int = 0,
361361
//| end: Optional[int] = None,
362-
//| swap: bool = False
362+
//| swap: bool = False,
363363
//| ) -> None:
364364
//| """Write the data contained in ``buffer`` to the state machine. If the buffer is empty, nothing happens.
365365
//|
@@ -419,7 +419,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(rp2pio_statemachine_write_obj, 2, rp2pio_statemachine
419419
//| once: Optional[ReadableBuffer] = None,
420420
//| *,
421421
//| loop: Optional[ReadableBuffer] = None,
422-
//| swap: bool = False
422+
//| swap: bool = False,
423423
//| ) -> None:
424424
//| """Write data to the TX fifo in the background, with optional looping.
425425
//|
@@ -564,7 +564,7 @@ const mp_obj_property_t rp2pio_statemachine_pending_obj = {
564564
//| *,
565565
//| start: int = 0,
566566
//| end: Optional[int] = None,
567-
//| swap: bool = False
567+
//| swap: bool = False,
568568
//| ) -> None:
569569
//| """Read into ``buffer``. If the number of bytes to read is 0, nothing happens. The buffer
570570
//| includes any data added to the fifo even if it was added before this was called.
@@ -628,7 +628,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(rp2pio_statemachine_readinto_obj, 2, rp2pio_statemach
628628
//| out_start: int = 0,
629629
//| out_end: Optional[int] = None,
630630
//| in_start: int = 0,
631-
//| in_end: Optional[int] = None
631+
//| in_end: Optional[int] = None,
632632
//| ) -> None:
633633
//| """Write out the data in ``buffer_out`` while simultaneously reading data into ``buffer_in``.
634634
//| The lengths of the slices defined by ``buffer_out[out_start:out_end]`` and ``buffer_in[in_start:in_end]``
@@ -788,6 +788,7 @@ MP_PROPERTY_GETTER(rp2pio_statemachine_rxstall_obj,
788788

789789
//| in_waiting: int
790790
//| """The number of words available to readinto"""
791+
//|
791792

792793
STATIC mp_obj_t rp2pio_statemachine_obj_get_in_waiting(mp_obj_t self_in) {
793794
rp2pio_statemachine_obj_t *self = MP_OBJ_TO_PTR(self_in);

ports/raspberrypi/bindings/rp2pio/__init__.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
//| def pins_are_sequential(pins: List[microcontroller.Pin]) -> bool:
4343
//| """Return True if the pins have sequential GPIO numbers, False otherwise"""
4444
//| ...
45+
//|
4546
STATIC mp_obj_t rp2pio_pins_are_sequential(const mp_obj_t pins) {
4647
size_t len;
4748
mp_obj_t *items;

shared-bindings/_bleio/Adapter.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
//| The Adapter can do both parts of this process: it can scan for other device
6363
//| advertisements and it can advertise its own data. Furthermore, Adapters can accept incoming
6464
//| connections and also initiate connections."""
65+
//|
6566

6667
//| def __init__(
6768
//| self, *, uart: busio.UART, rts: digitalio.DigitalInOut, cts: digitalio.DigitalInOut
@@ -435,6 +436,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_adapter_connect_obj, 1, bleio_adapter_co
435436
//| def erase_bonding(self) -> None:
436437
//| """Erase all bonding information stored in flash memory."""
437438
//| ...
439+
//|
438440
STATIC mp_obj_t bleio_adapter_erase_bonding(mp_obj_t self_in) {
439441
bleio_adapter_obj_t *self = MP_OBJ_TO_PTR(self_in);
440442

shared-bindings/_bleio/Address.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
//| class Address:
3838
//| """Encapsulates the address of a BLE device."""
39+
//|
3940

4041
//| def __init__(self, address: ReadableBuffer, address_type: int) -> None:
4142
//| """Create a new Address object encapsulating the address value.
@@ -185,6 +186,7 @@ STATIC void bleio_address_print(const mp_print_t *print, mp_obj_t self_in, mp_pr
185186
//|
186187
//| RANDOM_PRIVATE_NON_RESOLVABLE: int
187188
//| """A randomly generated address that changes on every connection."""
189+
//|
188190
STATIC const mp_rom_map_elem_t bleio_address_locals_dict_table[] = {
189191
{ MP_ROM_QSTR(MP_QSTR_address_bytes), MP_ROM_PTR(&bleio_address_address_bytes_obj) },
190192
{ MP_ROM_QSTR(MP_QSTR_type), MP_ROM_PTR(&bleio_address_type_obj) },

0 commit comments

Comments
 (0)