From 2fbc08c462e247e7f78460783c9a07c76c5b762e Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 8 Jun 2023 15:51:50 +1000 Subject: [PATCH] extmod/asyncio: Rename uasyncio to asyncio. The asyncio module now has much better CPython compatibility and deserves to be just called "asyncio". This will avoid people having to write `from uasyncio import asyncio`. Renames all files, and updates port manifests to use the new path. Also renames the built-in _uasyncio to _asyncio. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- extmod/{uasyncio => asyncio}/__init__.py | 2 +- extmod/{uasyncio => asyncio}/core.py | 4 +-- extmod/{uasyncio => asyncio}/event.py | 2 +- extmod/{uasyncio => asyncio}/funcs.py | 2 +- extmod/{uasyncio => asyncio}/lock.py | 2 +- extmod/{uasyncio => asyncio}/manifest.py | 2 +- extmod/{uasyncio => asyncio}/stream.py | 2 +- extmod/{uasyncio => asyncio}/task.py | 2 +- extmod/extmod.cmake | 2 +- extmod/extmod.mk | 2 +- extmod/{moduasyncio.c => modasyncio.c} | 32 +++++++++---------- ports/esp32/boards/manifest.py | 2 +- ports/esp8266/boards/GENERIC/manifest.py | 4 +-- .../esp8266/boards/GENERIC_1M/mpconfigboard.h | 2 +- .../boards/GENERIC_512K/mpconfigboard.h | 2 +- ports/mimxrt/boards/manifest.py | 2 +- ports/nrf/modules/manifest.py | 2 +- ports/renesas-ra/boards/manifest.py | 2 +- ports/rp2/boards/manifest.py | 2 +- ports/samd/mcu/samd51/manifest.py | 2 +- ports/samd/mpconfigport.h | 2 +- .../boards/NUCLEO_G474RE/mpconfigboard.h | 2 +- ports/stm32/boards/manifest.py | 2 +- ports/unix/variants/standard/manifest.py | 2 +- ports/windows/msvc/sources.props | 2 +- ports/windows/variants/dev/manifest.py | 2 +- ports/windows/variants/dev/mpconfigvariant.h | 4 +-- py/mpconfig.h | 4 +-- 28 files changed, 47 insertions(+), 47 deletions(-) rename extmod/{uasyncio => asyncio}/__init__.py (95%) rename extmod/{uasyncio => asyncio}/core.py (99%) rename extmod/{uasyncio => asyncio}/event.py (98%) rename extmod/{uasyncio => asyncio}/funcs.py (99%) rename extmod/{uasyncio => asyncio}/lock.py (98%) rename extmod/{uasyncio => asyncio}/manifest.py (94%) rename extmod/{uasyncio => asyncio}/stream.py (99%) rename extmod/{uasyncio => asyncio}/task.py (99%) rename extmod/{moduasyncio.c => modasyncio.c} (91%) diff --git a/extmod/uasyncio/__init__.py b/extmod/asyncio/__init__.py similarity index 95% rename from extmod/uasyncio/__init__.py rename to extmod/asyncio/__init__.py index 373de52af4..1f83750c5a 100644 --- a/extmod/uasyncio/__init__.py +++ b/extmod/asyncio/__init__.py @@ -1,4 +1,4 @@ -# MicroPython uasyncio module +# MicroPython asyncio module # MIT license; Copyright (c) 2019 Damien P. George from .core import * diff --git a/extmod/uasyncio/core.py b/extmod/asyncio/core.py similarity index 99% rename from extmod/uasyncio/core.py rename to extmod/asyncio/core.py index f191d202e2..be5119ba61 100644 --- a/extmod/uasyncio/core.py +++ b/extmod/asyncio/core.py @@ -1,4 +1,4 @@ -# MicroPython uasyncio module +# MicroPython asyncio module # MIT license; Copyright (c) 2019 Damien P. George from time import ticks_ms as ticks, ticks_diff, ticks_add @@ -6,7 +6,7 @@ import sys, select # Import TaskQueue and Task, preferring built-in C code over Python code try: - from _uasyncio import TaskQueue, Task + from _asyncio import TaskQueue, Task except: from .task import TaskQueue, Task diff --git a/extmod/uasyncio/event.py b/extmod/asyncio/event.py similarity index 98% rename from extmod/uasyncio/event.py rename to extmod/asyncio/event.py index 8a90534590..e0b41f7324 100644 --- a/extmod/uasyncio/event.py +++ b/extmod/asyncio/event.py @@ -1,4 +1,4 @@ -# MicroPython uasyncio module +# MicroPython asyncio module # MIT license; Copyright (c) 2019-2020 Damien P. George from . import core diff --git a/extmod/uasyncio/funcs.py b/extmod/asyncio/funcs.py similarity index 99% rename from extmod/uasyncio/funcs.py rename to extmod/asyncio/funcs.py index dc52ad3958..599091dfbd 100644 --- a/extmod/uasyncio/funcs.py +++ b/extmod/asyncio/funcs.py @@ -1,4 +1,4 @@ -# MicroPython uasyncio module +# MicroPython asyncio module # MIT license; Copyright (c) 2019-2022 Damien P. George from . import core diff --git a/extmod/uasyncio/lock.py b/extmod/asyncio/lock.py similarity index 98% rename from extmod/uasyncio/lock.py rename to extmod/asyncio/lock.py index 85a9437b4f..0a46ac3261 100644 --- a/extmod/uasyncio/lock.py +++ b/extmod/asyncio/lock.py @@ -1,4 +1,4 @@ -# MicroPython uasyncio module +# MicroPython asyncio module # MIT license; Copyright (c) 2019-2020 Damien P. George from . import core diff --git a/extmod/uasyncio/manifest.py b/extmod/asyncio/manifest.py similarity index 94% rename from extmod/uasyncio/manifest.py rename to extmod/asyncio/manifest.py index d425a467b3..0aba5b1856 100644 --- a/extmod/uasyncio/manifest.py +++ b/extmod/asyncio/manifest.py @@ -1,7 +1,7 @@ # This list of package files doesn't include task.py because that's provided # by the C module. package( - "uasyncio", + "asyncio", ( "__init__.py", "core.py", diff --git a/extmod/uasyncio/stream.py b/extmod/asyncio/stream.py similarity index 99% rename from extmod/uasyncio/stream.py rename to extmod/asyncio/stream.py index ac297cce04..c47c48cf09 100644 --- a/extmod/uasyncio/stream.py +++ b/extmod/asyncio/stream.py @@ -1,4 +1,4 @@ -# MicroPython uasyncio module +# MicroPython asyncio module # MIT license; Copyright (c) 2019-2020 Damien P. George from . import core diff --git a/extmod/uasyncio/task.py b/extmod/asyncio/task.py similarity index 99% rename from extmod/uasyncio/task.py rename to extmod/asyncio/task.py index 4ead2a1308..30be2170eb 100644 --- a/extmod/uasyncio/task.py +++ b/extmod/asyncio/task.py @@ -1,4 +1,4 @@ -# MicroPython uasyncio module +# MicroPython asyncio module # MIT license; Copyright (c) 2019-2020 Damien P. George # This file contains the core TaskQueue based on a pairing heap, and the core Task class. diff --git a/extmod/extmod.cmake b/extmod/extmod.cmake index 59f07b8ae4..67f33cf91f 100644 --- a/extmod/extmod.cmake +++ b/extmod/extmod.cmake @@ -19,7 +19,7 @@ set(MICROPY_SOURCE_EXTMOD ${MICROPY_EXTMOD_DIR}/modlwip.c ${MICROPY_EXTMOD_DIR}/modnetwork.c ${MICROPY_EXTMOD_DIR}/modonewire.c - ${MICROPY_EXTMOD_DIR}/moduasyncio.c + ${MICROPY_EXTMOD_DIR}/modasyncio.c ${MICROPY_EXTMOD_DIR}/modbinascii.c ${MICROPY_EXTMOD_DIR}/modcryptolib.c ${MICROPY_EXTMOD_DIR}/moductypes.c diff --git a/extmod/extmod.mk b/extmod/extmod.mk index c544e81792..41d200fce4 100644 --- a/extmod/extmod.mk +++ b/extmod/extmod.mk @@ -11,6 +11,7 @@ SRC_EXTMOD_C += \ extmod/machine_signal.c \ extmod/machine_spi.c \ extmod/machine_timer.c \ + extmod/modasyncio.c \ extmod/modbinascii.c \ extmod/modbluetooth.c \ extmod/modbtree.c \ @@ -31,7 +32,6 @@ SRC_EXTMOD_C += \ extmod/modssl_axtls.c \ extmod/modssl_mbedtls.c \ extmod/modtime.c \ - extmod/moduasyncio.c \ extmod/moductypes.c \ extmod/modwebrepl.c \ extmod/modwebsocket.c \ diff --git a/extmod/moduasyncio.c b/extmod/modasyncio.c similarity index 91% rename from extmod/moduasyncio.c rename to extmod/modasyncio.c index c05a8dfc60..a6a54eba87 100644 --- a/extmod/moduasyncio.c +++ b/extmod/modasyncio.c @@ -29,7 +29,7 @@ #include "py/pairheap.h" #include "py/mphal.h" -#if MICROPY_PY_UASYNCIO +#if MICROPY_PY_ASYNCIO // Used when task cannot be guaranteed to be non-NULL. #define TASK_PAIRHEAP(task) ((task) ? &(task)->pairheap : NULL) @@ -155,8 +155,8 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( /******************************************************************************/ // Task class -// This is the core uasyncio context with cur_task, _task_queue and CancelledError. -STATIC mp_obj_t uasyncio_context = MP_OBJ_NULL; +// This is the core asyncio context with cur_task, _task_queue and CancelledError. +STATIC mp_obj_t asyncio_context = MP_OBJ_NULL; STATIC mp_obj_t task_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 2, false); @@ -168,7 +168,7 @@ STATIC mp_obj_t task_make_new(const mp_obj_type_t *type, size_t n_args, size_t n self->state = TASK_STATE_RUNNING_NOT_WAITED_ON; self->ph_key = MP_OBJ_NEW_SMALL_INT(0); if (n_args == 2) { - uasyncio_context = args[1]; + asyncio_context = args[1]; } return MP_OBJ_FROM_PTR(self); } @@ -186,7 +186,7 @@ STATIC mp_obj_t task_cancel(mp_obj_t self_in) { return mp_const_false; } // Can't cancel self (not supported yet). - mp_obj_t cur_task = mp_obj_dict_get(uasyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_cur_task)); + mp_obj_t cur_task = mp_obj_dict_get(asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_cur_task)); if (self_in == cur_task) { mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("can't cancel self")); } @@ -195,7 +195,7 @@ STATIC mp_obj_t task_cancel(mp_obj_t self_in) { self = MP_OBJ_TO_PTR(self->data); } - mp_obj_t _task_queue = mp_obj_dict_get(uasyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR__task_queue)); + mp_obj_t _task_queue = mp_obj_dict_get(asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR__task_queue)); // Reschedule Task as a cancelled task. mp_obj_t dest[3]; @@ -218,7 +218,7 @@ STATIC mp_obj_t task_cancel(mp_obj_t self_in) { task_queue_push(2, dest); } - self->data = mp_obj_dict_get(uasyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_CancelledError)); + self->data = mp_obj_dict_get(asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_CancelledError)); return mp_const_true; } @@ -278,7 +278,7 @@ STATIC mp_obj_t task_iternext(mp_obj_t self_in) { nlr_raise(self->data); } else { // Put calling task on waiting queue. - mp_obj_t cur_task = mp_obj_dict_get(uasyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_cur_task)); + mp_obj_t cur_task = mp_obj_dict_get(asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_cur_task)); mp_obj_t args[2] = { self->state, cur_task }; task_queue_push(2, args); // Set calling task's data to this task that it waits on, to double-link it. @@ -302,20 +302,20 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); /******************************************************************************/ -// C-level uasyncio module +// C-level asyncio module -STATIC const mp_rom_map_elem_t mp_module_uasyncio_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__uasyncio) }, +STATIC const mp_rom_map_elem_t mp_module_asyncio_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__asyncio) }, { MP_ROM_QSTR(MP_QSTR_TaskQueue), MP_ROM_PTR(&task_queue_type) }, { MP_ROM_QSTR(MP_QSTR_Task), MP_ROM_PTR(&task_type) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_uasyncio_globals, mp_module_uasyncio_globals_table); +STATIC MP_DEFINE_CONST_DICT(mp_module_asyncio_globals, mp_module_asyncio_globals_table); -const mp_obj_module_t mp_module_uasyncio = { +const mp_obj_module_t mp_module_asyncio = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&mp_module_uasyncio_globals, + .globals = (mp_obj_dict_t *)&mp_module_asyncio_globals, }; -MP_REGISTER_MODULE(MP_QSTR__uasyncio, mp_module_uasyncio); +MP_REGISTER_MODULE(MP_QSTR__asyncio, mp_module_asyncio); -#endif // MICROPY_PY_UASYNCIO +#endif // MICROPY_PY_ASYNCIO diff --git a/ports/esp32/boards/manifest.py b/ports/esp32/boards/manifest.py index fa851b5eea..290d98c4e4 100644 --- a/ports/esp32/boards/manifest.py +++ b/ports/esp32/boards/manifest.py @@ -1,5 +1,5 @@ freeze("$(PORT_DIR)/modules") -include("$(MPY_DIR)/extmod/uasyncio") +include("$(MPY_DIR)/extmod/asyncio") # Useful networking-related packages. require("bundle-networking") diff --git a/ports/esp8266/boards/GENERIC/manifest.py b/ports/esp8266/boards/GENERIC/manifest.py index ef70884624..fd9c41dc54 100644 --- a/ports/esp8266/boards/GENERIC/manifest.py +++ b/ports/esp8266/boards/GENERIC/manifest.py @@ -1,8 +1,8 @@ # base modules include("$(PORT_DIR)/boards/manifest.py") -# uasyncio -include("$(MPY_DIR)/extmod/uasyncio") +# asyncio +include("$(MPY_DIR)/extmod/asyncio") # drivers require("ssd1306") diff --git a/ports/esp8266/boards/GENERIC_1M/mpconfigboard.h b/ports/esp8266/boards/GENERIC_1M/mpconfigboard.h index f811f70592..41752e692b 100644 --- a/ports/esp8266/boards/GENERIC_1M/mpconfigboard.h +++ b/ports/esp8266/boards/GENERIC_1M/mpconfigboard.h @@ -13,5 +13,5 @@ #define MICROPY_PY_FSTRINGS (0) #define MICROPY_PY_REVERSE_SPECIAL_METHODS (0) -#define MICROPY_PY_UASYNCIO (0) +#define MICROPY_PY_ASYNCIO (0) #define MICROPY_PY_CRYPTOLIB (1) diff --git a/ports/esp8266/boards/GENERIC_512K/mpconfigboard.h b/ports/esp8266/boards/GENERIC_512K/mpconfigboard.h index fc933cd3eb..c29e23d5ad 100644 --- a/ports/esp8266/boards/GENERIC_512K/mpconfigboard.h +++ b/ports/esp8266/boards/GENERIC_512K/mpconfigboard.h @@ -8,6 +8,6 @@ #define MICROPY_PY_ALL_SPECIAL_METHODS (0) #define MICROPY_PY_REVERSE_SPECIAL_METHODS (0) #define MICROPY_PY_SYS_STDIO_BUFFER (0) -#define MICROPY_PY_UASYNCIO (0) +#define MICROPY_PY_ASYNCIO (0) #define MICROPY_PY_RE_SUB (0) #define MICROPY_PY_FRAMEBUF (0) diff --git a/ports/mimxrt/boards/manifest.py b/ports/mimxrt/boards/manifest.py index e4e5a236a3..d7acab3837 100644 --- a/ports/mimxrt/boards/manifest.py +++ b/ports/mimxrt/boards/manifest.py @@ -1,5 +1,5 @@ freeze("$(PORT_DIR)/modules") -include("$(MPY_DIR)/extmod/uasyncio") +include("$(MPY_DIR)/extmod/asyncio") require("onewire") require("ds18x20") require("dht") diff --git a/ports/nrf/modules/manifest.py b/ports/nrf/modules/manifest.py index 6efaf62d79..7ba0f80d88 100644 --- a/ports/nrf/modules/manifest.py +++ b/ports/nrf/modules/manifest.py @@ -1,2 +1,2 @@ module("_mkfs.py", base_path="$(PORT_DIR)/modules/scripts", opt=3) -include("$(MPY_DIR)/extmod/uasyncio") +include("$(MPY_DIR)/extmod/asyncio") diff --git a/ports/renesas-ra/boards/manifest.py b/ports/renesas-ra/boards/manifest.py index 01699c3d6e..c650136f66 100644 --- a/ports/renesas-ra/boards/manifest.py +++ b/ports/renesas-ra/boards/manifest.py @@ -1,4 +1,4 @@ -include("$(MPY_DIR)/extmod/uasyncio") +include("$(MPY_DIR)/extmod/asyncio") require("dht") require("onewire") require("sdcard") diff --git a/ports/rp2/boards/manifest.py b/ports/rp2/boards/manifest.py index e62d02f308..92260f798a 100644 --- a/ports/rp2/boards/manifest.py +++ b/ports/rp2/boards/manifest.py @@ -1,5 +1,5 @@ freeze("$(PORT_DIR)/modules") -include("$(MPY_DIR)/extmod/uasyncio") +include("$(MPY_DIR)/extmod/asyncio") require("onewire") require("ds18x20") require("dht") diff --git a/ports/samd/mcu/samd51/manifest.py b/ports/samd/mcu/samd51/manifest.py index 4a79f6818f..2a19a843f8 100644 --- a/ports/samd/mcu/samd51/manifest.py +++ b/ports/samd/mcu/samd51/manifest.py @@ -1,5 +1,5 @@ include("$(PORT_DIR)/boards/manifest.py") -include("$(MPY_DIR)/extmod/uasyncio") +include("$(MPY_DIR)/extmod/asyncio") require("onewire") require("ds18x20") require("dht") diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h index 8a9947468e..7bf4acb84e 100644 --- a/ports/samd/mpconfigport.h +++ b/ports/samd/mpconfigport.h @@ -92,7 +92,7 @@ #define MICROPY_PY_HEAPQ (1) #define MICROPY_PY_RANDOM (1) #define MICROPY_PY_ZLIB (1) -#define MICROPY_PY_UASYNCIO (1) +#define MICROPY_PY_ASYNCIO (1) #define MICROPY_PY_MACHINE_RTC (1) #ifndef MICROPY_PY_MACHINE_ADC #define MICROPY_PY_MACHINE_ADC (1) diff --git a/ports/stm32/boards/NUCLEO_G474RE/mpconfigboard.h b/ports/stm32/boards/NUCLEO_G474RE/mpconfigboard.h index 336d95c42c..e10f63da73 100644 --- a/ports/stm32/boards/NUCLEO_G474RE/mpconfigboard.h +++ b/ports/stm32/boards/NUCLEO_G474RE/mpconfigboard.h @@ -9,7 +9,7 @@ #define MICROPY_HW_HAS_SWITCH (1) #define MICROPY_HW_HAS_FLASH (0) // QSPI extflash not mounted -#define MICROPY_PY_UASYNCIO (0) +#define MICROPY_PY_ASYNCIO (0) #define MICROPY_PY_ZLIB (0) #define MICROPY_PY_BINASCII (0) #define MICROPY_PY_HASHLIB (0) diff --git a/ports/stm32/boards/manifest.py b/ports/stm32/boards/manifest.py index e6b77f8ab3..4f38179713 100644 --- a/ports/stm32/boards/manifest.py +++ b/ports/stm32/boards/manifest.py @@ -1,4 +1,4 @@ -include("$(MPY_DIR)/extmod/uasyncio") +include("$(MPY_DIR)/extmod/asyncio") require("dht") require("onewire") diff --git a/ports/unix/variants/standard/manifest.py b/ports/unix/variants/standard/manifest.py index dd521258e1..d27bf3c47f 100644 --- a/ports/unix/variants/standard/manifest.py +++ b/ports/unix/variants/standard/manifest.py @@ -1,3 +1,3 @@ include("$(PORT_DIR)/variants/manifest.py") -include("$(MPY_DIR)/extmod/uasyncio") +include("$(MPY_DIR)/extmod/asyncio") diff --git a/ports/windows/msvc/sources.props b/ports/windows/msvc/sources.props index 18d053b811..6277b74e20 100644 --- a/ports/windows/msvc/sources.props +++ b/ports/windows/msvc/sources.props @@ -7,7 +7,7 @@ - + diff --git a/ports/windows/variants/dev/manifest.py b/ports/windows/variants/dev/manifest.py index f65a3d35e9..d5d9cc7959 100644 --- a/ports/windows/variants/dev/manifest.py +++ b/ports/windows/variants/dev/manifest.py @@ -1,2 +1,2 @@ include("$(PORT_DIR)/variants/manifest.py") -include("$(MPY_DIR)/extmod/uasyncio") +include("$(MPY_DIR)/extmod/asyncio") diff --git a/ports/windows/variants/dev/mpconfigvariant.h b/ports/windows/variants/dev/mpconfigvariant.h index d6ce7bf36f..70a4a4d045 100644 --- a/ports/windows/variants/dev/mpconfigvariant.h +++ b/ports/windows/variants/dev/mpconfigvariant.h @@ -38,6 +38,6 @@ #define MICROPY_PY_BUILTINS_SLICE_INDICES (1) #define MICROPY_PY_SELECT (1) -#ifndef MICROPY_PY_UASYNCIO -#define MICROPY_PY_UASYNCIO (1) +#ifndef MICROPY_PY_ASYNCIO +#define MICROPY_PY_ASYNCIO (1) #endif diff --git a/py/mpconfig.h b/py/mpconfig.h index 831fd534fd..2bbe3849b0 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1541,8 +1541,8 @@ typedef double mp_float_t; // Extended modules -#ifndef MICROPY_PY_UASYNCIO -#define MICROPY_PY_UASYNCIO (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +#ifndef MICROPY_PY_ASYNCIO +#define MICROPY_PY_ASYNCIO (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif #ifndef MICROPY_PY_UCTYPES