Even though we now have a `string` module, just keep the existing
IDENTCHARS definition.
- If someone doesn't already have string installed (or aren't otherwise
importing it), this would add an extra dependency and more memory used.
- If they do, then the resulting concatenated string has to be allocated
separately, so there's no gain from using the string.x components.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This splits out each algorithm into its own extension package, so that only
the necessary algorithms can be installed.
This allows for a significant reduction in RAM and flash. i.e. previously
installing hashlib meant that all algorithms were imported.
Additionally ensures that any built-in hash algorithms (from uhashlib) are
still exposed (e.g. `md5`), and retains the existing behavior to use the
built-in preferentially.
Also includes a refactoring of the algorithms to reduce code size and
reduce the number of allocations they do as well as using bytearrays in
place of list-of-int where possible.
Add more comprehensive tests (using unittest).
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Prior to this commit, if no tests were found when running unittest discover
then nothing at all was written to stdout, leading one to think it's not
working at all. CPython unittest does display a "0 tests run" sort of
output in such a case, and this commit ensures this package does the same.
This is not included by default in most builds, and isn't necessary for
this module anyway.
Also fix the local variable shadowing the traceback module in _capture_exc.
Added test for both (works on CPython and MicroPython).
Version bump to 0.10.2.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Previously a child logger just uses the global default when unset.
Modified to matches the CPython behavior of using the parent's level.
Also implemented CPython's getEffectiveLevel() which provides a convenient
way to implement this. In our version, we only ever have one parent
(the root), so it only has to recurse one level.
Also set the default level to WARNING to match CPython.
Updated the examples to highlight the differences (but they now match).
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* Add instructions for how to use micropython-lib.
* Add a terminology guide and use consistent terminology
(package/module/library).
* Improve code conventions and contributor guidelines.
* Misc readme updates.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Add support for all format specifiers, support for `datefmt` using
(optional) strftime, and support for Stream and File handlers.
Ports/boards that need to use `FileHandlers` should enable
`MICROPY_PY_SYS_ATEXIT`, and enabled `MICROPY_PY_SYS_EXC_INFO` if using
`logging.exception()`.
This adds most of the common functionality of pathlib.Path.
The glob functionality could use some work; currently it only supports a
single "*" wildcard; however, this is the vast majority of common use-cases
and it won't fail silently if non-supported glob patterns are provided.
This allows a much more natural way of implementing unitttest-discover:
- unittest provides unittest/__init__.py
- unittest-discover provides unittest/__main__.py
It also fixes an bug where unittest.py previously detected the presence of
unittest-discover.py by importing an checking for the ImportError. But that
could also be raised by a missing dependency. Now when you run
`micropython -m unittest` without unittest-discover, you get
`ImportError: no module named 'unittest.__main__'`, and without the
required deps, `ImportError: no module named 'argparse'`.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Works like "python -m venv path" and creates a rudimentary virtual
environment for the Unix port:
- sets MICROPYPATH
- copies the micropython binary to venv/bin/micropython which is in $PATH
- installs mip & mip-cmdline in the venv
Using the venv is the same as for CPython -- source the activate script to
enter, and call the deactivate function to leave.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
The statement "with assertRaises(errtype) as ctxt" checks the type of a
raised exception, but did not store the exception into ctxt like unittest
of CPython. The exception instance is usually used to check its message or
other args.
In order to make this more suitable for non-unix ports, the discovery
functionality is moved to a separate 'extension' module which can be
optionally installed.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Although this primarily makes sense for the unix port, there's nothing
preventing it being used on any port, and it's written for MicroPython.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
With the dependencies captured in manifest.py, several packages in
python-stdlib were still unix-only due to direct or transitive dependencies
on unix-only or ffi modules. Or they just make no sense to run on
microcontroller targets.
In a few cases (e.g. base64) where possible, the unix dependency could be
removed.
Updates manifest.py to use the `unix_ffi=True` arg to `require()` for these
libraries.
Rename re-pcre to re now that unix-ffi is effectively its own namespace.
Update unix-ffi/README.md, and strengthen the wording that the unix
libraries are unmaintained.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Uses the new require()/package()/module() functions from manifestfile.py.
Add manifest.py for iperf3 and pyjwt.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This library was non-functional unless used with the micropython-lib
pure-Python implementation of hashlib, even if the device provides
sha1 and sha256.
This updates hmac to be significantly more RAM efficient (removes the
512-byte table), and functional with the built-in hash functions.
The only unsupported function is "copy", but this is non-critical, and now
fails with a NotSupportedError.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>