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 <jim.mussared@gmail.com>
This commit is contained in:
Jim Mussared 2023-06-08 15:51:50 +10:00 committed by Damien George
parent ed962f1f23
commit 2fbc08c462
28 changed files with 47 additions and 47 deletions

View File

@ -1,4 +1,4 @@
# MicroPython uasyncio module # MicroPython asyncio module
# MIT license; Copyright (c) 2019 Damien P. George # MIT license; Copyright (c) 2019 Damien P. George
from .core import * from .core import *

View File

@ -1,4 +1,4 @@
# MicroPython uasyncio module # MicroPython asyncio module
# MIT license; Copyright (c) 2019 Damien P. George # MIT license; Copyright (c) 2019 Damien P. George
from time import ticks_ms as ticks, ticks_diff, ticks_add 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 # Import TaskQueue and Task, preferring built-in C code over Python code
try: try:
from _uasyncio import TaskQueue, Task from _asyncio import TaskQueue, Task
except: except:
from .task import TaskQueue, Task from .task import TaskQueue, Task

View File

@ -1,4 +1,4 @@
# MicroPython uasyncio module # MicroPython asyncio module
# MIT license; Copyright (c) 2019-2020 Damien P. George # MIT license; Copyright (c) 2019-2020 Damien P. George
from . import core from . import core

View File

@ -1,4 +1,4 @@
# MicroPython uasyncio module # MicroPython asyncio module
# MIT license; Copyright (c) 2019-2022 Damien P. George # MIT license; Copyright (c) 2019-2022 Damien P. George
from . import core from . import core

View File

@ -1,4 +1,4 @@
# MicroPython uasyncio module # MicroPython asyncio module
# MIT license; Copyright (c) 2019-2020 Damien P. George # MIT license; Copyright (c) 2019-2020 Damien P. George
from . import core from . import core

View File

@ -1,7 +1,7 @@
# This list of package files doesn't include task.py because that's provided # This list of package files doesn't include task.py because that's provided
# by the C module. # by the C module.
package( package(
"uasyncio", "asyncio",
( (
"__init__.py", "__init__.py",
"core.py", "core.py",

View File

@ -1,4 +1,4 @@
# MicroPython uasyncio module # MicroPython asyncio module
# MIT license; Copyright (c) 2019-2020 Damien P. George # MIT license; Copyright (c) 2019-2020 Damien P. George
from . import core from . import core

View File

@ -1,4 +1,4 @@
# MicroPython uasyncio module # MicroPython asyncio module
# MIT license; Copyright (c) 2019-2020 Damien P. George # 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. # This file contains the core TaskQueue based on a pairing heap, and the core Task class.

View File

@ -19,7 +19,7 @@ set(MICROPY_SOURCE_EXTMOD
${MICROPY_EXTMOD_DIR}/modlwip.c ${MICROPY_EXTMOD_DIR}/modlwip.c
${MICROPY_EXTMOD_DIR}/modnetwork.c ${MICROPY_EXTMOD_DIR}/modnetwork.c
${MICROPY_EXTMOD_DIR}/modonewire.c ${MICROPY_EXTMOD_DIR}/modonewire.c
${MICROPY_EXTMOD_DIR}/moduasyncio.c ${MICROPY_EXTMOD_DIR}/modasyncio.c
${MICROPY_EXTMOD_DIR}/modbinascii.c ${MICROPY_EXTMOD_DIR}/modbinascii.c
${MICROPY_EXTMOD_DIR}/modcryptolib.c ${MICROPY_EXTMOD_DIR}/modcryptolib.c
${MICROPY_EXTMOD_DIR}/moductypes.c ${MICROPY_EXTMOD_DIR}/moductypes.c

View File

@ -11,6 +11,7 @@ SRC_EXTMOD_C += \
extmod/machine_signal.c \ extmod/machine_signal.c \
extmod/machine_spi.c \ extmod/machine_spi.c \
extmod/machine_timer.c \ extmod/machine_timer.c \
extmod/modasyncio.c \
extmod/modbinascii.c \ extmod/modbinascii.c \
extmod/modbluetooth.c \ extmod/modbluetooth.c \
extmod/modbtree.c \ extmod/modbtree.c \
@ -31,7 +32,6 @@ SRC_EXTMOD_C += \
extmod/modssl_axtls.c \ extmod/modssl_axtls.c \
extmod/modssl_mbedtls.c \ extmod/modssl_mbedtls.c \
extmod/modtime.c \ extmod/modtime.c \
extmod/moduasyncio.c \
extmod/moductypes.c \ extmod/moductypes.c \
extmod/modwebrepl.c \ extmod/modwebrepl.c \
extmod/modwebsocket.c \ extmod/modwebsocket.c \

View File

@ -29,7 +29,7 @@
#include "py/pairheap.h" #include "py/pairheap.h"
#include "py/mphal.h" #include "py/mphal.h"
#if MICROPY_PY_UASYNCIO #if MICROPY_PY_ASYNCIO
// Used when task cannot be guaranteed to be non-NULL. // Used when task cannot be guaranteed to be non-NULL.
#define TASK_PAIRHEAP(task) ((task) ? &(task)->pairheap : NULL) #define TASK_PAIRHEAP(task) ((task) ? &(task)->pairheap : NULL)
@ -155,8 +155,8 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE(
/******************************************************************************/ /******************************************************************************/
// Task class // Task class
// This is the core uasyncio context with cur_task, _task_queue and CancelledError. // This is the core asyncio context with cur_task, _task_queue and CancelledError.
STATIC mp_obj_t uasyncio_context = MP_OBJ_NULL; 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) { 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); 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->state = TASK_STATE_RUNNING_NOT_WAITED_ON;
self->ph_key = MP_OBJ_NEW_SMALL_INT(0); self->ph_key = MP_OBJ_NEW_SMALL_INT(0);
if (n_args == 2) { if (n_args == 2) {
uasyncio_context = args[1]; asyncio_context = args[1];
} }
return MP_OBJ_FROM_PTR(self); 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; return mp_const_false;
} }
// Can't cancel self (not supported yet). // 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) { if (self_in == cur_task) {
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("can't cancel self")); 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); 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. // Reschedule Task as a cancelled task.
mp_obj_t dest[3]; 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); 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; return mp_const_true;
} }
@ -278,7 +278,7 @@ STATIC mp_obj_t task_iternext(mp_obj_t self_in) {
nlr_raise(self->data); nlr_raise(self->data);
} else { } else {
// Put calling task on waiting queue. // 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 }; mp_obj_t args[2] = { self->state, cur_task };
task_queue_push(2, args); task_queue_push(2, args);
// Set calling task's data to this task that it waits on, to double-link it. // 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[] = { STATIC const mp_rom_map_elem_t mp_module_asyncio_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__uasyncio) }, { 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_TaskQueue), MP_ROM_PTR(&task_queue_type) },
{ MP_ROM_QSTR(MP_QSTR_Task), MP_ROM_PTR(&task_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 }, .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

View File

@ -1,5 +1,5 @@
freeze("$(PORT_DIR)/modules") freeze("$(PORT_DIR)/modules")
include("$(MPY_DIR)/extmod/uasyncio") include("$(MPY_DIR)/extmod/asyncio")
# Useful networking-related packages. # Useful networking-related packages.
require("bundle-networking") require("bundle-networking")

View File

@ -1,8 +1,8 @@
# base modules # base modules
include("$(PORT_DIR)/boards/manifest.py") include("$(PORT_DIR)/boards/manifest.py")
# uasyncio # asyncio
include("$(MPY_DIR)/extmod/uasyncio") include("$(MPY_DIR)/extmod/asyncio")
# drivers # drivers
require("ssd1306") require("ssd1306")

View File

@ -13,5 +13,5 @@
#define MICROPY_PY_FSTRINGS (0) #define MICROPY_PY_FSTRINGS (0)
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (0) #define MICROPY_PY_REVERSE_SPECIAL_METHODS (0)
#define MICROPY_PY_UASYNCIO (0) #define MICROPY_PY_ASYNCIO (0)
#define MICROPY_PY_CRYPTOLIB (1) #define MICROPY_PY_CRYPTOLIB (1)

View File

@ -8,6 +8,6 @@
#define MICROPY_PY_ALL_SPECIAL_METHODS (0) #define MICROPY_PY_ALL_SPECIAL_METHODS (0)
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (0) #define MICROPY_PY_REVERSE_SPECIAL_METHODS (0)
#define MICROPY_PY_SYS_STDIO_BUFFER (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_RE_SUB (0)
#define MICROPY_PY_FRAMEBUF (0) #define MICROPY_PY_FRAMEBUF (0)

View File

@ -1,5 +1,5 @@
freeze("$(PORT_DIR)/modules") freeze("$(PORT_DIR)/modules")
include("$(MPY_DIR)/extmod/uasyncio") include("$(MPY_DIR)/extmod/asyncio")
require("onewire") require("onewire")
require("ds18x20") require("ds18x20")
require("dht") require("dht")

View File

@ -1,2 +1,2 @@
module("_mkfs.py", base_path="$(PORT_DIR)/modules/scripts", opt=3) module("_mkfs.py", base_path="$(PORT_DIR)/modules/scripts", opt=3)
include("$(MPY_DIR)/extmod/uasyncio") include("$(MPY_DIR)/extmod/asyncio")

View File

@ -1,4 +1,4 @@
include("$(MPY_DIR)/extmod/uasyncio") include("$(MPY_DIR)/extmod/asyncio")
require("dht") require("dht")
require("onewire") require("onewire")
require("sdcard") require("sdcard")

View File

@ -1,5 +1,5 @@
freeze("$(PORT_DIR)/modules") freeze("$(PORT_DIR)/modules")
include("$(MPY_DIR)/extmod/uasyncio") include("$(MPY_DIR)/extmod/asyncio")
require("onewire") require("onewire")
require("ds18x20") require("ds18x20")
require("dht") require("dht")

View File

@ -1,5 +1,5 @@
include("$(PORT_DIR)/boards/manifest.py") include("$(PORT_DIR)/boards/manifest.py")
include("$(MPY_DIR)/extmod/uasyncio") include("$(MPY_DIR)/extmod/asyncio")
require("onewire") require("onewire")
require("ds18x20") require("ds18x20")
require("dht") require("dht")

View File

@ -92,7 +92,7 @@
#define MICROPY_PY_HEAPQ (1) #define MICROPY_PY_HEAPQ (1)
#define MICROPY_PY_RANDOM (1) #define MICROPY_PY_RANDOM (1)
#define MICROPY_PY_ZLIB (1) #define MICROPY_PY_ZLIB (1)
#define MICROPY_PY_UASYNCIO (1) #define MICROPY_PY_ASYNCIO (1)
#define MICROPY_PY_MACHINE_RTC (1) #define MICROPY_PY_MACHINE_RTC (1)
#ifndef MICROPY_PY_MACHINE_ADC #ifndef MICROPY_PY_MACHINE_ADC
#define MICROPY_PY_MACHINE_ADC (1) #define MICROPY_PY_MACHINE_ADC (1)

View File

@ -9,7 +9,7 @@
#define MICROPY_HW_HAS_SWITCH (1) #define MICROPY_HW_HAS_SWITCH (1)
#define MICROPY_HW_HAS_FLASH (0) // QSPI extflash not mounted #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_ZLIB (0)
#define MICROPY_PY_BINASCII (0) #define MICROPY_PY_BINASCII (0)
#define MICROPY_PY_HASHLIB (0) #define MICROPY_PY_HASHLIB (0)

View File

@ -1,4 +1,4 @@
include("$(MPY_DIR)/extmod/uasyncio") include("$(MPY_DIR)/extmod/asyncio")
require("dht") require("dht")
require("onewire") require("onewire")

View File

@ -1,3 +1,3 @@
include("$(PORT_DIR)/variants/manifest.py") include("$(PORT_DIR)/variants/manifest.py")
include("$(MPY_DIR)/extmod/uasyncio") include("$(MPY_DIR)/extmod/asyncio")

View File

@ -7,7 +7,7 @@
<PyExtModSource Include="$(PyBaseDir)extmod\machine_pinbase.c" /> <PyExtModSource Include="$(PyBaseDir)extmod\machine_pinbase.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\machine_pulse.c" /> <PyExtModSource Include="$(PyBaseDir)extmod\machine_pulse.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\machine_signal.c" /> <PyExtModSource Include="$(PyBaseDir)extmod\machine_signal.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\moduasyncio.c" /> <PyExtModSource Include="$(PyBaseDir)extmod\modasyncio.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\modbinascii.c" /> <PyExtModSource Include="$(PyBaseDir)extmod\modbinascii.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\moductypes.c" /> <PyExtModSource Include="$(PyBaseDir)extmod\moductypes.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\modhashlib.c" /> <PyExtModSource Include="$(PyBaseDir)extmod\modhashlib.c" />

View File

@ -1,2 +1,2 @@
include("$(PORT_DIR)/variants/manifest.py") include("$(PORT_DIR)/variants/manifest.py")
include("$(MPY_DIR)/extmod/uasyncio") include("$(MPY_DIR)/extmod/asyncio")

View File

@ -38,6 +38,6 @@
#define MICROPY_PY_BUILTINS_SLICE_INDICES (1) #define MICROPY_PY_BUILTINS_SLICE_INDICES (1)
#define MICROPY_PY_SELECT (1) #define MICROPY_PY_SELECT (1)
#ifndef MICROPY_PY_UASYNCIO #ifndef MICROPY_PY_ASYNCIO
#define MICROPY_PY_UASYNCIO (1) #define MICROPY_PY_ASYNCIO (1)
#endif #endif

View File

@ -1541,8 +1541,8 @@ typedef double mp_float_t;
// Extended modules // Extended modules
#ifndef MICROPY_PY_UASYNCIO #ifndef MICROPY_PY_ASYNCIO
#define MICROPY_PY_UASYNCIO (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #define MICROPY_PY_ASYNCIO (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
#endif #endif
#ifndef MICROPY_PY_UCTYPES #ifndef MICROPY_PY_UCTYPES