Skip to content

Commit

Permalink
usys: Add version info.
Browse files Browse the repository at this point in the history
Fixes #119
  • Loading branch information
laurensvalk committed Dec 1, 2022
1 parent 5534908 commit e51ae3e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 14 deletions.
25 changes: 25 additions & 0 deletions doc/main/micropython/usys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions examples/micropython/usys/micropython_version.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions examples/micropython/usys/pybricks_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from pybricks import version

# ('essentialhub', '3.2.0b5', 'v3.2.0b5 on 2022-11-11')
print(version)
4 changes: 2 additions & 2 deletions src/pybricks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

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",
)
39 changes: 27 additions & 12 deletions src/usys/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Writing may modify newline characters. Use ``stdin.buffer`` instead if
this is undesirable.
This is a stream object (:class:`uio.FileIO`) that receives input from a
connected terminal, if any.
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."""

0 comments on commit e51ae3e

Please sign in to comment.