Wykres commitów

107 Commity (master)

Autor SHA1 Wiadomość Data
Matt Trentini a2e4efa09a collections: Remove micropython-lib Python implementation of deque.
It's no longer necessary since the built-in C version of this type now
implements all the functionality here.

Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
2024-05-15 14:12:14 +10:00
Damien George 45ead11f96 ssl: Use "from tls import *" to be compatible with axtls.
axtls doesn't define all the CERT_xxx constants, nor the MBEDTLS_VERSION
constant.

This change means that `tls.SSLContext` is imported into the module, but
that's subsequently overridden by the class definition in this module.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-28 17:44:37 +11:00
Jim Mussared 5c7e3fc0bc json: Move to unix-ffi.
It requires the unix pcre-based re module.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2024-03-19 17:23:07 +11:00
Damien George ffb07dbce5 gzip: Fix recursion error in open() function.
And give the `mode` parameter a default, matching CPython.

Signed-off-by: Damien George <damien@micropython.org>
2024-02-29 14:54:24 +11:00
ubi de feo 8058b2935b tarfile-write: Fix permissions when adding to archive.
Signed-off-by: ubi de feo <me@ubidefeo.com>
2024-02-09 10:43:05 +11:00
Adam Knowles ddb1a27957 hmac: Fix passing in a string for digestmod argument.
The built-in `hashlib` module does not have a `.new` method (although the
Python version in this repository does).
2024-02-07 12:45:03 +11:00
Felix Dörre 35d41dbb0e ssl: Restructure micropython SSL interface to a new tls module.
MicroPython now supplies SSL/TLS functionality in a new built-in `tls`
module.  The `ssl` module is now implemented purely in Python, in this
repository.  Other libraries are updated to work with this scheme.

Signed-off-by: Felix Dörre <felix@dogcraft.de>
2024-02-07 12:12:13 +11:00
scivision ae8ea8d113 os-path: Implement os.path.isfile().
Signed-off-by: Michael Hirsch <michael@scivision.dev>
2023-12-20 14:46:57 +11:00
Yu Ting 41aa257a31 base64: Implement custom maketrans and translate methods.
Re-implemented bytes.maketrans() and bytes.translate() as there are no such
functions in MicroPython.
2023-12-20 12:26:13 +11:00
Matt Trentini 340243e205 time: Add README to explain the purpose of the time extension library.
Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
2023-12-20 12:05:35 +11:00
Matthias Urlichs 55d1d23d6f __future__: Add "annotations".
MicroPython ignores types anyway.
2023-10-04 12:53:52 +11:00
Jim Mussared 36e74c1b57 zlib: Add zlib module.
This is a replacement for the `zlib` module that used to be built-in and
has been replaced by the MicroPython-specific `deflate` module.

Also updates the `gzip` module in a similar fashion and provide the
`gzip.GzipFile` class and `gzip.open` function.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-25 18:19:51 +10:00
Jim Mussared 8fc9edabf3 all: Standardise x.y.z versioning for all packages.
- For packages that were just x.y, update to x.y.0.
- For that were x.y.z-n, update to x.y.(z+1)

From now on we'll apply semver rules:
- MAJOR version when you make incompatible API changes
- MINOR version when you add functionality in a backward compatible manner
- PATCH version when you make backward compatible bug fixes

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-23 11:48:57 +10:00
Jim Mussared ebbb78e8e4 logging: Bump minor version.
For changes in 5329ef5301.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-23 11:48:46 +10:00
Jim Mussared a19d2a3596 copy: Bump patch version.
For changes in 0e68c7d518.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-23 11:48:29 +10:00
Jim Mussared 5004436164 tarfile: Rename from utarfile.
This is compatible with the CPython module, so should
be named tarfile.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-23 11:41:44 +10:00
Andrew Leech e45a7f6c18 fnmatch: Fix compatibility with ure -> re.
With the recent MicroPython change to remove the u prefix by default on
builtins (micropython/micropython#11740) the format checker in fnmatch
which was detecting ure no longer works.

This commit updates the module to filter the regex automatically as needed.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2023-07-21 17:19:43 +10:00
Jim Mussared 6103823b1b all: Remove __version__ from .py files.
It is inserted automatically during publish/freezing and having them in the
code prevents the automatic process from happening.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21 17:15:00 +10:00
Andrew Leech 0e68c7d518 copy: Declare dependency on types. 2023-07-21 17:07:06 +10:00
Andrew Leech 5329ef5301 logging: Add full support for logging exception tracebacks.
This commit allows you to pass an exception object in as the exc_info kwarg
(CPython allows this), so logging exceptions can work even if the
MICROPY_PY_SYS_EXC_INFO option is disabled in the firmware.

Separately to that, currently even when sys.exc_info() is enabled, it's
only printing the traceback to _stream = sys.stderr - not to the configured
logging handlers.  This means for instance if you've got a file log
handler it misses out on the tracebacks.  That's also fixed in this commit.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2023-07-21 17:01:42 +10:00
Andrew Leech 028a369f90 keyword: Add manifest file. 2023-07-21 16:58:48 +10:00
Andrew Leech b95deb31e5 json: Add manifest file. 2023-07-21 16:58:48 +10:00
Andrew Leech 0f768c9af7 bisect: Add manifest file. 2023-07-21 16:58:48 +10:00
Andrew Leech c2b44ea83b types: Add manifest file. 2023-07-21 16:58:48 +10:00
Jim Mussared fe3e0a2fae cmd: Remove comments about using the string module.
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>
2023-07-21 15:28:14 +10:00
Jim Mussared da5ddfc6e2 hashlib: Refactor, split, and optimise.
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>
2023-07-20 23:28:08 +10:00
Andrew Leech f672353180 unittest-discover: Print results when no tests are found/run.
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.
2023-03-27 12:06:04 +11:00
Gavin Douch 23018a86bf unittest: Add subtest usage examples.
This work was funded by Planet Innovation.
2023-02-21 23:56:06 +11:00
Jim Mussared a08087249f top: Update Python formatting to black "2023 stable style".
See https://black.readthedocs.io/en/stable/the_black_code_style/index.html

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-02-03 17:12:38 +11:00
Andrzej Kowalczyk 863a018b89 unittest: Remove dependence on sys.exc_info.
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>
2023-01-31 12:38:00 +11:00
Damien George 423f5fa2c2 logging: Bump version to 0.5.
Signed-off-by: Damien George <damien@micropython.org>
2022-12-21 14:55:56 +11:00
Jim Mussared 8a7eb40009 logging: Simplify check for strftime.
Only needs to be checked at the call site.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-12-21 12:08:43 +11:00
Jim Mussared 58bab0add3 logging: Fall back to root logger level for unset child.
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>
2022-12-21 09:52:26 +11:00
Jim Mussared a9e52d085c top: Update top-level docs.
* 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>
2022-12-16 17:16:03 +11:00
Damien George 8d653e96db time: Add unit test for time.strftime.
Signed-off-by: Damien George <damien@micropython.org>
2022-12-14 11:57:55 +11:00
iabdalkader 8456a2aa68 time: Add time module to provide strftime. 2022-12-14 11:57:12 +11:00
iabdalkader d717b04cb3 logging: Improve the logging module.
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()`.
2022-12-06 17:40:10 +11:00
Brian Pugh 0051a5ef50 pathlib: Add initial pathlib implementation.
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.
2022-11-17 14:26:33 +11:00
Damien George 56dc65b6a7 tempfile: Add manifest.py file at version 0.0.1.
Signed-off-by: Damien George <damien@micropython.org>
2022-11-11 13:05:04 +11:00
Brian Pugh a99b80186d tempfile: Add unit tests for tempfile, and don't use os.path.join. 2022-11-11 13:04:16 +11:00
Brian Pugh 8ce4adf8bf shutil: Add unit tests for shutil. 2022-11-11 13:04:16 +11:00
Brian Pugh 69e8a502dd shutil: Don't allow an empty string in rmtree. 2022-11-11 13:04:14 +11:00
Brian Pugh 4ae896afdc shutil: Fix shutil.rmtree to use os.ilistdir instead of os.walk. 2022-11-11 13:01:23 +11:00
Brian Pugh ee286ed28c tempfile: Add initial tempfile implementation.
With TemporaryDirectory class and mkdtemp function.
2022-11-11 13:00:51 +11:00
Jim Mussared 038b4ac657 unittest: Convert to a package.
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>
2022-11-09 14:56:34 +11:00
Patrick Joy a14226f7c5 shutil: Add disk_usage function.
Signed-off-by: Patrick Joy <patrick@joytech.com.au>
2022-11-09 14:44:40 +11:00
Jim Mussared c26d77b52e venv: Add a command-line package for creating virtual environments.
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>
2022-11-09 12:52:03 +11:00
Oliver Joos 9bc0b15f11 unittest: Make AssertRaisesContext store exception for later retrieval.
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.
2022-10-04 12:28:43 +11:00
Andrew Leech 459e13921a os.path: Remove external / ffi dependencies in os.path.
This work was funded by Planet Innovation.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2022-09-30 17:51:06 +10:00
Jim Mussared 122b68968c uu: Fix dependency on os-path.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-28 00:58:35 +10:00