Skip to content

Commit

Permalink
extmod/asyncio: Rename uasyncio to asyncio.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jimmo authored and dpgeorge committed Jun 19, 2023
1 parent ed962f1 commit 2fbc08c
Show file tree
Hide file tree
Showing 28 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion extmod/uasyncio/__init__.py → extmod/asyncio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MicroPython uasyncio module
# MicroPython asyncio module
# MIT license; Copyright (c) 2019 Damien P. George

from .core import *
Expand Down
4 changes: 2 additions & 2 deletions extmod/uasyncio/core.py → extmod/asyncio/core.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# 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
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

Expand Down
2 changes: 1 addition & 1 deletion extmod/uasyncio/event.py → extmod/asyncio/event.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MicroPython uasyncio module
# MicroPython asyncio module
# MIT license; Copyright (c) 2019-2020 Damien P. George

from . import core
Expand Down
2 changes: 1 addition & 1 deletion extmod/uasyncio/funcs.py → extmod/asyncio/funcs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MicroPython uasyncio module
# MicroPython asyncio module
# MIT license; Copyright (c) 2019-2022 Damien P. George

from . import core
Expand Down
2 changes: 1 addition & 1 deletion extmod/uasyncio/lock.py → extmod/asyncio/lock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MicroPython uasyncio module
# MicroPython asyncio module
# MIT license; Copyright (c) 2019-2020 Damien P. George

from . import core
Expand Down
2 changes: 1 addition & 1 deletion extmod/uasyncio/manifest.py → extmod/asyncio/manifest.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion extmod/uasyncio/stream.py → extmod/asyncio/stream.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MicroPython uasyncio module
# MicroPython asyncio module
# MIT license; Copyright (c) 2019-2020 Damien P. George

from . import core
Expand Down
2 changes: 1 addition & 1 deletion extmod/uasyncio/task.py → extmod/asyncio/task.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion extmod/extmod.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion extmod/extmod.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down
32 changes: 16 additions & 16 deletions extmod/moduasyncio.c → extmod/modasyncio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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"));
}
Expand All @@ -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];
Expand All @@ -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;
}
Expand Down Expand Up @@ -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.
Expand All @@ -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
2 changes: 1 addition & 1 deletion ports/esp32/boards/manifest.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
4 changes: 2 additions & 2 deletions ports/esp8266/boards/GENERIC/manifest.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
2 changes: 1 addition & 1 deletion ports/esp8266/boards/GENERIC_1M/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion ports/esp8266/boards/GENERIC_512K/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion ports/mimxrt/boards/manifest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
freeze("$(PORT_DIR)/modules")
include("$(MPY_DIR)/extmod/uasyncio")
include("$(MPY_DIR)/extmod/asyncio")
require("onewire")
require("ds18x20")
require("dht")
2 changes: 1 addition & 1 deletion ports/nrf/modules/manifest.py
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 1 addition & 1 deletion ports/renesas-ra/boards/manifest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include("$(MPY_DIR)/extmod/uasyncio")
include("$(MPY_DIR)/extmod/asyncio")
require("dht")
require("onewire")
require("sdcard")
2 changes: 1 addition & 1 deletion ports/rp2/boards/manifest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
freeze("$(PORT_DIR)/modules")
include("$(MPY_DIR)/extmod/uasyncio")
include("$(MPY_DIR)/extmod/asyncio")
require("onewire")
require("ds18x20")
require("dht")
Expand Down
2 changes: 1 addition & 1 deletion ports/samd/mcu/samd51/manifest.py
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 1 addition & 1 deletion ports/samd/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ports/stm32/boards/NUCLEO_G474RE/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ports/stm32/boards/manifest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include("$(MPY_DIR)/extmod/uasyncio")
include("$(MPY_DIR)/extmod/asyncio")

require("dht")
require("onewire")
2 changes: 1 addition & 1 deletion ports/unix/variants/standard/manifest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include("$(PORT_DIR)/variants/manifest.py")

include("$(MPY_DIR)/extmod/uasyncio")
include("$(MPY_DIR)/extmod/asyncio")
2 changes: 1 addition & 1 deletion ports/windows/msvc/sources.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PyExtModSource Include="$(PyBaseDir)extmod\machine_pinbase.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\machine_pulse.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\moductypes.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\modhashlib.c" />
Expand Down
2 changes: 1 addition & 1 deletion ports/windows/variants/dev/manifest.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include("$(PORT_DIR)/variants/manifest.py")
include("$(MPY_DIR)/extmod/uasyncio")
include("$(MPY_DIR)/extmod/asyncio")
4 changes: 2 additions & 2 deletions ports/windows/variants/dev/mpconfigvariant.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions py/mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2fbc08c

Please sign in to comment.