8000 all: Rename "sys" module to "usys". · larsks/micropython@40ad8f1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 40ad8f1

Browse files
stinosdpgeorge
authored andcommitted
all: Rename "sys" module to "usys".
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".
1 parent b0932fc commit 40ad8f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+142
-89
lines changed

docs/library/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ it will fallback to loading the built-in ``ujson`` module.
7777
cmath.rst
7878
gc.rst
7979
math.rst
80-
sys.rst
8180
uarray.rst
8281
uasyncio.rst
8382
ubinascii.rst
@@ -93,6 +92,7 @@ it will fallback to loading the built-in ``ujson`` module.
9392
usocket.rst
9493
ussl.rst
9594
ustruct.rst
95+
usys.rst
9696
utime.rst
9797
uzlib.rst
9898
_thread.rst

docs/library/sys.rst renamed to docs/library/usys.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
:mod:`sys` -- system specific functions
2-
=======================================
1+
:mod:`usys` -- system specific functions
2+
========================================
33

4-
.. module:: sys
4+
.. module:: usys
55
:synopsis: system specific functions
66

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

31-
.. function:: print_exception(exc, file=sys.stdout, /)
31+
.. function:: print_exception(exc, file=usys.stdout, /)
3232

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

3636
.. admonition:: Difference to CPython
3737
:class: attention
@@ -84,7 +84,7 @@ Constants
8484
value directly, but instead count number of bits in it::
8585

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

118118
.. data:: stderr
119119

drivers/nrf24l01/nrf24l01test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Test for nrf24l01 module. Portable between MicroPython targets."""
22

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

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

2626
# Addresses are in little-endian format. They correspond to big-endian
2727
# 0xf0f0f0f0e1, 0xf0f0f0f0d2

extmod/webrepl/websocket_helper.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import sys
1+
try:
2+
import usys as sys
3+
except ImportError:
4+
import sys
25

36
try:
47
import ubinascii as binascii

py/objmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = {
159159
#endif
160160
#endif
161161
#if MICROPY_PY_SYS
162-
{ MP_ROM_QSTR(MP_QSTR_sys), MP_ROM_PTR(&mp_module_sys) },
162+
{ MP_ROM_QSTR(MP_QSTR_usys), MP_ROM_PTR(&mp_module_sys) },
163163
#endif
164164
#if MICROPY_PY_GC && MICROPY_ENABLE_GC
165165
{ MP_ROM_QSTR(MP_QSTR_gc), MP_ROM_PTR(&mp_module_gc) },

tests/basics/async_await2.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# test await expression
22

3-
import sys
3+
try:
4+
import usys as sys
5+
except ImportError:
6+
import sys
47
if sys.implementation.name == 'micropython':
58
# uPy allows normal generators to be awaitables
69
coroutine = lambda f: f

tests/basics/async_for2.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# test waiting within "async for" __anext__ function
22

3-
import sys
3+
try:
4+
import usys as sys
5+
except ImportError:
6+
import sys
47
if sys.implementation.name == 'micropython':
58
# uPy allows normal generators to be awaitables
69
coroutine = lambda f: f

tests/basics/async_with2.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# test waiting within async with enter/exit functions
22

3-
import sys
3+
try:
4+
import usys as sys
5+
except ImportError:
6+
import sys
47
if sys.implementation.name == 'micropython':
58
# uPy allows normal generators to be awaitables
69
coroutine = lambda f: f

tests/basics/attrtuple1.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# test attrtuple
22
# we can't test this type directly so we use sys.implementation object
33

4-
import sys
4+
try:
5+
import usys as sys
6+
except ImportError:
7+
import sys
58
t = sys.implementation
69

710
# It can be just a normal tuple on small ports

tests/basics/builtin_callable.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
print(callable("dfsd"))
88

99
# modules should not be callabe
10-
import sys
10+
try:
11+
import usys as sys
12+
except ImportError:
13+
import sys
1114
print(callable(sys))
1215

1316
# builtins should be callable

tests/basics/builtin_dir.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
print('__name__' 10000 in dir())
55

66
# dir of module
7-
import sys
7+
try:
8+
import usys as sys
9+
except ImportError:
10+
import sys
811
print('version' in dir(sys))
912

1013
# dir of type

tests/basics/int_big1.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@
102102
x = -4611686018427387904 # big
103103

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

108111
# test extraction of big int value via mp_obj_get_int_maybe

tests/basics/module2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# uPy behaviour only: builtin modules are read-only
2-
import sys
2+
import usys
33
try:
4-
sys.x = 1
4+
usys.x = 1
55
except AttributeError:
66
print("AttributeError")

tests/basics/python34.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def test_syntax(code):
3333

3434
# from basics/sys1.py
3535
# uPy prints version 3.4
36-
import sys
37-
print(sys.version[:3])
38-
print(sys.version_info[0], sys.version_info[1])
36+
import usys
37+
print(usys.version[:3])
38+
print(usys.version_info[0], usys.version_info[1])
3939

4040
# from basics/exception1.py
4141
# in 3.7 no comma is printed if there is only 1 arg (in 3.4-3.6 one is printed)

tests/basics/string_compare.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@
5151

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

5760
# this special string would have a hash of 0 but is incremented to 1

tests/basics/sys1.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# test sys module
22

3-
import sys
3+
try:
4+
import usys as sys
5+
except ImportError:
6+
import sys
47

58
print(sys.__name__)
69
print(type(sys.path))

tests/basics/sys_exit.py

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# test sys module's exit function
22

3-
import sys
3+
try:
4+
import usys as sys
5+
except ImportError:
6+
import sys
47

58
try:
69
sys.exit

tests/basics/sys_getsizeof.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# test sys.getsizeof() function
22

3-
import sys
3+
try:
4+
import usys as sys
5+
except ImportError:
6+
import sys
47
try:
58
sys.getsizeof
69
except AttributeError:

tests/extmod/uctypes_array_assign_native_le.py

Lines changed: 2 additions & 2 deletions
17AE
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import sys
1+
import usys
22

33
try:
44
import uctypes
55
except ImportError:
66
print("SKIP")
77
raise SystemExit
88

9-
if sys.byteorder != "little":
9+
if usys.byteorder != "little":
1010
print("SKIP")
1111
raise SystemExit
1212

tests/extmod/uctypes_array_assign_native_le_intbig.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import sys
1+
import usys
22

33
try:
44
import uctypes
55
except ImportError:
66
print("SKIP")
77
raise SystemExit
88

9-
if sys.byteorder != "little":
9+
if usys.byteorder != "little":
1010
print("SKIP")
1111
raise SystemExit
1212

tests/extmod/uctypes_native_le.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# This test is exactly like uctypes_le.py, but uses native structure layout.
22
# Codepaths for packed vs native structures are different. This test only works
33
# on little-endian machine (no matter if 32 or 64 bit).
4-
import sys
4+
import usys
55

66
try:
77
import uctypes
88
except ImportError:
99
print("SKIP")
1010
raise SystemExit
1111

12-
if sys.byteorder != "little":
12+
if usys.byteorder != "little":
1313
print("SKIP")
1414
raise SystemExit
1515

tests/extmod/uctypes_ptr_le.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import sys
1+
import usys
22

33
try:
44
import uctypes
55
except ImportError:
66
print("SKIP")
77
raise SystemExit
88

9-
if sys.byteorder != "little":
9+
if usys.byteorder != "little":
1010
print("SKIP")
1111
raise SystemExit
1212

tests/extmod/uctypes_ptr_native_le.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import sys
1+
import usys
22

33
try:
44
import uctypes
55
except ImportError:
66
print("SKIP")
77
raise SystemExit
88

9-
if sys.byteorder != "little":
9+
if usys.byteorder != "little":
1010
print("SKIP")
1111
raise SystemExit
1212

tests/extmod/vfs_fat_more.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ def ioctl(self, op, arg):
111111
print(uos.listdir("sys"))
112112

113113
# test importing a file from a mounted FS
114-
import sys
114+
import usys
115115

116-
sys.path.clear()
117-
sys.path.append("/sys")
116+
usys.path.clear()
117+
usys.path.append("/sys")
118118
with open("sys/test_module.py", "w") as f:
119119
f.write('print("test_module!")')
120120
import test_module

tests/extmod/vfs_lfs_mount.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ def test(bdev, vfs_class):
6868
uos.umount("/lfs")
6969

7070
# clear imported modules
71-
sys.modules.clear()
71+
usys.modules.clear()
7272

7373

7474
bdev = RAMBlockDevice(30)
7575

7676
# initialise path
77-
import sys
77+
import usys
7878

79-
sys.path.clear()
80-
sys.path.append("/lfs")
81-
sys.path.append("")
79+
usys.path.clear()
80+
usys.path.append("/lfs")
81+
usys.path.append("")
8282

8383
# run tests
8484
test(bdev, uos.VfsLfs1)

tests/extmod/vfs_userfs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# test VFS functionality with a user-defined filesystem
22
# also tests parts of uio.IOBase implementation
33

4-
import sys
4+
import usys
55

66
try:
77
import uio
@@ -76,9 +76,9 @@ def open(self, path, mode):
7676
print(f.read())
7777

7878
# import files from the user filesystem
79-
sys.path.append("/userfs")
79+
usys.path.append("/userfs")
8080
import usermod1
8181

8282
# unmount and undo path addition
8383
uos.umount("/userfs")
84-
sys.path.pop()
84+
usys.path.pop()

tests/feature_check/byteorder.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
import sys
1+
try:
2+
import usys as sys
3+
except ImportError:
4+
import sys
25

36
print(sys.byteorder)

0 commit comments

Comments
 (0)
0