Skip to content

Commit 8e9a12d

Browse files
committed
Merge branch 'asi2700-master' into asi-master
2 parents 8c73bf3 + 60b4417 commit 8e9a12d

File tree

360 files changed

+9488
-1094
lines changed

Some content is hidden

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

360 files changed

+9488
-1094
lines changed

README.md

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,69 @@
1-
~~~~
2-
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3-
micropython-lib is a highly experimental community project.
4-
5-
Please help to drive it to just "experimental" state by testing
6-
provided packages with MicroPython.
7-
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
8-
~~~~
9-
101
micropython-lib
112
===============
123
micropython-lib is a project to develop a non-monolothic standard library
13-
for MicroPython. Each module or package is available as a separate
14-
distribution package from PyPI. Each module is either written from scratch or
15-
ported from CPython.
4+
for "advanced" MicroPython fork (https://github.com/pfalcon/micropython).
5+
Each module or package is available as a separate distribution package from
6+
PyPI. Each module comes from one of the following sources (and thus each
7+
module has its own licensing terms):
168

17-
Note that the main target of micropython-lib is a "Unix" port of MicroPython
18-
(additional ports to support are to be determined). Actual system requirements
19-
vary per module. Though if a module is not related to I/O, the module should
20-
work without problem on bare-metal ports too (e.g. pyboard).
9+
* written from scratch specifically for MicroPython
10+
* ported from CPython
11+
* ported from some other Python implementation, e.g. PyPy
12+
* some modules actually aren't implemented yet and are dummy
13+
14+
Note that the main target of micropython-lib is a "Unix" port of the
15+
aforementioned fork of MicroPython. Actual system requirements vary per
16+
module. Majority of modules are compatible with the upstream MicroPython,
17+
though some may require additional functionality/optimizations present in
18+
the "advanced" fork. Modules not related to I/O may also work without
19+
problems on bare-metal ports, not just on "Unix" port (e.g. pyboard).
2120

2221

2322
Usage
2423
-----
2524
micropython-lib packages are published on PyPI (Python Package Index),
2625
the standard Python community package repository: http://pypi.python.org/ .
27-
On PyPi, you can search for MicroPython related packages and read
28-
additional package information.
26+
On PyPI, you can search for MicroPython related packages and read
27+
additional package information. By convention, all micropython-lib package
28+
names are prefixed with "micropython-" (the reverse is not true - some
29+
package starting with "micropython-" aren't part of micropython-lib and
30+
were released by 3rd parties).
2931

30-
To install packages from PyPI for usage on your local system, use the
31-
`pip-micropython` tool, which is a simple wrapper around the standard
32-
`pip` tool, which is used to install packages for CPython.
33-
The `pip-micropython` tool can be found in `tools` subdirectory
34-
of the main MicroPython repository (https://github.com/micropython/micropython).
35-
Just install the `pip-micropython` script somewhere on your `PATH`.
32+
Browse available packages
33+
[via this URL](https://pypi.python.org/pypi?%3Aaction=search&term=micropython).
3634

37-
Afterwards, just use `pip-micropython` in a way similar to `pip`:
35+
To install packages from PyPI for usage on your local system, use the
36+
`upip` tool, which is MicroPython's native package manager, similar to
37+
`pip`, which is used to install packages for CPython. `upip` is bundled
38+
with MicroPython "Unix" port (i.e. if you build "Unix" port, you
39+
automatically have `upip` tool). Following examples assume that
40+
`micropython` binary is available on your `PATH`:
3841

3942
~~~~
40-
$ pip-micropython install micropython-copy
43+
$ micropython -m upip install micropython-pystone
44+
...
4145
$ micropython
42-
>>> import copy
43-
>>> copy.copy([1, 2, 3])
44-
[1, 2, 3]
46+
>>> import pystone
47+
>>> pystone.main()
48+
Pystone(1.2) time for 50000 passes = 0.534
49+
This machine benchmarks at 93633 pystones/second
4550
~~~~
4651

47-
Review the `pip-micropython` source code for more info.
52+
Run `micropython -m upip --help` for more information about `upip`.
4853

4954

5055
Development
5156
-----------
5257
To install modules during development, use `make install`. By default, all
53-
available packages will be installed. To install a specific module, add the
58+
available packages will be installed. To install a specific module, add the
5459
`MOD=<module>` parameter to the end of the `make install` command.
5560

5661

5762
Links
5863
-----
59-
More information is on GitHub and in the MicroPython forums:
64+
If you would like to trace evolution of MicroPython packaging support,
65+
you may find following links useful (note that they may contain outdated
66+
information):
6067

6168
* https://github.com/micropython/micropython/issues/405
6269
* http://forum.micropython.org/viewtopic.php?f=5&t=70

__future__/setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
sys.path.pop(0)
55
from setuptools import setup
66
sys.path.append("..")
7-
import optimize_upip
7+
import sdist_upip
88

99
setup(name='micropython-future',
1010
version='0.0.3',
1111
description='Dummy __future__ module for MicroPython',
1212
long_description='This is a dummy implementation of a module for MicroPython standard library.\nIt contains zero or very little functionality, and primarily intended to\navoid import errors (using idea that even if an application imports a\nmodule, it may be not using it onevery code path, so may work at least\npartially). It is expected that more complete implementation of the module\nwill be provided later. Please help with the development if you are\ninterested in this module.',
1313
url='https://github.com/micropython/micropython-lib',
14-
author='MicroPython Developers',
14+
author='micropython-lib Developers',
1515
author_email='[email protected]',
16-
maintainer='MicroPython Developers',
16+
maintainer='micropython-lib Developers',
1717
maintainer_email='[email protected]',
1818
license='MIT',
19-
cmdclass={'optimize_upip': optimize_upip.OptimizeUpip},
19+
cmdclass={'sdist': sdist_upip.sdist},
2020
py_modules=['__future__'])

_libc/setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
sys.path.pop(0)
55
from setuptools import setup
66
sys.path.append("..")
7-
import optimize_upip
7+
import sdist_upip
88

99
setup(name='micropython-libc',
1010
version='0.3.1',
@@ -13,8 +13,8 @@
1313
url='https://github.com/micropython/micropython-lib',
1414
author='Paul Sokolovsky',
1515
author_email='[email protected]',
16-
maintainer='MicroPython Developers',
16+
maintainer='micropython-lib Developers',
1717
maintainer_email='[email protected]',
1818
license='MIT',
19-
cmdclass={'optimize_upip': optimize_upip.OptimizeUpip},
19+
cmdclass={'sdist': sdist_upip.sdist},
2020
py_modules=['_libc'])

_markupbase/setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
sys.path.pop(0)
55
from setuptools import setup
66
sys.path.append("..")
7-
import optimize_upip
7+
import sdist_upip
88

99
setup(name='micropython-_markupbase',
1010
version='3.3.3-1',
@@ -13,9 +13,9 @@
1313
url='https://github.com/micropython/micropython-lib',
1414
author='CPython Developers',
1515
author_email='[email protected]',
16-
maintainer='MicroPython Developers',
16+
maintainer='micropython-lib Developers',
1717
maintainer_email='[email protected]',
1818
license='Python',
19-
cmdclass={'optimize_upip': optimize_upip.OptimizeUpip},
19+
cmdclass={'sdist': sdist_upip.sdist},
2020
py_modules=['_markupbase'],
2121
install_requires=['micropython-re-pcre'])

abc/setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
sys.path.pop(0)
55
from setuptools import setup
66
sys.path.append("..")
7-
import optimize_upip
7+
import sdist_upip
88

99
setup(name='micropython-abc',
1010
version='0.0.1',
1111
description='Dummy abc module for MicroPython',
1212
long_description='This is a dummy implementation of a module for MicroPython standard library.\nIt contains zero or very little functionality, and primarily intended to\navoid import errors (using idea that even if an application imports a\nmodule, it may be not using it onevery code path, so may work at least\npartially). It is expected that more complete implementation of the module\nwill be provided later. Please help with the development if you are\ninterested in this module.',
1313
url='https://github.com/micropython/micropython-lib',
14-
author='MicroPython Developers',
14+
author='micropython-lib Developers',
1515
author_email='[email protected]',
16-
maintainer='MicroPython Developers',
16+
maintainer='micropython-lib Developers',
1717
maintainer_email='[email protected]',
1818
license='MIT',
19-
cmdclass={'optimize_upip': optimize_upip.OptimizeUpip},
19+
cmdclass={'sdist': sdist_upip.sdist},
2020
py_modules=['abc'])

argparse/argparse.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,25 +144,37 @@ def render_arg(arg):
144144
print(" %-16s%s" % (', '.join(opt.names) + render_arg(opt), opt.help))
145145

146146
def parse_args(self, args=None):
147+
return self._parse_args_impl(args, False)
148+
149+
def parse_known_args(self, args=None):
150+
return self._parse_args_impl(args, True)
151+
152+
def _parse_args_impl(self, args, return_unknown):
147153
if args is None:
148154
args = sys.argv[1:]
149155
else:
150156
args = args[:]
151157
try:
152-
return self._parse_args(args)
158+
return self._parse_args(args, return_unknown)
153159
except _ArgError as e:
154160
self.usage(False)
155161
print("error:", e)
156162
sys.exit(2)
157163

158-
def _parse_args(self, args):
164+
def _parse_args(self, args, return_unknown):
159165
# add optional args with defaults
160166
arg_dest = []
161167
arg_vals = []
162168
for opt in self.opt:
163169
arg_dest.append(opt.dest)
164170
arg_vals.append(opt.default)
165171

172+
# deal with unknown arguments, if needed
173+
unknown = []
174+
def consume_unknown():
175+
while args and not args[0].startswith("-"):
176+
unknown.append(args.pop(0))
177+
166178
# parse all args
167179
parsed_pos = False
168180
while args or not parsed_pos:
@@ -179,15 +191,26 @@ def _parse_args(self, args):
179191
found = True
180192
break
181193
if not found:
182-
raise _ArgError("unknown option %s" % a)
194+
if return_unknown:
195+
unknown.append(a)
196+
consume_unknown()
197+
else:
198+
raise _ArgError("unknown option %s" % a)
183199
else:
184200
# positional arg
185201
if parsed_pos:
186-
raise _ArgError("extra args: %s" % " ".join(args))
202+
if return_unknown:
203+
unknown = unknown + args
204+
break
205+
else:
206+
raise _ArgError("extra args: %s" % " ".join(args))
187207
for pos in self.pos:
188208
arg_dest.append(pos.dest)
189209
arg_vals.append(pos.parse(pos.names[0], args))
190210
parsed_pos = True
211+
if return_unknown:
212+
consume_unknown()
191213

192214
# build and return named tuple with arg values
193-
return namedtuple("args", arg_dest)(*arg_vals)
215+
values = namedtuple("args", arg_dest)(*arg_vals)
216+
return (values, unknown) if return_unknown else values

argparse/metadata.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
srctype = micropython-lib
22
type = module
3-
version = 0.3.3
3+
version = 0.4
44
author = Damien George

argparse/setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
sys.path.pop(0)
55
from setuptools import setup
66
sys.path.append("..")
7-
import optimize_upip
7+
import sdist_upip
88

99
setup(name='micropython-argparse',
10-
version='0.3.3',
10+
version='0.4',
1111
description='argparse module for MicroPython',
1212
long_description="This is a module reimplemented specifically for MicroPython standard library,\nwith efficient and lean design in mind. Note that this module is likely work\nin progress and likely supports just a subset of CPython's corresponding\nmodule. Please help with the development if you are interested in this\nmodule.",
1313
url='https://github.com/micropython/micropython-lib',
1414
author='Damien George',
1515
author_email='[email protected]',
16-
maintainer='MicroPython Developers',
16+
maintainer='micropython-lib Developers',
1717
maintainer_email='[email protected]',
1818
license='MIT',
19-
cmdclass={'optimize_upip': optimize_upip.OptimizeUpip},
19+
cmdclass={'sdist': sdist_upip.sdist},
2020
py_modules=['argparse'])

argparse/test_argparse.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,25 @@
4444
assert args.files1 == ["a", "b"] and args.files2 == []
4545
args = parser.parse_args(["a", "b", "c"])
4646
assert args.files1 == ["a", "b"] and args.files2 == ["c"]
47+
48+
parser = argparse.ArgumentParser()
49+
parser.add_argument("a", nargs=2)
50+
parser.add_argument("-b")
51+
args, rest = parser.parse_known_args(["a", "b", "-b", "2"])
52+
assert args.a == ["a", "b"] and args.b == "2"
53+
assert rest == []
54+
args, rest = parser.parse_known_args(["-b", "2", "a", "b", "c"])
55+
assert args.a == ["a", "b"] and args.b == "2"
56+
assert rest == ["c"]
57+
args, rest = parser.parse_known_args(["a", "b", "-b", "2", "c"])
58+
assert args.a == ["a", "b"] and args.b == "2"
59+
assert rest == ["c"]
60+
args, rest = parser.parse_known_args(["-b", "2", "a", "b", "-", "c"])
61+
assert args.a == ["a", "b"] and args.b == "2"
62+
assert rest == ["-", "c"]
63+
args, rest = parser.parse_known_args(["a", "b", "-b", "2", "-", "x", "y"])
64+
assert args.a == ["a", "b"] and args.b == "2"
65+
assert rest == ["-", "x", "y"]
66+
args, rest = parser.parse_known_args(["a", "b", "c", "-b", "2", "--x", "5", "1"])
67+
assert args.a == ["a", "b"] and args.b == "2"
68+
assert rest == ["c", "--x", "5", "1"]

array/metadata.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
srctype = dummy
2+
type = module
3+
version = 0.0.0

array/setup.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
# Remove current dir from sys.path, otherwise setuptools will peek up our
3+
# module instead of system's.
4+
sys.path.pop(0)
5+
from setuptools import setup
6+
sys.path.append("..")
7+
import sdist_upip
8+
9+
setup(name='micropython-array',
10+
version='0.0.0',
11+
description='Dummy array module for MicroPython',
12+
long_description='This is a dummy implementation of a module for MicroPython standard library.\nIt contains zero or very little functionality, and primarily intended to\navoid import errors (using idea that even if an application imports a\nmodule, it may be not using it onevery code path, so may work at least\npartially). It is expected that more complete implementation of the module\nwill be provided later. Please help with the development if you are\ninterested in this module.',
13+
url='https://github.com/micropython/micropython-lib',
14+
author='micropython-lib Developers',
15+
author_email='[email protected]',
16+
maintainer='micropython-lib Developers',
17+
maintainer_email='[email protected]',
18+
license='MIT',
19+
cmdclass={'sdist': sdist_upip.sdist},
20+
py_modules=['array'])

asyncio/setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
sys.path.pop(0)
55
from setuptools import setup
66
sys.path.append("..")
7-
import optimize_upip
7+
import sdist_upip
88

99
setup(name='micropython-asyncio',
1010
version='0.0.0',
1111
description='Dummy asyncio module for MicroPython',
1212
long_description='This is a dummy implementation of a module for MicroPython standard library.\nIt contains zero or very little functionality, and primarily intended to\navoid import errors (using idea that even if an application imports a\nmodule, it may be not using it onevery code path, so may work at least\npartially). It is expected that more complete implementation of the module\nwill be provided later. Please help with the development if you are\ninterested in this module.',
1313
url='https://github.com/micropython/micropython-lib',
14-
author='MicroPython Developers',
14+
author='micropython-lib Developers',
1515
author_email='[email protected]',
16-
maintainer='MicroPython Developers',
16+
maintainer='micropython-lib Developers',
1717
maintainer_email='[email protected]',
1818
license='MIT',
19-
cmdclass={'optimize_upip': optimize_upip.OptimizeUpip},
19+
cmdclass={'sdist': sdist_upip.sdist},
2020
py_modules=['asyncio'])

asyncio_slow/asyncio_slow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _cb():
4747
self.call_soon(_cb)
4848

4949
def run_until_complete(self, coro):
50-
t = async(coro)
50+
t = ensure_future(coro)
5151
t.add_done_callback(lambda a: self.stop())
5252
self.run_forever()
5353

@@ -109,7 +109,7 @@ def coroutine(f):
109109
return f
110110

111111

112-
def async(coro):
112+
def ensure_future(coro):
113113
if isinstance(coro, Future):
114114
return coro
115115
return Task(coro)
@@ -136,7 +136,7 @@ def wait(coro_list, loop=_def_event_loop):
136136
w = _Wait(len(coro_list))
137137

138138
for c in coro_list:
139-
t = async(c)
139+
t = ensure_future(c)
140140
t.add_done_callback(lambda val: w._done())
141141

142142
return w
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

base64/metadata.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
srctype=cpython
22
type=module
3-
version = 3.3.3-3
4-
depends = struct
3+
version = 3.3.3-4
4+
depends = binascii, re-pcre, struct

0 commit comments

Comments
 (0)