Skip to content

Commit

Permalink
all: Rename "sys" module to "usys".
Browse files Browse the repository at this point in the history
This is consistent with the other 'micro' modules and allows implementing
additional features in Python via e.g. micropython-lib's sys.

Note this is a breaking change (not backwards compatible) for ports which
do not enable weak links, as "import sys" must now be replaced with
"import usys".
  • Loading branch information
stinos authored and dpgeorge committed Sep 3, 2020
1 parent b0932fc commit 40ad8f1
Show file tree
Hide file tree
Showing 46 changed files with 142 additions and 89 deletions.
2 changes: 1 addition & 1 deletion docs/library/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ it will fallback to loading the built-in ``ujson`` module.
cmath.rst
gc.rst
math.rst
sys.rst
uarray.rst
uasyncio.rst
ubinascii.rst
Expand All @@ -93,6 +92,7 @@ it will fallback to loading the built-in ``ujson`` module.
usocket.rst
ussl.rst
ustruct.rst
usys.rst
utime.rst
uzlib.rst
_thread.rst
Expand Down
14 changes: 7 additions & 7 deletions docs/library/sys.rst → docs/library/usys.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
:mod:`sys` -- system specific functions
=======================================
:mod:`usys` -- system specific functions
========================================

.. module:: sys
.. module:: usys
:synopsis: system specific functions

|see_cpython_module| :mod:`python:sys`.
Expand All @@ -28,10 +28,10 @@ Functions
This function is a MicroPython extension intended to provide similar
functionality to the :mod:`atexit` module in CPython.

.. function:: print_exception(exc, file=sys.stdout, /)
.. function:: print_exception(exc, file=usys.stdout, /)

Print exception with a traceback to a file-like object *file* (or
`sys.stdout` by default).
`usys.stdout` by default).

.. admonition:: Difference to CPython
:class: attention
Expand Down Expand Up @@ -84,7 +84,7 @@ Constants
value directly, but instead count number of bits in it::

bits = 0
v = sys.maxsize
v = usys.maxsize
while v:
bits += 1
v >>= 1
Expand Down Expand Up @@ -113,7 +113,7 @@ Constants
is an identifier of a board, e.g. ``"pyboard"`` for the original MicroPython
reference board. It thus can be used to distinguish one board from another.
If you need to check whether your program runs on MicroPython (vs other
Python implementation), use `sys.implementation` instead.
Python implementation), use `usys.implementation` instead.

.. data:: stderr

Expand Down
10 changes: 5 additions & 5 deletions drivers/nrf24l01/nrf24l01test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Test for nrf24l01 module. Portable between MicroPython targets."""

import sys
import usys
import ustruct as struct
import utime
from machine import Pin, SPI
Expand All @@ -14,14 +14,14 @@
# master may be a slow device. Value tested with Pyboard, ESP32 and ESP8266.
_SLAVE_SEND_DELAY = const(10)

if sys.platform == "pyboard":
if usys.platform == "pyboard":
cfg = {"spi": 2, "miso": "Y7", "mosi": "Y8", "sck": "Y6", "csn": "Y5", "ce": "Y4"}
elif sys.platform == "esp8266": # Hardware SPI
elif usys.platform == "esp8266": # Hardware SPI
cfg = {"spi": 1, "miso": 12, "mosi": 13, "sck": 14, "csn": 4, "ce": 5}
elif sys.platform == "esp32": # Software SPI
elif usys.platform == "esp32": # Software SPI
cfg = {"spi": -1, "miso": 32, "mosi": 33, "sck": 25, "csn": 26, "ce": 27}
else:
raise ValueError("Unsupported platform {}".format(sys.platform))
raise ValueError("Unsupported platform {}".format(usys.platform))

# Addresses are in little-endian format. They correspond to big-endian
# 0xf0f0f0f0e1, 0xf0f0f0f0d2
Expand Down
5 changes: 4 additions & 1 deletion extmod/webrepl/websocket_helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import sys
try:
import usys as sys
except ImportError:
import sys

try:
import ubinascii as binascii
Expand Down
2 changes: 1 addition & 1 deletion py/objmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = {
#endif
#endif
#if MICROPY_PY_SYS
{ MP_ROM_QSTR(MP_QSTR_sys), MP_ROM_PTR(&mp_module_sys) },
{ MP_ROM_QSTR(MP_QSTR_usys), MP_ROM_PTR(&mp_module_sys) },
#endif
#if MICROPY_PY_GC && MICROPY_ENABLE_GC
{ MP_ROM_QSTR(MP_QSTR_gc), MP_ROM_PTR(&mp_module_gc) },
Expand Down
5 changes: 4 additions & 1 deletion tests/basics/async_await2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# test await expression

import sys
try:
import usys as sys
except ImportError:
import sys
if sys.implementation.name == 'micropython':
# uPy allows normal generators to be awaitables
coroutine = lambda f: f
Expand Down
5 changes: 4 additions & 1 deletion tests/basics/async_for2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# test waiting within "async for" __anext__ function

import sys
try:
import usys as sys
except ImportError:
import sys
if sys.implementation.name == 'micropython':
# uPy allows normal generators to be awaitables
coroutine = lambda f: f
Expand Down
5 changes: 4 additions & 1 deletion tests/basics/async_with2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# test waiting within async with enter/exit functions

import sys
try:
import usys as sys
except ImportError:
import sys
if sys.implementation.name == 'micropython':
# uPy allows normal generators to be awaitables
coroutine = lambda f: f
Expand Down
5 changes: 4 additions & 1 deletion tests/basics/attrtuple1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# test attrtuple
# we can't test this type directly so we use sys.implementation object

import sys
try:
import usys as sys
except ImportError:
import sys
t = sys.implementation

# It can be just a normal tuple on small ports
Expand Down
5 changes: 4 additions & 1 deletion tests/basics/builtin_callable.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
print(callable("dfsd"))

# modules should not be callabe
import sys
try:
import usys as sys
except ImportError:
import sys
print(callable(sys))

# builtins should be callable
Expand Down
5 changes: 4 additions & 1 deletion tests/basics/builtin_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
print('__name__' in dir())

# dir of module
import sys
try:
import usys as sys
except ImportError:
import sys
print('version' in dir(sys))

# dir of type
Expand Down
5 changes: 4 additions & 1 deletion tests/basics/int_big1.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@
x = -4611686018427387904 # big

# sys.maxsize is a constant mpz, so test it's compatible with dynamic ones
import sys
try:
import usys as sys
except ImportError:
import sys
print(sys.maxsize + 1 - 1 == sys.maxsize)

# test extraction of big int value via mp_obj_get_int_maybe
Expand Down
4 changes: 2 additions & 2 deletions tests/basics/module2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# uPy behaviour only: builtin modules are read-only
import sys
import usys
try:
sys.x = 1
usys.x = 1
except AttributeError:
print("AttributeError")
6 changes: 3 additions & 3 deletions tests/basics/python34.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def test_syntax(code):

# from basics/sys1.py
# uPy prints version 3.4
import sys
print(sys.version[:3])
print(sys.version_info[0], sys.version_info[1])
import usys
print(usys.version[:3])
print(usys.version_info[0], usys.version_info[1])

# from basics/exception1.py
# in 3.7 no comma is printed if there is only 1 arg (in 3.4-3.6 one is printed)
Expand Down
5 changes: 4 additions & 1 deletion tests/basics/string_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@

# this tests an internal string that doesn't have a hash with a string
# that does have a hash, but the lengths of the two strings are different
import sys
try:
import usys as sys
except ImportError:
import sys
print(sys.version == 'a long string that has a hash')

# this special string would have a hash of 0 but is incremented to 1
Expand Down
5 changes: 4 additions & 1 deletion tests/basics/sys1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# test sys module

import sys
try:
import usys as sys
except ImportError:
import sys

print(sys.__name__)
print(type(sys.path))
Expand Down
5 changes: 4 additions & 1 deletion tests/basics/sys_exit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# test sys module's exit function

import sys
try:
import usys as sys
except ImportError:
import sys

try:
sys.exit
Expand Down
5 changes: 4 additions & 1 deletion tests/basics/sys_getsizeof.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# test sys.getsizeof() function

import sys
try:
import usys as sys
except ImportError:
import sys
try:
sys.getsizeof
except AttributeError:
Expand Down
4 changes: 2 additions & 2 deletions tests/extmod/uctypes_array_assign_native_le.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import sys
import usys

try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit

if sys.byteorder != "little":
if usys.byteorder != "little":
print("SKIP")
raise SystemExit

Expand Down
4 changes: 2 additions & 2 deletions tests/extmod/uctypes_array_assign_native_le_intbig.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import sys
import usys

try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit

if sys.byteorder != "little":
if usys.byteorder != "little":
print("SKIP")
raise SystemExit

Expand Down
4 changes: 2 additions & 2 deletions tests/extmod/uctypes_native_le.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# This test is exactly like uctypes_le.py, but uses native structure layout.
# Codepaths for packed vs native structures are different. This test only works
# on little-endian machine (no matter if 32 or 64 bit).
import sys
import usys

try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit

if sys.byteorder != "little":
if usys.byteorder != "little":
print("SKIP")
raise SystemExit

Expand Down
4 changes: 2 additions & 2 deletions tests/extmod/uctypes_ptr_le.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import sys
import usys

try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit

if sys.byteorder != "little":
if usys.byteorder != "little":
print("SKIP")
raise SystemExit

Expand Down
4 changes: 2 additions & 2 deletions tests/extmod/uctypes_ptr_native_le.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import sys
import usys

try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit

if sys.byteorder != "little":
if usys.byteorder != "little":
print("SKIP")
raise SystemExit

Expand Down
6 changes: 3 additions & 3 deletions tests/extmod/vfs_fat_more.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ def ioctl(self, op, arg):
print(uos.listdir("sys"))

# test importing a file from a mounted FS
import sys
import usys

sys.path.clear()
sys.path.append("/sys")
usys.path.clear()
usys.path.append("/sys")
with open("sys/test_module.py", "w") as f:
f.write('print("test_module!")')
import test_module
10 changes: 5 additions & 5 deletions tests/extmod/vfs_lfs_mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ def test(bdev, vfs_class):
uos.umount("/lfs")

# clear imported modules
sys.modules.clear()
usys.modules.clear()


bdev = RAMBlockDevice(30)

# initialise path
import sys
import usys

sys.path.clear()
sys.path.append("/lfs")
sys.path.append("")
usys.path.clear()
usys.path.append("/lfs")
usys.path.append("")

# run tests
test(bdev, uos.VfsLfs1)
Expand Down
6 changes: 3 additions & 3 deletions tests/extmod/vfs_userfs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# test VFS functionality with a user-defined filesystem
# also tests parts of uio.IOBase implementation

import sys
import usys

try:
import uio
Expand Down Expand Up @@ -76,9 +76,9 @@ def open(self, path, mode):
print(f.read())

# import files from the user filesystem
sys.path.append("/userfs")
usys.path.append("/userfs")
import usermod1

# unmount and undo path addition
uos.umount("/userfs")
sys.path.pop()
usys.path.pop()
5 changes: 4 additions & 1 deletion tests/feature_check/byteorder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import sys
try:
import usys as sys
except ImportError:
import sys

print(sys.byteorder)
Loading

0 comments on commit 40ad8f1

Please sign in to comment.