Skip to content

Commit

Permalink
Merge pull request adafruit#8524 from tannewt/displayio_warnings
Browse files Browse the repository at this point in the history
Add `warnings` and warn about displayio changes
  • Loading branch information
dhalbert committed Oct 27, 2023
2 parents 8790ce0 + cf08ef0 commit 4ecc51e
Show file tree
Hide file tree
Showing 13 changed files with 384 additions and 33 deletions.
73 changes: 44 additions & 29 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,23 @@ msgstr ""
msgid "%q length must be >= %d"
msgstr ""

#: py/objmodule.c py/runtime.c
msgid "%q moved from %q to %q"
msgstr ""

#: py/argcheck.c
msgid "%q must be %d"
msgstr ""

#: py/argcheck.c shared-bindings/displayio/Bitmap.c
#: shared-bindings/displayio/Display.c
#: py/argcheck.c shared-bindings/busdisplay/BusDisplay.c
#: shared-bindings/displayio/Bitmap.c
#: shared-bindings/framebufferio/FramebufferDisplay.c
#: shared-bindings/is31fl3741/FrameBuffer.c
#: shared-bindings/rgbmatrix/RGBMatrix.c
msgid "%q must be %d-%d"
msgstr ""

#: shared-bindings/displayio/Display.c
#: shared-bindings/busdisplay/BusDisplay.c
msgid "%q must be 1 when %q is True"
msgstr ""

Expand All @@ -212,6 +216,10 @@ msgstr ""
msgid "%q must be a bytearray or array of type 'h', 'H', 'b', or 'B'"
msgstr ""

#: shared-bindings/warnings/__init__.c
msgid "%q must be a subclass of %q"
msgstr ""

#: ports/espressif/common-hal/analogbufio/BufferedIn.c
msgid "%q must be array of type 'H'"
msgstr ""
Expand Down Expand Up @@ -247,6 +255,10 @@ msgstr ""
msgid "%q out of range"
msgstr ""

#: py/objmodule.c py/runtime.c
msgid "%q renamed %q"
msgstr ""

#: py/objrange.c py/objslice.c shared-bindings/random/__init__.c
msgid "%q step cannot be zero"
msgstr ""
Expand Down Expand Up @@ -434,8 +446,8 @@ msgstr ""
msgid ", in %q\n"
msgstr ""

#: shared-bindings/displayio/Display.c
#: shared-bindings/displayio/EPaperDisplay.c
#: shared-bindings/busdisplay/BusDisplay.c
#: shared-bindings/epaperdisplay/EPaperDisplay.c
#: shared-bindings/framebufferio/FramebufferDisplay.c
msgid ".show(x) removed. Use .root_group = x"
msgstr ""
Expand Down Expand Up @@ -625,7 +637,7 @@ msgstr ""
msgid "Baudrate not supported by peripheral"
msgstr ""

#: shared-module/displayio/Display.c
#: shared-module/busdisplay/BusDisplay.c
#: shared-module/framebufferio/FramebufferDisplay.c
msgid "Below minimum frame rate"
msgstr ""
Expand Down Expand Up @@ -658,7 +670,7 @@ msgstr ""
msgid "Both pins must support hardware interrupts"
msgstr ""

#: shared-bindings/displayio/Display.c
#: shared-bindings/busdisplay/BusDisplay.c
#: shared-bindings/framebufferio/FramebufferDisplay.c
msgid "Brightness not adjustable"
msgstr ""
Expand Down Expand Up @@ -695,7 +707,8 @@ msgstr ""
msgid "Buffer too short by %d bytes"
msgstr ""

#: ports/cxd56/common-hal/camera/Camera.c shared-bindings/displayio/Display.c
#: ports/cxd56/common-hal/camera/Camera.c
#: shared-bindings/busdisplay/BusDisplay.c
#: shared-bindings/framebufferio/FramebufferDisplay.c
#: shared-bindings/struct/__init__.c shared-module/struct/__init__.c
msgid "Buffer too small"
Expand All @@ -705,10 +718,10 @@ msgstr ""
msgid "Buffers must be same size"
msgstr ""

#: ports/atmel-samd/common-hal/paralleldisplay/ParallelBus.c
#: ports/espressif/common-hal/paralleldisplay/ParallelBus.c
#: ports/nrf/common-hal/paralleldisplay/ParallelBus.c
#: ports/raspberrypi/common-hal/paralleldisplay/ParallelBus.c
#: ports/atmel-samd/common-hal/paralleldisplaybus/ParallelBus.c
#: ports/espressif/common-hal/paralleldisplaybus/ParallelBus.c
#: ports/nrf/common-hal/paralleldisplaybus/ParallelBus.c
#: ports/raspberrypi/common-hal/paralleldisplaybus/ParallelBus.c
#, c-format
msgid "Bus pin %d is already in use"
msgstr ""
Expand Down Expand Up @@ -893,8 +906,8 @@ msgstr ""
msgid "DAC already in use"
msgstr ""

#: ports/atmel-samd/common-hal/paralleldisplay/ParallelBus.c
#: ports/nrf/common-hal/paralleldisplay/ParallelBus.c
#: ports/atmel-samd/common-hal/paralleldisplaybus/ParallelBus.c
#: ports/nrf/common-hal/paralleldisplaybus/ParallelBus.c
msgid "Data 0 pin must be byte aligned"
msgstr ""

Expand Down Expand Up @@ -924,13 +937,13 @@ msgstr ""
msgid "Device in use"
msgstr ""

#: shared-bindings/displayio/Display.c
#: shared-bindings/busdisplay/BusDisplay.c
#: shared-bindings/framebufferio/FramebufferDisplay.c
msgid "Display must have a 16 bit colorspace."
msgstr ""

#: shared-bindings/displayio/Display.c
#: shared-bindings/displayio/EPaperDisplay.c
#: shared-bindings/busdisplay/BusDisplay.c
#: shared-bindings/epaperdisplay/EPaperDisplay.c
#: shared-bindings/framebufferio/FramebufferDisplay.c
msgid "Display rotation must be in 90 degree increments"
msgstr ""
Expand Down Expand Up @@ -1104,7 +1117,7 @@ msgid "Generic Failure"
msgstr ""

#: shared-bindings/framebufferio/FramebufferDisplay.c
#: shared-module/displayio/Display.c
#: shared-module/busdisplay/BusDisplay.c
#: shared-module/framebufferio/FramebufferDisplay.c
msgid "Group already used"
msgstr ""
Expand Down Expand Up @@ -1202,7 +1215,7 @@ msgstr ""
msgid "Internal define error"
msgstr ""

#: ports/espressif/common-hal/paralleldisplay/ParallelBus.c
#: ports/espressif/common-hal/paralleldisplaybus/ParallelBus.c
#: shared-module/os/getenv.c
msgid "Internal error"
msgstr ""
Expand All @@ -1225,7 +1238,7 @@ msgstr ""
#: ports/raspberrypi/bindings/picodvi/Framebuffer.c
#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c
#: shared-bindings/digitalio/DigitalInOut.c
#: shared-bindings/displayio/EPaperDisplay.c
#: shared-bindings/epaperdisplay/EPaperDisplay.c
msgid "Invalid %q"
msgstr ""

Expand Down Expand Up @@ -1428,9 +1441,10 @@ msgstr ""
#: ports/mimxrt10xx/common-hal/busio/SPI.c
#: ports/mimxrt10xx/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c
#: ports/raspberrypi/common-hal/busio/UART.c ports/stm/common-hal/busio/SPI.c
#: ports/stm/common-hal/busio/UART.c shared-bindings/displayio/FourWire.c
#: shared-bindings/displayio/I2CDisplay.c
#: shared-bindings/paralleldisplay/ParallelBus.c shared-module/bitbangio/SPI.c
#: ports/stm/common-hal/busio/UART.c shared-bindings/fourwire/FourWire.c
#: shared-bindings/i2cdisplaybus/I2CDisplayBus.c
#: shared-bindings/paralleldisplaybus/ParallelBus.c
#: shared-module/bitbangio/SPI.c
msgid "No %q pin"
msgstr ""

Expand Down Expand Up @@ -1562,7 +1576,7 @@ msgstr ""
msgid "Not playing"
msgstr ""

#: ports/espressif/common-hal/paralleldisplay/ParallelBus.c
#: ports/espressif/common-hal/paralleldisplaybus/ParallelBus.c
#, c-format
msgid "Number of data_pins must be 8 or 16, not %d"
msgstr ""
Expand Down Expand Up @@ -1852,7 +1866,7 @@ msgstr ""
msgid "Reconnecting"
msgstr ""

#: shared-bindings/displayio/EPaperDisplay.c
#: shared-bindings/epaperdisplay/EPaperDisplay.c
msgid "Refresh too soon"
msgstr ""

Expand Down Expand Up @@ -1953,7 +1967,7 @@ msgstr ""
msgid "Source and destination buffers must be the same length"
msgstr ""

#: shared-bindings/paralleldisplay/ParallelBus.c
#: shared-bindings/paralleldisplaybus/ParallelBus.c
msgid "Specify exactly one of data0 or data_pins"
msgstr ""

Expand Down Expand Up @@ -2013,7 +2027,7 @@ msgstr ""
msgid "This microcontroller does not support continuous capture."
msgstr ""

#: shared-module/paralleldisplay/ParallelBus.c
#: shared-module/paralleldisplaybus/ParallelBus.c
msgid ""
"This microcontroller only supports data0=, not data_pins=, because it "
"requires contiguous pins."
Expand Down Expand Up @@ -2148,7 +2162,8 @@ msgstr ""
msgid "Unable to create lock"
msgstr ""

#: shared-module/displayio/I2CDisplay.c shared-module/is31fl3741/IS31FL3741.c
#: shared-module/i2cdisplaybus/I2CDisplayBus.c
#: shared-module/is31fl3741/IS31FL3741.c
#, c-format
msgid "Unable to find I2C Display at %x"
msgstr ""
Expand Down Expand Up @@ -2258,7 +2273,7 @@ msgstr ""
msgid "Unsupported colorspace"
msgstr ""

#: shared-module/displayio/display_core.c
#: shared-module/displayio/bus_core.c
msgid "Unsupported display bus type"
msgstr ""

Expand Down
8 changes: 6 additions & 2 deletions py/circuitpy_defns.mk
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ endif
ifeq ($(CIRCUITPY_VIDEOCORE),1)
SRC_PATTERNS += videocore/%
endif
ifeq ($(CIRCUITPY_WARNINGS),1)
SRC_PATTERNS += warnings/%
endif
ifeq ($(CIRCUITPY_WATCHDOG),1)
SRC_PATTERNS += watchdog/%
endif
Expand Down Expand Up @@ -680,13 +683,14 @@ SRC_SHARED_MODULE_ALL = \
usb/core/__init__.c \
usb/core/Device.c \
ustack/__init__.c \
watchdog/__init__.c \
zlib/__init__.c \
vectorio/Circle.c \
vectorio/Polygon.c \
vectorio/Rectangle.c \
vectorio/VectorShape.c \
vectorio/__init__.c \
warnings/__init__.c \
watchdog/__init__.c \
zlib/__init__.c \

# All possible sources are listed here, and are filtered by SRC_PATTERNS.
SRC_SHARED_MODULE = $(filter $(SRC_PATTERNS), $(SRC_SHARED_MODULE_ALL))
Expand Down
3 changes: 3 additions & 0 deletions py/circuitpy_mpconfig.mk
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@ CIRCUITPY_ULAB_OPTIMIZE_SIZE ?= 0
CIRCUITPY_VIDEOCORE ?= 0
CFLAGS += -DCIRCUITPY_VIDEOCORE=$(CIRCUITPY_VIDEOCORE)

CIRCUITPY_WARNINGS ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_WARNINGS=$(CIRCUITPY_WARNINGS)

# watchdog hardware support
CIRCUITPY_WATCHDOG ?= 0
CFLAGS += -DCIRCUITPY_WATCHDOG=$(CIRCUITPY_WATCHDOG)
Expand Down
4 changes: 4 additions & 0 deletions py/modbuiltins.c
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,10 @@ STATIC const mp_rom_map_elem_t mp_module_builtins_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_ViperTypeError), MP_ROM_PTR(&mp_type_ViperTypeError) },
#endif
{ MP_ROM_QSTR(MP_QSTR_ZeroDivisionError), MP_ROM_PTR(&mp_type_ZeroDivisionError) },
#if CIRCUITPY_WARNINGS
{ MP_ROM_QSTR(MP_QSTR_Warning), MP_ROM_PTR(&mp_type_Warning) },
{ MP_ROM_QSTR(MP_QSTR_FutureWarning), MP_ROM_PTR(&mp_type_FutureWarning) },
#endif

// Extra builtins as defined by a port
MICROPY_PORT_BUILTINS
Expand Down
8 changes: 8 additions & 0 deletions py/mpstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
#include "py/objlist.h"
#include "py/objexcept.h"

#if CIRCUITPY_WARNINGS
#include "shared-bindings/warnings/__init__.h"
#endif

// #if CIRCUITPY
// #error CIRCUITPY is TRUE in mpstate.h.
// #else
Expand Down Expand Up @@ -311,6 +315,10 @@ typedef struct _mp_state_thread_t {
bool prof_callback_is_executing;
struct _mp_code_state_t *current_code_state;
#endif

#if CIRCUITPY_WARNINGS
warnings_action_t warnings_action;
#endif
} mp_state_thread_t;

// This structure combines the above 3 structures.
Expand Down
4 changes: 4 additions & 0 deletions py/obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,10 @@ extern const mp_obj_type_t mp_type_ZeroDivisionError;
#if CIRCUITPY_ALARM
extern const mp_obj_type_t mp_type_DeepSleepRequest;
#endif
#if CIRCUITPY_WARNINGS
extern const mp_obj_type_t mp_type_Warning;
extern const mp_obj_type_t mp_type_FutureWarning;
#endif


// Constant objects, globally accessible: None, False, True
Expand Down
6 changes: 4 additions & 2 deletions py/objexcept.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,14 +452,16 @@ MP_DEFINE_EXCEPTION(Exception, BaseException)
#if CIRCUITPY_ALARM
MP_DEFINE_EXCEPTION(DeepSleepRequest, BaseException)
#endif
/*
#if CIRCUITPY_WARNINGS
MP_DEFINE_EXCEPTION(Warning, Exception)
MP_DEFINE_EXCEPTION(FutureWarning, Warning)
#endif
/*
MP_DEFINE_EXCEPTION(DeprecationWarning, Warning)
MP_DEFINE_EXCEPTION(PendingDeprecationWarning, Warning)
MP_DEFINE_EXCEPTION(RuntimeWarning, Warning)
MP_DEFINE_EXCEPTION(SyntaxWarning, Warning)
MP_DEFINE_EXCEPTION(UserWarning, Warning)
MP_DEFINE_EXCEPTION(FutureWarning, Warning)
MP_DEFINE_EXCEPTION(ImportWarning, Warning)
MP_DEFINE_EXCEPTION(UnicodeWarning, Warning)
MP_DEFINE_EXCEPTION(BytesWarning, Warning)
Expand Down
35 changes: 35 additions & 0 deletions py/objmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#include "py/runtime.h"
#include "py/builtin.h"

#if CIRCUITPY_WARNINGS
#include "shared-module/warnings/__init__.h"
#endif

STATIC void module_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
(void)kind;
mp_obj_module_t *self = MP_OBJ_TO_PTR(self_in);
Expand Down Expand Up @@ -62,6 +66,32 @@ STATIC void module_attr_try_delegation(mp_obj_t self_in, qstr attr, mp_obj_t *de
STATIC void module_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
mp_obj_module_t *self = MP_OBJ_TO_PTR(self_in);
if (dest[0] == MP_OBJ_NULL) {
#if CIRCUITPY_DISPLAYIO && CIRCUITPY_WARNINGS
if (self == &displayio_module) {
#if CIRCUITPY_BUSDISPLAY
if (attr == MP_QSTR_Display) {
warnings_warn(&mp_type_FutureWarning, translate("%q moved from %q to %q"), MP_QSTR_Display, MP_QSTR_displayio, MP_QSTR_busdisplay);
warnings_warn(&mp_type_FutureWarning, translate("%q renamed %q"), MP_QSTR_Display, MP_QSTR_BusDisplay);
}
#endif
#if CIRCUITPY_EPAPERDISPLAY
if (attr == MP_QSTR_EPaperDisplay) {
warnings_warn(&mp_type_FutureWarning, translate("%q moved from %q to %q"), MP_QSTR_EPaperDisplay, MP_QSTR_displayio, MP_QSTR_epaperdisplay);
}
#endif
#if CIRCUITPY_FOURWIRE
if (attr == MP_QSTR_FourWire) {
warnings_warn(&mp_type_FutureWarning, translate("%q moved from %q to %q"), MP_QSTR_FourWire, MP_QSTR_displayio, MP_QSTR_fourwire);
}
#endif
#if CIRCUITPY_I2CDISPLAYBUS
if (attr == MP_QSTR_I2CDisplay) {
warnings_warn(&mp_type_FutureWarning, translate("%q moved from %q to %q"), MP_QSTR_I2CDisplay, MP_QSTR_displayio, MP_QSTR_i2cdisplaybus);
warnings_warn(&mp_type_FutureWarning, translate("%q renamed %q"), MP_QSTR_I2CDisplay, MP_QSTR_I2CDisplayBus);
}
#endif
}
#endif
// load attribute
mp_map_elem_t *elem = mp_map_lookup(&self->globals->map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP);
if (elem != NULL) {
Expand Down Expand Up @@ -173,6 +203,11 @@ STATIC const mp_module_delegation_entry_t mp_builtin_module_delegation_table[] =
// Attempts to find (and initialise) a built-in, otherwise returns
// MP_OBJ_NULL.
mp_obj_t mp_module_get_builtin(qstr module_name, bool extensible) {
#if CIRCUITPY_PARALLELDISPLAYBUS && CIRCUITPY_WARNINGS
if (module_name == MP_QSTR_paralleldisplay) {
warnings_warn(&mp_type_FutureWarning, translate("%q renamed %q"), MP_QSTR_paralleldisplay, MP_QSTR_paralleldisplaybus);
}
#endif
mp_map_elem_t *elem = mp_map_lookup((mp_map_t *)(extensible ? &mp_builtin_extensible_module_map : &mp_builtin_module_map), MP_OBJ_NEW_QSTR(module_name), MP_MAP_LOOKUP);
if (!elem) {
#if MICROPY_PY_SYS
Expand Down
Loading

0 comments on commit 4ecc51e

Please sign in to comment.