From 3c0aaea20780084f805c478eb6c5a037cb1e7d3f Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Thu, 1 Dec 2022 15:00:39 +0100 Subject: [PATCH] usys: Add version info. Fixes https://github.com/pybricks/pybricks-api/issues/119 --- doc/main/micropython/usys.rst | 25 ++++++++++++ .../micropython/usys/micropython_version.py | 10 +++++ examples/micropython/usys/pybricks_version.py | 4 ++ jedi/tests/test_complete_import.py | 3 ++ src/pybricks/__init__.py | 4 +- src/usys/__init__.py | 39 +++++++++++++------ 6 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 examples/micropython/usys/micropython_version.py create mode 100644 examples/micropython/usys/pybricks_version.py diff --git a/doc/main/micropython/usys.rst b/doc/main/micropython/usys.rst index aabfe84..8023ac1 100644 --- a/doc/main/micropython/usys.rst +++ b/doc/main/micropython/usys.rst @@ -5,6 +5,8 @@ This MicroPython module is a subset of the `sys module`_ in Python. +.. rubric:: Input and output streams + .. module:: usys .. autodata:: usys.stdin @@ -16,9 +18,32 @@ This MicroPython module is a subset of the `sys module`_ in Python. .. autodata:: usys.stderr :annotation: +.. rubric:: Version info + +.. autodata:: implementation + :annotation: + +.. autodata:: version + :annotation: + +.. autodata:: version_info + :annotation: + Examples --------------- +Version information +******************************* + +.. literalinclude:: + ../../../examples/micropython/usys/pybricks_version.py + +.. literalinclude:: + ../../../examples/micropython/usys/micropython_version.py + +Standard input and output +******************************* + The ``stdin`` stream can be used to capture input via the Pybricks Code input/output window. See the `keyboard input`_ project to learn how this works. This approach can be extended to exchange data with any `other device`_ as well. diff --git a/examples/micropython/usys/micropython_version.py b/examples/micropython/usys/micropython_version.py new file mode 100644 index 0000000..2bafc81 --- /dev/null +++ b/examples/micropython/usys/micropython_version.py @@ -0,0 +1,10 @@ +import usys + +# ('micropython', (1, 19, 1), 'SPIKE Essential Hub with STM32F413RG', 6) +print(usys.implementation) + +# '3.4.0; Pybricks MicroPython v3.2.0b5 on 2022-11-11' +print(usys.version) + +# (3, 4, 0) +print(usys.version_info) diff --git a/examples/micropython/usys/pybricks_version.py b/examples/micropython/usys/pybricks_version.py new file mode 100644 index 0000000..5f3d124 --- /dev/null +++ b/examples/micropython/usys/pybricks_version.py @@ -0,0 +1,4 @@ +from pybricks import version + +# ('essentialhub', '3.2.0b5', 'v3.2.0b5 on 2022-11-11') +print(version) diff --git a/jedi/tests/test_complete_import.py b/jedi/tests/test_complete_import.py index 7e85928..48dd6cd 100644 --- a/jedi/tests/test_complete_import.py +++ b/jedi/tests/test_complete_import.py @@ -251,7 +251,10 @@ def test_from_usys_import(): code = "from usys import " completions: list[CompletionItem] = json.loads(complete(code, 1, len(code) + 1)) assert [c["insertText"] for c in completions] == [ + "implementation", "stderr", "stdin", "stdout", + "version", + "version_info", ] diff --git a/src/pybricks/__init__.py b/src/pybricks/__init__.py index 712e14b..ffceb7b 100644 --- a/src/pybricks/__init__.py +++ b/src/pybricks/__init__.py @@ -3,6 +3,6 @@ from typing import Tuple version: Tuple[str, str, str] = ( "hub", - "3.2.0b1", - "v3.2.0b1-GIT_HASH on DATE", + "3.X.YbZ", + "v3.X.YbZ-GIT_HASH on DATE", ) diff --git a/src/usys/__init__.py b/src/usys/__init__.py index 0f0cf6d..f8b8b81 100644 --- a/src/usys/__init__.py +++ b/src/usys/__init__.py @@ -9,30 +9,45 @@ This module provides a subset of the standard Python ``sys`` module. """ +from typing import Tuple + from uio import FileIO as _FileIO stdin: _FileIO = _FileIO() """ -This is a stream object (:class:`uio.FileIO`) that receives input from a connected -terminal, if any. +This is a stream object (:class:`uio.FileIO`) that receives input from a +connected terminal, if any. -Writing may modify newline characters. Use ``stdin.buffer`` instead if -this is undesirable. - -Also see :func:`micropython.kbd_intr` to disable ``KeyboardInterrupt`` if you -are passing binary data via ``stdin``. +Also see :func:`kbd_intr ` to disable +``KeyboardInterrupt`` when passing binary data via ``stdin``. """ stdout: _FileIO = _FileIO() """ -This is a stream object (:class:`uio.FileIO`) that sends output to a connected terminal, -if any. - -Reading may modify newline characters. Use ``stdout.buffer`` instead if -this is undesirable. +This is a stream object (:class:`uio.FileIO`) that sends output to a connected +terminal, if any. """ stderr: _FileIO = _FileIO() """ Alias for :data:`stdout`. """ + +implementation: Tuple[str, Tuple[int, int, int], str, int] = ( + "micropython", + (1, 19, 1), + "NAME Hub with PROCESSOR", + 6, +) +""" +MicroPython version tuple. See format and example below. +""" + +version: str = "3.4.0; Pybricks MicroPython v3.2.0b5 on 2022-11-11" +""" +Python compatibility version, Pybricks version, and build date. +See format and example below. +""" + +version_info: Tuple[int, int, int] = (3, 4, 0) +"""Python compatibility version. See format and example below."""