AmirHmZz / mpbridge

CLI tool to synchronise and manage files on MicroPython running devices
https://pypi.org/project/mpbridge
MIT License
51 stars 5 forks source link

Wish to keep using the REPL while the port is occupied. #8

Closed Wind-stormger closed 1 year ago

Wind-stormger commented 1 year ago

I've been using mpbridge lately and, on purpose, I've stopped using other 3rd party tools.

I hope this uncovers some of the more pressing needs of using mpbridge.

I found that I needed to close mpbridge anyway, and then use other tools to connect to the port, because only one program can occupy the port at a time.

Of course, I directly use mpremote to connect to the port and view the REPL.

I would like to make an initial suggestion.

When there is no operation on the file, enable REPL on the terminal, allowing users to use REPL to interact with micropython devices. When any changes occur in the local temporary folder, interrupt REPL, start synchronizing files, and continue to enable REPL after completion.

Wind-stormger commented 1 year ago

Of course, it is not only the changes in the local temporary folder that are worth paying attention to. When the program is running, there may also be files in the micropython device that have been changed.

For this matter, I personally think that the files in the micropython device should take precedence.

When the REPL stops, we need to synchronize immediately, pull the files in the micropython device to the local first, and then push the changes in the local temporary folder to the device.

If there is a conflict, report an error and ask the user to resolve the conflict.

Perhaps, this seems like git.

Wind-stormger commented 1 year ago

Let's discuss this first, maybe I'm just being greedy.

AmirHmZz commented 1 year ago

Let's discuss this first, maybe I'm just being greedy

Believe me or not, I've had this dream too when I started developing mpbridge. This means it makes two of us ;) But before reading my comment, Tell me how you are going to use this feature? In my own idea I needed an active development cycle which seems like: Develope >> Updating codes on board >> Run and see the results >> Develope >> ... But I really need to know what is in your mind.

Anyway, this dream needs hash checking before putting and getting files in order to speed up synchronization progress. Of course we can check file sizes before cheking hashes.

I think we also need another ability to prevent specific files or directories beeing synced. We can implement something like .gitignore. This indeed is needed to prevent syncing some directories created by IDEs like .idea which is created by JetBrains IDEs.

I have some other notes about other parts but I need you to clearify how this feature is going to be used by you.

Wind-stormger commented 1 year ago

this dream needs hash checking before putting and getting files in order to speed up synchronization progress.

After some testing, I determined that the following code can be run without any modification in micropython device and in Cpython for hash checking.

import hashlib
import binascii
file_name = "boot.py"

with open(file_name, 'rb') as fp:
    data = fp.read()
    print(data)
    file_hash = hashlib.sha256(data)
    file_hexlify = binascii.hexlify(file_hash.digest())
    print(file_hexlify)

Board: GENERIC_S3_SPIRAM Firmware: v1.19.1-782-g699477d12 (2022-12-20)

AmirHmZz commented 1 year ago

@Wind-stormger Thanks for your snippet. The hash checking part is not the hard part. I think it's important to discuss about this question first of all :

Tell me how you are going to use this feature? In my own idea I needed an active development cycle which seems like: Develope >> Updating codes on board >> Run and see the results >> Develope >> ... But I really need to know what is in your mind.

Are you going to use this feature as same as I mentioned? How this feature can exactly help you?

AmirHmZz commented 1 year ago

@Wind-stormger Would you please update mpbridge to the latest version (0.1.3) and check if sync command satisfy your needs or not? It also checks file hashes before putting files.

AmirHmZz commented 1 year ago

With development mode which is implemented in https://github.com/AmirHmZz/mpbridge/commit/791a5dff1e8a9f25350d999b60ecb2833eaad6c0 it is possible now to use repl in the same terminal window. This feature will be available in v1.0.0. Thanks :)

Wind-stormger commented 1 year ago

The sync command is very simple and effective.

Now I have begun to rely on these two commands:

mpbridge sync COM21 D:\temp\ 
mpremote connect COM21 repl

Hash checking really saves a lot of time! We can sync very quickly and get feedback in REPL. 💯

AmirHmZz commented 1 year ago

Now update mpbridge to version 1.0 and try the development mode which starts the REPL in the same shell window.