From 0865a5863230b0d1a42d20d87fa99e855ecbeb3d Mon Sep 17 00:00:00 2001 From: David Lechner Date: Tue, 6 Jul 2021 15:53:06 -0500 Subject: [PATCH] uerrno: add uerrno module stubs and docs Issue: https://github.com/pybricks/support/issues/236 --- doc/api/index.rst | 1 + doc/api/uerrno.rst | 4 +++ pyproject.toml | 1 + src/uerrno/__init__.py | 69 ++++++++++++++++++++++++++++++++++++++++++ src/uerrno/py.typed | 0 5 files changed, 75 insertions(+) create mode 100644 doc/api/uerrno.rst create mode 100644 src/uerrno/__init__.py create mode 100644 src/uerrno/py.typed diff --git a/doc/api/index.rst b/doc/api/index.rst index ccb6f0b..f7d60c9 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -78,6 +78,7 @@ findings on our `support page`_ so we can make Pybricks even better. :hidden: micropython + uerrno .. toctree:: :maxdepth: 1 diff --git a/doc/api/uerrno.rst b/doc/api/uerrno.rst new file mode 100644 index 0000000..138a2b3 --- /dev/null +++ b/doc/api/uerrno.rst @@ -0,0 +1,4 @@ +:mod:`uerrno` -- System error codes +=================================== + +.. automodule:: uerrno diff --git a/pyproject.toml b/pyproject.toml index 7264de4..3f7c5df 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,7 @@ classifiers = [ packages = [ { include = "pybricks", from = "src" }, { include = "micropython", from = "src" }, + { include = "uerrno", from = "src" }, ] [tool.poetry.dependencies] diff --git a/src/uerrno/__init__.py b/src/uerrno/__init__.py new file mode 100644 index 0000000..d42e17f --- /dev/null +++ b/src/uerrno/__init__.py @@ -0,0 +1,69 @@ +# SPDX-License-Identifier: MIT +# Copyright (c) 2021 The Pybricks Authors +# +# Portions of documentation copied from: +# https://raw.githubusercontent.com/micropython/micropython/1e6d18c915ccea0b6a19ffec9710d33dd7e5f866/docs/library/uerrno.rst +# Copyright (c) 2014-2021, Damien P. George, Paul Sokolovsky, and contributors + +""" +This module provides access to symbolic error codes for `OSError` exception. +""" + +from typing import Dict + +EAGAIN: int +""" +The operation is not complete and should be tried again soon. +""" + +EBUSY: int +""" +The device or resource is busy and cannot be used right now. +""" + +ECANCELED: int +""" +The operation was canceled. +""" + +EINVAL: int +""" +An invalid argument was given. Usually ``ValueError`` is used instead. +""" + +EIO: int +""" +An unspecified error occurred. +""" + +ENODEV: int +""" +Device was not found. For example, a sensor or motor is not plugged in the correct port. +""" + +EOPNOTSUPP: int +""" +The operation is not supported on this hub or on the connected device. +""" + +EPERM: int +""" +The operation cannot be performed in the current state. +""" + +ETIMEDOUT: int +""" +The operation timed out. +""" + +# TODO: ev3dev has additional constants +# https://github.com/pybricks/pybricks-micropython/blob/11f19bc9c24fde66aa8ad42233a345e6683f5beb/bricks/ev3dev/mpconfigport.h#L156-L203 + +errorcode: Dict[int, str] +""" +Dictionary mapping numeric error codes to strings with symbolic error +code (see above):: + + >>> print(uerrno.errorcode[uerrno.EEXIST]) + EEXIST +""" diff --git a/src/uerrno/py.typed b/src/uerrno/py.typed new file mode 100644 index 0000000..e69de29