usys: Add version info.

Fixes https://github.com/pybricks/pybricks-api/issues/119
This commit is contained in:
Laurens Valk
2022-12-01 15:02:25 +01:00
parent 553490874b
commit 3c0aaea207
6 changed files with 71 additions and 14 deletions
+25
View File
@@ -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.
@@ -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)
@@ -0,0 +1,4 @@
from pybricks import version
# ('essentialhub', '3.2.0b5', 'v3.2.0b5 on 2022-11-11')
print(version)
+3
View File
@@ -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",
]
+2 -2
View File
@@ -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",
)
+27 -12
View File
@@ -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 <micropython.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."""