python-ecosys/uminio: Add uminio package.#1040
Conversation
uminio is a MicroPython client for MinIO object storage. This commit add the uminio filder and all its content in the python-ecosys folder. Original implementation for AWS S3: https://github.com/DanielMilstein/uboto3/ Signed-off-by: Luigi Palumbo <paluigi@gmail.com>
|
I tried to figure our why the lint/formatting fails...but I'm lost. |
|
If you look here: https://github.com/micropython/micropython-lib/actions/runs/16717239939/job/47313198532?pr=1040 it shows you the problems. Basically you need to put a few things on one line, instead of over many lines. |
This commit remove redundant lines and correct formatting for code in python-ecosys/uminio/uminio/__init__.py. Signed-off-by: Luigi Palumbo <paluigi@gmail.com>
|
Thanks, code formatted! |
agatti
left a comment
There was a problem hiding this comment.
Thanks for the PR.
I've had a quick look at the code and there are a couple of places where I believe this could be improved. It could also help if you'd squash the two commits into just one, since the second one is just minor changes to the source formatting.
| import urequests | ||
| import uhashlib | ||
| import ubinascii | ||
| import utime |
There was a problem hiding this comment.
Most, if not all, of these imports can now be accessed without the u prefix.
| k_signing_bytes = self._hmac_sha256(k_service_bytes, b"aws4_request") | ||
| return k_signing_bytes | ||
|
|
||
| def sync_time(self) -> None: |
There was a problem hiding this comment.
If knowing the current time as retrieved by the NTP server is important, this function could be changed to return the time.gmtime() tuple instead.
| Synchronizes the device's real-time clock with an NTP server. | ||
| This is crucial for generating a valid signature. | ||
| """ | ||
| print("Synchronizing time with NTP server...") |
There was a problem hiding this comment.
Maybe these print() statements could be taken out. Same applies to upload_file too.
| now_utc[5], | ||
| ) | ||
| ) | ||
| except Exception as e: |
There was a problem hiding this comment.
I'd let the exception propagate rather than ignoring it here.
If the lack of exception propagation is critical then this bit could be either a simple pass statement or, if the function was modified to return the new timestamp, make it return None instead.
| :param content_type: The MIME type of the file. | ||
| :return: True if upload was successful (HTTP 200), False otherwise. | ||
| """ | ||
| try: |
There was a problem hiding this comment.
These exceptions could also be let to propagate (file I/O and network). As far as I can see there's no recovery mechanism besides a print statement and returning a value, that can be handled by catching the exception upstream.
It also saves quite some space when compiled into bytecode :)
| signed_headers_list.append(key) | ||
| signed_headers_str = ";".join(signed_headers_list) | ||
|
|
||
| canonical_request = ( |
There was a problem hiding this comment.
If these are all guaranteed to be strings, "\n".join(method, canonical_uri, canonical_querystring, canonical_headers_str, signed_headers_str, payload_hash_hex) is actually shorter by ~19 bytes when compiled into bytecode.
Even with "\n".join(map(str, (method, ...))) to pre-convert variables to strings, it is still shorter by 7 bytes.
| hashed_canonical_request_bytes | ||
| ).decode() | ||
|
|
||
| string_to_sign = ( |
There was a problem hiding this comment.
This one could be converted into "\n".join(...) too.
|
|
||
| ## Usage Example | ||
|
|
||
| Here's how to use `uminio` to upload a local file from your MicroPython device to MinIO: |
There was a problem hiding this comment.
Maybe you can just point to the example file in the same directory rather than reproducing it verbatim here.
| * MicroPython firmware flashed on your device. | ||
| * Network connectivity (WiFi) configured on the device. | ||
| * The following MicroPython libraries: | ||
| * `urequests` |
There was a problem hiding this comment.
The u prefix for most modules has been deprecated,
But more importantly, they should be part of a manifest.py, rather than just documented.
|
|
||
| ## Setup | ||
|
|
||
| 1. **Copy `__init__.py`:** Create a `uminio` folder in the `/lib` directory of your MicroPython device and copy the `__init__.py` file into it. |
There was a problem hiding this comment.
Installation for a package should be using mop, not copy
| @@ -0,0 +1,3 @@ | |||
| metadata(version="0.0.1", description="MIcroPython client for MinIO object storage.") | |||
|
|
|||
| package("uminio") | |||
There was a problem hiding this comment.
What about the preqeq packages mentioned in the readme file?
The should be included in the manifest, so they are installed automatically
uminio is a MicroPython client for MinIO object storage.
This commit add the uminio folder and all its content in the python-ecosys folder.
Original implementation for AWS S3:
https://github.com/DanielMilstein/uboto3/